window_media_preview.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 "media/clip/media_clip_reader.h"
  9. #include "ui/effects/animations.h"
  10. #include "data/data_file_origin.h"
  11. #include "ui/rp_widget.h"
  12. namespace Data {
  13. class PhotoMedia;
  14. class DocumentMedia;
  15. } // namespace Data
  16. namespace Lottie {
  17. class SinglePlayer;
  18. } // namespace Lottie
  19. namespace Window {
  20. class SessionController;
  21. class MediaPreviewWidget final : public Ui::RpWidget {
  22. public:
  23. MediaPreviewWidget(
  24. QWidget *parent,
  25. not_null<Window::SessionController*> controller);
  26. void showPreview(
  27. Data::FileOrigin origin,
  28. not_null<DocumentData*> document);
  29. void showPreview(
  30. Data::FileOrigin origin,
  31. not_null<PhotoData*> photo);
  32. void hidePreview();
  33. ~MediaPreviewWidget();
  34. protected:
  35. void paintEvent(QPaintEvent *e) override;
  36. void resizeEvent(QResizeEvent *e) override;
  37. private:
  38. void validateGifAnimation();
  39. void startGifAnimation(const Media::Clip::ReaderPointer &gif);
  40. QSize currentDimensions() const;
  41. QPixmap currentImage() const;
  42. void createLottieIfReady(not_null<DocumentData*> document);
  43. void setupLottie();
  44. void startShow();
  45. void fillEmojiString();
  46. void resetGifAndCache();
  47. [[nodiscard]] QPoint innerPosition(QSize size) const;
  48. [[nodiscard]] QPoint outerPosition(QSize size) const;
  49. [[nodiscard]] QRect updateArea() const;
  50. not_null<Window::SessionController*> _controller;
  51. Ui::Animations::Simple _a_shown;
  52. bool _hiding = false;
  53. Data::FileOrigin _origin;
  54. PhotoData *_photo = nullptr;
  55. DocumentData *_document = nullptr;
  56. std::shared_ptr<Data::PhotoMedia> _photoMedia;
  57. std::shared_ptr<Data::DocumentMedia> _documentMedia;
  58. Media::Clip::ReaderPointer _gif, _gifThumbnail;
  59. bool _gifWithAlpha = false;
  60. crl::time _gifLastPosition = 0;
  61. std::unique_ptr<Lottie::SinglePlayer> _lottie;
  62. std::unique_ptr<Lottie::SinglePlayer> _effect;
  63. int _emojiSize;
  64. std::vector<not_null<EmojiPtr>> _emojiList;
  65. void clipCallback(Media::Clip::Notification notification);
  66. enum CacheStatus {
  67. CacheNotLoaded,
  68. CacheThumbLoaded,
  69. CacheLoaded,
  70. };
  71. mutable CacheStatus _cacheStatus = CacheNotLoaded;
  72. mutable QPixmap _cache;
  73. mutable QSize _cachedSize;
  74. };
  75. } // namespace Window