From b2a1c100361f61d5cc35982c202290aeea707a6c Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Wed, 31 Mar 2021 03:26:32 +0300 Subject: [PATCH] Removed masks panel when there are no masks. --- Telegram/SourceFiles/boxes/stickers_box.cpp | 2 +- .../chat_helpers/stickers_list_widget.cpp | 5 ++ .../chat_helpers/stickers_list_widget.h | 2 + .../chat_helpers/tabbed_selector.cpp | 53 ++++++++++++++----- .../chat_helpers/tabbed_selector.h | 2 + 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/boxes/stickers_box.cpp b/Telegram/SourceFiles/boxes/stickers_box.cpp index e78fd0cb6..5d6164832 100644 --- a/Telegram/SourceFiles/boxes/stickers_box.cpp +++ b/Telegram/SourceFiles/boxes/stickers_box.cpp @@ -641,7 +641,7 @@ void StickersBox::refreshTabs() { sections.push_back(tr::lng_stickers_installed_tab(tr::now).toUpper()); _tabIndices.push_back(Section::Installed); } - if (!stickers.maskSetsOrder().isEmpty() && _masks.widget()) { + if (_masks.widget()) { sections.push_back(tr::lng_stickers_masks_tab(tr::now).toUpper()); _tabIndices.push_back(Section::Masks); } diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp index 06499ce08..bb6dbb599 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.cpp @@ -3237,6 +3237,7 @@ void StickersListWidget::removeSet(uint64 setId) { if (writeRecent) { session().saveSettings(); } + session().data().stickers().notifyUpdated(); } _removingSetId = 0; _checkForHide.fire({}); @@ -3258,6 +3259,10 @@ Data::StickersSetsOrder &StickersListWidget::defaultSetsOrderRef() { : session().data().stickers().maskSetsOrderRef(); } +bool StickersListWidget::mySetsEmpty() const { + return _mySets.empty(); +} + StickersListWidget::~StickersListWidget() = default; } // namespace ChatHelpers diff --git a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h index eeba5ac9b..58fa39802 100644 --- a/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h +++ b/Telegram/SourceFiles/chat_helpers/stickers_list_widget.h @@ -89,6 +89,8 @@ public: not_null menu, SendMenu::Type type) override; + bool mySetsEmpty() const; + ~StickersListWidget(); protected: diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp index 8c6564495..e4e75f11f 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.cpp @@ -496,11 +496,19 @@ rpl::producer<> TabbedSelector::slideFinished() const { return _slideFinished.events(); } -void TabbedSelector::resizeEvent(QResizeEvent *e) { - if (_tabsSlider) { - _tabsSlider->resizeToWidth(width()); - _tabsSlider->moveToLeft(0, 0); +void TabbedSelector::updateTabsSliderGeometry() { + if (!_tabsSlider) { + return; } + const auto w = mediaEditor() && hasMasksTab() && masks()->mySetsEmpty() + ? width() / 2 + : width(); + _tabsSlider->resizeToWidth(w); + _tabsSlider->moveToLeft(0, 0); +} + +void TabbedSelector::resizeEvent(QResizeEvent *e) { + updateTabsSliderGeometry(); if (_topShadow && _tabsSlider) { _topShadow->setGeometry( _tabsSlider->x(), @@ -680,9 +688,16 @@ void TabbedSelector::refreshStickers() { } } if (hasMasksTab()) { - masks()->refreshStickers(); + const auto masksList = masks(); + masksList->refreshStickers(); if (isHidden() || _currentTabType != SelectorTab::Masks) { - masks()->preloadImages(); + masksList->preloadImages(); + } + + fillTabsSliderSections(); + updateTabsSliderGeometry(); + if (hasStickersTab() && masksList->mySetsEmpty()) { + _tabsSlider->setActiveSection(indexByType(SelectorTab::Stickers)); } } } @@ -869,9 +884,27 @@ void TabbedSelector::setRoundRadius(int radius) { void TabbedSelector::createTabsSlider() { _tabsSlider.create(this, st::emojiTabs); + fillTabsSliderSections(); + + _tabsSlider->setActiveSectionFast(indexByType(_currentTabType)); + _tabsSlider->sectionActivated( + ) | rpl::start_with_next([=] { + switchTab(); + }, lifetime()); +} + +void TabbedSelector::fillTabsSliderSections() { + if (!_tabsSlider) { + return; + } + const auto sections = ranges::views::all( _tabs - ) | ranges::views::transform([=](const Tab &tab) { + ) | ranges::views::filter([&](const Tab &tab) { + return (tab.type() == SelectorTab::Masks) + ? !masks()->mySetsEmpty() + : true; + }) | ranges::views::transform([&](const Tab &tab) { return [type = tab.type()] { switch (type) { case SelectorTab::Emoji: @@ -886,12 +919,6 @@ void TabbedSelector::createTabsSlider() { }()(tr::now).toUpper(); }) | ranges::to_vector; _tabsSlider->setSections(sections); - - _tabsSlider->setActiveSectionFast(indexByType(_currentTabType)); - _tabsSlider->sectionActivated( - ) | rpl::start_with_next([=] { - switchTab(); - }, lifetime()); } bool TabbedSelector::hasSectionIcons() const { diff --git a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h index bd881cb31..ff5b7fad5 100644 --- a/Telegram/SourceFiles/chat_helpers/tabbed_selector.h +++ b/Telegram/SourceFiles/chat_helpers/tabbed_selector.h @@ -198,6 +198,8 @@ private: bool hasSectionIcons() const; void setWidgetToScrollArea(); void createTabsSlider(); + void fillTabsSliderSections(); + void updateTabsSliderGeometry(); void switchTab(); not_null getTab(int index);