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();
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;
};

View File

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

View File

@ -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());
}
}

View File

@ -4,6 +4,7 @@
#include <QStateMachine>
#include <QWidget>
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

View File

@ -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

View File

@ -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);