make sure all animations have a parent

This commit is contained in:
laserpants 2016-06-21 15:42:49 +03:00
parent 0269911b2e
commit 264e4c71ed
6 changed files with 66 additions and 50 deletions

View File

@ -19,15 +19,15 @@ public:
void init(); void init();
Tabs *const q_ptr; Tabs *const q_ptr;
TabsInkBar *const inkBar; TabsInkBar *const inkBar;
QHBoxLayout *const tabLayout; QHBoxLayout *const tabLayout;
QColor inkColor; QColor inkColor;
QColor backgroundColor; QColor backgroundColor;
QColor textColor; QColor textColor;
int tab; int tab;
bool useThemeColors; bool useThemeColors;
bool showHalo; bool showHalo;
Material::RippleStyle rippleStyle; Material::RippleStyle rippleStyle;
}; };

View File

@ -9,6 +9,7 @@
TextFieldPrivate::TextFieldPrivate(TextField *q) TextFieldPrivate::TextFieldPrivate(TextField *q)
: q_ptr(q), : q_ptr(q),
label(0), label(0),
machine(0),
labelFontSize(9.5), labelFontSize(9.5),
showLabel(false), showLabel(false),
useThemeColors(true) useThemeColors(true)

View File

@ -8,9 +8,11 @@
TextFieldStateMachine::TextFieldStateMachine(TextField *parent) TextFieldStateMachine::TextFieldStateMachine(TextField *parent)
: QStateMachine(parent), : QStateMachine(parent),
textField(parent), textField(parent),
label(0),
_normalState(new QState), _normalState(new QState),
_focusedState(new QState), _focusedState(new QState),
_label(0),
_offsetAnimation(0),
_colorAnimation(0),
_progress(0) _progress(0)
{ {
addState(_normalState); addState(_normalState);
@ -25,7 +27,7 @@ TextFieldStateMachine::TextFieldStateMachine(TextField *parent)
transition->setTargetState(_focusedState); transition->setTargetState(_focusedState);
_normalState->addTransition(transition); _normalState->addTransition(transition);
animation = new QPropertyAnimation(this, "progress"); animation = new QPropertyAnimation(this, "progress", this);
animation->setEasingCurve(QEasingCurve::InCubic); animation->setEasingCurve(QEasingCurve::InCubic);
animation->setDuration(340); animation->setDuration(340);
transition->addAnimation(animation); transition->addAnimation(animation);
@ -34,7 +36,7 @@ TextFieldStateMachine::TextFieldStateMachine(TextField *parent)
transition->setTargetState(_normalState); transition->setTargetState(_normalState);
_focusedState->addTransition(transition); _focusedState->addTransition(transition);
animation = new QPropertyAnimation(this, "progress"); animation = new QPropertyAnimation(this, "progress", this);
animation->setEasingCurve(QEasingCurve::OutCubic); animation->setEasingCurve(QEasingCurve::OutCubic);
animation->setDuration(340); animation->setDuration(340);
transition->addAnimation(animation); transition->addAnimation(animation);
@ -53,20 +55,30 @@ TextFieldStateMachine::~TextFieldStateMachine()
void TextFieldStateMachine::setLabel(TextFieldLabel *widget) 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"); _colorAnimation = new QPropertyAnimation(_label, "color", this);
animation->setDuration(210); _colorAnimation->setDuration(210);
animation->setEasingCurve(QEasingCurve::OutCubic); addDefaultAnimation(_colorAnimation);
addDefaultAnimation(animation);
animation = new QPropertyAnimation(label, "color");
animation->setDuration(210);
addDefaultAnimation(animation);
} }
assignProperties(); assignProperties();
@ -84,19 +96,19 @@ void TextFieldStateMachine::assignProperties()
p.setColor(QPalette::Normal, QPalette::Base, textField->backgroundColor()); p.setColor(QPalette::Normal, QPalette::Base, textField->backgroundColor());
textField->setPalette(p); textField->setPalette(p);
if (label) if (_label)
{ {
const int m = textField->textMargins().top(); 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()) { if (textField->text().isEmpty()) {
_normalState->assignProperty(label, "offset", QPointF(0, 26)); _normalState->assignProperty(_label, "offset", QPointF(0, 26));
} else { } else {
_normalState->assignProperty(label, "offset", QPointF(0, 0-m)); _normalState->assignProperty(_label, "offset", QPointF(0, 0-m));
} }
_focusedState->assignProperty(label, "color", textField->inkColor()); _focusedState->assignProperty(_label, "color", textField->inkColor());
_normalState->assignProperty(label, "color", textField->hintColor()); _normalState->assignProperty(_label, "color", textField->hintColor());
} }
} }

View File

@ -4,6 +4,7 @@
#include <QStateMachine> #include <QStateMachine>
#include <QWidget> #include <QWidget>
class QPropertyAnimation;
class TextField; class TextField;
class TextFieldLabel; class TextFieldLabel;
@ -31,9 +32,11 @@ private:
friend class TextField; friend class TextField;
TextField *const textField; TextField *const textField;
TextFieldLabel *label;
QState *const _normalState; QState *const _normalState;
QState *const _focusedState; QState *const _focusedState;
TextFieldLabel *_label;
QPropertyAnimation *_offsetAnimation;
QPropertyAnimation *_colorAnimation;
qreal _progress; qreal _progress;
}; };
@ -65,10 +68,10 @@ private:
Q_DISABLE_COPY(TextFieldLabel) Q_DISABLE_COPY(TextFieldLabel)
TextField *const label; TextField *const label;
qreal _scale; qreal _scale;
qreal _posX; qreal _posX;
qreal _posY; qreal _posY;
QColor _color; QColor _color;
}; };
#endif // TEXTFIELD_INTERNAL_H #endif // TEXTFIELD_INTERNAL_H

View File

@ -17,18 +17,18 @@ public:
TextFieldPrivate(TextField *q); TextFieldPrivate(TextField *q);
void init(); void init();
TextField *const q_ptr; TextField *const q_ptr;
TextFieldLabel *label; TextFieldLabel *label;
TextFieldStateMachine *machine; TextFieldStateMachine *machine;
QColor textColor; QColor textColor;
QColor backgroundColor; QColor backgroundColor;
QColor inkColor; QColor inkColor;
QColor underlineColor; QColor underlineColor;
QColor hintColor; QColor hintColor;
QString labelString; QString labelString;
qreal labelFontSize; qreal labelFontSize;
bool showLabel; bool showLabel;
bool useThemeColors; bool useThemeColors;
}; };
#endif // TEXTFIELD_P_H #endif // TEXTFIELD_P_H

View File

@ -47,20 +47,20 @@ void TogglePrivate::init()
transition->setTargetState(onState); transition->setTargetState(onState);
offState->addTransition(transition); offState->addTransition(transition);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("shift"); animation->setPropertyName("shift");
animation->setTargetObject(thumb); animation->setTargetObject(thumb);
animation->setDuration(200); animation->setDuration(200);
animation->setEasingCurve(QEasingCurve::OutQuad); animation->setEasingCurve(QEasingCurve::OutQuad);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("trackColor"); animation->setPropertyName("trackColor");
animation->setTargetObject(track); animation->setTargetObject(track);
animation->setDuration(150); animation->setDuration(150);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("thumbColor"); animation->setPropertyName("thumbColor");
animation->setTargetObject(thumb); animation->setTargetObject(thumb);
animation->setDuration(150); animation->setDuration(150);
@ -72,20 +72,20 @@ void TogglePrivate::init()
transition->setTargetState(offState); transition->setTargetState(offState);
onState->addTransition(transition); onState->addTransition(transition);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("shift"); animation->setPropertyName("shift");
animation->setTargetObject(thumb); animation->setTargetObject(thumb);
animation->setDuration(200); animation->setDuration(200);
animation->setEasingCurve(QEasingCurve::OutQuad); animation->setEasingCurve(QEasingCurve::OutQuad);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("trackColor"); animation->setPropertyName("trackColor");
animation->setTargetObject(track); animation->setTargetObject(track);
animation->setDuration(150); animation->setDuration(150);
transition->addAnimation(animation); transition->addAnimation(animation);
animation = new QPropertyAnimation; animation = new QPropertyAnimation(q);
animation->setPropertyName("thumbColor"); animation->setPropertyName("thumbColor");
animation->setTargetObject(thumb); animation->setTargetObject(thumb);
animation->setDuration(150); animation->setDuration(150);