diff --git a/components/textfield.cpp b/components/textfield.cpp index 8366497..3be307f 100644 --- a/components/textfield.cpp +++ b/components/textfield.cpp @@ -1,81 +1,105 @@ -#include -#include -#include -#include #include "textfield.h" -#include "lib/style.h" +#include "textfield_p.h" + +TextFieldPrivate::TextFieldPrivate(TextField *q) + : q_ptr(q) +{ +} + +void TextFieldPrivate::init() +{ +} TextField::TextField(QWidget *parent) : QLineEdit(parent), - _animation(new QPropertyAnimation(this)), - _progress(1) + d_ptr(new TextFieldPrivate(this)) { - setStyle(&Style::instance()); - - _animation->setPropertyName("progress"); - _animation->setTargetObject(this); - _animation->setEasingCurve(QEasingCurve::InCubic); - _animation->setDuration(350); - _animation->setStartValue(1); - _animation->setEndValue(0); + d_func()->init(); } TextField::~TextField() { } -void TextField::setProgress(qreal progress) -{ - if (_progress == progress) - return; - _progress = progress; - - emit progressChanged(progress); - update(); -} - -void TextField::focusInEvent(QFocusEvent *event) -{ - _animation->setDirection(QAbstractAnimation::Forward); - _animation->start(); - - QLineEdit::focusInEvent(event); -} - -void TextField::focusOutEvent(QFocusEvent *event) -{ - _animation->setDirection(QAbstractAnimation::Backward); - _animation->start(); - - QLineEdit::focusOutEvent(event); -} - -void TextField::mousePressEvent(QMouseEvent *event) -{ - QLineEdit::mousePressEvent(event); -} - -void TextField::mouseReleaseEvent(QMouseEvent *event) -{ - QLineEdit::mouseReleaseEvent(event); -} - -void TextField::paintEvent(QPaintEvent *event) -{ - QLineEdit::paintEvent(event); - - QPainter painter(this); - - QBrush brush; - brush.setStyle(Qt::SolidPattern); - - if (!qFuzzyCompare(1, _progress)) { - - painter.setPen(Qt::NoPen); - painter.setBrush(brush); - - int w = _progress*static_cast(width()/2); - - painter.drawRect(w, height()-2, width()-w*2, 2); - } -} +//#include +//#include +//#include +//#include +//#include "textfield.h" +//#include "lib/style.h" +// +//TextField::TextField(QWidget *parent) +// : QLineEdit(parent), +// _animation(new QPropertyAnimation(this)), +// _progress(1) +//{ +// setStyle(&Style::instance()); +// +// _animation->setPropertyName("progress"); +// _animation->setTargetObject(this); +// _animation->setEasingCurve(QEasingCurve::InCubic); +// _animation->setDuration(350); +// _animation->setStartValue(1); +// _animation->setEndValue(0); +//} +// +//TextField::~TextField() +//{ +//} +// +//void TextField::setProgress(qreal progress) +//{ +// if (_progress == progress) +// return; +// _progress = progress; +// +// emit progressChanged(progress); +// update(); +//} +// +//void TextField::focusInEvent(QFocusEvent *event) +//{ +// _animation->setDirection(QAbstractAnimation::Forward); +// _animation->start(); +// +// QLineEdit::focusInEvent(event); +//} +// +//void TextField::focusOutEvent(QFocusEvent *event) +//{ +// _animation->setDirection(QAbstractAnimation::Backward); +// _animation->start(); +// +// QLineEdit::focusOutEvent(event); +//} +// +//void TextField::mousePressEvent(QMouseEvent *event) +//{ +// QLineEdit::mousePressEvent(event); +//} +// +//void TextField::mouseReleaseEvent(QMouseEvent *event) +//{ +// QLineEdit::mouseReleaseEvent(event); +//} +// +//void TextField::paintEvent(QPaintEvent *event) +//{ +// QLineEdit::paintEvent(event); +// +// QPainter painter(this); +// +// QBrush brush; +// brush.setStyle(Qt::SolidPattern); +// +// if (!qFuzzyCompare(1, _progress)) { +// +// painter.setPen(Qt::NoPen); +// painter.setBrush(brush); +// +// int w = _progress*static_cast(width()/2); +// +// painter.drawRect(w, height()-2, width()-w*2, 2); +// } +//} +// diff --git a/components/textfield.h b/components/textfield.h index 72a38f0..fb3c7cb 100644 --- a/components/textfield.h +++ b/components/textfield.h @@ -3,34 +3,54 @@ #include -class QPropertyAnimation; +class TextFieldPrivate; class TextField : public QLineEdit { Q_OBJECT - Q_PROPERTY(qreal progress WRITE setProgress READ progress NOTIFY progressChanged) - public: explicit TextField(QWidget *parent = 0); ~TextField(); - void setProgress(qreal progress); - inline qreal progress() const { return _progress; } - -signals: - void progressChanged(qreal); - protected: - void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; - void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; - void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; - void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; + const QScopedPointer d_ptr; private: - QPropertyAnimation *const _animation; - qreal _progress; + Q_DISABLE_COPY(TextField) + Q_DECLARE_PRIVATE(TextField) }; +//#include +// +//class QPropertyAnimation; +// +//class TextField : public QLineEdit +//{ +// Q_OBJECT +// +// Q_PROPERTY(qreal progress WRITE setProgress READ progress NOTIFY progressChanged) +// +//public: +// explicit TextField(QWidget *parent = 0); +// ~TextField(); +// +// void setProgress(qreal progress); +// inline qreal progress() const { return _progress; } +// +//signals: +// void progressChanged(qreal); +// +//protected: +// void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE; +// void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE; +// void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE; +// void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE; +// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; +// +//private: +// QPropertyAnimation *const _animation; +// qreal _progress; +//}; + #endif // TEXTFIELD_H diff --git a/components/textfield_p.h b/components/textfield_p.h new file mode 100644 index 0000000..eda1149 --- /dev/null +++ b/components/textfield_p.h @@ -0,0 +1,20 @@ +#ifndef TEXTFIELD_P_H +#define TEXTFIELD_P_H + +#include + +class TextField; + +class TextFieldPrivate +{ + Q_DISABLE_COPY(TextFieldPrivate) + Q_DECLARE_PUBLIC(TextField) + +public: + TextFieldPrivate(TextField *q); + void init(); + + TextField *const q_ptr; +}; + +#endif // TEXTFIELD_P_H diff --git a/qt-material-widgets.pro b/qt-material-widgets.pro index deb777d..321e244 100644 --- a/qt-material-widgets.pro +++ b/qt-material-widgets.pro @@ -130,7 +130,8 @@ HEADERS += mainwindow.h \ lib/checkable_p.h \ lib/checkable_internal.h \ components/snackbar.h \ - components/snackbar_p.h + components/snackbar_p.h \ + components/textfield_p.h RESOURCES += \ resources.qrc