From 76f0abecfd143f8ad876d804ffe1626eb69f39a0 Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 10 Sep 2019 00:48:34 +0300 Subject: [PATCH] Show sticker set on Ctrl+Click in stickers list. --- .../SourceFiles/boxes/sticker_set_box.cpp | 7 +-- Telegram/SourceFiles/boxes/sticker_set_box.h | 2 +- .../chat_helpers/stickers_list_widget.cpp | 45 ++++++++++++------- .../chat_helpers/stickers_list_widget.h | 5 ++- Telegram/SourceFiles/mainwidget.cpp | 2 + 5 files changed, 41 insertions(+), 20 deletions(-) diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 3517771d3..98faa1e5d 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -135,16 +135,17 @@ StickerSetBox::StickerSetBox( , _set(set) { } -void StickerSetBox::Show( +QPointer StickerSetBox::Show( not_null controller, not_null document) { if (const auto sticker = document->sticker()) { if (sticker->set.type() != mtpc_inputStickerSetEmpty) { - Ui::show( + return Ui::show( Box(controller, sticker->set), - LayerOption::KeepOther); + LayerOption::KeepOther).data(); } } + return nullptr; } void StickerSetBox::prepare() { diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 97e4fe83b..4c5cc61fe 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -28,7 +28,7 @@ public: not_null controller, const MTPInputStickerSet &set); - static void Show( + static QPointer Show( not_null controller, not_null document); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index e4368c76d..a33cbf155 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -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(&pressed)) { Assert(set->section >= 0 && set->section < sets.size()); displaySet(sets[set->section].id); @@ -2529,7 +2540,7 @@ void StickersListWidget::fillIcons(QList &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(_megagroupSet)); - connect(box, &QObject::destroyed, this, [this] { - _displayingSetId = 0; - _checkForHide.fire({}); - }); + _displayingSet = true; + checkHideWithBox(Ui::show( + Box(_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(controller(), Stickers::inputSetId(*it)), - LayerOption::KeepOther); - connect(box, &QObject::destroyed, this, [this] { - _displayingSetId = 0; - _checkForHide.fire({}); - }); + LayerOption::KeepOther).data()); } } +void StickersListWidget::checkHideWithBox(QPointer 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); diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index 6da5c3ba8..bfe030dbd 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -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 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; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 83373f906..3ee3ff980 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -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();