2017-09-13 17:01:23 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2017-09-13 17:01:23 +00:00
|
|
|
*/
|
2017-09-24 15:46:37 +00:00
|
|
|
#include "info/profile/info_profile_widget.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
2017-09-24 15:46:37 +00:00
|
|
|
#include "info/profile/info_profile_inner_widget.h"
|
2017-11-17 13:23:36 +00:00
|
|
|
#include "info/profile/info_profile_members.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2017-10-31 18:25:22 +00:00
|
|
|
#include "info/info_controller.h"
|
2017-09-13 17:01:23 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Profile {
|
2017-09-15 17:34:41 +00:00
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
|
|
|
: Memento(
|
|
|
|
controller->peerId(),
|
|
|
|
controller->migratedPeerId()) {
|
|
|
|
}
|
|
|
|
|
2018-01-22 19:51:38 +00:00
|
|
|
Memento::Memento(PeerId peerId, PeerId migratedPeerId)
|
|
|
|
: ContentMemento(peerId, migratedPeerId) {
|
|
|
|
}
|
|
|
|
|
2017-10-31 18:25:22 +00:00
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(Section::Type::Profile);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller,
|
2017-09-13 17:01:23 +00:00
|
|
|
const QRect &geometry) {
|
|
|
|
auto result = object_ptr<Widget>(
|
|
|
|
parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
controller);
|
2017-09-13 17:01:23 +00:00
|
|
|
result->setInternalState(geometry, this);
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
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;
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
2017-10-31 18:25:22 +00:00
|
|
|
not_null<Controller*> controller)
|
|
|
|
: ContentWidget(parent, controller) {
|
2017-11-17 13:23:36 +00:00
|
|
|
controller->setSearchEnabledByContent(false);
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(
|
|
|
|
this,
|
2017-10-31 18:25:22 +00:00
|
|
|
controller));
|
2017-09-13 17:01:23 +00:00
|
|
|
_inner->move(0, 0);
|
2017-12-22 07:05:20 +00:00
|
|
|
_inner->scrollToRequests(
|
|
|
|
) | rpl::start_with_next([this](Ui::ScrollToRequest request) {
|
|
|
|
if (request.ymin < 0) {
|
|
|
|
scrollTopRestore(
|
|
|
|
qMin(scrollTopSave(), request.ymax));
|
|
|
|
} else {
|
|
|
|
scrollTo(request);
|
|
|
|
}
|
|
|
|
}, lifetime());
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-20 17:54:51 +00:00
|
|
|
void Widget::setIsStackBottom(bool isStackBottom) {
|
|
|
|
_inner->setIsStackBottom(isStackBottom);
|
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
void Widget::setInnerFocus() {
|
|
|
|
_inner->setFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
2017-10-31 18:25:22 +00:00
|
|
|
if (!controller()->validateMementoPeer(memento)) {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-13 17:01:23 +00:00
|
|
|
if (auto profileMemento = dynamic_cast<Memento*>(memento.get())) {
|
2017-10-31 18:25:22 +00:00
|
|
|
restoreState(profileMemento);
|
|
|
|
return true;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-17 13:23:36 +00:00
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
2017-09-13 17:01:23 +00:00
|
|
|
setGeometry(geometry);
|
2017-12-26 12:41:48 +00:00
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
2017-09-13 17:01:23 +00:00
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2017-11-03 18:26:14 +00:00
|
|
|
std::unique_ptr<ContentMemento> Widget::doCreateMemento() {
|
2017-10-31 18:25:22 +00:00
|
|
|
auto result = std::make_unique<Memento>(controller());
|
2017-09-13 17:01:23 +00:00
|
|
|
saveState(result.get());
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2017-09-13 17:01:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Profile
|
|
|
|
} // namespace Info
|