round_checkbox.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/effects/animations.h"
  9. namespace style {
  10. struct RoundCheckbox;
  11. struct RoundImageCheckbox;
  12. } // namespace style
  13. class Painter;
  14. enum class ImageRoundRadius;
  15. namespace Ui {
  16. struct OutlineSegment;
  17. class RoundCheckbox {
  18. public:
  19. RoundCheckbox(const style::RoundCheckbox &st, Fn<void()> updateCallback);
  20. void paint(QPainter &p, int x, int y, int outerWidth, float64 masterScale = 1.) const;
  21. void setDisplayInactive(bool displayInactive);
  22. bool checked() const {
  23. return _checked;
  24. }
  25. void setChecked(
  26. bool newChecked,
  27. anim::type animated = anim::type::normal);
  28. void invalidateCache();
  29. private:
  30. void prepareInactiveCache();
  31. const style::RoundCheckbox &_st;
  32. Fn<void()> _updateCallback;
  33. bool _checked = false;
  34. Ui::Animations::Simple _checkedProgress;
  35. bool _displayInactive = false;
  36. QPixmap _inactiveCacheBg, _inactiveCacheFg;
  37. };
  38. class RoundImageCheckbox {
  39. public:
  40. using PaintRoundImage = Fn<void(Painter &p, int x, int y, int outerWidth, int size)>;
  41. RoundImageCheckbox(
  42. const style::RoundImageCheckbox &st,
  43. Fn<void()> updateCallback,
  44. PaintRoundImage &&paintRoundImage,
  45. Fn<std::optional<int>(int size)> roundingRadius = nullptr);
  46. RoundImageCheckbox(RoundImageCheckbox&&);
  47. ~RoundImageCheckbox();
  48. void paint(Painter &p, int x, int y, int outerWidth) const;
  49. float64 checkedAnimationRatio() const;
  50. void setColorOverride(std::optional<QBrush> fg);
  51. void setCustomizedSegments(std::vector<OutlineSegment> segments);
  52. bool checked() const {
  53. return _check.checked();
  54. }
  55. void setChecked(
  56. bool newChecked,
  57. anim::type animated = anim::type::normal);
  58. void invalidateCache() {
  59. _check.invalidateCache();
  60. }
  61. private:
  62. void prepareWideCache();
  63. const style::RoundImageCheckbox &_st;
  64. Fn<void()> _updateCallback;
  65. PaintRoundImage _paintRoundImage;
  66. Fn<std::optional<int>(int size)> _roundingRadius;
  67. QPixmap _wideCache;
  68. Ui::Animations::Simple _selection;
  69. RoundCheckbox _check;
  70. //std::optional<QBrush> _fgOverride;
  71. std::vector<OutlineSegment> _segments;
  72. };
  73. } // namespace Ui