qt-material-widgets/components/textfield_internal.h

78 lines
1.9 KiB
C
Raw Normal View History

#ifndef TEXTFIELD_INTERNAL_H
#define TEXTFIELD_INTERNAL_H
2016-06-14 15:37:41 +00:00
#include <QStateMachine>
2016-06-16 16:08:54 +00:00
#include <QWidget>
2016-06-14 15:37:41 +00:00
2016-06-21 12:42:49 +00:00
class QPropertyAnimation;
2016-06-14 15:37:41 +00:00
class TextField;
2016-06-16 16:08:54 +00:00
class TextFieldLabel;
2016-06-14 15:37:41 +00:00
class TextFieldStateMachine : public QStateMachine
{
Q_OBJECT
2016-06-14 17:29:20 +00:00
Q_PROPERTY(qreal progress WRITE setProgress READ progress)
2016-06-14 15:37:41 +00:00
public:
TextFieldStateMachine(TextField *parent);
~TextFieldStateMachine();
2016-06-16 16:08:54 +00:00
void setLabel(TextFieldLabel *widget);
2016-06-14 17:29:20 +00:00
void setProgress(qreal progress);
inline qreal progress() const { return _progress; }
2016-06-16 16:08:54 +00:00
protected slots:
void assignProperties();
2016-06-14 15:37:41 +00:00
private:
Q_DISABLE_COPY(TextFieldStateMachine)
2016-06-16 16:08:54 +00:00
friend class TextField;
TextField *const textField;
QState *const _normalState;
QState *const _focusedState;
2016-06-21 12:42:49 +00:00
TextFieldLabel *_label;
QPropertyAnimation *_offsetAnimation;
QPropertyAnimation *_colorAnimation;
2016-06-16 16:08:54 +00:00
qreal _progress;
};
class TextFieldLabel : public QWidget
{
Q_OBJECT
Q_PROPERTY(qreal scale WRITE setScale READ scale)
Q_PROPERTY(QPointF offset WRITE setOffset READ offset)
Q_PROPERTY(QColor color WRITE setColor READ color)
public:
TextFieldLabel(TextField *parent);
~TextFieldLabel();
inline void setScale(qreal scale) { _scale = scale; update(); }
inline qreal scale() const { return _scale; }
inline void setOffset(const QPointF &pos) { _posX = pos.x(); _posY = pos.y(); update(); }
inline QPointF offset() const { return QPointF(_posX, _posY); }
inline void setColor(const QColor &color) { _color = color; update(); }
inline QColor color() const { return _color; }
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
Q_DISABLE_COPY(TextFieldLabel)
TextField *const label;
2016-06-21 12:42:49 +00:00
qreal _scale;
qreal _posX;
qreal _posY;
QColor _color;
2016-06-14 15:37:41 +00:00
};
#endif // TEXTFIELD_INTERNAL_H