tdesktop/Telegram/SourceFiles/info/profile/info_profile_widget.cpp

147 lines
3.7 KiB
C++
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
2017-09-24 15:46:37 +00:00
#include "info/profile/info_profile_widget.h"
2017-09-24 15:46:37 +00:00
#include "info/profile/info_profile_inner_widget.h"
#include "info/profile/info_profile_members.h"
#include "ui/widgets/scroll_area.h"
2019-09-13 12:22:54 +00:00
#include "ui/ui_utility.h"
#include "data/data_peer.h"
#include "data/data_channel.h"
#include "data/data_forum_topic.h"
#include "data/data_user.h"
#include "lang/lang_keys.h"
#include "info/info_controller.h"
2022-09-27 12:05:47 +00:00
namespace Info::Profile {
Memento::Memento(not_null<Controller*> controller)
: Memento(
2020-06-08 09:06:50 +00:00
controller->peer(),
controller->topic(),
controller->migratedPeerId()) {
}
2020-06-08 09:06:50 +00:00
Memento::Memento(not_null<PeerData*> peer, PeerId migratedPeerId)
: Memento(peer, nullptr, migratedPeerId) {
}
Memento::Memento(
not_null<PeerData*> peer,
Data::ForumTopic *topic,
PeerId migratedPeerId)
: ContentMemento(peer, topic, migratedPeerId) {
2018-01-22 19:51:38 +00:00
}
2022-09-27 12:05:47 +00:00
Memento::Memento(not_null<Data::ForumTopic*> topic)
: ContentMemento(topic->channel(), topic, 0) {
2022-09-27 12:05:47 +00:00
}
Section Memento::section() const {
return Section(Section::Type::Profile);
}
object_ptr<ContentWidget> Memento::createWidget(
QWidget *parent,
not_null<Controller*> controller,
const QRect &geometry) {
2022-09-27 12:05:47 +00:00
auto result = object_ptr<Widget>(parent, controller);
result->setInternalState(geometry, this);
return result;
}
void Memento::setMembersState(std::unique_ptr<MembersState> state) {
_membersState = std::move(state);
}
std::unique_ptr<MembersState> Memento::membersState() {
return std::move(_membersState);
}
Memento::~Memento() = default;
2022-09-27 12:05:47 +00:00
Widget::Widget(QWidget *parent, not_null<Controller*> controller)
: ContentWidget(parent, controller) {
controller->setSearchEnabledByContent(false);
_inner = setInnerWidget(object_ptr<InnerWidget>(
this,
controller));
_inner->move(0, 0);
_inner->scrollToRequests(
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
if (request.ymin < 0) {
scrollTopRestore(
qMin(scrollTopSave(), request.ymax));
} else {
scrollTo(request);
}
}, lifetime());
}
void Widget::setInnerFocus() {
_inner->setFocus();
}
rpl::producer<QString> Widget::title() {
2022-09-27 12:05:47 +00:00
if (const auto topic = controller()->key().topic()) {
2022-10-14 13:25:05 +00:00
return tr::lng_info_topic_title();
2022-09-27 12:05:47 +00:00
}
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;
}
if (auto profileMemento = dynamic_cast<Memento*>(memento.get())) {
restoreState(profileMemento);
return true;
}
return false;
}
void Widget::setInternalState(
const QRect &geometry,
not_null<Memento*> memento) {
setGeometry(geometry);
Ui::SendPendingMoveResizeEvents(this);
restoreState(memento);
}
2020-12-14 14:48:10 +00:00
std::shared_ptr<ContentMemento> Widget::doCreateMemento() {
auto result = std::make_shared<Memento>(controller());
saveState(result.get());
return result;
}
void Widget::saveState(not_null<Memento*> memento) {
memento->setScrollTop(scrollTopSave());
_inner->saveState(memento);
}
void Widget::restoreState(not_null<Memento*> memento) {
_inner->restoreState(memento);
scrollTopRestore(memento->scrollTop());
}
2022-09-27 12:05:47 +00:00
} // namespace Info::Profile