2016-08-17 15:14:08 +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.
|
2016-08-17 15:14:08 +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
|
2016-08-17 15:14:08 +00:00
|
|
|
*/
|
2018-09-02 14:23:52 +00:00
|
|
|
#include "old_settings/settings_inner_widget.h"
|
2016-08-17 15:14:08 +00:00
|
|
|
|
2017-04-18 17:37:14 +00:00
|
|
|
#include "lang/lang_instance.h"
|
2018-09-02 14:23:52 +00:00
|
|
|
#include "styles/style_old_settings.h"
|
|
|
|
#include "old_settings/settings_cover.h"
|
|
|
|
#include "old_settings/settings_block_widget.h"
|
|
|
|
#include "old_settings/settings_info_widget.h"
|
|
|
|
#include "old_settings/settings_notifications_widget.h"
|
|
|
|
#include "old_settings/settings_general_widget.h"
|
|
|
|
#include "old_settings/settings_chat_settings_widget.h"
|
|
|
|
#include "old_settings/settings_scale_widget.h"
|
|
|
|
#include "old_settings/settings_background_widget.h"
|
|
|
|
#include "old_settings/settings_privacy_widget.h"
|
|
|
|
#include "old_settings/settings_advanced_widget.h"
|
2016-08-19 17:26:31 +00:00
|
|
|
|
2018-09-02 14:23:52 +00:00
|
|
|
namespace OldSettings {
|
2016-08-17 15:14:08 +00:00
|
|
|
|
2017-02-03 20:07:26 +00:00
|
|
|
InnerWidget::InnerWidget(QWidget *parent) : LayerInner(parent)
|
2017-09-18 17:04:45 +00:00
|
|
|
, _blocks(this)
|
|
|
|
, _self(App::self()) {
|
2016-08-19 17:26:31 +00:00
|
|
|
refreshBlocks();
|
2017-04-18 17:37:14 +00:00
|
|
|
subscribe(Global::RefSelfChanged(), [this] { fullRebuild(); });
|
|
|
|
subscribe(Lang::Current().updated(), [this] { fullRebuild(); });
|
2016-08-27 04:49:18 +00:00
|
|
|
}
|
|
|
|
|
2017-04-18 17:37:14 +00:00
|
|
|
void InnerWidget::fullRebuild() {
|
2016-08-27 04:49:18 +00:00
|
|
|
_self = App::self();
|
|
|
|
refreshBlocks();
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2018-04-18 15:42:02 +00:00
|
|
|
int InnerWidget::getUpdateTop() const {
|
|
|
|
return _getUpdateTop ? _getUpdateTop() : -1;
|
|
|
|
}
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
void InnerWidget::refreshBlocks() {
|
2016-11-18 13:34:58 +00:00
|
|
|
if (App::quitting()) {
|
2017-09-13 16:57:44 +00:00
|
|
|
_cover.destroy();
|
|
|
|
_blocks.destroy();
|
2016-11-18 13:34:58 +00:00
|
|
|
return;
|
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
_cover = _self
|
|
|
|
? object_ptr<CoverWidget>(this, _self)
|
|
|
|
: nullptr;
|
|
|
|
_blocks = object_ptr<Ui::VerticalLayout>(this);
|
|
|
|
resizeToWidth(width(), _contentLeft);
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
if (_self) {
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->add(object_ptr<InfoWidget>(this, _self));
|
|
|
|
_blocks->add(object_ptr<NotificationsWidget>(this, _self));
|
2016-08-28 20:23:32 +00:00
|
|
|
}
|
2018-04-18 15:42:02 +00:00
|
|
|
const auto general = make_weak(_blocks->add(object_ptr<GeneralWidget>(
|
|
|
|
this,
|
|
|
|
_self)));
|
|
|
|
_getUpdateTop = [=] {
|
|
|
|
if (!general) {
|
|
|
|
return -1;
|
|
|
|
} else if (const auto top = general->getUpdateTop(); top >= 0) {
|
|
|
|
return _blocks->y() + general->y() + top;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
};
|
2016-08-28 20:23:32 +00:00
|
|
|
if (!cRetina()) {
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->add(object_ptr<ScaleWidget>(this, _self));
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
if (_self) {
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->add(object_ptr<ChatSettingsWidget>(this, _self));
|
|
|
|
_blocks->add(object_ptr<BackgroundWidget>(this, _self));
|
|
|
|
_blocks->add(object_ptr<PrivacyWidget>(this, _self));
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->add(object_ptr<AdvancedWidget>(this, _self));
|
2016-08-27 04:49:18 +00:00
|
|
|
|
|
|
|
if (_cover) {
|
|
|
|
_cover->show();
|
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->show();
|
2017-12-22 07:05:20 +00:00
|
|
|
_blocks->heightValue(
|
|
|
|
) | rpl::start_with_next([this](int blocksHeight) {
|
|
|
|
resize(width(), _blocks->y() + blocksHeight);
|
|
|
|
}, lifetime());
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
int InnerWidget::resizeGetHeight(int newWidth) {
|
2016-08-19 17:26:31 +00:00
|
|
|
if (_cover) {
|
2016-08-22 17:16:21 +00:00
|
|
|
_cover->setContentLeft(_contentLeft);
|
2016-08-19 17:26:31 +00:00
|
|
|
_cover->resizeToWidth(newWidth);
|
|
|
|
}
|
2017-09-13 16:57:44 +00:00
|
|
|
_blocks->resizeToWidth(newWidth - 2 * _contentLeft);
|
|
|
|
_blocks->moveToLeft(
|
|
|
|
_contentLeft,
|
|
|
|
(_cover ? (_cover->y() + _cover->height()) : 0)
|
|
|
|
+ st::settingsBlocksTop);
|
|
|
|
return height();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
void InnerWidget::visibleTopBottomUpdated(
|
|
|
|
int visibleTop,
|
|
|
|
int visibleBottom) {
|
|
|
|
setChildVisibleTopBottom(
|
|
|
|
_cover,
|
|
|
|
visibleTop,
|
|
|
|
visibleBottom);
|
|
|
|
setChildVisibleTopBottom(
|
|
|
|
_blocks,
|
|
|
|
visibleTop,
|
|
|
|
visibleBottom);
|
2016-08-17 15:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|