premium_top_bar.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 "base/object_ptr.h"
  9. #include "ui/rp_widget.h"
  10. #include "ui/effects/premium_stars_colored.h"
  11. namespace style {
  12. struct PremiumCover;
  13. } // namespace style
  14. namespace st {
  15. extern const style::PremiumCover &defaultPremiumCover;
  16. } // namespace st
  17. namespace Ui {
  18. class FlatLabel;
  19. } // namespace Ui
  20. namespace Ui::Premium {
  21. class TopBarAbstract : public RpWidget {
  22. public:
  23. TopBarAbstract(
  24. QWidget *parent = nullptr,
  25. const style::PremiumCover &st = st::defaultPremiumCover);
  26. void setRoundEdges(bool value);
  27. virtual void setPaused(bool paused) = 0;
  28. virtual void setTextPosition(int x, int y) = 0;
  29. [[nodiscard]] virtual rpl::producer<int> additionalHeight() const = 0;
  30. [[nodiscard]] const style::PremiumCover &st() const {
  31. return _st;
  32. }
  33. protected:
  34. void paintEdges(QPainter &p, const QBrush &brush) const;
  35. void paintEdges(QPainter &p) const;
  36. [[nodiscard]] QRectF starRect(
  37. float64 topProgress,
  38. float64 sizeProgress) const;
  39. [[nodiscard]] bool isDark() const;
  40. void computeIsDark();
  41. private:
  42. const style::PremiumCover &_st;
  43. bool _roundEdges = true;
  44. bool _isDark = false;
  45. };
  46. struct TopBarDescriptor {
  47. Fn<QVariant()> clickContextOther;
  48. QString logo;
  49. rpl::producer<QString> title;
  50. rpl::producer<TextWithEntities> about;
  51. bool light = false;
  52. bool optimizeMinistars = true;
  53. std::optional<QGradientStops> gradientStops;
  54. };
  55. class TopBar final : public TopBarAbstract {
  56. public:
  57. TopBar(
  58. not_null<QWidget*> parent,
  59. const style::PremiumCover &st,
  60. TopBarDescriptor &&descriptor);
  61. ~TopBar();
  62. void setPaused(bool paused) override;
  63. void setTextPosition(int x, int y) override;
  64. rpl::producer<int> additionalHeight() const override;
  65. protected:
  66. void paintEvent(QPaintEvent *e) override;
  67. void resizeEvent(QResizeEvent *e) override;
  68. private:
  69. const bool _light = false;
  70. const QString _logo;
  71. const style::font &_titleFont;
  72. const style::margins &_titlePadding;
  73. object_ptr<FlatLabel> _about;
  74. ColoredMiniStars _ministars;
  75. QSvgRenderer _star;
  76. QImage _dollar;
  77. struct {
  78. float64 top = 0.;
  79. float64 body = 0.;
  80. float64 title = 0.;
  81. float64 scaleTitle = 0.;
  82. } _progress;
  83. QRectF _starRect;
  84. QPoint _titlePosition;
  85. QPainterPath _titlePath;
  86. };
  87. } // namespace Ui::Premium