background_preview_box.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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/layers/box_content.h"
  9. #include "base/binary_guard.h"
  10. #include "history/admin_log/history_admin_log_item.h"
  11. #include "history/view/history_view_element.h"
  12. #include "ui/effects/animations.h"
  13. #include "ui/effects/radial_animation.h"
  14. #include "data/data_wall_paper.h"
  15. namespace Data {
  16. class DocumentMedia;
  17. } // namespace Data
  18. namespace Window {
  19. class SessionController;
  20. } // namespace Window
  21. namespace Ui {
  22. class Checkbox;
  23. class ChatStyle;
  24. class MediaSlider;
  25. template <typename Widget>
  26. class SlideWrap;
  27. template <typename Widget>
  28. class FadeWrap;
  29. } // namespace Ui
  30. struct BackgroundPreviewArgs {
  31. PeerData *forPeer = nullptr;
  32. FullMsgId fromMessageId;
  33. };
  34. class BackgroundPreviewBox
  35. : public Ui::BoxContent
  36. , private HistoryView::SimpleElementDelegate {
  37. public:
  38. BackgroundPreviewBox(
  39. QWidget*,
  40. not_null<Window::SessionController*> controller,
  41. const Data::WallPaper &paper,
  42. BackgroundPreviewArgs args = {});
  43. ~BackgroundPreviewBox();
  44. static bool Start(
  45. not_null<Window::SessionController*> controller,
  46. const QString &slug,
  47. const QMap<QString, QString> &params);
  48. protected:
  49. void prepare() override;
  50. void paintEvent(QPaintEvent *e) override;
  51. private:
  52. struct OverridenStyle;
  53. using Element = HistoryView::Element;
  54. not_null<HistoryView::ElementDelegate*> delegate();
  55. HistoryView::Context elementContext() override;
  56. void apply();
  57. void applyForPeer();
  58. void applyForPeer(bool both);
  59. void applyForEveryone();
  60. void uploadForPeer(bool both);
  61. void setExistingForPeer(const Data::WallPaper &paper, bool both);
  62. void share();
  63. void radialAnimationCallback(crl::time now);
  64. QRect radialRect() const;
  65. void generateBackground();
  66. void checkLoadedDocument();
  67. void setScaledFromThumb();
  68. void setScaledFromImage(QImage &&image, QImage &&blurred);
  69. void updateServiceBg(const std::vector<QColor> &bg);
  70. void paintImage(Painter &p);
  71. void paintRadial(Painter &p);
  72. void paintTexts(Painter &p, crl::time ms);
  73. void recreateBlurCheckbox();
  74. int textsTop() const;
  75. void startFadeInFrom(QPixmap previous);
  76. void checkBlurAnimationStart();
  77. [[nodiscard]] const style::Box &overridenStyle(bool dark);
  78. void paletteReady();
  79. void applyDarkMode(bool dark);
  80. [[nodiscard]] OverridenStyle prepareOverridenStyle(bool dark);
  81. [[nodiscard]] bool forChannel() const;
  82. [[nodiscard]] bool forGroup() const;
  83. void checkLevelForChannel();
  84. void recreate(bool dark);
  85. void resetTitle();
  86. void rebuildButtons(bool dark);
  87. void createDimmingSlider(bool dark);
  88. const not_null<Window::SessionController*> _controller;
  89. PeerData * const _forPeer = nullptr;
  90. bool _forPeerLevelCheck = false;
  91. FullMsgId _fromMessageId;
  92. std::unique_ptr<Ui::ChatStyle> _chatStyle;
  93. const not_null<History*> _serviceHistory;
  94. AdminLog::OwnedItem _service;
  95. AdminLog::OwnedItem _text1;
  96. AdminLog::OwnedItem _text2;
  97. QString _paperEmojiId;
  98. Data::WallPaper _paper;
  99. std::shared_ptr<Data::DocumentMedia> _media;
  100. QImage _full;
  101. QPixmap _generated, _scaled, _blurred, _fadeOutThumbnail;
  102. Ui::Animations::Simple _fadeIn;
  103. Ui::RadialAnimation _radial;
  104. base::binary_guard _generating;
  105. std::optional<QColor> _serviceBg;
  106. object_ptr<Ui::Checkbox> _blur = { nullptr };
  107. rpl::variable<bool> _appNightMode;
  108. rpl::variable<bool> _boxDarkMode;
  109. std::unique_ptr<OverridenStyle> _light, _dark;
  110. std::unique_ptr<style::palette> _lightPalette, _darkPalette;
  111. bool _waitingForPalette = false;
  112. object_ptr<Ui::SlideWrap<Ui::RpWidget>> _dimmingWrap = { nullptr };
  113. Ui::RpWidget *_dimmingContent = nullptr;
  114. Ui::MediaSlider *_dimmingSlider = nullptr;
  115. int _dimmingIntensity = 0;
  116. rpl::variable<int> _dimmingHeight = 0;
  117. bool _dimmed = false;
  118. bool _dimmingToggleScheduled = false;
  119. FullMsgId _uploadId;
  120. float64 _uploadProgress = 0.;
  121. rpl::lifetime _uploadLifetime;
  122. std::unique_ptr<Ui::FadeWrap<Ui::RpWidget>> _forBothOverlay;
  123. rpl::variable<QColor> _paletteServiceBg;
  124. rpl::lifetime _serviceBgLifetime;
  125. };