From d9bbfeead13bcb5427efd7ee97d08cff81187566 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 4 Apr 2022 10:36:45 +0400 Subject: [PATCH] Provide section title from the section class. --- .../info_common_groups_widget.cpp | 5 ++ .../common_groups/info_common_groups_widget.h | 2 + .../info/downloads/info_downloads_widget.cpp | 4 ++ .../info/downloads/info_downloads_widget.h | 2 + .../SourceFiles/info/info_content_widget.cpp | 8 +++ .../SourceFiles/info/info_content_widget.h | 7 +- Telegram/SourceFiles/info/info_top_bar.cpp | 71 ------------------- Telegram/SourceFiles/info/info_top_bar.h | 5 -- .../SourceFiles/info/info_wrap_widget.cpp | 7 +- .../info/media/info_media_widget.cpp | 27 +++++++ .../info/media/info_media_widget.h | 2 + .../info/members/info_members_widget.cpp | 12 ++++ .../info/members/info_members_widget.h | 2 + .../info/polls/info_polls_results_widget.cpp | 8 +++ .../info/polls/info_polls_results_widget.h | 2 + .../info/profile/info_profile_inner_widget.h | 5 -- .../info/profile/info_profile_widget.cpp | 25 +++++-- .../info/profile/info_profile_widget.h | 4 +- .../info/settings/info_settings_widget.cpp | 4 ++ .../info/settings/info_settings_widget.h | 2 + 20 files changed, 110 insertions(+), 94 deletions(-) diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp index 8b3283419..134e89f28 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.cpp @@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/search_field_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/ui_utility.h" +#include "lang/lang_keys.h" #include "data/data_user.h" #include "data/data_session.h" #include "main/main_session.h" @@ -62,6 +63,10 @@ Widget::Widget( user)); } +rpl::producer Widget::title() { + return tr::lng_profile_common_groups_section(); +} + not_null Widget::user() const { return _inner->user(); } diff --git a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h index 02d04466d..78a8dc23a 100644 --- a/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h +++ b/Telegram/SourceFiles/info/common_groups/info_common_groups_widget.h @@ -60,6 +60,8 @@ public: const QRect &geometry, not_null memento); + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/downloads/info_downloads_widget.cpp b/Telegram/SourceFiles/info/downloads/info_downloads_widget.cpp index 20c751750..3033c68e0 100644 --- a/Telegram/SourceFiles/info/downloads/info_downloads_widget.cpp +++ b/Telegram/SourceFiles/info/downloads/info_downloads_widget.cpp @@ -101,6 +101,10 @@ void Widget::selectionAction(SelectionAction action) { _inner->selectionAction(action); } +rpl::producer Widget::title() { + return tr::lng_downloads_section(); +} + std::shared_ptr Make(not_null self) { return std::make_shared( std::vector>( diff --git a/Telegram/SourceFiles/info/downloads/info_downloads_widget.h b/Telegram/SourceFiles/info/downloads/info_downloads_widget.h index 98e523483..3da1a4f79 100644 --- a/Telegram/SourceFiles/info/downloads/info_downloads_widget.h +++ b/Telegram/SourceFiles/info/downloads/info_downloads_widget.h @@ -57,6 +57,8 @@ public: rpl::producer selectedListValue() const override; void selectionAction(SelectionAction action) override; + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/info_content_widget.cpp b/Telegram/SourceFiles/info/info_content_widget.cpp index ac2536ffe..0f5d3049e 100644 --- a/Telegram/SourceFiles/info/info_content_widget.cpp +++ b/Telegram/SourceFiles/info/info_content_widget.cpp @@ -100,6 +100,14 @@ std::shared_ptr ContentWidget::createMemento() { return result; } +void ContentWidget::setIsStackBottom(bool isStackBottom) { + _isStackBottom = isStackBottom; +} + +bool ContentWidget::isStackBottom() const { + return _isStackBottom; +} + void ContentWidget::paintEvent(QPaintEvent *e) { Painter p(this); p.fillRect(e->rect(), _bg); diff --git a/Telegram/SourceFiles/info/info_content_widget.h b/Telegram/SourceFiles/info/info_content_widget.h index 35b67f39e..b1b5656bb 100644 --- a/Telegram/SourceFiles/info/info_content_widget.h +++ b/Telegram/SourceFiles/info/info_content_widget.h @@ -45,8 +45,8 @@ public: not_null memento) = 0; std::shared_ptr createMemento(); - virtual void setIsStackBottom(bool isStackBottom) { - } + virtual void setIsStackBottom(bool isStackBottom); + [[nodiscard]] bool isStackBottom() const; rpl::producer scrollHeightValue() const; rpl::producer desiredHeightValue() const override; @@ -73,6 +73,8 @@ public: virtual void selectionAction(SelectionAction action) { } + [[nodiscard]] virtual rpl::producer title() = 0; + virtual void saveChanges(FnMut done); protected: @@ -111,6 +113,7 @@ private: base::unique_qptr _searchWrap = nullptr; QPointer _searchField; int _innerDesiredHeight = 0; + bool _isStackBottom = false; // Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent(). int _topDelta = 0; diff --git a/Telegram/SourceFiles/info/info_top_bar.cpp b/Telegram/SourceFiles/info/info_top_bar.cpp index 3b7155349..f5651aa5d 100644 --- a/Telegram/SourceFiles/info/info_top_bar.cpp +++ b/Telegram/SourceFiles/info/info_top_bar.cpp @@ -560,75 +560,4 @@ void TopBar::performDelete() { _selectionActionRequests.fire(SelectionAction::Delete); } -rpl::producer TitleValue( - const Section §ion, - Key key, - bool isStackBottom) { - const auto peer = key.peer(); - - switch (section.type()) { - case Section::Type::Profile: - if (const auto user = peer->asUser()) { - return (user->isBot() && !user->isSupport()) - ? tr::lng_info_bot_title() - : tr::lng_info_user_title(); - } else if (const auto channel = peer->asChannel()) { - return channel->isMegagroup() - ? tr::lng_info_group_title() - : tr::lng_info_channel_title(); - } else if (peer->isChat()) { - return tr::lng_info_group_title(); - } - Unexpected("Bad peer type in Info::TitleValue()"); - - case Section::Type::Media: - if (peer->sharedMediaInfo() && isStackBottom) { - return tr::lng_profile_shared_media(); - } - switch (section.mediaType()) { - case Section::MediaType::Photo: - return tr::lng_media_type_photos(); - case Section::MediaType::GIF: - return tr::lng_media_type_gifs(); - case Section::MediaType::Video: - return tr::lng_media_type_videos(); - case Section::MediaType::MusicFile: - return tr::lng_media_type_songs(); - case Section::MediaType::File: - return tr::lng_media_type_files(); - case Section::MediaType::RoundVoiceFile: - return tr::lng_media_type_audios(); - case Section::MediaType::Link: - return tr::lng_media_type_links(); - case Section::MediaType::RoundFile: - return tr::lng_media_type_rounds(); - } - Unexpected("Bad media type in Info::TitleValue()"); - - case Section::Type::CommonGroups: - return tr::lng_profile_common_groups_section(); - - case Section::Type::Members: - if (const auto channel = peer->asChannel()) { - return channel->isMegagroup() - ? tr::lng_profile_participants_section() - : tr::lng_profile_subscribers_section(); - } - return tr::lng_profile_participants_section(); - - case Section::Type::Settings: - return section.settingsType()()->title(); - - case Section::Type::PollResults: - return key.poll()->quiz() - ? tr::lng_polls_quiz_results_title() - : tr::lng_polls_poll_results_title(); - - case Section::Type::Downloads: - return tr::lng_downloads_section(); - - } - Unexpected("Bad section type in Info::TitleValue()"); -} - } // namespace Info diff --git a/Telegram/SourceFiles/info/info_top_bar.h b/Telegram/SourceFiles/info/info_top_bar.h index caa3793b5..a2ed052c5 100644 --- a/Telegram/SourceFiles/info/info_top_bar.h +++ b/Telegram/SourceFiles/info/info_top_bar.h @@ -35,11 +35,6 @@ namespace Info { class Key; class Section; -rpl::producer TitleValue( - const Section §ion, - Key key, - bool isStackBottom); - class TopBar : public Ui::RpWidget { public: TopBar( diff --git a/Telegram/SourceFiles/info/info_wrap_widget.cpp b/Telegram/SourceFiles/info/info_wrap_widget.cpp index f2cb903bf..7b94f26a7 100644 --- a/Telegram/SourceFiles/info/info_wrap_widget.cpp +++ b/Telegram/SourceFiles/info/info_wrap_widget.cpp @@ -355,10 +355,6 @@ void WrapWidget::createTopBar() { _content->selectionAction(action); }, _topBar->lifetime()); - _topBar->setTitle(TitleValue( - _controller->section(), - _controller->key(), - !hasStackHistory())); if (wrapValue == Wrap::Narrow || hasStackHistory()) { _topBar->enableBackButton(); _topBar->backRequest( @@ -616,8 +612,9 @@ void WrapWidget::showContent(object_ptr content) { } void WrapWidget::finishShowContent() { - _content->setIsStackBottom(!hasStackHistory()); updateContentGeometry(); + _content->setIsStackBottom(!hasStackHistory()); + _topBar->setTitle(_content->title()); _desiredHeights.fire(desiredHeightForContent()); _desiredShadowVisibilities.fire(_content->desiredShadowVisibility()); _selectedLists.fire(_content->selectedListValue()); diff --git a/Telegram/SourceFiles/info/media/info_media_widget.cpp b/Telegram/SourceFiles/info/media/info_media_widget.cpp index 1e76ed824..32db7bee2 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.cpp +++ b/Telegram/SourceFiles/info/media/info_media_widget.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/ui_utility.h" #include "data/data_peer.h" #include "data/data_user.h" +#include "lang/lang_keys.h" #include "styles/style_info.h" namespace Info { @@ -97,7 +98,33 @@ void Widget::selectionAction(SelectionAction action) { _inner->selectionAction(action); } +rpl::producer Widget::title() { + if (controller()->key().peer()->sharedMediaInfo() && isStackBottom()) { + return tr::lng_profile_shared_media(); + } + switch (controller()->section().mediaType()) { + case Section::MediaType::Photo: + return tr::lng_media_type_photos(); + case Section::MediaType::GIF: + return tr::lng_media_type_gifs(); + case Section::MediaType::Video: + return tr::lng_media_type_videos(); + case Section::MediaType::MusicFile: + return tr::lng_media_type_songs(); + case Section::MediaType::File: + return tr::lng_media_type_files(); + case Section::MediaType::RoundVoiceFile: + return tr::lng_media_type_audios(); + case Section::MediaType::Link: + return tr::lng_media_type_links(); + case Section::MediaType::RoundFile: + return tr::lng_media_type_rounds(); + } + Unexpected("Bad media type in Info::TitleValue()"); +} + void Widget::setIsStackBottom(bool isStackBottom) { + ContentWidget::setIsStackBottom(isStackBottom); _inner->setIsStackBottom(isStackBottom); } diff --git a/Telegram/SourceFiles/info/media/info_media_widget.h b/Telegram/SourceFiles/info/media/info_media_widget.h index ca523b1f5..f0a734ee2 100644 --- a/Telegram/SourceFiles/info/media/info_media_widget.h +++ b/Telegram/SourceFiles/info/media/info_media_widget.h @@ -108,6 +108,8 @@ public: rpl::producer selectedListValue() const override; void selectionAction(SelectionAction action) override; + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/members/info_members_widget.cpp b/Telegram/SourceFiles/info/members/info_members_widget.cpp index c3b33b842..5ddea3ec7 100644 --- a/Telegram/SourceFiles/info/members/info_members_widget.cpp +++ b/Telegram/SourceFiles/info/members/info_members_widget.cpp @@ -11,6 +11,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/info_controller.h" #include "ui/widgets/scroll_area.h" #include "ui/ui_utility.h" +#include "data/data_peer.h" +#include "data/data_channel.h" +#include "lang/lang_keys.h" #include "styles/style_info.h" namespace Info { @@ -79,6 +82,15 @@ void Widget::setInternalState( restoreState(memento); } +rpl::producer Widget::title() { + if (const auto channel = controller()->key().peer()->asChannel()) { + return channel->isMegagroup() + ? tr::lng_profile_participants_section() + : tr::lng_profile_subscribers_section(); + } + return tr::lng_profile_participants_section(); +} + std::shared_ptr Widget::doCreateMemento() { auto result = std::make_shared(controller()); saveState(result.get()); diff --git a/Telegram/SourceFiles/info/members/info_members_widget.h b/Telegram/SourceFiles/info/members/info_members_widget.h index 23a2eac46..f91af76b7 100644 --- a/Telegram/SourceFiles/info/members/info_members_widget.h +++ b/Telegram/SourceFiles/info/members/info_members_widget.h @@ -56,6 +56,8 @@ public: const QRect &geometry, not_null memento); + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/polls/info_polls_results_widget.cpp b/Telegram/SourceFiles/info/polls/info_polls_results_widget.cpp index e6a0ef169..301da512d 100644 --- a/Telegram/SourceFiles/info/polls/info_polls_results_widget.cpp +++ b/Telegram/SourceFiles/info/polls/info_polls_results_widget.cpp @@ -9,6 +9,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/polls/info_polls_results_inner_widget.h" #include "boxes/peer_list_box.h" +#include "lang/lang_keys.h" +#include "data/data_poll.h" namespace Info { namespace Polls { @@ -88,6 +90,12 @@ void Widget::setInternalState( restoreState(memento); } +rpl::producer Widget::title() { + return poll()->quiz() + ? tr::lng_polls_quiz_results_title() + : tr::lng_polls_poll_results_title(); +} + std::shared_ptr Widget::doCreateMemento() { auto result = std::make_shared(poll(), contextId()); saveState(result.get()); diff --git a/Telegram/SourceFiles/info/polls/info_polls_results_widget.h b/Telegram/SourceFiles/info/polls/info_polls_results_widget.h index 6f3fa8a42..556ac549b 100644 --- a/Telegram/SourceFiles/info/polls/info_polls_results_widget.h +++ b/Telegram/SourceFiles/info/polls/info_polls_results_widget.h @@ -56,6 +56,8 @@ public: const QRect &geometry, not_null memento); + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h index 938e7712a..99cd4e152 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h +++ b/Telegram/SourceFiles/info/profile/info_profile_inner_widget.h @@ -44,9 +44,6 @@ public: void saveState(not_null memento); void restoreState(not_null memento); - void setIsStackBottom(bool isStackBottom) { - _isStackBottom = isStackBottom; - } rpl::producer scrollToRequests() const; rpl::producer desiredHeightValue() const override; @@ -68,8 +65,6 @@ private: bool canHideDetailsEver() const; rpl::producer canHideDetails() const; - rpl::variable _isStackBottom = true; - const not_null _controller; const not_null _peer; PeerData * const _migrated = nullptr; diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp index 531125813..f4b3133a2 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.cpp @@ -11,6 +11,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "info/profile/info_profile_members.h" #include "ui/widgets/scroll_area.h" #include "ui/ui_utility.h" +#include "data/data_peer.h" +#include "data/data_channel.h" +#include "data/data_user.h" +#include "lang/lang_keys.h" #include "info/info_controller.h" namespace Info { @@ -72,14 +76,27 @@ Widget::Widget( }, lifetime()); } -void Widget::setIsStackBottom(bool isStackBottom) { - _inner->setIsStackBottom(isStackBottom); -} - void Widget::setInnerFocus() { _inner->setFocus(); } +rpl::producer Widget::title() { + const auto peer = controller()->key().peer(); + if (const auto user = peer->asUser()) { + return (user->isBot() && !user->isSupport()) + ? tr::lng_info_bot_title() + : tr::lng_info_user_title(); + } else if (const auto channel = peer->asChannel()) { + return channel->isMegagroup() + ? tr::lng_info_group_title() + : tr::lng_info_channel_title(); + } else if (peer->isChat()) { + return tr::lng_info_group_title(); + } + Unexpected("Bad peer type in Info::TitleValue()"); + +} + bool Widget::showInternal(not_null memento) { if (!controller()->validateMementoPeer(memento)) { return false; diff --git a/Telegram/SourceFiles/info/profile/info_profile_widget.h b/Telegram/SourceFiles/info/profile/info_profile_widget.h index 6b9af0236..a50e2f16c 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_widget.h +++ b/Telegram/SourceFiles/info/profile/info_profile_widget.h @@ -51,8 +51,6 @@ public: QWidget *parent, not_null controller); - void setIsStackBottom(bool isStackBottom) override; - bool showInternal( not_null memento) override; @@ -62,6 +60,8 @@ public: void setInnerFocus() override; + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento); diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp index 57e6152c1..fa825fc7c 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.cpp +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.cpp @@ -90,6 +90,10 @@ rpl::producer Widget::desiredShadowVisibility() const { : rpl::single(true); } +rpl::producer Widget::title() { + return _type()->title(); +} + std::shared_ptr Widget::doCreateMemento() { auto result = std::make_shared(self(), _type); saveState(result.get()); diff --git a/Telegram/SourceFiles/info/settings/info_settings_widget.h b/Telegram/SourceFiles/info/settings/info_settings_widget.h index 6c95e1c94..2959b2be4 100644 --- a/Telegram/SourceFiles/info/settings/info_settings_widget.h +++ b/Telegram/SourceFiles/info/settings/info_settings_widget.h @@ -67,6 +67,8 @@ public: rpl::producer desiredShadowVisibility() const override; + rpl::producer title() override; + private: void saveState(not_null memento); void restoreState(not_null memento);