diff --git a/components/tabs_p.h b/components/tabs_p.h index d12c8dc..67b1fb4 100644 --- a/components/tabs_p.h +++ b/components/tabs_p.h @@ -19,15 +19,15 @@ public: void init(); - Tabs *const q_ptr; - TabsInkBar *const inkBar; - QHBoxLayout *const tabLayout; - QColor inkColor; - QColor backgroundColor; - QColor textColor; - int tab; - bool useThemeColors; - bool showHalo; + Tabs *const q_ptr; + TabsInkBar *const inkBar; + QHBoxLayout *const tabLayout; + QColor inkColor; + QColor backgroundColor; + QColor textColor; + int tab; + bool useThemeColors; + bool showHalo; Material::RippleStyle rippleStyle; }; diff --git a/components/textfield.cpp b/components/textfield.cpp index e5b3fe3..4dc33fd 100644 --- a/components/textfield.cpp +++ b/components/textfield.cpp @@ -9,6 +9,7 @@ TextFieldPrivate::TextFieldPrivate(TextField *q) : q_ptr(q), label(0), + machine(0), labelFontSize(9.5), showLabel(false), useThemeColors(true) diff --git a/components/textfield_internal.cpp b/components/textfield_internal.cpp index 46d2aa3..bd9f9d3 100644 --- a/components/textfield_internal.cpp +++ b/components/textfield_internal.cpp @@ -8,9 +8,11 @@ TextFieldStateMachine::TextFieldStateMachine(TextField *parent) : QStateMachine(parent), textField(parent), - label(0), _normalState(new QState), _focusedState(new QState), + _label(0), + _offsetAnimation(0), + _colorAnimation(0), _progress(0) { addState(_normalState); @@ -25,7 +27,7 @@ TextFieldStateMachine::TextFieldStateMachine(TextField *parent) transition->setTargetState(_focusedState); _normalState->addTransition(transition); - animation = new QPropertyAnimation(this, "progress"); + animation = new QPropertyAnimation(this, "progress", this); animation->setEasingCurve(QEasingCurve::InCubic); animation->setDuration(340); transition->addAnimation(animation); @@ -34,7 +36,7 @@ TextFieldStateMachine::TextFieldStateMachine(TextField *parent) transition->setTargetState(_normalState); _focusedState->addTransition(transition); - animation = new QPropertyAnimation(this, "progress"); + animation = new QPropertyAnimation(this, "progress", this); animation->setEasingCurve(QEasingCurve::OutCubic); animation->setDuration(340); transition->addAnimation(animation); @@ -53,20 +55,30 @@ TextFieldStateMachine::~TextFieldStateMachine() void TextFieldStateMachine::setLabel(TextFieldLabel *widget) { - label = widget; + if (_label) { + delete _label; + } + if (_offsetAnimation) { + removeDefaultAnimation(_offsetAnimation); + delete _offsetAnimation; + } + if (_colorAnimation) { + removeDefaultAnimation(_colorAnimation); + delete _colorAnimation; + } - if (label) + _label = widget; + + if (_label) { - QPropertyAnimation *animation; + _offsetAnimation = new QPropertyAnimation(_label, "offset", this); + _offsetAnimation->setDuration(210); + _offsetAnimation->setEasingCurve(QEasingCurve::OutCubic); + addDefaultAnimation(_offsetAnimation); - animation = new QPropertyAnimation(label, "offset"); - animation->setDuration(210); - animation->setEasingCurve(QEasingCurve::OutCubic); - addDefaultAnimation(animation); - - animation = new QPropertyAnimation(label, "color"); - animation->setDuration(210); - addDefaultAnimation(animation); + _colorAnimation = new QPropertyAnimation(_label, "color", this); + _colorAnimation->setDuration(210); + addDefaultAnimation(_colorAnimation); } assignProperties(); @@ -84,19 +96,19 @@ void TextFieldStateMachine::assignProperties() p.setColor(QPalette::Normal, QPalette::Base, textField->backgroundColor()); textField->setPalette(p); - if (label) + if (_label) { const int m = textField->textMargins().top(); - _focusedState->assignProperty(label, "offset", QPointF(0, 0-m)); + _focusedState->assignProperty(_label, "offset", QPointF(0, 0-m)); if (textField->text().isEmpty()) { - _normalState->assignProperty(label, "offset", QPointF(0, 26)); + _normalState->assignProperty(_label, "offset", QPointF(0, 26)); } else { - _normalState->assignProperty(label, "offset", QPointF(0, 0-m)); + _normalState->assignProperty(_label, "offset", QPointF(0, 0-m)); } - _focusedState->assignProperty(label, "color", textField->inkColor()); - _normalState->assignProperty(label, "color", textField->hintColor()); + _focusedState->assignProperty(_label, "color", textField->inkColor()); + _normalState->assignProperty(_label, "color", textField->hintColor()); } } diff --git a/components/textfield_internal.h b/components/textfield_internal.h index b4d2346..d6ba97e 100644 --- a/components/textfield_internal.h +++ b/components/textfield_internal.h @@ -4,6 +4,7 @@ #include #include +class QPropertyAnimation; class TextField; class TextFieldLabel; @@ -31,9 +32,11 @@ private: friend class TextField; TextField *const textField; - TextFieldLabel *label; QState *const _normalState; QState *const _focusedState; + TextFieldLabel *_label; + QPropertyAnimation *_offsetAnimation; + QPropertyAnimation *_colorAnimation; qreal _progress; }; @@ -65,10 +68,10 @@ private: Q_DISABLE_COPY(TextFieldLabel) TextField *const label; - qreal _scale; - qreal _posX; - qreal _posY; - QColor _color; + qreal _scale; + qreal _posX; + qreal _posY; + QColor _color; }; #endif // TEXTFIELD_INTERNAL_H diff --git a/components/textfield_p.h b/components/textfield_p.h index a046377..8b28e18 100644 --- a/components/textfield_p.h +++ b/components/textfield_p.h @@ -17,18 +17,18 @@ public: TextFieldPrivate(TextField *q); void init(); - TextField *const q_ptr; + TextField *const q_ptr; TextFieldLabel *label; TextFieldStateMachine *machine; - QColor textColor; - QColor backgroundColor; - QColor inkColor; - QColor underlineColor; - QColor hintColor; - QString labelString; - qreal labelFontSize; - bool showLabel; - bool useThemeColors; + QColor textColor; + QColor backgroundColor; + QColor inkColor; + QColor underlineColor; + QColor hintColor; + QString labelString; + qreal labelFontSize; + bool showLabel; + bool useThemeColors; }; #endif // TEXTFIELD_P_H diff --git a/components/toggle.cpp b/components/toggle.cpp index 6587105..a5978b1 100644 --- a/components/toggle.cpp +++ b/components/toggle.cpp @@ -47,20 +47,20 @@ void TogglePrivate::init() transition->setTargetState(onState); offState->addTransition(transition); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("shift"); animation->setTargetObject(thumb); animation->setDuration(200); animation->setEasingCurve(QEasingCurve::OutQuad); transition->addAnimation(animation); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("trackColor"); animation->setTargetObject(track); animation->setDuration(150); transition->addAnimation(animation); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("thumbColor"); animation->setTargetObject(thumb); animation->setDuration(150); @@ -72,20 +72,20 @@ void TogglePrivate::init() transition->setTargetState(offState); onState->addTransition(transition); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("shift"); animation->setTargetObject(thumb); animation->setDuration(200); animation->setEasingCurve(QEasingCurve::OutQuad); transition->addAnimation(animation); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("trackColor"); animation->setTargetObject(track); animation->setDuration(150); transition->addAnimation(animation); - animation = new QPropertyAnimation; + animation = new QPropertyAnimation(q); animation->setPropertyName("thumbColor"); animation->setTargetObject(thumb); animation->setDuration(150);