2018-09-05 22:05:49 +03: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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
2022-02-09 13:43:07 +03:00
|
|
|
#include "ui/round_rect.h"
|
2019-09-13 15:22:54 +03:00
|
|
|
#include "base/object_ptr.h"
|
2018-09-05 22:05:49 +03:00
|
|
|
|
2019-07-24 16:00:30 +02:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2018-09-06 20:58:44 +03:00
|
|
|
namespace Ui {
|
|
|
|
class VerticalLayout;
|
2019-09-04 18:59:43 +03:00
|
|
|
class FlatLabel;
|
2019-11-02 20:06:47 +03:00
|
|
|
class SettingsButton;
|
2021-05-06 19:57:40 +04:00
|
|
|
class AbstractButton;
|
2018-09-06 20:58:44 +03:00
|
|
|
} // namespace Ui
|
|
|
|
|
2018-09-05 22:39:35 +03:00
|
|
|
namespace Window {
|
2019-06-06 13:21:40 +03:00
|
|
|
class SessionController;
|
2018-09-05 22:39:35 +03:00
|
|
|
} // namespace Window
|
|
|
|
|
2018-09-07 12:40:25 +03:00
|
|
|
namespace style {
|
2022-03-01 08:22:56 +03:00
|
|
|
struct FlatLabel;
|
2019-11-02 20:06:47 +03:00
|
|
|
struct SettingsButton;
|
2018-09-07 12:40:25 +03:00
|
|
|
} // namespace style
|
|
|
|
|
2018-09-05 22:05:49 +03:00
|
|
|
namespace Settings {
|
|
|
|
|
2022-03-14 10:20:36 +04:00
|
|
|
extern const char kOptionMonoSettingsIcons[];
|
|
|
|
|
2018-09-05 22:05:49 +03:00
|
|
|
enum class Type {
|
|
|
|
Main,
|
|
|
|
Information,
|
|
|
|
Notifications,
|
|
|
|
PrivacySecurity,
|
2021-11-29 17:29:45 +04:00
|
|
|
Sessions,
|
2018-09-20 19:47:02 +03:00
|
|
|
Advanced,
|
2018-09-05 22:05:49 +03:00
|
|
|
Chat,
|
2020-03-18 14:07:11 +04:00
|
|
|
Folders,
|
2019-01-05 14:08:02 +03:00
|
|
|
Calls,
|
2022-01-25 16:25:51 +03:00
|
|
|
Experimental,
|
2018-09-05 22:05:49 +03:00
|
|
|
};
|
|
|
|
|
2019-11-02 20:06:47 +03:00
|
|
|
using Button = Ui::SettingsButton;
|
2018-09-05 22:05:49 +03:00
|
|
|
|
|
|
|
class Section : public Ui::RpWidget {
|
|
|
|
public:
|
|
|
|
using RpWidget::RpWidget;
|
|
|
|
|
|
|
|
virtual rpl::producer<Type> sectionShowOther() {
|
2019-06-18 16:07:45 +02:00
|
|
|
return nullptr;
|
2018-09-05 22:05:49 +03:00
|
|
|
}
|
2018-09-09 20:38:08 +03:00
|
|
|
virtual void sectionSaveChanges(FnMut<void()> done) {
|
|
|
|
done();
|
|
|
|
}
|
2018-09-05 22:05:49 +03:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2022-02-09 13:43:07 +03:00
|
|
|
inline constexpr auto kIconRed = 1;
|
|
|
|
inline constexpr auto kIconGreen = 2;
|
|
|
|
inline constexpr auto kIconLightOrange = 3;
|
|
|
|
inline constexpr auto kIconLightBlue = 4;
|
|
|
|
inline constexpr auto kIconDarkBlue = 5;
|
|
|
|
inline constexpr auto kIconPurple = 6;
|
|
|
|
inline constexpr auto kIconDarkOrange = 8;
|
|
|
|
inline constexpr auto kIconGray = 9;
|
|
|
|
|
2022-02-10 12:56:57 +03:00
|
|
|
enum class IconType {
|
|
|
|
Rounded,
|
|
|
|
Round,
|
|
|
|
};
|
|
|
|
|
2022-02-09 13:43:07 +03:00
|
|
|
struct IconDescriptor {
|
|
|
|
const style::icon *icon = nullptr;
|
|
|
|
int color = 0; // settingsIconBg{color}, 9 for settingsIconBgArchive.
|
2022-02-10 12:56:57 +03:00
|
|
|
IconType type = IconType::Rounded;
|
2022-02-09 13:43:07 +03:00
|
|
|
const style::color *background = nullptr;
|
|
|
|
|
|
|
|
explicit operator bool() const {
|
|
|
|
return (icon != nullptr);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Icon final {
|
|
|
|
public:
|
|
|
|
explicit Icon(IconDescriptor descriptor);
|
|
|
|
|
|
|
|
void paint(QPainter &p, QPoint position) const;
|
|
|
|
void paint(QPainter &p, int x, int y) const;
|
|
|
|
|
|
|
|
[[nodiscard]] int width() const;
|
|
|
|
[[nodiscard]] int height() const;
|
|
|
|
[[nodiscard]] QSize size() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
not_null<const style::icon*> _icon;
|
|
|
|
std::optional<Ui::RoundRect> _background;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-09-05 22:05:49 +03:00
|
|
|
object_ptr<Section> CreateSection(
|
|
|
|
Type type,
|
|
|
|
not_null<QWidget*> parent,
|
2019-07-24 16:00:30 +02:00
|
|
|
not_null<Window::SessionController*> controller);
|
2018-09-05 22:05:49 +03:00
|
|
|
|
2018-09-06 20:58:44 +03:00
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container);
|
2018-09-07 15:19:56 +03:00
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip);
|
2018-09-06 20:58:44 +03:00
|
|
|
void AddDivider(not_null<Ui::VerticalLayout*> container);
|
2018-09-09 15:10:54 +03:00
|
|
|
void AddDividerText(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text);
|
2022-02-09 13:43:07 +03:00
|
|
|
void AddButtonIcon(
|
2021-05-06 19:57:40 +04:00
|
|
|
not_null<Ui::AbstractButton*> button,
|
2022-02-09 13:43:07 +03:00
|
|
|
const style::SettingsButton &st,
|
|
|
|
IconDescriptor &&descriptor);
|
2020-03-24 11:26:08 +04:00
|
|
|
object_ptr<Button> CreateButton(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
rpl::producer<QString> text,
|
|
|
|
const style::SettingsButton &st,
|
2022-02-09 13:43:07 +03:00
|
|
|
IconDescriptor &&descriptor = {});
|
2018-09-13 23:09:26 +03:00
|
|
|
not_null<Button*> AddButton(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text,
|
2019-11-02 20:06:47 +03:00
|
|
|
const style::SettingsButton &st,
|
2022-02-09 13:43:07 +03:00
|
|
|
IconDescriptor &&descriptor = {});
|
2018-09-07 12:40:25 +03:00
|
|
|
not_null<Button*> AddButtonWithLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2019-06-18 14:16:43 +02:00
|
|
|
rpl::producer<QString> text,
|
2018-09-07 12:40:25 +03:00
|
|
|
rpl::producer<QString> label,
|
2019-11-02 20:06:47 +03:00
|
|
|
const style::SettingsButton &st,
|
2022-02-09 13:43:07 +03:00
|
|
|
IconDescriptor &&descriptor = {});
|
2018-09-09 15:10:54 +03:00
|
|
|
void CreateRightLabel(
|
|
|
|
not_null<Button*> button,
|
2018-09-15 13:37:48 +03:00
|
|
|
rpl::producer<QString> label,
|
2019-11-02 20:06:47 +03:00
|
|
|
const style::SettingsButton &st,
|
2019-06-18 14:16:43 +02:00
|
|
|
rpl::producer<QString> buttonText);
|
2019-09-04 18:59:43 +03:00
|
|
|
not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
2018-09-29 15:18:26 +03:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-02-13 16:30:43 +03:00
|
|
|
rpl::producer<QString> text,
|
2022-03-01 08:22:56 +03:00
|
|
|
style::margins addPadding = {},
|
|
|
|
const style::FlatLabel *st = nullptr);
|
2018-09-06 20:58:44 +03:00
|
|
|
|
2018-09-06 18:24:24 +03:00
|
|
|
using MenuCallback = Fn<QAction*(
|
|
|
|
const QString &text,
|
2021-12-09 21:56:24 +04:00
|
|
|
Fn<void()> handler,
|
|
|
|
const style::icon *icon)>;
|
2018-09-06 18:24:24 +03:00
|
|
|
|
|
|
|
void FillMenu(
|
2019-09-08 15:47:22 +03:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Type type,
|
2018-09-06 18:24:24 +03:00
|
|
|
Fn<void(Type)> showOther,
|
|
|
|
MenuCallback addAction);
|
|
|
|
|
2018-09-05 22:05:49 +03:00
|
|
|
} // namespace Settings
|