2016-08-16 19:53:10 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-08-16 19:53:10 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-08-16 19:53:10 +03:00
|
|
|
*/
|
2018-09-02 17:23:52 +03:00
|
|
|
#include "old_settings/settings_widget.h"
|
2016-08-16 19:53:10 +03:00
|
|
|
|
2018-09-02 17:23:52 +03:00
|
|
|
#include "old_settings/settings_inner_widget.h"
|
|
|
|
#include "old_settings/settings_fixed_bar.h"
|
2018-03-18 12:51:14 +04:00
|
|
|
#include "platform/platform_specific.h"
|
2016-11-16 13:44:06 +03:00
|
|
|
#include "ui/widgets/scroll_area.h"
|
2016-12-13 20:07:56 +03:00
|
|
|
#include "ui/widgets/buttons.h"
|
2018-03-18 12:51:14 +04:00
|
|
|
#include "ui/toast/toast.h"
|
2016-08-17 18:14:08 +03:00
|
|
|
#include "mainwindow.h"
|
2016-09-25 22:04:02 +03:00
|
|
|
#include "mainwidget.h"
|
2018-06-20 01:02:36 +01:00
|
|
|
#include "data/data_session.h"
|
2017-03-04 13:23:56 +03:00
|
|
|
#include "storage/localstorage.h"
|
2017-04-06 17:38:10 +03:00
|
|
|
#include "boxes/confirm_box.h"
|
2017-04-13 11:27:10 +03:00
|
|
|
#include "lang/lang_keys.h"
|
2017-05-30 20:58:25 +03:00
|
|
|
#include "lang/lang_cloud_manager.h"
|
2017-02-23 13:59:19 +03:00
|
|
|
#include "messenger.h"
|
2017-03-01 20:22:37 +03:00
|
|
|
#include "mtproto/mtp_instance.h"
|
|
|
|
#include "mtproto/dc_options.h"
|
2017-02-28 17:05:30 +03:00
|
|
|
#include "core/file_utilities.h"
|
2018-04-27 17:08:04 +04:00
|
|
|
#include "core/update_checker.h"
|
2017-02-03 23:07:26 +03:00
|
|
|
#include "window/themes/window_theme.h"
|
|
|
|
#include "window/themes/window_theme_editor.h"
|
2017-05-08 12:08:24 +03:00
|
|
|
#include "media/media_audio_track.h"
|
2018-06-02 17:29:21 +03:00
|
|
|
#include "mainwindow.h"
|
|
|
|
#include "window/window_controller.h"
|
2018-09-02 17:23:52 +03:00
|
|
|
#include "styles/style_old_settings.h"
|
2018-06-20 01:02:36 +01:00
|
|
|
#include "styles/style_window.h"
|
|
|
|
#include "styles/style_boxes.h"
|
2016-08-17 18:14:08 +03:00
|
|
|
|
2018-09-02 17:23:52 +03:00
|
|
|
namespace OldSettings {
|
2016-08-16 19:53:10 +03:00
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
Widget::Widget(QWidget *parent) {
|
2017-04-18 20:37:14 +03:00
|
|
|
refreshLang();
|
2017-05-30 16:54:05 +03:00
|
|
|
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
|
2017-04-18 20:37:14 +03:00
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
_inner = setInnerWidget(object_ptr<InnerWidget>(this));
|
|
|
|
setCloseClickHandler([]() {
|
2016-12-13 20:07:56 +03:00
|
|
|
Ui::hideSettingsAndLayer();
|
|
|
|
});
|
2017-02-03 23:07:26 +03:00
|
|
|
}
|
2016-08-26 22:49:18 -06:00
|
|
|
|
2017-04-18 20:37:14 +03:00
|
|
|
void Widget::refreshLang() {
|
|
|
|
setTitle(lang(lng_menu_settings));
|
|
|
|
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2018-04-18 19:42:02 +04:00
|
|
|
void Widget::scrollToUpdateRow() {
|
|
|
|
if (const auto top = _inner->getUpdateTop(); top >= 0) {
|
|
|
|
scrollToY(top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
void Widget::keyPressEvent(QKeyEvent *e) {
|
|
|
|
return LayerWidget::keyPressEvent(e);
|
2016-12-13 20:07:56 +03:00
|
|
|
}
|
|
|
|
|
2016-08-17 18:14:08 +03:00
|
|
|
void Widget::parentResized() {
|
2016-11-05 11:36:24 +03:00
|
|
|
auto parentSize = parentWidget()->size();
|
2017-02-03 23:07:26 +03:00
|
|
|
auto windowWidth = parentSize.width();
|
|
|
|
auto newWidth = st::settingsMaxWidth;
|
|
|
|
auto newContentLeft = st::settingsMaxPadding;
|
2016-08-17 18:14:08 +03:00
|
|
|
if (windowWidth <= st::settingsMaxWidth) {
|
|
|
|
newWidth = windowWidth;
|
|
|
|
newContentLeft = st::settingsMinPadding;
|
2016-11-04 11:23:50 +03:00
|
|
|
if (windowWidth > st::windowMinWidth) {
|
|
|
|
// Width changes from st::windowMinWidth to st::settingsMaxWidth.
|
2016-08-17 18:14:08 +03:00
|
|
|
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
|
2016-11-04 11:23:50 +03:00
|
|
|
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
|
2016-08-17 18:14:08 +03:00
|
|
|
}
|
|
|
|
} else if (windowWidth < st::settingsMaxWidth + 2 * st::settingsMargin) {
|
|
|
|
newWidth = windowWidth - 2 * st::settingsMargin;
|
|
|
|
newContentLeft = st::settingsMinPadding;
|
2016-11-04 11:23:50 +03:00
|
|
|
if (windowWidth > st::windowMinWidth) {
|
|
|
|
// Width changes from st::windowMinWidth to st::settingsMaxWidth.
|
2016-08-17 18:14:08 +03:00
|
|
|
// Padding changes from st::settingsMinPadding to st::settingsMaxPadding.
|
2016-11-04 11:23:50 +03:00
|
|
|
newContentLeft += ((newWidth - st::windowMinWidth) * (st::settingsMaxPadding - st::settingsMinPadding)) / (st::settingsMaxWidth - st::windowMinWidth);
|
2016-08-17 18:14:08 +03:00
|
|
|
}
|
|
|
|
}
|
2017-02-03 23:07:26 +03:00
|
|
|
resizeToWidth(newWidth, newContentLeft);
|
2016-08-26 22:49:18 -06:00
|
|
|
}
|
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
void Widget::resizeUsingInnerHeight(int newWidth, int innerHeight) {
|
2017-09-13 19:57:44 +03:00
|
|
|
if (!parentWidget()) return;
|
2016-08-26 22:49:18 -06:00
|
|
|
|
2016-11-05 11:36:24 +03:00
|
|
|
auto parentSize = parentWidget()->size();
|
2017-02-03 23:07:26 +03:00
|
|
|
auto windowWidth = parentSize.width();
|
|
|
|
auto windowHeight = parentSize.height();
|
|
|
|
auto maxHeight = st::settingsFixedBarHeight + innerHeight;
|
|
|
|
auto newHeight = maxHeight + st::boxRadius;
|
2016-08-17 18:14:08 +03:00
|
|
|
if (newHeight > windowHeight || newWidth >= windowWidth) {
|
|
|
|
newHeight = windowHeight;
|
|
|
|
}
|
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
auto roundedCorners = newHeight < windowHeight;
|
|
|
|
setRoundedCorners(roundedCorners);
|
|
|
|
setAttribute(Qt::WA_OpaquePaintEvent, !roundedCorners);
|
2016-12-13 20:07:56 +03:00
|
|
|
|
2016-11-05 11:36:24 +03:00
|
|
|
setGeometry((windowWidth - newWidth) / 2, (windowHeight - newHeight) / 2, newWidth, newHeight);
|
2016-08-17 18:14:08 +03:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2016-08-16 19:53:10 +03:00
|
|
|
} // namespace Settings
|