Button.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef BUTTON_H
  2. #define BUTTON_H
  3. #include "Common/Icon.h"
  4. #include <QPushButton>
  5. #include <QRadioButton>
  6. #include <QToolButton>
  7. #include <QUrl>
  8. class FluentIconBase;
  9. class PushButton : public QPushButton
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit PushButton(const QString &text, QWidget *parent = nullptr);
  14. explicit PushButton(const QString &text, FluentIconBase *ficon, QWidget *parent = nullptr);
  15. void setIcon(FluentIconBase *ficon);
  16. FluentIconBase *ficon() const;
  17. QIcon icon() const;
  18. virtual void drawIcon(QPainter *painter, const QRect &rect);
  19. protected:
  20. void mousePressEvent(QMouseEvent *event) override;
  21. void mouseReleaseEvent(QMouseEvent *event) override;
  22. void paintEvent(QPaintEvent *event) override;
  23. private:
  24. bool m_isPressed;
  25. QScopedPointer<FluentIconBase> m_ficon;
  26. };
  27. class PrimaryPushButton : public PushButton
  28. {
  29. Q_OBJECT
  30. public:
  31. explicit PrimaryPushButton(const QString &text, QWidget *parent = nullptr);
  32. explicit PrimaryPushButton(const QString &text, FluentIconBase *ficon, QWidget *parent = nullptr);
  33. void drawIcon(QPainter *painter, const QRect &rect) override;
  34. };
  35. class HyperlinkButton : public QPushButton
  36. {
  37. Q_OBJECT
  38. public:
  39. explicit HyperlinkButton(const QString &url, const QString &text, QWidget *parent = nullptr);
  40. private:
  41. QUrl m_url;
  42. };
  43. class RadioButton : public QRadioButton
  44. {
  45. Q_OBJECT
  46. public:
  47. explicit RadioButton(const QString &text, QWidget *parent = nullptr);
  48. };
  49. class ToolButton : public QToolButton
  50. {
  51. Q_OBJECT
  52. public:
  53. explicit ToolButton(FluentIconBase *ficon, QWidget *parent = nullptr);
  54. void setIcon(FluentIconBase *ficon);
  55. FluentIconBase *ficon() const;
  56. // QWidget interface
  57. protected:
  58. void mousePressEvent(QMouseEvent *event) override;
  59. void mouseReleaseEvent(QMouseEvent *event) override;
  60. void paintEvent(QPaintEvent *event) override;
  61. private:
  62. bool m_isPressed;
  63. QScopedPointer<FluentIconBase> m_ficon;
  64. };
  65. class TransparentToolButton : public QToolButton
  66. {
  67. Q_OBJECT
  68. public:
  69. explicit TransparentToolButton(FluentIconBase *ficon, QWidget *parent = nullptr);
  70. // QWidget interface
  71. protected:
  72. void paintEvent(QPaintEvent *event) override;
  73. private:
  74. QScopedPointer<FluentIconBase> m_ficon;
  75. };
  76. #endif // BUTTON_H