diff --git a/components/qtmaterialtextfield.cpp b/components/qtmaterialtextfield.cpp index 080da82..938a811 100644 --- a/components/qtmaterialtextfield.cpp +++ b/components/qtmaterialtextfield.cpp @@ -5,26 +5,28 @@ #include "qtmaterialtextfield_internal.h" #include "lib/qtmaterialstyle.h" #include +namespace md +{ /*! * \class QtMaterialTextFieldPrivate * \internal */ -QtMaterialTextFieldPrivate::QtMaterialTextFieldPrivate(QtMaterialTextField *q) +TextFieldPrivate::TextFieldPrivate(TextField *q) : q_ptr(q) { } -QtMaterialTextFieldPrivate::~QtMaterialTextFieldPrivate() +TextFieldPrivate::~TextFieldPrivate() { } -void QtMaterialTextFieldPrivate::init() +void TextFieldPrivate::init() { - Q_Q(QtMaterialTextField); + Q_Q(TextField); - stateMachine = new QtMaterialTextFieldStateMachine(q); + stateMachine = new TextFieldStateMachine(q); label = 0; labelFontSize = 9.5; showLabel = false; @@ -32,7 +34,7 @@ void QtMaterialTextFieldPrivate::init() useThemeColors = true; q->setFrame(false); - q->setStyle(&QtMaterialStyle::instance()); + q->setStyle(&Style::instance()); q->setAttribute(Qt::WA_Hover); q->setMouseTracking(true); q->setTextMargins(0, 2, 0, 4); @@ -47,20 +49,20 @@ void QtMaterialTextFieldPrivate::init() * \class QtMaterialTextField */ -QtMaterialTextField::QtMaterialTextField(QWidget *parent) +TextField::TextField(QWidget *parent) : QLineEdit(parent), - d_ptr(new QtMaterialTextFieldPrivate(this)) + d_ptr(new TextFieldPrivate(this)) { d_func()->init(); } -QtMaterialTextField::~QtMaterialTextField() +TextField::~TextField() { } -void QtMaterialTextField::setUseThemeColors(bool value) +void TextField::setUseThemeColors(bool value) { - Q_D(QtMaterialTextField); + Q_D(TextField); if (d->useThemeColors == value) { return; @@ -70,16 +72,16 @@ void QtMaterialTextField::setUseThemeColors(bool value) d->stateMachine->setupProperties(); } -bool QtMaterialTextField::useThemeColors() const +bool TextField::useThemeColors() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); return d->useThemeColors; } -void QtMaterialTextField::setShowLabel(bool value) +void TextField::setShowLabel(bool value) { - Q_D(QtMaterialTextField); + Q_D(TextField); if (d->showLabel == value) { return; @@ -88,7 +90,7 @@ void QtMaterialTextField::setShowLabel(bool value) d->showLabel = value; if (!d->label && value) { - d->label = new QtMaterialTextFieldLabel(this); + d->label = new TextFieldLabel(this); d->stateMachine->setLabel(d->label); } @@ -99,16 +101,16 @@ void QtMaterialTextField::setShowLabel(bool value) } } -bool QtMaterialTextField::hasLabel() const +bool TextField::hasLabel() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); return d->showLabel; } -void QtMaterialTextField::setLabelFontSize(qreal size) +void TextField::setLabelFontSize(qreal size) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->labelFontSize = size; @@ -121,32 +123,32 @@ void QtMaterialTextField::setLabelFontSize(qreal size) } } -qreal QtMaterialTextField::labelFontSize() const +qreal TextField::labelFontSize() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); return d->labelFontSize; } -void QtMaterialTextField::setLabel(const QString &label) +void TextField::setLabel(const QString &label) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->labelString = label; setShowLabel(true); d->label->update(); } -QString QtMaterialTextField::label() const +QString TextField::label() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); return d->labelString; } -void QtMaterialTextField::setTextColor(const QColor &color) +void TextField::setTextColor(const QColor &color) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->textColor = color; setStyleSheet(QString("QLineEdit { color: %1; }").arg(color.name())); @@ -155,20 +157,20 @@ void QtMaterialTextField::setTextColor(const QColor &color) d->stateMachine->setupProperties(); } -QColor QtMaterialTextField::textColor() const +QColor TextField::textColor() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); if (d->useThemeColors || !d->textColor.isValid()) { - return QtMaterialStyle::instance().themeColor("text"); + return Style::instance().themeColor("text"); } else { return d->textColor; } } -void QtMaterialTextField::setLabelColor(const QColor &color) +void TextField::setLabelColor(const QColor &color) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->labelColor = color; @@ -176,20 +178,20 @@ void QtMaterialTextField::setLabelColor(const QColor &color) d->stateMachine->setupProperties(); } -QColor QtMaterialTextField::labelColor() const +QColor TextField::labelColor() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); if (d->useThemeColors || !d->labelColor.isValid()) { - return QtMaterialStyle::instance().themeColor("accent3"); + return Style::instance().themeColor("accent3"); } else { return d->labelColor; } } -void QtMaterialTextField::setInkColor(const QColor &color) +void TextField::setInkColor(const QColor &color) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->inkColor = color; @@ -197,20 +199,20 @@ void QtMaterialTextField::setInkColor(const QColor &color) d->stateMachine->setupProperties(); } -QColor QtMaterialTextField::inkColor() const +QColor TextField::inkColor() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); if (d->useThemeColors || !d->inkColor.isValid()) { - return QtMaterialStyle::instance().themeColor("primary1"); + return Style::instance().themeColor("primary1"); } else { return d->inkColor; } } -void QtMaterialTextField::setInputLineColor(const QColor &color) +void TextField::setInputLineColor(const QColor &color) { - Q_D(QtMaterialTextField); + Q_D(TextField); d->inputLineColor = color; @@ -218,20 +220,20 @@ void QtMaterialTextField::setInputLineColor(const QColor &color) d->stateMachine->setupProperties(); } -QColor QtMaterialTextField::inputLineColor() const +QColor TextField::inputLineColor() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); if (d->useThemeColors || !d->inputLineColor.isValid()) { - return QtMaterialStyle::instance().themeColor("border"); + return Style::instance().themeColor("border"); } else { return d->inputLineColor; } } -void QtMaterialTextField::setShowInputLine(bool value) +void TextField::setShowInputLine(bool value) { - Q_D(QtMaterialTextField); + Q_D(TextField); if (d->showInputLine == value) { return; @@ -241,14 +243,14 @@ void QtMaterialTextField::setShowInputLine(bool value) update(); } -bool QtMaterialTextField::hasInputLine() const +bool TextField::hasInputLine() const { - Q_D(const QtMaterialTextField); + Q_D(const TextField); return d->showInputLine; } -QtMaterialTextField::QtMaterialTextField(QtMaterialTextFieldPrivate &d, QWidget *parent) +TextField::TextField(TextFieldPrivate &d, QWidget *parent) : QLineEdit(parent), d_ptr(&d) { @@ -258,9 +260,9 @@ QtMaterialTextField::QtMaterialTextField(QtMaterialTextFieldPrivate &d, QWidget /*! * \reimp */ -bool QtMaterialTextField::event(QEvent *event) +bool TextField::event(QEvent *event) { - Q_D(QtMaterialTextField); + Q_D(TextField); switch (event->type()) { @@ -279,9 +281,9 @@ bool QtMaterialTextField::event(QEvent *event) /*! * \reimp */ -void QtMaterialTextField::paintEvent(QPaintEvent *event) +void TextField::paintEvent(QPaintEvent *event) { - Q_D(QtMaterialTextField); + Q_D(TextField); QLineEdit::paintEvent(event); @@ -324,3 +326,4 @@ void QtMaterialTextField::paintEvent(QPaintEvent *event) } } } +} diff --git a/components/qtmaterialtextfield.h b/components/qtmaterialtextfield.h index dead5cc..c845809 100644 --- a/components/qtmaterialtextfield.h +++ b/components/qtmaterialtextfield.h @@ -3,10 +3,12 @@ #include #include +namespace md +{ -class QtMaterialTextFieldPrivate; +class TextFieldPrivate; -class QtMaterialTextField : public QLineEdit +class TextField : public QLineEdit { Q_OBJECT @@ -15,8 +17,8 @@ class QtMaterialTextField : public QLineEdit Q_PROPERTY(QColor inputLineColor WRITE setInputLineColor READ inputLineColor) public: - explicit QtMaterialTextField(QWidget *parent = 0); - ~QtMaterialTextField(); + explicit TextField(QWidget *parent = 0); + ~TextField(); void setUseThemeColors(bool value); bool useThemeColors() const; @@ -46,16 +48,16 @@ public: bool hasInputLine() const; protected: - QtMaterialTextField(QtMaterialTextFieldPrivate &d, QWidget *parent = 0); + TextField(TextFieldPrivate &d, QWidget *parent = 0); bool event(QEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; - const QScopedPointer d_ptr; + const QScopedPointer d_ptr; private: - Q_DISABLE_COPY(QtMaterialTextField) - Q_DECLARE_PRIVATE(QtMaterialTextField) + Q_DISABLE_COPY(TextField) + Q_DECLARE_PRIVATE(TextField) }; - +} #endif // QTMATERIALTEXTFIELD_H diff --git a/components/qtmaterialtextfield_internal.cpp b/components/qtmaterialtextfield_internal.cpp index b8b4ce7..fa148ce 100644 --- a/components/qtmaterialtextfield_internal.cpp +++ b/components/qtmaterialtextfield_internal.cpp @@ -3,13 +3,15 @@ #include #include #include "qtmaterialtextfield.h" +namespace md +{ /*! * \class QtMaterialTextFieldStateMachine * \internal */ -QtMaterialTextFieldStateMachine::QtMaterialTextFieldStateMachine(QtMaterialTextField *parent) +TextFieldStateMachine::TextFieldStateMachine(TextField *parent) : QStateMachine(parent), m_textField(parent), m_normalState(new QState), @@ -55,11 +57,11 @@ QtMaterialTextFieldStateMachine::QtMaterialTextFieldStateMachine(QtMaterialTextF connect(m_textField, SIGNAL(textChanged(QString)), this, SLOT(setupProperties())); } -QtMaterialTextFieldStateMachine::~QtMaterialTextFieldStateMachine() +TextFieldStateMachine::~TextFieldStateMachine() { } -void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) +void TextFieldStateMachine::setLabel(TextFieldLabel *label) { if (m_label) { delete m_label; @@ -92,7 +94,7 @@ void QtMaterialTextFieldStateMachine::setLabel(QtMaterialTextFieldLabel *label) setupProperties(); } -void QtMaterialTextFieldStateMachine::setupProperties() +void TextFieldStateMachine::setupProperties() { if (m_label) { @@ -123,7 +125,7 @@ void QtMaterialTextFieldStateMachine::setupProperties() * \internal */ -QtMaterialTextFieldLabel::QtMaterialTextFieldLabel(QtMaterialTextField *parent) +TextFieldLabel::TextFieldLabel(TextField *parent) : QWidget(parent), m_textField(parent), m_scale(1), @@ -138,14 +140,14 @@ QtMaterialTextFieldLabel::QtMaterialTextFieldLabel(QtMaterialTextField *parent) setFont(font); } -QtMaterialTextFieldLabel::~QtMaterialTextFieldLabel() +TextFieldLabel::~TextFieldLabel() { } /*! * \reimp */ -void QtMaterialTextFieldLabel::paintEvent(QPaintEvent *event) +void TextFieldLabel::paintEvent(QPaintEvent *event) { Q_UNUSED(event) @@ -162,3 +164,4 @@ void QtMaterialTextFieldLabel::paintEvent(QPaintEvent *event) QPointF pos(2+m_posX, height()-36+m_posY); painter.drawText(pos.x(), pos.y(), m_textField->label()); } +} diff --git a/components/qtmaterialtextfield_internal.h b/components/qtmaterialtextfield_internal.h index e510287..fd8ab58 100644 --- a/components/qtmaterialtextfield_internal.h +++ b/components/qtmaterialtextfield_internal.h @@ -4,21 +4,23 @@ #include #include #include "qtmaterialtextfield.h" +namespace md +{ class QPropertyAnimation; -class QtMaterialTextFieldLabel; +class TextFieldLabel; -class QtMaterialTextFieldStateMachine : public QStateMachine +class TextFieldStateMachine : public QStateMachine { Q_OBJECT Q_PROPERTY(qreal progress WRITE setProgress READ progress) public: - QtMaterialTextFieldStateMachine(QtMaterialTextField *parent); - ~QtMaterialTextFieldStateMachine(); + TextFieldStateMachine(TextField *parent); + ~TextFieldStateMachine(); - void setLabel(QtMaterialTextFieldLabel *label); + void setLabel(TextFieldLabel *label); inline void setProgress(qreal progress); inline qreal progress() const; @@ -27,29 +29,29 @@ public slots: void setupProperties(); private: - Q_DISABLE_COPY(QtMaterialTextFieldStateMachine) + Q_DISABLE_COPY(TextFieldStateMachine) - QtMaterialTextField *const m_textField; + TextField *const m_textField; QState *const m_normalState; QState *const m_focusedState; - QtMaterialTextFieldLabel *m_label; + TextFieldLabel *m_label; QPropertyAnimation *m_offsetAnimation; QPropertyAnimation *m_colorAnimation; qreal m_progress; }; -inline void QtMaterialTextFieldStateMachine::setProgress(qreal progress) +inline void TextFieldStateMachine::setProgress(qreal progress) { m_progress = progress; m_textField->update(); } -inline qreal QtMaterialTextFieldStateMachine::progress() const +inline qreal TextFieldStateMachine::progress() const { return m_progress; } -class QtMaterialTextFieldLabel : public QWidget +class TextFieldLabel : public QWidget { Q_OBJECT @@ -58,8 +60,8 @@ class QtMaterialTextFieldLabel : public QWidget Q_PROPERTY(QColor color WRITE setColor READ color) public: - QtMaterialTextFieldLabel(QtMaterialTextField *parent); - ~QtMaterialTextFieldLabel(); + TextFieldLabel(TextField *parent); + ~TextFieldLabel(); inline void setScale(qreal scale); inline qreal scale() const; @@ -74,47 +76,47 @@ protected: void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; private: - Q_DISABLE_COPY(QtMaterialTextFieldLabel) + Q_DISABLE_COPY(TextFieldLabel) - QtMaterialTextField *const m_textField; + TextField *const m_textField; qreal m_scale; qreal m_posX; qreal m_posY; QColor m_color; }; -inline void QtMaterialTextFieldLabel::setScale(qreal scale) +inline void TextFieldLabel::setScale(qreal scale) { m_scale = scale; update(); } -inline qreal QtMaterialTextFieldLabel::scale() const +inline qreal TextFieldLabel::scale() const { return m_scale; } -inline void QtMaterialTextFieldLabel::setOffset(const QPointF &pos) +inline void TextFieldLabel::setOffset(const QPointF &pos) { m_posX = pos.x(); m_posY = pos.y(); update(); } -inline QPointF QtMaterialTextFieldLabel::offset() const +inline QPointF TextFieldLabel::offset() const { return QPointF(m_posX, m_posY); } -inline void QtMaterialTextFieldLabel::setColor(const QColor &color) +inline void TextFieldLabel::setColor(const QColor &color) { m_color = color; update(); } -inline QColor QtMaterialTextFieldLabel::color() const +inline QColor TextFieldLabel::color() const { return m_color; } - +} #endif // QTMATERIALTEXTFIELD_INTERNAL_H diff --git a/components/qtmaterialtextfield_p.h b/components/qtmaterialtextfield_p.h index 9e8c835..a3682be 100644 --- a/components/qtmaterialtextfield_p.h +++ b/components/qtmaterialtextfield_p.h @@ -4,24 +4,26 @@ #include #include -class QtMaterialTextField; -class QtMaterialTextFieldStateMachine; -class QtMaterialTextFieldLabel; - -class QtMaterialTextFieldPrivate +namespace md { - Q_DISABLE_COPY(QtMaterialTextFieldPrivate) - Q_DECLARE_PUBLIC(QtMaterialTextField) +class TextField; +class TextFieldStateMachine; +class TextFieldLabel; + +class TextFieldPrivate +{ + Q_DISABLE_COPY(TextFieldPrivate) + Q_DECLARE_PUBLIC(TextField) public: - QtMaterialTextFieldPrivate(QtMaterialTextField *q); - virtual ~QtMaterialTextFieldPrivate(); + TextFieldPrivate(TextField *q); + virtual ~TextFieldPrivate(); void init(); - QtMaterialTextField *const q_ptr; - QtMaterialTextFieldStateMachine *stateMachine; - QtMaterialTextFieldLabel *label; + TextField *const q_ptr; + TextFieldStateMachine *stateMachine; + TextFieldLabel *label; QColor textColor; QColor labelColor; QColor inkColor; @@ -32,5 +34,6 @@ public: bool showInputLine; bool useThemeColors; }; +} #endif // QTMATERIALTEXTFIELD_P_H