unread_badge.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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_custom_emoji.h"
  9. #include "ui/rp_widget.h"
  10. namespace style {
  11. struct VerifiedBadge;
  12. } // namespace style
  13. namespace Ui {
  14. class UnreadBadge : public RpWidget {
  15. public:
  16. using RpWidget::RpWidget;
  17. void setText(const QString &text, bool active);
  18. int textBaseline() const;
  19. protected:
  20. void paintEvent(QPaintEvent *e) override;
  21. private:
  22. QString _text;
  23. bool _active = false;
  24. };
  25. struct BotVerifyDetails {
  26. UserId botId = 0;
  27. DocumentId iconId = 0;
  28. TextWithEntities description;
  29. explicit operator bool() const {
  30. return iconId != 0;
  31. }
  32. friend inline bool operator==(
  33. const BotVerifyDetails &,
  34. const BotVerifyDetails &) = default;
  35. };
  36. class PeerBadge {
  37. public:
  38. PeerBadge();
  39. ~PeerBadge();
  40. struct Descriptor {
  41. not_null<PeerData*> peer;
  42. QRect rectForName;
  43. int nameWidth = 0;
  44. int outerWidth = 0;
  45. const style::icon *verified = nullptr;
  46. const style::icon *premium = nullptr;
  47. const style::color *scam = nullptr;
  48. const style::color *premiumFg = nullptr;
  49. Fn<void()> customEmojiRepaint;
  50. crl::time now = 0;
  51. bool prioritizeVerification = false;
  52. bool bothVerifyAndStatus = false;
  53. bool paused = false;
  54. };
  55. int drawGetWidth(Painter &p, Descriptor &&descriptor);
  56. void unload();
  57. [[nodiscard]] bool ready(const BotVerifyDetails *details) const;
  58. void set(
  59. not_null<const BotVerifyDetails*> details,
  60. Text::CustomEmojiFactory factory,
  61. Fn<void()> repaint);
  62. // How much horizontal space the badge took.
  63. int drawVerified(
  64. QPainter &p,
  65. QPoint position,
  66. const style::VerifiedBadge &st);
  67. private:
  68. struct EmojiStatus;
  69. struct BotVerifiedData;
  70. int drawScamOrFake(Painter &p, const Descriptor &descriptor);
  71. int drawVerifyCheck(Painter &p, const Descriptor &descriptor);
  72. int drawPremiumEmojiStatus(Painter &p, const Descriptor &descriptor);
  73. int drawPremiumStar(Painter &p, const Descriptor &descriptor);
  74. std::unique_ptr<EmojiStatus> _emojiStatus;
  75. mutable std::unique_ptr<BotVerifiedData> _botVerifiedData;
  76. };
  77. QSize ScamBadgeSize(bool fake);
  78. void DrawScamBadge(
  79. bool fake,
  80. Painter &p,
  81. QRect rect,
  82. int outerWidth,
  83. const style::color &color);
  84. } // namespace Ui