TitleBarButton.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef TITLEBARBUTTON_H
  2. #define TITLEBARBUTTON_H
  3. #include <QAbstractButton>
  4. #include <QDomDocument>
  5. enum TitleBarButtonState
  6. {
  7. NORMAL = 0,
  8. HOVER = 1,
  9. PRESSED = 2
  10. };
  11. class TitleBarButton : public QAbstractButton
  12. {
  13. Q_OBJECT
  14. Q_PROPERTY(QColor normalColor READ getNormalColor WRITE setNormalColor)
  15. Q_PROPERTY(QColor hoverColor READ getHoverColor WRITE setHoverColor)
  16. Q_PROPERTY(QColor pressedColor READ getPressedColor WRITE setPressedColor)
  17. Q_PROPERTY(QColor normalBackgroundColor READ getNormalBackgroundColor WRITE setNormalBackgroundColor)
  18. Q_PROPERTY(QColor hoverBackgroundColor READ getHoverBackgroundColor WRITE setHoverBackgroundColor)
  19. Q_PROPERTY(QColor pressedBackgroundColor READ getPressedBackgroundColor WRITE setPressedBackgroundColor)
  20. public:
  21. explicit TitleBarButton(QWidget *parent = nullptr);
  22. void setState(TitleBarButtonState state);
  23. bool isPressed();
  24. QColor getNormalColor();
  25. QColor getHoverColor();
  26. QColor getPressedColor();
  27. QColor getNormalBackgroundColor();
  28. QColor getHoverBackgroundColor();
  29. QColor getPressedBackgroundColor();
  30. void setNormalColor(const QColor &color);
  31. void setHoverColor(const QColor &color);
  32. void setPressedColor(const QColor &color);
  33. void setNormalBackgroundColor(const QColor &color);
  34. void setHoverBackgroundColor(const QColor &color);
  35. void setPressedBackgroundColor(const QColor &color);
  36. QVector<QColor> getColors();
  37. private:
  38. TitleBarButtonState m_state;
  39. // icon color
  40. QColor m_normalColor;
  41. QColor m_hoverColor;
  42. QColor m_pressedColor;
  43. // background color
  44. QColor m_normalBgColor;
  45. QColor m_hoverBgColor;
  46. QColor m_pressedBgColor;
  47. signals:
  48. // QWidget interface
  49. protected:
  50. void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  51. void enterEvent(QEvent *event) Q_DECL_OVERRIDE;
  52. void leaveEvent(QEvent *event) Q_DECL_OVERRIDE;
  53. };
  54. class SvgTitleBarButton : public TitleBarButton
  55. {
  56. Q_OBJECT
  57. public:
  58. explicit SvgTitleBarButton(const QString &iconPath, QWidget *parent = nullptr);
  59. ~SvgTitleBarButton();
  60. void setIcon(const QString &iconPath);
  61. private:
  62. QDomDocument *m_svgDom;
  63. // QWidget interface
  64. protected:
  65. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  66. };
  67. class MinimizeButton : public TitleBarButton
  68. {
  69. Q_OBJECT
  70. public:
  71. explicit MinimizeButton(QWidget *parent = nullptr);
  72. // QWidget interface
  73. protected:
  74. void paintEvent(QPaintEvent *event);
  75. };
  76. class MaximizeButton : public TitleBarButton
  77. {
  78. Q_OBJECT
  79. public:
  80. explicit MaximizeButton(QWidget *parent = nullptr);
  81. void setMaxState(bool isMax);
  82. private:
  83. bool m_isMax;
  84. // QWidget interface
  85. protected:
  86. void paintEvent(QPaintEvent *event);
  87. };
  88. class CloseButton : public SvgTitleBarButton
  89. {
  90. Q_OBJECT
  91. public:
  92. explicit CloseButton(QWidget *parent = nullptr);
  93. };
  94. #endif // TITLEBARBUTTON_H