call_button.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 "base/object_ptr.h"
  9. #include "ui/widgets/buttons.h"
  10. #include "ui/effects/animations.h"
  11. namespace Ui {
  12. class FlatLabel;
  13. struct CallButtonColors {
  14. std::optional<QColor> bg;
  15. std::optional<QColor> ripple;
  16. };
  17. class CallButton final : public RippleButton {
  18. public:
  19. CallButton(
  20. QWidget *parent,
  21. const style::CallButton &stFrom,
  22. const style::CallButton *stTo = nullptr);
  23. void setProgress(float64 progress);
  24. void setOuterValue(float64 value);
  25. void setText(rpl::producer<QString> text);
  26. void setColorOverrides(rpl::producer<CallButtonColors> &&colors);
  27. void setStyle(
  28. const style::CallButton &stFrom,
  29. const style::CallButton *stTo = nullptr);
  30. [[nodiscard]] not_null<CallButton*> addCornerButton(
  31. const style::CallButton &stFrom,
  32. const style::CallButton *stTo = nullptr);
  33. private:
  34. void paintEvent(QPaintEvent *e) override;
  35. void onStateChanged(State was, StateChangeSource source) override;
  36. QImage prepareRippleMask() const override;
  37. QPoint prepareRippleStartPosition() const override;
  38. void init();
  39. QPoint iconPosition(not_null<const style::CallButton*> st) const;
  40. void mixIconMasks();
  41. not_null<const style::CallButton*> _stFrom;
  42. const style::CallButton *_stTo = nullptr;
  43. CallButton *_corner = nullptr;
  44. float64 _progress = 0.;
  45. object_ptr<FlatLabel> _label = { nullptr };
  46. std::optional<QColor> _bgOverride;
  47. std::optional<QColor> _rippleOverride;
  48. QImage _bgMask, _bg;
  49. QPixmap _bgFrom, _bgTo;
  50. QImage _iconMixedMask, _iconFrom, _iconTo, _iconMixed;
  51. float64 _outerValue = 0.;
  52. Animations::Simple _outerAnimation;
  53. };
  54. } // namespace Ui