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
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/rp_widget.h"
|
2022-02-09 10:43:07 +00:00
|
|
|
#include "ui/round_rect.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2022-04-01 11:53:23 +00:00
|
|
|
#include "settings/settings_type.h"
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2022-05-04 07:39:53 +00:00
|
|
|
namespace anim {
|
|
|
|
enum class repeat : uchar;
|
|
|
|
} // namespace anim
|
|
|
|
|
2019-07-24 14:00:30 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
|
|
|
|
2018-09-06 17:58:44 +00:00
|
|
|
namespace Ui {
|
|
|
|
class VerticalLayout;
|
2019-09-04 15:59:43 +00:00
|
|
|
class FlatLabel;
|
2019-11-02 17:06:47 +00:00
|
|
|
class SettingsButton;
|
2021-05-06 15:57:40 +00:00
|
|
|
class AbstractButton;
|
2023-01-05 10:48:46 +00:00
|
|
|
class MediaSlider;
|
2018-09-06 17:58:44 +00:00
|
|
|
} // namespace Ui
|
|
|
|
|
2022-06-03 16:07:33 +00:00
|
|
|
namespace Ui::Menu {
|
|
|
|
struct MenuCallback;
|
|
|
|
} // namespace Ui::Menu
|
|
|
|
|
2018-09-05 19:39:35 +00:00
|
|
|
namespace Window {
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2018-09-05 19:39:35 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2018-09-07 09:40:25 +00:00
|
|
|
namespace style {
|
2022-03-01 05:22:56 +00:00
|
|
|
struct FlatLabel;
|
2019-11-02 17:06:47 +00:00
|
|
|
struct SettingsButton;
|
2023-01-05 10:48:46 +00:00
|
|
|
struct MediaSlider;
|
2018-09-07 09:40:25 +00:00
|
|
|
} // namespace style
|
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
namespace Lottie {
|
|
|
|
struct IconDescriptor;
|
|
|
|
} // namespace Lottie
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
namespace Settings {
|
|
|
|
|
2022-03-14 06:20:36 +00:00
|
|
|
extern const char kOptionMonoSettingsIcons[];
|
|
|
|
|
2022-04-01 11:53:23 +00:00
|
|
|
using Button = Ui::SettingsButton;
|
|
|
|
|
|
|
|
class AbstractSection;
|
|
|
|
|
|
|
|
struct SectionMeta {
|
|
|
|
[[nodiscard]] virtual object_ptr<AbstractSection> create(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller) const = 0;
|
2018-09-05 19:05:49 +00:00
|
|
|
};
|
|
|
|
|
2022-04-01 11:53:23 +00:00
|
|
|
template <typename SectionType>
|
|
|
|
struct SectionMetaImplementation : SectionMeta {
|
|
|
|
object_ptr<AbstractSection> create(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
not_null<Window::SessionController*> controller
|
|
|
|
) const final override {
|
|
|
|
return object_ptr<SectionType>(parent, controller);
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] static not_null<SectionMeta*> Meta() {
|
|
|
|
static SectionMetaImplementation result;
|
|
|
|
return &result;
|
|
|
|
}
|
|
|
|
};
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2022-04-01 11:53:23 +00:00
|
|
|
class AbstractSection : public Ui::RpWidget {
|
2018-09-05 19:05:49 +00:00
|
|
|
public:
|
|
|
|
using RpWidget::RpWidget;
|
|
|
|
|
2022-04-01 11:53:23 +00:00
|
|
|
[[nodiscard]] virtual Type id() const = 0;
|
|
|
|
[[nodiscard]] virtual rpl::producer<Type> sectionShowOther() {
|
2019-06-18 14:07:45 +00:00
|
|
|
return nullptr;
|
2018-09-05 19:05:49 +00:00
|
|
|
}
|
2022-05-04 15:05:10 +00:00
|
|
|
[[nodiscard]] virtual rpl::producer<> sectionShowBack() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-05-03 04:02:51 +00:00
|
|
|
[[nodiscard]] virtual rpl::producer<std::vector<Type>> removeFromStack() {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-04-13 08:05:10 +00:00
|
|
|
[[nodiscard]] virtual rpl::producer<QString> title() = 0;
|
2018-09-09 17:38:08 +00:00
|
|
|
virtual void sectionSaveChanges(FnMut<void()> done) {
|
|
|
|
done();
|
|
|
|
}
|
2022-04-13 08:05:10 +00:00
|
|
|
virtual void showFinished() {
|
|
|
|
}
|
2022-05-04 03:53:42 +00:00
|
|
|
virtual void setInnerFocus() {
|
2022-05-13 15:38:28 +00:00
|
|
|
setFocus();
|
2022-05-04 03:53:42 +00:00
|
|
|
}
|
2022-05-31 17:11:59 +00:00
|
|
|
[[nodiscard]] virtual const Ui::RoundRect *bottomSkipRounding() const {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-05-01 12:33:32 +00:00
|
|
|
[[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToTop(
|
|
|
|
not_null<QWidget*> parent) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-05-03 15:43:04 +00:00
|
|
|
[[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToBottom(
|
|
|
|
not_null<Ui::RpWidget*> parent) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-05-21 03:25:01 +00:00
|
|
|
[[nodiscard]] virtual bool hasFlexibleTopBar() const {
|
|
|
|
return false;
|
|
|
|
}
|
2022-05-05 20:20:05 +00:00
|
|
|
virtual void setStepDataReference(std::any &data) {
|
|
|
|
}
|
2022-04-01 11:53:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename SectionType>
|
|
|
|
class Section : public AbstractSection {
|
|
|
|
public:
|
|
|
|
using AbstractSection::AbstractSection;
|
2018-09-05 19:05:49 +00:00
|
|
|
|
2022-04-01 11:53:23 +00:00
|
|
|
[[nodiscard]] static Type Id() {
|
|
|
|
return &SectionMetaImplementation<SectionType>::Meta;
|
|
|
|
}
|
|
|
|
[[nodiscard]] Type id() const final override {
|
|
|
|
return Id();
|
|
|
|
}
|
2018-09-05 19:05:49 +00:00
|
|
|
};
|
|
|
|
|
2022-02-09 10:43:07 +00: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 09:56:57 +00:00
|
|
|
enum class IconType {
|
|
|
|
Rounded,
|
|
|
|
Round,
|
|
|
|
};
|
|
|
|
|
2022-02-09 10:43:07 +00:00
|
|
|
struct IconDescriptor {
|
|
|
|
const style::icon *icon = nullptr;
|
|
|
|
int color = 0; // settingsIconBg{color}, 9 for settingsIconBgArchive.
|
2022-02-10 09:56:57 +00:00
|
|
|
IconType type = IconType::Rounded;
|
2022-02-09 10:43:07 +00:00
|
|
|
const style::color *background = nullptr;
|
2022-05-18 23:35:39 +00:00
|
|
|
std::optional<QBrush> backgroundBrush; // Can be useful for gragdients.
|
2022-02-09 10:43:07 +00:00
|
|
|
|
|
|
|
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;
|
2022-05-18 23:35:39 +00:00
|
|
|
std::optional<std::pair<int, QBrush>> _backgroundBrush;
|
2022-02-09 10:43:07 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-09-06 17:58:44 +00:00
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container);
|
2018-09-07 12:19:56 +00:00
|
|
|
void AddSkip(not_null<Ui::VerticalLayout*> container, int skip);
|
2018-09-06 17:58:44 +00:00
|
|
|
void AddDivider(not_null<Ui::VerticalLayout*> container);
|
2018-09-09 12:10:54 +00:00
|
|
|
void AddDividerText(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text);
|
2022-02-09 10:43:07 +00:00
|
|
|
void AddButtonIcon(
|
2021-05-06 15:57:40 +00:00
|
|
|
not_null<Ui::AbstractButton*> button,
|
2022-02-09 10:43:07 +00:00
|
|
|
const style::SettingsButton &st,
|
|
|
|
IconDescriptor &&descriptor);
|
2020-03-24 07:26:08 +00:00
|
|
|
object_ptr<Button> CreateButton(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
rpl::producer<QString> text,
|
|
|
|
const style::SettingsButton &st,
|
2022-02-09 10:43:07 +00:00
|
|
|
IconDescriptor &&descriptor = {});
|
2018-09-13 20:09:26 +00:00
|
|
|
not_null<Button*> AddButton(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
|
|
|
rpl::producer<QString> text,
|
2019-11-02 17:06:47 +00:00
|
|
|
const style::SettingsButton &st,
|
2022-02-09 10:43:07 +00:00
|
|
|
IconDescriptor &&descriptor = {});
|
2018-09-07 09:40:25 +00:00
|
|
|
not_null<Button*> AddButtonWithLabel(
|
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> text,
|
2018-09-07 09:40:25 +00:00
|
|
|
rpl::producer<QString> label,
|
2019-11-02 17:06:47 +00:00
|
|
|
const style::SettingsButton &st,
|
2022-02-09 10:43:07 +00:00
|
|
|
IconDescriptor &&descriptor = {});
|
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,
|
2019-11-02 17:06:47 +00:00
|
|
|
const style::SettingsButton &st,
|
2019-06-18 12:16:43 +00:00
|
|
|
rpl::producer<QString> buttonText);
|
2019-09-04 15:59:43 +00:00
|
|
|
not_null<Ui::FlatLabel*> AddSubsectionTitle(
|
2018-09-29 12:18:26 +00:00
|
|
|
not_null<Ui::VerticalLayout*> container,
|
2022-02-13 13:30:43 +00:00
|
|
|
rpl::producer<QString> text,
|
2022-03-01 05:22:56 +00:00
|
|
|
style::margins addPadding = {},
|
|
|
|
const style::FlatLabel *st = nullptr);
|
2023-01-07 05:15:27 +00:00
|
|
|
void AddDividerTextWithLottie(
|
|
|
|
not_null<Ui::VerticalLayout*> parent,
|
|
|
|
rpl::producer<> showFinished,
|
|
|
|
rpl::producer<TextWithEntities> text,
|
|
|
|
const QString &lottie);
|
2018-09-06 17:58:44 +00:00
|
|
|
|
2022-04-13 08:05:10 +00:00
|
|
|
struct LottieIcon {
|
|
|
|
object_ptr<Ui::RpWidget> widget;
|
2022-05-04 07:39:53 +00:00
|
|
|
Fn<void(anim::repeat repeat)> animate;
|
2022-04-13 08:05:10 +00:00
|
|
|
};
|
|
|
|
[[nodiscard]] LottieIcon CreateLottieIcon(
|
|
|
|
not_null<QWidget*> parent,
|
|
|
|
Lottie::IconDescriptor &&descriptor,
|
2022-05-04 07:39:53 +00:00
|
|
|
style::margins padding = {});
|
2022-04-13 08:05:10 +00:00
|
|
|
|
2018-09-06 15:24:24 +00:00
|
|
|
void FillMenu(
|
2019-09-08 12:47:22 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
|
|
|
Type type,
|
2018-09-06 15:24:24 +00:00
|
|
|
Fn<void(Type)> showOther,
|
2022-06-03 16:07:33 +00:00
|
|
|
Ui::Menu::MenuCallback addAction);
|
2018-09-06 15:24:24 +00:00
|
|
|
|
2023-01-05 10:48:46 +00:00
|
|
|
struct SliderWithLabel {
|
|
|
|
object_ptr<Ui::RpWidget> widget;
|
|
|
|
not_null<Ui::MediaSlider*> slider;
|
|
|
|
not_null<Ui::FlatLabel*> label;
|
|
|
|
};
|
|
|
|
[[nodiscard]] SliderWithLabel MakeSliderWithLabel(
|
|
|
|
QWidget *parent,
|
|
|
|
const style::MediaSlider &sliderSt,
|
|
|
|
const style::FlatLabel &labelSt,
|
|
|
|
int skip,
|
|
|
|
int minLabelWidth = 0);
|
|
|
|
|
2018-09-05 19:05:49 +00:00
|
|
|
} // namespace Settings
|