download_bar.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/wrap/slide_wrap.h"
  9. #include "ui/effects/radial_animation.h"
  10. #include "ui/widgets/shadow.h"
  11. #include "ui/text/text.h"
  12. namespace Ui {
  13. class RippleButton;
  14. struct DownloadBarProgress {
  15. int64 ready = 0;
  16. int64 total = 0;
  17. };
  18. struct DownloadBarContent {
  19. TextWithEntities singleName;
  20. QImage singleThumbnail;
  21. int count = 0;
  22. int done = 0;
  23. };
  24. class DownloadBar final {
  25. public:
  26. DownloadBar(
  27. not_null<QWidget*> parent,
  28. rpl::producer<DownloadBarProgress> progress);
  29. ~DownloadBar();
  30. void show(DownloadBarContent &&content);
  31. [[nodiscard]] bool isHidden() const;
  32. [[nodiscard]] int height() const;
  33. [[nodiscard]] rpl::producer<int> heightValue() const;
  34. [[nodiscard]] rpl::producer<bool> shownValue() const;
  35. void setGeometry(int left, int top, int width, int height);
  36. [[nodiscard]] rpl::producer<> clicks() const;
  37. [[nodiscard]] rpl::lifetime &lifetime();
  38. private:
  39. void paint(Painter &p, QRect clip);
  40. void refreshIcon();
  41. void refreshThumbnail();
  42. void refreshInfo(const DownloadBarProgress &progress);
  43. void radialAnimationCallback(crl::time now);
  44. [[nodiscard]] float64 computeProgress() const;
  45. SlideWrap<RippleButton> _button;
  46. PlainShadow _shadow;
  47. DownloadBarContent _content;
  48. rpl::variable<DownloadBarProgress> _progress;
  49. Ui::Animations::Simple _finishedAnimation;
  50. bool _finished = false;
  51. QImage _documentIconLarge;
  52. QImage _documentIcon;
  53. QImage _documentIconDone;
  54. qint64 _thumbnailCacheKey = 0;
  55. QImage _thumbnailLarge;
  56. QImage _thumbnail;
  57. QImage _thumbnailDone;
  58. Text::String _title;
  59. Text::String _info;
  60. RadialAnimation _radial;
  61. };
  62. } // namespace Ui