113 lines
3.0 KiB
C++
113 lines
3.0 KiB
C++
/*
|
|
This file is part of Telegram Desktop,
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
|
*/
|
|
#include "info/profile/info_profile_widget.h"
|
|
|
|
#include "info/profile/info_profile_inner_widget.h"
|
|
#include "ui/widgets/scroll_area.h"
|
|
#include "info/info_controller.h"
|
|
|
|
namespace Info {
|
|
namespace Profile {
|
|
|
|
Memento::Memento(not_null<Controller*> controller)
|
|
: Memento(
|
|
controller->peerId(),
|
|
controller->migratedPeerId()) {
|
|
}
|
|
|
|
Section Memento::section() const {
|
|
return Section(Section::Type::Profile);
|
|
}
|
|
|
|
object_ptr<ContentWidget> Memento::createWidget(
|
|
QWidget *parent,
|
|
not_null<Controller*> controller,
|
|
const QRect &geometry) {
|
|
auto result = object_ptr<Widget>(
|
|
parent,
|
|
controller);
|
|
result->setInternalState(geometry, this);
|
|
return std::move(result);
|
|
}
|
|
|
|
Widget::Widget(
|
|
QWidget *parent,
|
|
not_null<Controller*> controller)
|
|
: ContentWidget(parent, controller) {
|
|
_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::setIsStackBottom(bool isStackBottom) {
|
|
_inner->setIsStackBottom(isStackBottom);
|
|
}
|
|
|
|
void Widget::setInnerFocus() {
|
|
_inner->setFocus();
|
|
}
|
|
|
|
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);
|
|
myEnsureResized(this);
|
|
restoreState(memento);
|
|
}
|
|
|
|
std::unique_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
auto result = std::make_unique<Memento>(controller());
|
|
saveState(result.get());
|
|
return std::move(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());
|
|
}
|
|
|
|
} // namespace Profile
|
|
} // namespace Info
|