Show sticker set on Ctrl+Click in stickers list.

This commit is contained in:
John Preston 2019-09-10 00:48:34 +03:00
parent ca45fb617e
commit 76f0abecfd
5 changed files with 41 additions and 20 deletions

View File

@ -135,16 +135,17 @@ StickerSetBox::StickerSetBox(
, _set(set) {
}
void StickerSetBox::Show(
QPointer<BoxContent> StickerSetBox::Show(
not_null<Window::SessionController*> controller,
not_null<DocumentData*> document) {
if (const auto sticker = document->sticker()) {
if (sticker->set.type() != mtpc_inputStickerSetEmpty) {
Ui::show(
return Ui::show(
Box<StickerSetBox>(controller, sticker->set),
LayerOption::KeepOther);
LayerOption::KeepOther).data();
}
}
return nullptr;
}
void StickerSetBox::prepare() {

View File

@ -28,7 +28,7 @@ public:
not_null<Window::SessionController*> controller,
const MTPInputStickerSet &set);
static void Show(
static QPointer<BoxContent> Show(
not_null<Window::SessionController*> controller,
not_null<DocumentData*> document);

View File

@ -1894,7 +1894,18 @@ void StickersListWidget::mouseReleaseEvent(QMouseEvent *e) {
}
return;
}
_chosen.fire_copy(set.stickers[sticker->index].document);
const auto document = set.stickers[sticker->index].document;
if (e->modifiers() & Qt::ControlModifier) {
if (document->sticker()
&& document->sticker()->set.type() != mtpc_inputStickerSetEmpty) {
_displayingSet = true;
checkHideWithBox(StickerSetBox::Show(
controller(),
document));
}
} else {
_chosen.fire_copy(document);
}
} else if (auto set = base::get_if<OverSet>(&pressed)) {
Assert(set->section >= 0 && set->section < sets.size());
displaySet(sets[set->section].id);
@ -2529,7 +2540,7 @@ void StickersListWidget::fillIcons(QList<StickerIcon> &icons) {
}
bool StickersListWidget::preventAutoHide() {
return _removingSetId != 0 || _displayingSetId != 0;
return _removingSetId != 0 || _displayingSet != 0;
}
void StickersListWidget::updateSelected() {
@ -2760,12 +2771,10 @@ void StickersListWidget::beforeHiding() {
void StickersListWidget::displaySet(uint64 setId) {
if (setId == Stickers::MegagroupSetId) {
if (_megagroupSet->canEditStickers()) {
_displayingSetId = setId;
auto box = Ui::show(Box<StickersBox>(_megagroupSet));
connect(box, &QObject::destroyed, this, [this] {
_displayingSetId = 0;
_checkForHide.fire({});
});
_displayingSet = true;
checkHideWithBox(Ui::show(
Box<StickersBox>(_megagroupSet),
LayerOption::KeepOther).data());
return;
} else if (_megagroupSet->mgInfo->stickerSet.type() == mtpc_inputStickerSetID) {
setId = _megagroupSet->mgInfo->stickerSet.c_inputStickerSetID().vid().v;
@ -2776,17 +2785,23 @@ void StickersListWidget::displaySet(uint64 setId) {
auto &sets = session().data().stickerSets();
auto it = sets.constFind(setId);
if (it != sets.cend()) {
_displayingSetId = setId;
auto box = Ui::show(
_displayingSet = true;
checkHideWithBox(Ui::show(
Box<StickerSetBox>(controller(), Stickers::inputSetId(*it)),
LayerOption::KeepOther);
connect(box, &QObject::destroyed, this, [this] {
_displayingSetId = 0;
_checkForHide.fire({});
});
LayerOption::KeepOther).data());
}
}
void StickersListWidget::checkHideWithBox(QPointer<BoxContent> box) {
if (!box) {
return;
}
connect(box, &QObject::destroyed, this, [=] {
_displayingSet = false;
_checkForHide.fire({});
});
}
void StickersListWidget::installSet(uint64 setId) {
auto &sets = session().data().stickerSets();
auto it = sets.constFind(setId);

View File

@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/variant.h"
#include "base/timer.h"
class BoxContent;
namespace Main {
class Session;
} // namespace Main
@ -201,6 +203,7 @@ private:
void setSection(Section section);
void displaySet(uint64 setId);
void checkHideWithBox(QPointer<BoxContent> box);
void installSet(uint64 setId);
void removeMegagroupSet(bool locally);
void removeSet(uint64 setId);
@ -310,7 +313,7 @@ private:
Section _section = Section::Stickers;
uint64 _displayingSetId = 0;
bool _displayingSet = false;
uint64 _removingSetId = 0;
Footer *_footer = nullptr;

View File

@ -3219,6 +3219,8 @@ void MainWidget::start() {
if (const auto availableAt = Local::ReadExportSettings().availableAt) {
session().data().suggestStartExport(availableAt);
}
session().data().notifyStickersUpdated();
session().data().notifySavedGifsUpdated();
_history->start();