send_button.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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/widgets/buttons.h"
  9. namespace style {
  10. struct SendButton;
  11. } // namespace style
  12. namespace Ui {
  13. class SendButton final : public RippleButton {
  14. public:
  15. SendButton(QWidget *parent, const style::SendButton &st);
  16. static constexpr auto kSlowmodeDelayLimit = 100 * 60;
  17. enum class Type {
  18. Send,
  19. Schedule,
  20. Save,
  21. Record,
  22. Round,
  23. Cancel,
  24. Slowmode,
  25. };
  26. struct State {
  27. Type type = Type::Send;
  28. int slowmodeDelay = 0;
  29. int starsToSend = 0;
  30. friend inline constexpr auto operator<=>(State, State) = default;
  31. friend inline constexpr bool operator==(State, State) = default;
  32. };
  33. [[nodiscard]] Type type() const {
  34. return _state.type;
  35. }
  36. [[nodiscard]] State state() const {
  37. return _state;
  38. }
  39. void setState(State state);
  40. void finishAnimating();
  41. protected:
  42. void paintEvent(QPaintEvent *e) override;
  43. QImage prepareRippleMask() const override;
  44. QPoint prepareRippleStartPosition() const override;
  45. private:
  46. struct StarsGeometry {
  47. QRect inner;
  48. QRect rounded;
  49. QRect outer;
  50. };
  51. [[nodiscard]] QPixmap grabContent();
  52. void updateSize();
  53. [[nodiscard]] StarsGeometry starsGeometry() const;
  54. void paintRecord(QPainter &p, bool over);
  55. void paintRound(QPainter &p, bool over);
  56. void paintSave(QPainter &p, bool over);
  57. void paintCancel(QPainter &p, bool over);
  58. void paintSend(QPainter &p, bool over);
  59. void paintSchedule(QPainter &p, bool over);
  60. void paintSlowmode(QPainter &p);
  61. void paintStarsToSend(QPainter &p, bool over);
  62. const style::SendButton &_st;
  63. State _state;
  64. QPixmap _contentFrom, _contentTo;
  65. Ui::Animations::Simple _stateChangeAnimation;
  66. int _stateChangeFromWidth = 0;
  67. QString _slowmodeDelayText;
  68. Ui::Text::String _starsToSendText;
  69. };
  70. } // namespace Ui