[Improvement] Use dropdown menu instead of popup menu in sticker set
This commit is contained in:
parent
15278d895d
commit
cb8d390402
2 changed files with 70 additions and 0 deletions
|
|
@ -21,6 +21,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include "dialogs/ui/dialogs_layout.h"
|
#include "dialogs/ui/dialogs_layout.h"
|
||||||
#include "ui/widgets/buttons.h"
|
#include "ui/widgets/buttons.h"
|
||||||
#include "ui/widgets/scroll_area.h"
|
#include "ui/widgets/scroll_area.h"
|
||||||
|
#include "ui/widgets/dropdown_menu.h"
|
||||||
#include "ui/image/image.h"
|
#include "ui/image/image.h"
|
||||||
#include "ui/image/image_location_factory.h"
|
#include "ui/image/image_location_factory.h"
|
||||||
#include "ui/text/text_utilities.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 "api/api_common.h"
|
||||||
#include "mainwidget.h"
|
#include "mainwidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "styles/style_info.h"
|
||||||
#include "styles/style_layers.h"
|
#include "styles/style_layers.h"
|
||||||
#include "styles/style_chat_helpers.h"
|
#include "styles/style_chat_helpers.h"
|
||||||
#include "styles/style_info.h"
|
#include "styles/style_info.h"
|
||||||
|
|
@ -303,6 +305,9 @@ void StickerSetBox::updateButtons() {
|
||||||
clearButtons();
|
clearButtons();
|
||||||
if (_inner->loaded()) {
|
if (_inner->loaded()) {
|
||||||
const auto isMasks = _inner->isMasksSet();
|
const auto isMasks = _inner->isMasksSet();
|
||||||
|
const auto moreButton = addTopButton(st::infoTopBarMenu);
|
||||||
|
moreButton->setClickedCallback([=] { showMenu(moreButton.data()); });
|
||||||
|
|
||||||
if (_inner->notInstalled()) {
|
if (_inner->notInstalled()) {
|
||||||
auto addText = isMasks
|
auto addText = isMasks
|
||||||
? tr::lng_stickers_add_masks()
|
? tr::lng_stickers_add_masks()
|
||||||
|
|
@ -310,6 +315,7 @@ void StickerSetBox::updateButtons() {
|
||||||
addButton(std::move(addText), [=] { addStickers(); });
|
addButton(std::move(addText), [=] { addStickers(); });
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
|
||||||
|
/*
|
||||||
if (!_inner->shortName().isEmpty()) {
|
if (!_inner->shortName().isEmpty()) {
|
||||||
const auto top = addTopButton(st::infoTopBarMenu);
|
const auto top = addTopButton(st::infoTopBarMenu);
|
||||||
const auto share = [=] {
|
const auto share = [=] {
|
||||||
|
|
@ -333,6 +339,7 @@ void StickerSetBox::updateButtons() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
} else if (_inner->official()) {
|
} else if (_inner->official()) {
|
||||||
addButton(tr::lng_about_done(), [=] { closeBox(); });
|
addButton(tr::lng_about_done(), [=] { closeBox(); });
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -346,6 +353,7 @@ void StickerSetBox::updateButtons() {
|
||||||
addButton(std::move(shareText), std::move(share));
|
addButton(std::move(shareText), std::move(share));
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
|
||||||
|
/*
|
||||||
if (!_inner->shortName().isEmpty()) {
|
if (!_inner->shortName().isEmpty()) {
|
||||||
const auto top = addTopButton(st::infoTopBarMenu);
|
const auto top = addTopButton(st::infoTopBarMenu);
|
||||||
const auto archive = [=] {
|
const auto archive = [=] {
|
||||||
|
|
@ -367,6 +375,7 @@ void StickerSetBox::updateButtons() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
addButton(tr::lng_cancel(), [=] { closeBox(); });
|
||||||
|
|
@ -374,6 +383,64 @@ void StickerSetBox::updateButtons() {
|
||||||
update();
|
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) {
|
void StickerSetBox::resizeEvent(QResizeEvent *e) {
|
||||||
BoxContent::resizeEvent(e);
|
BoxContent::resizeEvent(e);
|
||||||
_inner->resize(width(), _inner->height());
|
_inner->resize(width(), _inner->height());
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ class SessionController;
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConfirmBox;
|
class ConfirmBox;
|
||||||
class PlainShadow;
|
class PlainShadow;
|
||||||
|
class DropdownMenu;
|
||||||
} // namespace Ui
|
} // namespace Ui
|
||||||
|
|
||||||
class StickerSetBox final : public Ui::BoxContent {
|
class StickerSetBox final : public Ui::BoxContent {
|
||||||
|
|
@ -43,12 +44,14 @@ private:
|
||||||
|
|
||||||
void updateTitleAndButtons();
|
void updateTitleAndButtons();
|
||||||
void updateButtons();
|
void updateButtons();
|
||||||
|
bool showMenu(not_null<Ui::IconButton*> button);
|
||||||
void addStickers();
|
void addStickers();
|
||||||
void copyStickersLink();
|
void copyStickersLink();
|
||||||
void handleError(Error error);
|
void handleError(Error error);
|
||||||
|
|
||||||
const not_null<Window::SessionController*> _controller;
|
const not_null<Window::SessionController*> _controller;
|
||||||
const StickerSetIdentifier _set;
|
const StickerSetIdentifier _set;
|
||||||
|
base::unique_qptr<Ui::DropdownMenu> _menu;
|
||||||
|
|
||||||
class Inner;
|
class Inner;
|
||||||
QPointer<Inner> _inner;
|
QPointer<Inner> _inner;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue