choose_theme_controller.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. class PeerData;
  9. namespace Window {
  10. class SessionController;
  11. } // namespace Window
  12. namespace Data {
  13. struct CloudTheme;
  14. } // namespace Data
  15. namespace Ui {
  16. class RpWidget;
  17. class PlainShadow;
  18. class VerticalLayout;
  19. class ChooseThemeController final {
  20. public:
  21. ChooseThemeController(
  22. not_null<RpWidget*> parent,
  23. not_null<Window::SessionController*> window,
  24. not_null<PeerData*> peer);
  25. ~ChooseThemeController();
  26. [[nodiscard]] bool shouldBeShown() const;
  27. [[nodiscard]] rpl::producer<bool> shouldBeShownValue() const;
  28. [[nodiscard]] int height() const;
  29. void hide();
  30. void show();
  31. void raise();
  32. void setFocus();
  33. [[nodiscard]] rpl::lifetime &lifetime();
  34. private:
  35. struct Entry;
  36. void init(rpl::producer<QSize> outer);
  37. void initButtons();
  38. void initList();
  39. void fill(const std::vector<Data::CloudTheme> &themes);
  40. void close();
  41. void clearCurrentBackgroundState();
  42. void paintEntry(QPainter &p, const Entry &entry);
  43. void applyInitialInnerLeft();
  44. void updateInnerLeft(int now);
  45. [[nodiscard]] Entry *findChosen();
  46. [[nodiscard]] const Entry *findChosen() const;
  47. const not_null<Window::SessionController*> _controller;
  48. const not_null<PeerData*> _peer;
  49. const std::unique_ptr<VerticalLayout> _wrap;
  50. const std::unique_ptr<PlainShadow> _topShadow;
  51. const not_null<RpWidget*> _content;
  52. const not_null<RpWidget*> _inner;
  53. const EmojiPtr _disabledEmoji = nullptr;
  54. std::vector<Entry> _entries;
  55. QString _pressed;
  56. rpl::variable<QString> _chosen;
  57. std::optional<QPoint> _pressPosition;
  58. std::optional<QPoint> _dragStartPosition;
  59. int _dragStartInnerLeft = 0;
  60. bool _initialInnerLeftApplied = false;
  61. rpl::variable<bool> _shouldBeShown = false;
  62. rpl::variable<bool> _forceHidden = false;
  63. rpl::variable<bool> _dark = false;
  64. rpl::lifetime _cachingLifetime;
  65. };
  66. } // namespace Ui