Provide section title from the section class.

This commit is contained in:
John Preston 2022-04-04 10:36:45 +04:00
parent b1e3b9688e
commit d9bbfeead1
20 changed files with 110 additions and 94 deletions

View File

@ -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<QString> Widget::title() {
return tr::lng_profile_common_groups_section();
}
not_null<UserData*> Widget::user() const {
return _inner->user();
}

View File

@ -60,6 +60,8 @@ public:
const QRect &geometry,
not_null<Memento*> memento);
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -101,6 +101,10 @@ void Widget::selectionAction(SelectionAction action) {
_inner->selectionAction(action);
}
rpl::producer<QString> Widget::title() {
return tr::lng_downloads_section();
}
std::shared_ptr<Info::Memento> Make(not_null<UserData*> self) {
return std::make_shared<Info::Memento>(
std::vector<std::shared_ptr<ContentMemento>>(

View File

@ -57,6 +57,8 @@ public:
rpl::producer<SelectedItems> selectedListValue() const override;
void selectionAction(SelectionAction action) override;
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -100,6 +100,14 @@ std::shared_ptr<ContentMemento> 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);

View File

@ -45,8 +45,8 @@ public:
not_null<ContentMemento*> memento) = 0;
std::shared_ptr<ContentMemento> createMemento();
virtual void setIsStackBottom(bool isStackBottom) {
}
virtual void setIsStackBottom(bool isStackBottom);
[[nodiscard]] bool isStackBottom() const;
rpl::producer<int> scrollHeightValue() const;
rpl::producer<int> desiredHeightValue() const override;
@ -73,6 +73,8 @@ public:
virtual void selectionAction(SelectionAction action) {
}
[[nodiscard]] virtual rpl::producer<QString> title() = 0;
virtual void saveChanges(FnMut<void()> done);
protected:
@ -111,6 +113,7 @@ private:
base::unique_qptr<Ui::RpWidget> _searchWrap = nullptr;
QPointer<Ui::InputField> _searchField;
int _innerDesiredHeight = 0;
bool _isStackBottom = false;
// Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent().
int _topDelta = 0;

View File

@ -560,75 +560,4 @@ void TopBar::performDelete() {
_selectionActionRequests.fire(SelectionAction::Delete);
}
rpl::producer<QString> TitleValue(
const Section &section,
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

View File

@ -35,11 +35,6 @@ namespace Info {
class Key;
class Section;
rpl::producer<QString> TitleValue(
const Section &section,
Key key,
bool isStackBottom);
class TopBar : public Ui::RpWidget {
public:
TopBar(

View File

@ -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<ContentWidget> 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());

View File

@ -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<QString> 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);
}

View File

@ -108,6 +108,8 @@ public:
rpl::producer<SelectedItems> selectedListValue() const override;
void selectionAction(SelectionAction action) override;
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -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<QString> 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<ContentMemento> Widget::doCreateMemento() {
auto result = std::make_shared<Memento>(controller());
saveState(result.get());

View File

@ -56,6 +56,8 @@ public:
const QRect &geometry,
not_null<Memento*> memento);
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -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<QString> Widget::title() {
return poll()->quiz()
? tr::lng_polls_quiz_results_title()
: tr::lng_polls_poll_results_title();
}
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
auto result = std::make_shared<Memento>(poll(), contextId());
saveState(result.get());

View File

@ -56,6 +56,8 @@ public:
const QRect &geometry,
not_null<Memento*> memento);
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -44,9 +44,6 @@ public:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);
void setIsStackBottom(bool isStackBottom) {
_isStackBottom = isStackBottom;
}
rpl::producer<Ui::ScrollToRequest> scrollToRequests() const;
rpl::producer<int> desiredHeightValue() const override;
@ -68,8 +65,6 @@ private:
bool canHideDetailsEver() const;
rpl::producer<bool> canHideDetails() const;
rpl::variable<bool> _isStackBottom = true;
const not_null<Controller*> _controller;
const not_null<PeerData*> _peer;
PeerData * const _migrated = nullptr;

View File

@ -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<QString> 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<ContentMemento*> memento) {
if (!controller()->validateMementoPeer(memento)) {
return false;

View File

@ -51,8 +51,6 @@ public:
QWidget *parent,
not_null<Controller*> controller);
void setIsStackBottom(bool isStackBottom) override;
bool showInternal(
not_null<ContentMemento*> memento) override;
@ -62,6 +60,8 @@ public:
void setInnerFocus() override;
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);

View File

@ -90,6 +90,10 @@ rpl::producer<bool> Widget::desiredShadowVisibility() const {
: rpl::single(true);
}
rpl::producer<QString> Widget::title() {
return _type()->title();
}
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
auto result = std::make_shared<Memento>(self(), _type);
saveState(result.get());

View File

@ -67,6 +67,8 @@ public:
rpl::producer<bool> desiredShadowVisibility() const override;
rpl::producer<QString> title() override;
private:
void saveState(not_null<Memento*> memento);
void restoreState(not_null<Memento*> memento);