qtmaterialflatbutton.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef QTMATERIALFLATBUTTON_H
  2. #define QTMATERIALFLATBUTTON_H
  3. #include <QtWidgets/QPushButton>
  4. #include <QScopedPointer>
  5. #include "lib/qtmaterialtheme.h"
  6. class QtMaterialFlatButtonPrivate;
  7. class QtMaterialFlatButton : public QPushButton
  8. {
  9. Q_OBJECT
  10. Q_PROPERTY(QColor foregroundColor WRITE setForegroundColor READ foregroundColor)
  11. Q_PROPERTY(QColor backgroundColor WRITE setBackgroundColor READ backgroundColor)
  12. Q_PROPERTY(QColor overlayColor WRITE setOverlayColor READ overlayColor)
  13. Q_PROPERTY(QColor disabledForegroundColor WRITE setDisabledForegroundColor READ disabledForegroundColor)
  14. Q_PROPERTY(QColor disabledBackgroundColor WRITE setDisabledBackgroundColor READ disabledBackgroundColor)
  15. Q_PROPERTY(qreal fontSize WRITE setFontSize READ fontSize)
  16. public:
  17. explicit QtMaterialFlatButton(QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset);
  18. explicit QtMaterialFlatButton(const QString &text, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset);
  19. QtMaterialFlatButton(const QString &text, Material::Role role, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset);
  20. ~QtMaterialFlatButton();
  21. void applyPreset(Material::ButtonPreset preset);
  22. void setUseThemeColors(bool value);
  23. bool useThemeColors() const;
  24. void setRole(Material::Role role);
  25. Material::Role role() const;
  26. void setForegroundColor(const QColor &color);
  27. QColor foregroundColor() const;
  28. void setBackgroundColor(const QColor &color);
  29. QColor backgroundColor() const;
  30. void setOverlayColor(const QColor &color);
  31. QColor overlayColor() const;
  32. void setDisabledForegroundColor(const QColor &color);
  33. QColor disabledForegroundColor() const;
  34. void setDisabledBackgroundColor(const QColor &color);
  35. QColor disabledBackgroundColor() const;
  36. void setFontSize(qreal size);
  37. qreal fontSize() const;
  38. void setHaloVisible(bool visible);
  39. bool isHaloVisible() const;
  40. void setOverlayStyle(Material::OverlayStyle style);
  41. Material::OverlayStyle overlayStyle() const;
  42. void setRippleStyle(Material::RippleStyle style);
  43. Material::RippleStyle rippleStyle() const;
  44. void setIconPlacement(Material::ButtonIconPlacement placement);
  45. Material::ButtonIconPlacement iconPlacement() const;
  46. void setCornerRadius(qreal radius);
  47. qreal cornerRadius() const;
  48. void setBackgroundMode(Qt::BGMode mode);
  49. Qt::BGMode backgroundMode() const;
  50. void setBaseOpacity(qreal opacity);
  51. qreal baseOpacity() const;
  52. void setCheckable(bool value);
  53. void setHasFixedRippleRadius(bool value);
  54. bool hasFixedRippleRadius() const;
  55. void setFixedRippleRadius(qreal radius);
  56. void setTextAlignment(Qt::Alignment alignment);
  57. Qt::Alignment textAlignment() const;
  58. QSize sizeHint() const Q_DECL_OVERRIDE;
  59. protected:
  60. enum {
  61. IconPadding = 12
  62. };
  63. QtMaterialFlatButton(QtMaterialFlatButtonPrivate &d, QWidget *parent = 0, Material::ButtonPreset preset = Material::FlatPreset);
  64. void checkStateSet() Q_DECL_OVERRIDE;
  65. void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  66. void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
  67. void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE;
  68. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  69. virtual void paintBackground(QPainter *painter);
  70. virtual void paintHalo(QPainter *painter);
  71. virtual void paintForeground(QPainter *painter);
  72. virtual void updateClipPath();
  73. const QScopedPointer<QtMaterialFlatButtonPrivate> d_ptr;
  74. private:
  75. Q_DISABLE_COPY(QtMaterialFlatButton)
  76. Q_DECLARE_PRIVATE(QtMaterialFlatButton)
  77. };
  78. #endif // QTMATERIALFLATBUTTON_H