[Improvement] Use dropdown menu instead of popup menu in sticker set

This commit is contained in:
Eric Kotato 2022-09-10 20:37:38 +03:00 committed by Eric Kotato
parent c31c3e0108
commit e15ec01c0d
2 changed files with 70 additions and 0 deletions

View file

@ -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<Ui::IconButton*> button) {
if (_menu) {
_menu->hideAnimated(Ui::InnerDropdown::HideOption::IgnoreShow);
return true;
}
_menu = base::make_unique_q<Ui::DropdownMenu>(
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());

View file

@ -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<Ui::IconButton*> button);
void addStickers();
void copyStickersLink();
void handleError(Error error);
@ -92,6 +94,7 @@ private:
const not_null<Main::Session*> _session;
const StickerSetIdentifier _set;
const Data::StickersType _type;
base::unique_qptr<Ui::DropdownMenu> _menu;
class Inner;
QPointer<Inner> _inner;