attach_album_thumbnail.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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/chat/attach/attach_controls.h"
  9. #include "ui/chat/attach/attach_send_files_way.h"
  10. #include "ui/effects/animations.h"
  11. #include "ui/grouped_layout.h"
  12. #include "ui/round_rect.h"
  13. #include "base/object_ptr.h"
  14. namespace style {
  15. struct ComposeControls;
  16. } // namespace style
  17. namespace Ui {
  18. struct PreparedFile;
  19. class IconButton;
  20. class SpoilerAnimation;
  21. class AlbumThumbnail final {
  22. public:
  23. AlbumThumbnail(
  24. const style::ComposeControls &st,
  25. const PreparedFile &file,
  26. const GroupMediaLayout &layout,
  27. QWidget *parent,
  28. Fn<void()> repaint,
  29. Fn<void()> editCallback,
  30. Fn<void()> deleteCallback);
  31. void moveToLayout(const GroupMediaLayout &layout);
  32. void animateLayoutToInitial();
  33. void resetLayoutAnimation();
  34. void setSpoiler(bool spoiler);
  35. [[nodiscard]] bool hasSpoiler() const;
  36. [[nodiscard]] int photoHeight() const;
  37. [[nodiscard]] int fileHeight() const;
  38. void paintInAlbum(
  39. QPainter &p,
  40. int left,
  41. int top,
  42. float64 shrinkProgress,
  43. float64 moveProgress);
  44. void paintPhoto(Painter &p, int left, int top, int outerWidth);
  45. void paintFile(Painter &p, int left, int top, int outerWidth);
  46. [[nodiscard]] QRect geometry() const;
  47. [[nodiscard]] bool containsPoint(QPoint position) const;
  48. [[nodiscard]] bool buttonsContainPoint(QPoint position) const;
  49. [[nodiscard]] AttachButtonType buttonTypeFromPoint(
  50. QPoint position) const;
  51. [[nodiscard]] int distanceTo(QPoint position) const;
  52. [[nodiscard]] bool isPointAfter(QPoint position) const;
  53. void moveInAlbum(QPoint to);
  54. [[nodiscard]] QPoint center() const;
  55. void suggestMove(float64 delta, Fn<void()> callback);
  56. void finishAnimations();
  57. void setButtonVisible(bool value);
  58. void moveButtons(int thumbTop);
  59. [[nodiscard]] bool isCompressedSticker() const;
  60. static constexpr auto kShrinkDuration = crl::time(150);
  61. private:
  62. QRect countRealGeometry() const;
  63. QRect countCurrentGeometry(float64 progress) const;
  64. void prepareCache(QSize size, int shrink);
  65. void drawSimpleFrame(QPainter &p, QRect to, QSize size) const;
  66. QRect paintButtons(
  67. QPainter &p,
  68. QRect geometry,
  69. float64 shrinkProgress);
  70. void paintPlayVideo(QPainter &p, QRect geometry);
  71. const style::ComposeControls &_st;
  72. GroupMediaLayout _layout;
  73. std::optional<QRect> _animateFromGeometry;
  74. const QImage _fullPreview;
  75. const int _shrinkSize;
  76. const bool _isPhoto;
  77. const bool _isVideo;
  78. QPixmap _albumImage;
  79. QPixmap _albumImageBlurred;
  80. QImage _albumCache;
  81. QPoint _albumPosition;
  82. RectParts _albumCorners = RectPart::None;
  83. QPixmap _photo;
  84. QPixmap _photoBlurred;
  85. QPixmap _fileThumb;
  86. QString _name;
  87. QString _status;
  88. int _nameWidth = 0;
  89. int _statusWidth = 0;
  90. float64 _suggestedMove = 0.;
  91. Animations::Simple _suggestedMoveAnimation;
  92. int _lastShrinkValue = 0;
  93. AttachControls _buttons;
  94. bool _isCompressedSticker = false;
  95. std::unique_ptr<SpoilerAnimation> _spoiler;
  96. QImage _cornerCache;
  97. Fn<void()> _repaint;
  98. QRect _lastRectOfModify;
  99. QRect _lastRectOfButtons;
  100. object_ptr<IconButton> _editMedia = { nullptr };
  101. object_ptr<IconButton> _deleteMedia = { nullptr };
  102. };
  103. } // namespace Ui