qtmaterialtextfield_internal.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef QTMATERIALTEXTFIELD_INTERNAL_H
  2. #define QTMATERIALTEXTFIELD_INTERNAL_H
  3. #include <QStateMachine>
  4. #include <QtWidgets/QWidget>
  5. #include "qtmaterialtextfield.h"
  6. class QPropertyAnimation;
  7. class QtMaterialTextFieldLabel;
  8. class QtMaterialTextFieldStateMachine : public QStateMachine
  9. {
  10. Q_OBJECT
  11. Q_PROPERTY(qreal progress WRITE setProgress READ progress)
  12. public:
  13. QtMaterialTextFieldStateMachine(QtMaterialTextField *parent);
  14. ~QtMaterialTextFieldStateMachine();
  15. void setLabel(QtMaterialTextFieldLabel *label);
  16. inline void setProgress(qreal progress);
  17. inline qreal progress() const;
  18. public slots:
  19. void setupProperties();
  20. private:
  21. Q_DISABLE_COPY(QtMaterialTextFieldStateMachine)
  22. QtMaterialTextField *const m_textField;
  23. QState *const m_normalState;
  24. QState *const m_focusedState;
  25. QtMaterialTextFieldLabel *m_label;
  26. QPropertyAnimation *m_offsetAnimation;
  27. QPropertyAnimation *m_colorAnimation;
  28. qreal m_progress;
  29. };
  30. inline void QtMaterialTextFieldStateMachine::setProgress(qreal progress)
  31. {
  32. m_progress = progress;
  33. m_textField->update();
  34. }
  35. inline qreal QtMaterialTextFieldStateMachine::progress() const
  36. {
  37. return m_progress;
  38. }
  39. class QtMaterialTextFieldLabel : public QWidget
  40. {
  41. Q_OBJECT
  42. Q_PROPERTY(qreal scale WRITE setScale READ scale)
  43. Q_PROPERTY(QPointF offset WRITE setOffset READ offset)
  44. Q_PROPERTY(QColor color WRITE setColor READ color)
  45. public:
  46. QtMaterialTextFieldLabel(QtMaterialTextField *parent);
  47. ~QtMaterialTextFieldLabel();
  48. inline void setScale(qreal scale);
  49. inline qreal scale() const;
  50. inline void setOffset(const QPointF &pos);
  51. inline QPointF offset() const;
  52. inline void setColor(const QColor &color);
  53. inline QColor color() const;
  54. protected:
  55. void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
  56. private:
  57. Q_DISABLE_COPY(QtMaterialTextFieldLabel)
  58. QtMaterialTextField *const m_textField;
  59. qreal m_scale;
  60. qreal m_posX;
  61. qreal m_posY;
  62. QColor m_color;
  63. };
  64. inline void QtMaterialTextFieldLabel::setScale(qreal scale)
  65. {
  66. m_scale = scale;
  67. update();
  68. }
  69. inline qreal QtMaterialTextFieldLabel::scale() const
  70. {
  71. return m_scale;
  72. }
  73. inline void QtMaterialTextFieldLabel::setOffset(const QPointF &pos)
  74. {
  75. m_posX = pos.x();
  76. m_posY = pos.y();
  77. update();
  78. }
  79. inline QPointF QtMaterialTextFieldLabel::offset() const
  80. {
  81. return QPointF(m_posX, m_posY);
  82. }
  83. inline void QtMaterialTextFieldLabel::setColor(const QColor &color)
  84. {
  85. m_color = color;
  86. update();
  87. }
  88. inline QColor QtMaterialTextFieldLabel::color() const
  89. {
  90. return m_color;
  91. }
  92. #endif // QTMATERIALTEXTFIELD_INTERNAL_H