settings_common.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "ui/text/text_variant.h"
  9. #include "ui/rp_widget.h"
  10. #include "ui/round_rect.h"
  11. #include "base/object_ptr.h"
  12. #include "settings/settings_type.h"
  13. namespace anim {
  14. enum class repeat : uchar;
  15. } // namespace anim
  16. namespace Info {
  17. struct SelectedItems;
  18. enum class SelectionAction;
  19. } // namespace Info
  20. namespace Main {
  21. class Session;
  22. } // namespace Main
  23. namespace Ui {
  24. class VerticalLayout;
  25. class FlatLabel;
  26. class SettingsButton;
  27. class AbstractButton;
  28. class MediaSlider;
  29. } // namespace Ui
  30. namespace Ui::Menu {
  31. struct MenuCallback;
  32. } // namespace Ui::Menu
  33. namespace Window {
  34. class SessionController;
  35. } // namespace Window
  36. namespace style {
  37. struct FlatLabel;
  38. struct SettingsButton;
  39. struct MediaSlider;
  40. } // namespace style
  41. namespace Lottie {
  42. struct IconDescriptor;
  43. } // namespace Lottie
  44. namespace Settings {
  45. using Button = Ui::SettingsButton;
  46. class AbstractSection : public Ui::RpWidget {
  47. public:
  48. using RpWidget::RpWidget;
  49. [[nodiscard]] virtual Type id() const = 0;
  50. [[nodiscard]] virtual rpl::producer<Type> sectionShowOther() {
  51. return nullptr;
  52. }
  53. [[nodiscard]] virtual rpl::producer<> sectionShowBack() {
  54. return nullptr;
  55. }
  56. [[nodiscard]] virtual rpl::producer<std::vector<Type>> removeFromStack() {
  57. return nullptr;
  58. }
  59. [[nodiscard]] virtual bool closeByOutsideClick() const {
  60. return true;
  61. }
  62. virtual void checkBeforeClose(Fn<void()> close) {
  63. close();
  64. }
  65. [[nodiscard]] virtual rpl::producer<QString> title() = 0;
  66. virtual void sectionSaveChanges(FnMut<void()> done) {
  67. done();
  68. }
  69. virtual void showFinished() {
  70. }
  71. virtual void setInnerFocus() {
  72. setFocus();
  73. }
  74. [[nodiscard]] virtual const Ui::RoundRect *bottomSkipRounding() const {
  75. return nullptr;
  76. }
  77. [[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToTop(
  78. not_null<QWidget*> parent) {
  79. return nullptr;
  80. }
  81. [[nodiscard]] virtual QPointer<Ui::RpWidget> createPinnedToBottom(
  82. not_null<Ui::RpWidget*> parent) {
  83. return nullptr;
  84. }
  85. [[nodiscard]] virtual bool hasFlexibleTopBar() const {
  86. return false;
  87. }
  88. virtual void setStepDataReference(std::any &data) {
  89. }
  90. [[nodiscard]] virtual auto selectedListValue()
  91. -> rpl::producer<Info::SelectedItems> {
  92. return nullptr;
  93. }
  94. virtual void selectionAction(Info::SelectionAction action) {
  95. }
  96. virtual void fillTopBarMenu(
  97. const Ui::Menu::MenuCallback &addAction) {
  98. }
  99. virtual bool paintOuter(
  100. not_null<QWidget*> outer,
  101. int maxVisibleHeight,
  102. QRect clip) {
  103. return false;
  104. }
  105. };
  106. enum class IconType {
  107. Rounded,
  108. Round,
  109. Simple,
  110. };
  111. struct IconDescriptor {
  112. const style::icon *icon = nullptr;
  113. IconType type = IconType::Rounded;
  114. const style::color *background = nullptr;
  115. std::optional<QBrush> backgroundBrush; // Can be useful for gradients.
  116. bool newBadge = false;
  117. explicit operator bool() const {
  118. return (icon != nullptr);
  119. }
  120. };
  121. class Icon final {
  122. public:
  123. explicit Icon(IconDescriptor descriptor);
  124. void paint(QPainter &p, QPoint position) const;
  125. void paint(QPainter &p, int x, int y) const;
  126. [[nodiscard]] int width() const;
  127. [[nodiscard]] int height() const;
  128. [[nodiscard]] QSize size() const;
  129. private:
  130. not_null<const style::icon*> _icon;
  131. std::optional<Ui::RoundRect> _background;
  132. std::optional<std::pair<int, QBrush>> _backgroundBrush;
  133. };
  134. void AddButtonIcon(
  135. not_null<Ui::AbstractButton*> button,
  136. const style::SettingsButton &st,
  137. IconDescriptor &&descriptor);
  138. object_ptr<Button> CreateButtonWithIcon(
  139. not_null<QWidget*> parent,
  140. rpl::producer<QString> text,
  141. const style::SettingsButton &st,
  142. IconDescriptor &&descriptor = {});
  143. not_null<Button*> AddButtonWithIcon(
  144. not_null<Ui::VerticalLayout*> container,
  145. rpl::producer<QString> text,
  146. const style::SettingsButton &st,
  147. IconDescriptor &&descriptor = {});
  148. not_null<Button*> AddButtonWithLabel(
  149. not_null<Ui::VerticalLayout*> container,
  150. rpl::producer<QString> text,
  151. rpl::producer<QString> label,
  152. const style::SettingsButton &st,
  153. IconDescriptor &&descriptor = {});
  154. void CreateRightLabel(
  155. not_null<Button*> button,
  156. rpl::producer<QString> label,
  157. const style::SettingsButton &st,
  158. rpl::producer<QString> buttonText);
  159. struct DividerWithLottieDescriptor {
  160. QString lottie;
  161. std::optional<anim::repeat> lottieRepeat;
  162. std::optional<int> lottieSize;
  163. std::optional<QMargins> lottieMargins;
  164. rpl::producer<> showFinished;
  165. rpl::producer<TextWithEntities> about;
  166. std::optional<QMargins> aboutMargins;
  167. RectParts parts = RectPart::Top | RectPart::Bottom;
  168. };
  169. void AddDividerTextWithLottie(
  170. not_null<Ui::VerticalLayout*> container,
  171. DividerWithLottieDescriptor &&descriptor);
  172. struct LottieIcon {
  173. object_ptr<Ui::RpWidget> widget;
  174. Fn<void(anim::repeat repeat)> animate;
  175. };
  176. [[nodiscard]] LottieIcon CreateLottieIcon(
  177. not_null<QWidget*> parent,
  178. Lottie::IconDescriptor &&descriptor,
  179. style::margins padding = {});
  180. struct SliderWithLabel {
  181. object_ptr<Ui::RpWidget> widget;
  182. not_null<Ui::MediaSlider*> slider;
  183. not_null<Ui::FlatLabel*> label;
  184. };
  185. [[nodiscard]] SliderWithLabel MakeSliderWithLabel(
  186. QWidget *parent,
  187. const style::MediaSlider &sliderSt,
  188. const style::FlatLabel &labelSt,
  189. int skip,
  190. int minLabelWidth = 0,
  191. bool ignoreWheel = false);
  192. } // namespace Settings