From 33342c6b106b501932427c041876825acb3c4850 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 ac4555120..f25e0e4a5 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" @@ -51,6 +52,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" @@ -537,6 +539,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 (!_session->premium() && _session->premiumPossible() @@ -567,6 +572,7 @@ void StickerSetBox::updateButtons() { addButton(tr::lng_cancel(), [=] { closeBox(); }); } + /* if (!_inner->shortName().isEmpty()) { const auto top = addTopButton(st::infoTopBarMenu); const auto menu @@ -587,6 +593,7 @@ void StickerSetBox::updateButtons() { return true; }); } + */ } else if (_inner->official()) { addButton(tr::lng_about_done(), [=] { closeBox(); }); } else { @@ -598,6 +605,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 = [=] { @@ -636,6 +644,7 @@ void StickerSetBox::updateButtons() { return true; }); } + */ } } else { addButton(tr::lng_cancel(), [=] { closeBox(); }); @@ -643,6 +652,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 c57a1f484..97b57b486 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 { @@ -84,6 +85,7 @@ private: void updateTitleAndButtons(); void updateButtons(); + bool showMenu(not_null button); void addStickers(); void copyStickersLink(); void handleError(Error error); @@ -92,6 +94,7 @@ private: const not_null _session; const StickerSetIdentifier _set; const Data::StickersType _type; + base::unique_qptr _menu; class Inner; QPointer _inner;