info_userpic_emoji_builder_preview.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/rp_widget.h"
  9. #include "ui/effects/animations.h"
  10. namespace Data {
  11. class DocumentMedia;
  12. } // namespace Data
  13. namespace HistoryView {
  14. class StickerPlayer;
  15. } // namespace HistoryView
  16. class DocumentData;
  17. namespace UserpicBuilder {
  18. struct Result;
  19. class PreviewPainter final {
  20. public:
  21. PreviewPainter(int size);
  22. [[nodiscard]] DocumentData *document() const;
  23. void setPlayOnce(bool value);
  24. void setDocument(
  25. not_null<DocumentData*> document,
  26. Fn<void()> updateCallback);
  27. void paintBackground(QPainter &p, const QImage &image);
  28. bool paintForeground(QPainter &p);
  29. private:
  30. const int _size;
  31. const int _emojiSize;
  32. const QRect _frameGeometry;
  33. const QRect _frameRect;
  34. QImage _mask;
  35. QImage _frame;
  36. std::shared_ptr<Data::DocumentMedia> _media;
  37. std::unique_ptr<HistoryView::StickerPlayer> _player;
  38. bool _playOnce = false;
  39. bool _paused = false;
  40. bool _firstFrameShown = false;
  41. rpl::lifetime _lifetime;
  42. };
  43. class EmojiUserpic final : public Ui::RpWidget {
  44. public:
  45. EmojiUserpic(
  46. not_null<Ui::RpWidget*> parent,
  47. const QSize &size,
  48. bool isForum);
  49. void result(int size, Fn<void(UserpicBuilder::Result)> done);
  50. void setGradientColors(std::vector<QColor> colors);
  51. void setDocument(not_null<DocumentData*> document);
  52. void setDuration(crl::time duration);
  53. protected:
  54. void paintEvent(QPaintEvent *event) override;
  55. private:
  56. const bool _forum;
  57. PreviewPainter _painter;
  58. std::optional<bool> _playOnce;
  59. QImage _previousImage;
  60. QImage _image;
  61. std::vector<QColor> _colors;
  62. crl::time _duration;
  63. Ui::Animations::Simple _animation;
  64. };
  65. } // namespace UserpicBuilder