diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index 48446cd38f..d36ec20dd0 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -368,7 +368,8 @@ void StickersBox::Tab::saveScrollTop() { StickersBox::StickersBox( QWidget*, not_null 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(); - 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); } } diff --git a/Telegram/SourceFiles/boxes/stickers_box.h b/Telegram/SourceFiles/boxes/stickers_box.h index 56cbc7d199..12d7353d11 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.h +++ b/Telegram/SourceFiles/boxes/stickers_box.h @@ -62,7 +62,8 @@ public: StickersBox( QWidget*, not_null controller, - Section section); + Section section, + bool masks = false); StickersBox( QWidget*, not_null controller, @@ -145,6 +146,7 @@ private: object_ptr _unreadBadge = { nullptr }; Section _section; + const bool _isMasks; Tab _installed; Tab _masks; diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index c9224407d9..0c41710b1a 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -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 _searchCancel = { nullptr }; QPointer _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( - _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(controller, StickersBox::Section::Installed)); + Box(controller, Section::Installed, _isMasks), + Ui::LayerOption::KeepOther); }); session().downloaderTaskFinished( @@ -967,6 +973,20 @@ object_ptr StickersListWidget::createFooter() { auto result = object_ptr