side_bar_button.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "ui/widgets/buttons.h"
  9. #include "ui/text/text.h"
  10. namespace style {
  11. struct SideBarButton;
  12. } // namespace style
  13. namespace Ui {
  14. class RippleAnimation;
  15. [[nodiscard]] QImage SideBarLockIcon(const style::color &fg);
  16. class SideBarButton final : public Ui::RippleButton {
  17. public:
  18. SideBarButton(
  19. not_null<QWidget*> parent,
  20. const TextWithEntities &title,
  21. const style::SideBarButton &st,
  22. Text::MarkedContext context = {},
  23. Fn<bool()> paused = nullptr);
  24. void setActive(bool active);
  25. void setBadge(const QString &badge, bool muted);
  26. void setIconOverride(
  27. const style::icon *iconOverride,
  28. const style::icon *iconOverrideActive = nullptr);
  29. void setLocked(bool locked);
  30. int resizeGetHeight(int newWidth) override;
  31. [[nodiscard]] bool locked() const;
  32. private:
  33. void paintEvent(QPaintEvent *e) override;
  34. [[nodiscard]] const style::icon &computeIcon() const;
  35. void validateIconCache();
  36. void validateLockIconCache();
  37. const style::SideBarButton &_st;
  38. const style::icon *_iconOverride = nullptr;
  39. const style::icon *_iconOverrideActive = nullptr;
  40. Ui::Text::String _text;
  41. Ui::Text::String _badge;
  42. QImage _iconCache;
  43. QImage _iconCacheActive;
  44. int _iconCacheBadgeWidth = 0;
  45. bool _active = false;
  46. bool _badgeMuted = false;
  47. Fn<bool()> _paused;
  48. Text::MarkedContext _context;
  49. struct {
  50. bool locked = false;
  51. QImage iconCache;
  52. QImage iconCacheActive;
  53. } _lock;
  54. };
  55. //
  56. //class SideBarMenu final {
  57. //public:
  58. // struct Item {
  59. // QString id;
  60. // QString title;
  61. // QString badge;
  62. // not_null<const style::icon*> icon;
  63. // not_null<const style::icon*> iconActive;
  64. // int iconTop = 0;
  65. // };
  66. //
  67. // SideBarMenu(not_null<QWidget*> parent, const style::SideBarMenu &st);
  68. // ~SideBarMenu();
  69. //
  70. // [[nodiscard]] not_null<const Ui::RpWidget*> widget() const;
  71. //
  72. // void setGeometry(QRect geometry);
  73. // void setItems(std::vector<Item> items);
  74. // void setActive(
  75. // const QString &id,
  76. // anim::type animated = anim::type::normal);
  77. // [[nodiscard]] rpl::producer<QString> activateRequests() const;
  78. //
  79. // [[nodiscard]] rpl::lifetime &lifetime();
  80. //
  81. //private:
  82. // struct MenuItem {
  83. // Item data;
  84. // Ui::Text::String text;
  85. // mutable std::unique_ptr<Ui::RippleAnimation> ripple;
  86. // int top = 0;
  87. // int height = 0;
  88. // };
  89. // void setup();
  90. // void paint(Painter &p, QRect clip) const;
  91. // [[nodiscard]] int countContentHeight(int width, int outerHeight);
  92. //
  93. // void mouseMove(QPoint position);
  94. // void mousePress(Qt::MouseButton button);
  95. // void mouseRelease(Qt::MouseButton button);
  96. //
  97. // void setSelected(int selected);
  98. // void setPressed(int pressed);
  99. // void addRipple(MenuItem &item, QPoint position);
  100. // void repaint(const QString &id);
  101. // [[nodiscard]] MenuItem *itemById(const QString &id);
  102. //
  103. // const style::SideBarMenu &_st;
  104. //
  105. // Ui::RpWidget _outer;
  106. // const not_null<Ui::ScrollArea*> _scroll;
  107. // const not_null<Ui::RpWidget*> _inner;
  108. // std::vector<MenuItem> _items;
  109. // int _selected = -1;
  110. // int _pressed = -1;
  111. //
  112. // QString _activeId;
  113. // rpl::event_stream<QString> _activateRequests;
  114. //
  115. //};
  116. } // namespace Ui