2016-08-17 15:14:08 +00:00
|
|
|
/*
|
|
|
|
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-2016 John Preston, https://desktop.telegram.org
|
|
|
|
*/
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "settings/settings_inner_widget.h"
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
#include "styles/style_settings.h"
|
|
|
|
#include "settings/settings_cover.h"
|
|
|
|
#include "settings/settings_block_widget.h"
|
|
|
|
#include "settings/settings_info_widget.h"
|
|
|
|
#include "settings/settings_notifications_widget.h"
|
|
|
|
#include "settings/settings_general_widget.h"
|
|
|
|
#include "settings/settings_chat_settings_widget.h"
|
|
|
|
#include "settings/settings_scale_widget.h"
|
|
|
|
#include "settings/settings_background_widget.h"
|
|
|
|
#include "settings/settings_privacy_widget.h"
|
|
|
|
#include "settings/settings_advanced_widget.h"
|
|
|
|
|
2016-08-17 15:14:08 +00:00
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
InnerWidget::InnerWidget(QWidget *parent) : TWidget(parent)
|
2016-08-19 17:26:31 +00:00
|
|
|
, _self(App::self()) {
|
|
|
|
refreshBlocks();
|
2016-08-27 04:49:18 +00:00
|
|
|
subscribe(Global::RefSelfChanged(), [this]() { selfUpdated(); });
|
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::selfUpdated() {
|
|
|
|
_self = App::self();
|
|
|
|
refreshBlocks();
|
|
|
|
|
|
|
|
if (_cover) {
|
|
|
|
_cover->setContentLeft(_contentLeft);
|
|
|
|
_cover->resizeToWidth(width());
|
|
|
|
}
|
|
|
|
for_const (auto block, _blocks) {
|
|
|
|
block->setContentLeft(_contentLeft);
|
|
|
|
block->resizeToWidth(width());
|
|
|
|
}
|
|
|
|
onBlockHeightUpdated();
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::refreshBlocks() {
|
2016-08-27 04:49:18 +00:00
|
|
|
_cover.destroyDelayed();
|
2016-08-19 17:26:31 +00:00
|
|
|
for_const (auto block, _blocks) {
|
|
|
|
block->deleteLater();
|
|
|
|
}
|
|
|
|
_blocks.clear();
|
2016-08-27 04:49:18 +00:00
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
if (_self) {
|
2016-08-27 04:49:18 +00:00
|
|
|
_cover = new CoverWidget(this, _self);
|
2016-08-19 17:26:31 +00:00
|
|
|
_blocks.push_back(new Settings::InfoWidget(this, _self));
|
|
|
|
_blocks.push_back(new Settings::NotificationsWidget(this, _self));
|
|
|
|
}
|
|
|
|
_blocks.push_back(new Settings::GeneralWidget(this, _self));
|
|
|
|
_blocks.push_back(new Settings::ScaleWidget(this, _self));
|
|
|
|
if (_self) {
|
|
|
|
_blocks.push_back(new Settings::ChatSettingsWidget(this, _self));
|
|
|
|
_blocks.push_back(new Settings::BackgroundWidget(this, _self));
|
|
|
|
_blocks.push_back(new Settings::PrivacyWidget(this, _self));
|
|
|
|
}
|
|
|
|
_blocks.push_back(new Settings::AdvancedWidget(this, _self));
|
2016-08-27 04:49:18 +00:00
|
|
|
|
|
|
|
if (_cover) {
|
|
|
|
_cover->show();
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
for_const (auto block, _blocks) {
|
2016-08-27 04:49:18 +00:00
|
|
|
block->show();
|
2016-08-22 17:16:21 +00:00
|
|
|
connect(block, SIGNAL(heightUpdated()), this, SLOT(onBlockHeightUpdated()));
|
|
|
|
}
|
2016-08-19 17:26:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InnerWidget::showFinished() {
|
|
|
|
if (_cover) {
|
|
|
|
_cover->showFinished();
|
|
|
|
}
|
2016-08-17 15:14:08 +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);
|
|
|
|
}
|
2016-08-22 17:16:21 +00:00
|
|
|
for_const (auto block, _blocks) {
|
|
|
|
block->setContentLeft(_contentLeft);
|
|
|
|
block->resizeToWidth(newWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
int result = refreshBlocksPositions();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
int InnerWidget::refreshBlocksPositions() {
|
|
|
|
int result = (_cover ? _cover->height() : 0) + st::settingsBlocksTop;
|
2016-08-19 17:26:31 +00:00
|
|
|
for_const (auto block, _blocks) {
|
|
|
|
if (block->isHidden()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
block->moveToLeft(0, result);
|
|
|
|
result += block->height();
|
|
|
|
}
|
2016-08-17 15:14:08 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-08-22 17:16:21 +00:00
|
|
|
void InnerWidget::onBlockHeightUpdated() {
|
|
|
|
int newHeight = refreshBlocksPositions();
|
|
|
|
if (newHeight != height()) {
|
|
|
|
resize(width(), newHeight);
|
2016-08-27 04:49:18 +00:00
|
|
|
emit heightUpdated();
|
2016-08-22 17:16:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-17 15:14:08 +00:00
|
|
|
void InnerWidget::setVisibleTopBottom(int visibleTop, int visibleBottom) {
|
|
|
|
_visibleTop = visibleTop;
|
|
|
|
_visibleBottom = visibleBottom;
|
|
|
|
|
2016-08-19 17:26:31 +00:00
|
|
|
for_const (auto block, _blocks) {
|
|
|
|
int blockY = block->y();
|
|
|
|
block->setVisibleTopBottom(visibleTop - blockY, visibleBottom - blockY);
|
|
|
|
}
|
2016-08-17 15:14:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Settings
|