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 "settings/settings_common.h"
|
|
|
|
|
|
|
|
#include "settings/settings_chat.h"
|
2018-09-20 16:47:02 +00:00
|
|
|
#include "settings/settings_advanced.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
#include "settings/settings_information.h"
|
|
|
|
#include "settings/settings_main.h"
|
|
|
|
#include "settings/settings_notifications.h"
|
|
|
|
#include "settings/settings_privacy_security.h"
|
2018-09-06 17:58:44 +00:00
|
|
|
#include "ui/wrap/padding_wrap.h"
|
|
|
|
#include "ui/wrap/vertical_layout.h"
|
2018-09-07 09:40:25 +00:00
|
|
|
#include "ui/widgets/labels.h"
|
|
|
|
#include "info/profile/info_profile_button.h"
|
2018-09-06 17:58:44 +00:00
|
|
|
#include "boxes/abstract_box.h"
|
2018-09-06 15:24:24 +00:00
|
|
|
#include "lang/lang_keys.h"
|
|
|
|
#include "mainwindow.h"
|
2018-09-09 12:10:54 +00:00
|
|
|
#include "styles/style_boxes.h"
|
2018-09-06 17:58:44 +00:00
|
|
|
#include "styles/style_settings.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
|
|
|
|
namespace Settings {
|
|
|
|
|
|
|
|
object_ptr<Section> CreateSection(
|
|
|
|
Type type,
|
|
|
|
not_null<QWidget*> parent,
|
2018-09-11 18:07:04 +00:00
|
|
|
Window::Controller *controller,
|
2018-09-05 19:05:49 +00:00
|
|
|
UserData *self) {
|
|
|
|
switch (type) {
|
|
|
|
case Type::Main:
|
2018-09-13 20:09:26 +00:00
|
|
|
return object_ptr<Main>(parent, controller, self);
|
2018-09-05 19:05:49 +00:00
|
|
|
case Type::Information:
|
2018-09-13 20:09:26 +00:00
|
|
|
return object_ptr<Information>(parent, controller, self);
|
2018-09-05 19:05:49 +00:00
|
|
|
case Type::Notifications:
|
2018-09-13 20:09:26 +00:00
|
|
|
return object_ptr<Notifications>(parent, self);
|
2018-09-05 19:05:49 +00:00
|
|
|
case Type::PrivacySecurity:
|
2018-09-13 20:09:26 +00:00
|
|
|
return object_ptr<PrivacySecurity>(parent, self);
|
2018-09-20 16:47:02 +00:00
|
|
|
case Type::Advanced:
|
|
|
|
return object_ptr<Advanced>(parent, self);
|
2018-09-05 19:05:49 +00:00
|
|
|
case Type::Chat:
|
2018-09-13 20:09:26 +00:00
|
|
|
return object_ptr<Chat>(parent, self);
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
|
|
|
Unexpected("Settings section type in Widget::createInnerWidget.");
|
|
|
|
}
|
|
|
|
|
2018-09-07 09:40:25 +00:00
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container) {
|
2018-09-07 12:19:56 +00:00
|
|
|
AddSkip(container, st::settingsSectionSkip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip) {
|
2018-09-07 09:40:25 +00:00
|
|
|
container->add(object_ptr<Ui::FixedHeightWidget>(
|
|
|
|
container,
|
2018-09-07 12:19:56 +00:00
|
|
|
skip));
|
2018-09-07 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AddDivider(not_null<Ui::VerticalLayout*> container) {
|
|
|
|
container->add(object_ptr<BoxContentDivider>(container));
|
|
|
|
}
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
void AddDividerText(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text) {
|
|
|
|
container->add(object_ptr<Ui::DividerLabel>(
|
|
|
|
container,
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
std::move(text),
|
|
|
|
st::boxDividerLabel),
|
|
|
|
st::settingsDividerLabelPadding));
|
|
|
|
}
|
|
|
|
|
2018-09-07 09:40:25 +00:00
|
|
|
not_null<Button*> AddButton(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
LangKey text,
|
2018-09-10 12:18:39 +00:00
|
|
|
const style::InfoProfileButton &st,
|
|
|
|
const style::icon *leftIcon) {
|
2018-09-13 20:09:26 +00:00
|
|
|
return AddButton(container, Lang::Viewer(text), st, leftIcon);
|
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Button*> AddButton(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text,
|
|
|
|
const style::InfoProfileButton &st,
|
|
|
|
const style::icon *leftIcon) {
|
2018-09-10 12:18:39 +00:00
|
|
|
const auto result = container->add(object_ptr<Button>(
|
2018-09-07 09:40:25 +00:00
|
|
|
container,
|
2018-09-13 20:09:26 +00:00
|
|
|
std::move(text),
|
2018-09-07 09:40:25 +00:00
|
|
|
st));
|
2018-09-10 12:18:39 +00:00
|
|
|
if (leftIcon) {
|
|
|
|
const auto icon = Ui::CreateChild<Ui::RpWidget>(result);
|
|
|
|
icon->setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
icon->resize(leftIcon->size());
|
2018-09-13 20:09:26 +00:00
|
|
|
result->sizeValue(
|
|
|
|
) | rpl::start_with_next([=](QSize size) {
|
2018-09-10 12:18:39 +00:00
|
|
|
icon->moveToLeft(
|
2018-09-13 20:09:26 +00:00
|
|
|
st::settingsSectionIconLeft,
|
|
|
|
(size.height() - icon->height()) / 2,
|
|
|
|
size.width());
|
2018-09-10 12:18:39 +00:00
|
|
|
}, icon->lifetime());
|
|
|
|
icon->paintRequest(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
Painter p(icon);
|
|
|
|
const auto width = icon->width();
|
2018-09-13 20:09:26 +00:00
|
|
|
const auto paintOver = (result->isOver() || result->isDown())
|
|
|
|
&& !result->isDisabled();
|
|
|
|
if (paintOver) {
|
2018-09-10 12:18:39 +00:00
|
|
|
leftIcon->paint(p, QPoint(), width, st::menuIconFgOver->c);
|
|
|
|
} else {
|
|
|
|
leftIcon->paint(p, QPoint(), width);
|
|
|
|
}
|
|
|
|
}, icon->lifetime());
|
|
|
|
}
|
|
|
|
return result;
|
2018-09-07 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
void CreateRightLabel(
|
|
|
|
not_null<Button*> button,
|
2018-09-15 10:37:48 +00:00
|
|
|
rpl::producer<QString> label,
|
2018-09-17 10:52:34 +00:00
|
|
|
const style::InfoProfileButton &st,
|
|
|
|
LangKey buttonText) {
|
2018-09-07 09:40:25 +00:00
|
|
|
const auto name = Ui::CreateChild<Ui::FlatLabel>(
|
|
|
|
button.get(),
|
|
|
|
st::settingsButtonRight);
|
|
|
|
rpl::combine(
|
2018-09-17 10:52:34 +00:00
|
|
|
button->widthValue(),
|
|
|
|
Lang::Viewer(buttonText),
|
|
|
|
std::move(label)
|
|
|
|
) | rpl::start_with_next([=, &st](
|
|
|
|
int width,
|
|
|
|
const QString &button,
|
|
|
|
const QString &text) {
|
|
|
|
const auto available = width
|
|
|
|
- st.padding.left()
|
|
|
|
- st.padding.right()
|
|
|
|
- st.font->width(button)
|
|
|
|
- st::settingsButtonRightSkip;
|
|
|
|
name->setText(text);
|
|
|
|
name->resizeToNaturalWidth(available);
|
2018-09-15 10:37:48 +00:00
|
|
|
name->moveToRight(st::settingsButtonRightSkip, st.padding.top());
|
2018-09-07 09:40:25 +00:00
|
|
|
}, name->lifetime());
|
|
|
|
name->setAttribute(Qt::WA_TransparentForMouseEvents);
|
2018-09-09 12:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
not_null<Button*> AddButtonWithLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
LangKey text,
|
|
|
|
rpl::producer<QString> label,
|
2018-09-10 12:18:39 +00:00
|
|
|
const style::InfoProfileButton &st,
|
|
|
|
const style::icon *leftIcon) {
|
|
|
|
const auto button = AddButton(container, text, st, leftIcon);
|
2018-09-17 10:52:34 +00:00
|
|
|
CreateRightLabel(button, std::move(label), st, text);
|
2018-09-07 09:40:25 +00:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2018-09-09 12:10:54 +00:00
|
|
|
void AddSubsectionTitle(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
LangKey text) {
|
|
|
|
container->add(
|
|
|
|
object_ptr<Ui::FlatLabel>(
|
|
|
|
container,
|
|
|
|
Lang::Viewer(text),
|
|
|
|
st::settingsSubsectionTitle),
|
|
|
|
st::settingsSubsectionTitlePadding);
|
|
|
|
}
|
|
|
|
|
2018-09-06 15:24:24 +00:00
|
|
|
void FillMenu(Fn<void(Type)> showOther, MenuCallback addAction) {
|
|
|
|
addAction(
|
|
|
|
lang(lng_settings_edit_info),
|
|
|
|
[=] { showOther(Type::Information); });
|
|
|
|
addAction(
|
|
|
|
lang(lng_settings_logout),
|
|
|
|
[=] { App::wnd()->onLogout(); });
|
|
|
|
}
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
} // namespace Settings
|