[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
parent 15278d895d
commit cb8d390402
2 changed files with 70 additions and 0 deletions

View file

@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/ui/dialogs_layout.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/scroll_area.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"
@ -41,6 +42,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"
@ -303,6 +305,9 @@ void StickerSetBox::updateButtons() {
clearButtons();
if (_inner->loaded()) {
const auto isMasks = _inner->isMasksSet();
const auto moreButton = addTopButton(st::infoTopBarMenu);
moreButton->setClickedCallback([=] { showMenu(moreButton.data()); });
if (_inner->notInstalled()) {
auto addText = isMasks
? tr::lng_stickers_add_masks()
@ -310,6 +315,7 @@ void StickerSetBox::updateButtons() {
addButton(std::move(addText), [=] { addStickers(); });
addButton(tr::lng_cancel(), [=] { closeBox(); });
/*
if (!_inner->shortName().isEmpty()) {
const auto top = addTopButton(st::infoTopBarMenu);
const auto share = [=] {
@ -333,6 +339,7 @@ void StickerSetBox::updateButtons() {
return true;
});
}
*/
} else if (_inner->official()) {
addButton(tr::lng_about_done(), [=] { closeBox(); });
} else {
@ -346,6 +353,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 = [=] {
@ -367,6 +375,7 @@ void StickerSetBox::updateButtons() {
return true;
});
}
*/
}
} else {
addButton(tr::lng_cancel(), [=] { closeBox(); });
@ -374,6 +383,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

@ -18,6 +18,7 @@ class SessionController;
namespace Ui {
class ConfirmBox;
class PlainShadow;
class DropdownMenu;
} // namespace Ui
class StickerSetBox final : public Ui::BoxContent {
@ -43,12 +44,14 @@ private:
void updateTitleAndButtons();
void updateButtons();
bool showMenu(not_null<Ui::IconButton*> button);
void addStickers();
void copyStickersLink();
void handleError(Error error);
const not_null<Window::SessionController*> _controller;
const StickerSetIdentifier _set;
base::unique_qptr<Ui::DropdownMenu> _menu;
class Inner;
QPointer<Inner> _inner;