2018-09-05 19:05:49 +00:00
|
|
|
/*
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
#include "info/settings/info_settings_widget.h"
|
|
|
|
|
|
|
|
#include "info/info_memento.h"
|
2018-09-05 19:39:35 +00:00
|
|
|
#include "info/info_controller.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "settings/settings_common.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "ui/ui_utility.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
namespace Info {
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
Memento::Memento(not_null<UserData*> self, Type type)
|
|
|
|
: ContentMemento(Tag{ self })
|
|
|
|
, _type(type) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Section Memento::section() const {
|
|
|
|
return Section(_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Memento::~Memento() = default;
|
|
|
|
|
|
|
|
Widget::Widget(
|
|
|
|
QWidget *parent,
|
|
|
|
not_null<Controller*> controller)
|
|
|
|
: ContentWidget(parent, controller)
|
|
|
|
, _self(controller->key().settingsSelf())
|
2018-09-09 17:38:08 +00:00
|
|
|
, _type(controller->section().settingsType())
|
2020-03-24 08:58:47 +00:00
|
|
|
, _inner(setInnerWidget(
|
|
|
|
::Settings::CreateSection(
|
|
|
|
_type,
|
|
|
|
this,
|
|
|
|
controller->parentController()))) {
|
2018-09-09 17:38:08 +00:00
|
|
|
_inner->sectionShowOther(
|
2018-09-05 19:05:49 +00:00
|
|
|
) | rpl::start_with_next([=](Type type) {
|
2020-03-24 08:58:47 +00:00
|
|
|
controller->showSettings(type);
|
2018-09-09 17:38:08 +00:00
|
|
|
}, _inner->lifetime());
|
|
|
|
|
|
|
|
controller->setCanSaveChanges(_inner->sectionCanSaveChanges());
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
2020-03-18 10:07:11 +00:00
|
|
|
Widget::~Widget() = default;
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
not_null<UserData*> Widget::self() const {
|
|
|
|
return _self;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Widget::showInternal(not_null<ContentMemento*> memento) {
|
|
|
|
//if (const auto myMemento = dynamic_cast<Memento*>(memento.get())) {
|
|
|
|
// Assert(myMemento->self() == self());
|
|
|
|
|
|
|
|
// if (_inner->showInternal(myMemento)) {
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::setInternalState(
|
|
|
|
const QRect &geometry,
|
|
|
|
not_null<Memento*> memento) {
|
|
|
|
setGeometry(geometry);
|
|
|
|
Ui::SendPendingMoveResizeEvents(this);
|
|
|
|
restoreState(memento);
|
|
|
|
}
|
|
|
|
|
2018-09-09 17:38:08 +00:00
|
|
|
rpl::producer<bool> Widget::canSaveChanges() const {
|
|
|
|
return _inner->sectionCanSaveChanges();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::saveChanges(FnMut<void()> done) {
|
|
|
|
_inner->sectionSaveChanges(std::move(done));
|
|
|
|
}
|
|
|
|
|
2018-09-13 20:09:26 +00:00
|
|
|
rpl::producer<bool> Widget::desiredShadowVisibility() const {
|
|
|
|
return (_type == Type::Main || _type == Type::Information)
|
|
|
|
? ContentWidget::desiredShadowVisibility()
|
|
|
|
: rpl::single(true);
|
|
|
|
}
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
std::unique_ptr<ContentMemento> Widget::doCreateMemento() {
|
|
|
|
auto result = std::make_unique<Memento>(self(), _type);
|
|
|
|
saveState(result.get());
|
2019-11-12 15:15:34 +00:00
|
|
|
return result;
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::saveState(not_null<Memento*> memento) {
|
|
|
|
memento->setScrollTop(scrollTopSave());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Widget::restoreState(not_null<Memento*> memento) {
|
|
|
|
const auto scrollTop = memento->scrollTop();
|
|
|
|
scrollTopRestore(memento->scrollTop());
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|
|
|
|
} // namespace Info
|