From a7ce31bdf9111d8bff5dd374ea9c2725332f1c7e Mon Sep 17 00:00:00 2001 From: RadRussianRus Date: Sat, 10 Sep 2022 20:37:38 +0300 Subject: [PATCH] [Improvement] Use dropdown menu instead of popup menu in sticker set --- .../SourceFiles/boxes/sticker_set_box.cpp | 67 +++++++++++++++++++ Telegram/SourceFiles/boxes/sticker_set_box.h | 3 + 2 files changed, 70 insertions(+) diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.cpp b/Telegram/SourceFiles/boxes/sticker_set_box.cpp index 592ba282c..90d375d42 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.cpp +++ b/Telegram/SourceFiles/boxes/sticker_set_box.cpp @@ -25,6 +25,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/buttons.h" #include "ui/widgets/scroll_area.h" #include "ui/widgets/gradient_round_button.h" +#include "ui/widgets/dropdown_menu.h" #include "ui/image/image.h" #include "ui/image/image_location_factory.h" #include "ui/text/text_utilities.h" @@ -49,6 +50,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_common.h" #include "mainwidget.h" #include "mainwindow.h" +#include "styles/style_info.h" #include "styles/style_layers.h" #include "styles/style_chat_helpers.h" #include "styles/style_info.h" @@ -511,6 +513,9 @@ void StickerSetBox::updateButtons() { ? tr::lng_stickers_copied_emoji(tr::now) : tr::lng_stickers_copied(tr::now))); }; + const auto moreButton = addTopButton(st::infoTopBarMenu); + moreButton->setClickedCallback([=] { showMenu(moreButton.data()); }); + if (_inner->notInstalled()) { if (!_controller->session().premium() && _controller->session().premiumPossible() @@ -537,6 +542,7 @@ void StickerSetBox::updateButtons() { addButton(tr::lng_cancel(), [=] { closeBox(); }); } + /* if (!_inner->shortName().isEmpty()) { const auto top = addTopButton(st::infoTopBarMenu); const auto menu = @@ -557,6 +563,7 @@ void StickerSetBox::updateButtons() { return true; }); } + */ } else if (_inner->official()) { addButton(tr::lng_about_done(), [=] { closeBox(); }); } else { @@ -568,6 +575,7 @@ void StickerSetBox::updateButtons() { addButton(std::move(shareText), std::move(share)); addButton(tr::lng_cancel(), [=] { closeBox(); }); + /* if (!_inner->shortName().isEmpty()) { const auto top = addTopButton(st::infoTopBarMenu); const auto archive = [=] { @@ -607,6 +615,7 @@ void StickerSetBox::updateButtons() { return true; }); } + */ } } else { addButton(tr::lng_cancel(), [=] { closeBox(); }); @@ -614,6 +623,64 @@ void StickerSetBox::updateButtons() { update(); } +bool StickerSetBox::showMenu(not_null button) { + if (_menu) { + _menu->hideAnimated(Ui::InnerDropdown::HideOption::IgnoreShow); + return true; + } + + _menu = base::make_unique_q( + window(), + st::dropdownMenuWithIcons); + const auto weak = _menu.get(); + _menu->setHiddenCallback([=] { + weak->deleteLater(); + if (_menu == weak) { + button->setForceRippled(false); + } + }); + _menu->setShowStartCallback([=] { + if (_menu == weak) { + button->setForceRippled(true); + } + }); + _menu->setHideStartCallback([=] { + if (_menu == weak) { + button->setForceRippled(false); + } + }); + button->installEventFilter(_menu); + + if (!_inner->shortName().isEmpty()) { + _menu->addAction( + tr::lng_stickers_share_pack(tr::now), + [=] { copyStickersLink(); }, + &st::menuIconShare); + } + + if (!_inner->notInstalled()) { + const auto archive = [=] { + _inner->archiveStickers(); + closeBox(); + }; + _menu->addAction( + tr::lng_stickers_archive_pack(tr::now), + archive, + &st::menuIconArchive); + } + + const auto parentTopLeft = window()->mapToGlobal(QPoint()); + const auto buttonTopLeft = button->mapToGlobal(QPoint()); + const auto parentRect = QRect(parentTopLeft, window()->size()); + const auto buttonRect = QRect(buttonTopLeft, button->size()); + _menu->move( + buttonRect.x() + buttonRect.width() - _menu->width() - parentRect.x(), + buttonRect.y() + buttonRect.height() - parentRect.y() - style::ConvertScale(18)); + _menu->showAnimated(Ui::PanelAnimation::Origin::TopRight); + + return true; +} + void StickerSetBox::resizeEvent(QResizeEvent *e) { BoxContent::resizeEvent(e); _inner->resize(width(), _inner->height()); diff --git a/Telegram/SourceFiles/boxes/sticker_set_box.h b/Telegram/SourceFiles/boxes/sticker_set_box.h index 73d99dc7d..035b602a6 100644 --- a/Telegram/SourceFiles/boxes/sticker_set_box.h +++ b/Telegram/SourceFiles/boxes/sticker_set_box.h @@ -17,6 +17,7 @@ class SessionController; namespace Ui { class PlainShadow; +class DropdownMenu; } // namespace Ui namespace Data { @@ -75,6 +76,7 @@ private: void updateTitleAndButtons(); void updateButtons(); + bool showMenu(not_null button); void addStickers(); void copyStickersLink(); void handleError(Error error); @@ -82,6 +84,7 @@ private: const not_null _controller; const StickerSetIdentifier _set; const Data::StickersType _type; + base::unique_qptr _menu; class Inner; QPointer _inner;