qt-material-widgets/components/qtmaterialtextfield_internal.h

123 lines
2.5 KiB
C
Raw Normal View History

2017-09-29 17:15:25 +00:00
#ifndef QTMATERIALTEXTFIELD_INTERNAL_H
#define QTMATERIALTEXTFIELD_INTERNAL_H
#include <QStateMachine>
#include <QtWidgets/QWidget>
#include "qtmaterialtextfield.h"
2022-02-17 03:08:05 +00:00
namespace md
{
2017-09-29 17:15:25 +00:00
class QPropertyAnimation;
2022-02-17 03:08:05 +00:00
class TextFieldLabel;
2017-09-29 17:15:25 +00:00
2022-02-17 03:08:05 +00:00
class TextFieldStateMachine : public QStateMachine
2017-09-29 17:15:25 +00:00
{
Q_OBJECT
Q_PROPERTY(qreal progress WRITE setProgress READ progress)
public:
2022-02-17 03:08:05 +00:00
TextFieldStateMachine(TextField *parent);
~TextFieldStateMachine();
2017-09-29 17:15:25 +00:00
2022-02-17 03:08:05 +00:00
void setLabel(TextFieldLabel *label);
2017-09-29 17:15:25 +00:00
inline void setProgress(qreal progress);
inline qreal progress() const;
public slots:
void setupProperties();
private:
2022-02-17 03:08:05 +00:00
Q_DISABLE_COPY(TextFieldStateMachine)
2017-09-29 17:15:25 +00:00
2022-02-17 03:08:05 +00:00
TextField *const m_textField;
2017-09-29 17:15:25 +00:00
QState *const m_normalState;
QState *const m_focusedState;
2022-02-17 03:08:05 +00:00
TextFieldLabel *m_label;
2017-09-29 17:15:25 +00:00
QPropertyAnimation *m_offsetAnimation;
QPropertyAnimation *m_colorAnimation;
qreal m_progress;
};
2022-02-17 03:08:05 +00:00
inline void TextFieldStateMachine::setProgress(qreal progress)
2017-09-29 17:15:25 +00:00
{
m_progress = progress;
m_textField->update();
}
2022-02-17 03:08:05 +00:00
inline qreal TextFieldStateMachine::progress() const
2017-09-29 17:15:25 +00:00
{
return m_progress;
}
2022-02-17 03:08:05 +00:00
class TextFieldLabel : public QWidget
2017-09-29 17:15:25 +00:00
{
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:
2022-02-17 03:08:05 +00:00
TextFieldLabel(TextField *parent);
~TextFieldLabel();
2017-09-29 17:15:25 +00:00
inline void setScale(qreal scale);
inline qreal scale() const;
inline void setOffset(const QPointF &pos);
inline QPointF offset() const;
inline void setColor(const QColor &color);
inline QColor color() const;
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private:
2022-02-17 03:08:05 +00:00
Q_DISABLE_COPY(TextFieldLabel)
2017-09-29 17:15:25 +00:00
2022-02-17 03:08:05 +00:00
TextField *const m_textField;
2017-09-29 17:15:25 +00:00
qreal m_scale;
qreal m_posX;
qreal m_posY;
QColor m_color;
};
2022-02-17 03:08:05 +00:00
inline void TextFieldLabel::setScale(qreal scale)
2017-09-29 17:15:25 +00:00
{
m_scale = scale;
update();
}
2022-02-17 03:08:05 +00:00
inline qreal TextFieldLabel::scale() const
2017-09-29 17:15:25 +00:00
{
return m_scale;
}
2022-02-17 03:08:05 +00:00
inline void TextFieldLabel::setOffset(const QPointF &pos)
2017-09-29 17:15:25 +00:00
{
m_posX = pos.x();
m_posY = pos.y();
update();
}
2022-02-17 03:08:05 +00:00
inline QPointF TextFieldLabel::offset() const
2017-09-29 17:15:25 +00:00
{
return QPointF(m_posX, m_posY);
}
2022-02-17 03:08:05 +00:00
inline void TextFieldLabel::setColor(const QColor &color)
2017-09-29 17:15:25 +00:00
{
m_color = color;
update();
}
2022-02-17 03:08:05 +00:00
inline QColor TextFieldLabel::color() const
2017-09-29 17:15:25 +00:00
{
return m_color;
}
2022-02-17 03:08:05 +00:00
}
2017-09-29 17:15:25 +00:00
#endif // QTMATERIALTEXTFIELD_INTERNAL_H