Moved mask management to separate box.

This commit is contained in:
23rd 2021-03-30 17:54:11 +03:00
parent 2a3115f461
commit 2d17bd02a3
3 changed files with 66 additions and 27 deletions

View File

@ -368,7 +368,8 @@ void StickersBox::Tab::saveScrollTop() {
StickersBox::StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
Section section)
Section section,
bool masks)
: _controller(controller)
, _api(&controller->session().mtp())
, _tabs(this, st::stickersTabs)
@ -376,10 +377,11 @@ StickersBox::StickersBox(
this,
controller->session().data().stickers().featuredSetsUnreadCountValue())
, _section(section)
, _installed(0, this, controller, Section::Installed)
, _masks(1, this, controller, Section::Masks)
, _featured(2, this, controller, Section::Featured)
, _archived(3, this, controller, Section::Archived) {
, _isMasks(masks)
, _installed(_isMasks ? Tab() : Tab(0, this, controller, Section::Installed))
, _masks(_isMasks ? Tab(0, this, controller, Section::Masks) : Tab())
, _featured(_isMasks ? Tab() : Tab(1, this, controller, Section::Featured))
, _archived((_isMasks ? 1 : 2), this, controller, Section::Archived) {
_tabs->setRippleTopRoundRadius(st::boxRadius);
}
@ -390,6 +392,7 @@ StickersBox::StickersBox(
: _controller(controller)
, _api(&controller->session().mtp())
, _section(Section::Installed)
, _isMasks(false)
, _installed(0, this, controller, megagroup)
, _megagroupSet(megagroup) {
_installed.widget()->scrollsToY(
@ -405,6 +408,7 @@ StickersBox::StickersBox(
: _controller(controller)
, _api(&controller->session().mtp())
, _section(Section::Attached)
, _isMasks(false)
, _attached(0, this, controller, Section::Attached)
, _attachedSets(attachedSets) {
}
@ -621,21 +625,27 @@ void StickersBox::prepare() {
}
void StickersBox::refreshTabs() {
if (!_tabs) return;
if (!_tabs) {
return;
}
auto &stickers = session().data().stickers();
_tabIndices.clear();
auto sections = std::vector<QString>();
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Installed);
if (!session().data().stickers().maskSetsOrder().isEmpty()) {
if (_installed.widget()) {
sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Installed);
}
if (!stickers.maskSetsOrder().isEmpty() && _masks.widget()) {
sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Masks);
}
if (!session().data().stickers().featuredSetsOrder().isEmpty()) {
if (!stickers.featuredSetsOrder().isEmpty() && _featured.widget()) {
sections.push_back(tr::lng_stickers_featured_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Featured);
}
if (!session().data().stickers().archivedSetsOrder().isEmpty()) {
if (!stickers.archivedSetsOrder().isEmpty() && _archived.widget()) {
sections.push_back(tr::lng_stickers_archived_tab(tr::now).toUpper());
_tabIndices.push_back(Section::Archived);
}
@ -701,7 +711,7 @@ void StickersBox::paintEvent(QPaintEvent *e) {
void StickersBox::updateTabsGeometry() {
if (!_tabs) return;
const auto maxTabs = 4;
const auto maxTabs = _isMasks ? 2 : 3;
_tabs->resizeToWidth(_tabIndices.size() * width() / maxTabs);
_unreadBadge->setVisible(_tabIndices.contains(Section::Featured));
@ -935,23 +945,30 @@ void StickersBox::rebuildList(Tab *tab) {
}
void StickersBox::saveChanges() {
const auto installed = _installed.widget();
const auto masks = _masks.widget();
// Make sure that our changes in other tabs are applied in the Installed tab.
rebuildList(&_installed);
rebuildList(&_masks);
if (installed) {
rebuildList(&_installed);
}
if (masks) {
rebuildList(&_masks);
}
if (_someArchivedLoaded) {
session().local().writeArchivedStickers();
}
if (const auto widget = _installed.widget()) {
if (installed) {
session().api().saveStickerSets(
widget->getOrder(),
widget->getRemovedSets(),
installed->getOrder(),
installed->getRemovedSets(),
false);
}
if (const auto widget = _masks.widget()) {
if (masks) {
session().api().saveStickerSets(
widget->getOrder(),
widget->getRemovedSets(),
masks->getOrder(),
masks->getRemovedSets(),
true);
}
}

View File

@ -62,7 +62,8 @@ public:
StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
Section section);
Section section,
bool masks = false);
StickersBox(
QWidget*,
not_null<Window::SessionController*> controller,
@ -145,6 +146,7 @@ private:
object_ptr<CounterWidget> _unreadBadge = { nullptr };
Section _section;
const bool _isMasks;
Tab _installed;
Tab _masks;

View File

@ -128,6 +128,8 @@ public:
void clearHeavyData();
rpl::producer<> openSettingsRequests() const;
protected:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
@ -197,6 +199,8 @@ private:
object_ptr<Ui::CrossButton> _searchCancel = { nullptr };
QPointer<QWidget> _focusTakenFrom;
rpl::event_stream<> _openSettingsRequests;
};
auto StickersListWidget::PrepareStickers(
@ -527,6 +531,10 @@ void StickersListWidget::Footer::resizeSearchControls() {
_searchCancel->moveToRight(st::gifsSearchCancelPosition.x(), st::gifsSearchCancelPosition.y());
}
rpl::producer<> StickersListWidget::Footer::openSettingsRequests() const {
return _openSettingsRequests.events();
}
void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
if (e->button() != Qt::LeftButton) {
return;
@ -535,11 +543,7 @@ void StickersListWidget::Footer::mousePressEvent(QMouseEvent *e) {
updateSelected();
if (_iconOver == SpecialOver::Settings) {
_pan->controller()->show(Box<StickersBox>(
_pan->controller(),
(hasOnlyFeaturedSets()
? StickersBox::Section::Featured
: StickersBox::Section::Installed)));
_openSettingsRequests.fire({});
} else if (_iconOver == SpecialOver::Search) {
toggleSearch(true);
} else {
@ -916,8 +920,10 @@ StickersListWidget::StickersListWidget(
setAttribute(Qt::WA_OpaquePaintEvent);
_settings->addClickHandler([=] {
using Section = StickersBox::Section;
controller->show(
Box<StickersBox>(controller, StickersBox::Section::Installed));
Box<StickersBox>(controller, Section::Installed, _isMasks),
Ui::LayerOption::KeepOther);
});
session().downloaderTaskFinished(
@ -967,6 +973,20 @@ object_ptr<TabbedSelector::InnerFooter> StickersListWidget::createFooter() {
auto result = object_ptr<Footer>(this);
_footer = result;
_footer->openSettingsRequests(
) | rpl::start_with_next([=] {
const auto onlyFeatured = _footer->hasOnlyFeaturedSets();
Ui::show(Box<StickersBox>(
controller(),
(onlyFeatured
? StickersBox::Section::Featured
: _isMasks
? StickersBox::Section::Masks
: StickersBox::Section::Installed),
onlyFeatured ? false : _isMasks),
Ui::LayerOption::KeepOther);
}, _footer->lifetime());
return result;
}