make Text Field pimpl class
This commit is contained in:
parent
c9908a41c4
commit
84c3ce96b4
|
@ -1,81 +1,105 @@
|
|||
#include <QPropertyAnimation>
|
||||
#include <QWidget>
|
||||
#include <QPainter>
|
||||
#include <QDebug>
|
||||
#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<qreal>(width()/2);
|
||||
|
||||
painter.drawRect(w, height()-2, width()-w*2, 2);
|
||||
}
|
||||
}
|
||||
//#include <QPropertyAnimation>
|
||||
//#include <QWidget>
|
||||
//#include <QPainter>
|
||||
//#include <QDebug>
|
||||
//#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<qreal>(width()/2);
|
||||
//
|
||||
// painter.drawRect(w, height()-2, width()-w*2, 2);
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
|
|
@ -3,34 +3,54 @@
|
|||
|
||||
#include <QLineEdit>
|
||||
|
||||
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<TextFieldPrivate> d_ptr;
|
||||
|
||||
private:
|
||||
QPropertyAnimation *const _animation;
|
||||
qreal _progress;
|
||||
Q_DISABLE_COPY(TextField)
|
||||
Q_DECLARE_PRIVATE(TextField)
|
||||
};
|
||||
|
||||
//#include <QLineEdit>
|
||||
//
|
||||
//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
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef TEXTFIELD_P_H
|
||||
#define TEXTFIELD_P_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue