arcs.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include "styles/style_widgets.h"
  9. class Painter;
  10. namespace Ui::Paint {
  11. class ArcsAnimation {
  12. public:
  13. enum class Direction {
  14. Up,
  15. Down,
  16. Left,
  17. Right,
  18. };
  19. ArcsAnimation(
  20. const style::ArcsAnimation &st,
  21. std::vector<float> thresholds,
  22. float64 startValue,
  23. Direction direction);
  24. void paint(
  25. QPainter &p,
  26. std::optional<QColor> colorOverride = std::nullopt);
  27. void setValue(float64 value);
  28. rpl::producer<> startUpdateRequests();
  29. rpl::producer<> stopUpdateRequests();
  30. void update(crl::time now);
  31. bool isFinished() const;
  32. float width() const;
  33. float maxWidth() const;
  34. float finishedWidth() const;
  35. float height() const;
  36. void setStrokeRatio(float ratio);
  37. private:
  38. struct Arc {
  39. QRectF rect;
  40. float threshold;
  41. crl::time startTime = 0;
  42. float64 progress = 0.;
  43. };
  44. void initArcs(std::vector<float> thresholds);
  45. QRectF computeArcRect(int index) const;
  46. bool isHorizontal() const;
  47. bool isArcFinished(const Arc &arc) const;
  48. void updateArcStartTime(
  49. Arc &arc,
  50. float64 previousValue,
  51. crl::time now);
  52. const style::ArcsAnimation &_st;
  53. const Direction _direction;
  54. const int _startAngle;
  55. const int _spanAngle;
  56. const QRectF _emptyRect;
  57. float64 _currentValue = 0.;
  58. float _strokeRatio = 0.;
  59. rpl::event_stream<> _startUpdateRequests;
  60. rpl::event_stream<> _stopUpdateRequests;
  61. std::vector<Arc> _arcs;
  62. };
  63. } // namespace Ui::Paint