qtmaterialslider_internal.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #ifndef QTMATERIALSLIDER_INTERNAL_H
  2. #define QTMATERIALSLIDER_INTERNAL_H
  3. #include <QStateMachine>
  4. #include "lib/qtmaterialoverlaywidget.h"
  5. class QtMaterialSlider;
  6. class QtMaterialSliderThumb;
  7. class QtMaterialSliderTrack;
  8. class QtMaterialSliderStateMachine : public QStateMachine
  9. {
  10. Q_OBJECT
  11. public:
  12. QtMaterialSliderStateMachine(QtMaterialSlider *slider,
  13. QtMaterialSliderThumb *thumb,
  14. QtMaterialSliderTrack *track);
  15. ~QtMaterialSliderStateMachine();
  16. void setupProperties();
  17. private:
  18. Q_DISABLE_COPY(QtMaterialSliderStateMachine)
  19. QtMaterialSlider *const m_slider;
  20. QtMaterialSliderThumb *const m_thumb;
  21. QtMaterialSliderTrack *const m_track;
  22. QState *const m_topState;
  23. QState *const m_fstState;
  24. QState *const m_sndState;
  25. QState *const m_inactiveState;
  26. QState *const m_focusState;
  27. QState *const m_slidingState;
  28. QState *const m_pulseOutState;
  29. QState *const m_pulseInState;
  30. QState *const m_minState;
  31. QState *const m_normalState;
  32. };
  33. class QtMaterialSliderThumb : public QtMaterialOverlayWidget
  34. {
  35. Q_OBJECT
  36. Q_PROPERTY(qreal diameter WRITE setDiameter READ diameter)
  37. Q_PROPERTY(qreal borderWidth WRITE setBorderWidth READ borderWidth)
  38. Q_PROPERTY(QColor borderColor WRITE setBorderColor READ borderColor)
  39. Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
  40. Q_PROPERTY(qreal haloSize WRITE setHaloSize READ haloSize)
  41. Q_PROPERTY(QColor haloColor WRITE setHaloColor READ haloColor)
  42. public:
  43. explicit QtMaterialSliderThumb(QtMaterialSlider *slider);
  44. ~QtMaterialSliderThumb();
  45. inline void setDiameter(qreal diameter);
  46. inline qreal diameter() const;
  47. inline void setBorderWidth(qreal width);
  48. inline qreal borderWidth() const;
  49. inline void setBorderColor(const QColor &color);
  50. inline QColor borderColor() const;
  51. inline void setFillColor(const QColor &color);
  52. inline QColor fillColor() const;
  53. inline void setHaloSize(qreal size);
  54. inline qreal haloSize() const;
  55. inline void setHaloColor(const QColor &color);
  56. inline QColor haloColor() const;
  57. inline void setOffset(int offset);
  58. inline int offset() const;
  59. protected:
  60. bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
  61. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  62. private:
  63. Q_DISABLE_COPY(QtMaterialSliderThumb)
  64. const QtMaterialSlider *const m_slider;
  65. QColor m_borderColor;
  66. QColor m_fillColor;
  67. QColor m_haloColor;
  68. qreal m_diameter;
  69. qreal m_borderWidth;
  70. qreal m_haloSize;
  71. int m_offset;
  72. };
  73. inline void QtMaterialSliderThumb::setDiameter(qreal diameter)
  74. {
  75. m_diameter = diameter;
  76. update();
  77. }
  78. inline qreal QtMaterialSliderThumb::diameter() const
  79. {
  80. return m_diameter;
  81. }
  82. inline void QtMaterialSliderThumb::setBorderWidth(qreal width)
  83. {
  84. m_borderWidth = width;
  85. update();
  86. }
  87. inline qreal QtMaterialSliderThumb::borderWidth() const
  88. {
  89. return m_borderWidth;
  90. }
  91. inline void QtMaterialSliderThumb::setBorderColor(const QColor &color)
  92. {
  93. m_borderColor = color;
  94. update();
  95. }
  96. inline QColor QtMaterialSliderThumb::borderColor() const
  97. {
  98. return m_borderColor;
  99. }
  100. inline void QtMaterialSliderThumb::setFillColor(const QColor &color)
  101. {
  102. m_fillColor = color;
  103. update();
  104. }
  105. inline QColor QtMaterialSliderThumb::fillColor() const
  106. {
  107. return m_fillColor;
  108. }
  109. inline void QtMaterialSliderThumb::setHaloSize(qreal size)
  110. {
  111. m_haloSize = size;
  112. update();
  113. }
  114. inline qreal QtMaterialSliderThumb::haloSize() const
  115. {
  116. return m_haloSize;
  117. }
  118. inline void QtMaterialSliderThumb::setHaloColor(const QColor &color)
  119. {
  120. m_haloColor = color;
  121. update();
  122. }
  123. inline QColor QtMaterialSliderThumb::haloColor() const
  124. {
  125. return m_haloColor;
  126. }
  127. inline void QtMaterialSliderThumb::setOffset(int offset)
  128. {
  129. m_offset = offset;
  130. update();
  131. }
  132. inline int QtMaterialSliderThumb::offset() const
  133. {
  134. return m_offset;
  135. }
  136. class QtMaterialSliderTrack : public QtMaterialOverlayWidget
  137. {
  138. Q_OBJECT
  139. Q_PROPERTY(QColor fillColor WRITE setFillColor READ fillColor)
  140. public:
  141. explicit QtMaterialSliderTrack(QtMaterialSliderThumb *thumb, QtMaterialSlider *slider);
  142. ~QtMaterialSliderTrack();
  143. inline void setFillColor(const QColor &color);
  144. inline QColor fillColor() const;
  145. inline void setTrackWidth(int width);
  146. inline int trackWidth() const;
  147. protected:
  148. bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
  149. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  150. private:
  151. Q_DISABLE_COPY(QtMaterialSliderTrack)
  152. const QtMaterialSlider *const m_slider;
  153. QtMaterialSliderThumb *const m_thumb;
  154. QColor m_fillColor;
  155. int m_trackWidth;
  156. };
  157. inline void QtMaterialSliderTrack::setFillColor(const QColor &color)
  158. {
  159. m_fillColor = color;
  160. update();
  161. }
  162. inline QColor QtMaterialSliderTrack::fillColor() const
  163. {
  164. return m_fillColor;
  165. }
  166. void QtMaterialSliderTrack::setTrackWidth(int width)
  167. {
  168. m_trackWidth = width;
  169. update();
  170. }
  171. int QtMaterialSliderTrack::trackWidth() const
  172. {
  173. return m_trackWidth;
  174. }
  175. #endif // QTMATERIALSLIDER_INTERNAL_H