qt-material-widgets/components/checkbox.cpp

88 lines
2.4 KiB
C++
Raw Normal View History

2016-03-19 08:32:49 +00:00
#include "checkbox.h"
2016-06-19 14:27:21 +00:00
#include "checkbox_p.h"
2016-06-13 23:27:37 +00:00
#include <QStateMachine>
2016-06-13 11:49:43 +00:00
#include <QEvent>
#include <QSignalTransition>
2016-06-13 23:27:37 +00:00
#include <QEventTransition>
2016-06-13 11:49:43 +00:00
#include <QPropertyAnimation>
#include <QApplication>
#include <QDebug>
2016-06-13 23:27:37 +00:00
CheckBoxPrivate::CheckBoxPrivate(CheckBox *q)
: CheckablePrivate(q)
2016-06-13 11:49:43 +00:00
{
}
2016-06-13 23:27:37 +00:00
CheckBoxPrivate::~CheckBoxPrivate()
2016-06-13 11:49:43 +00:00
{
2016-06-13 23:27:37 +00:00
}
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
void CheckBoxPrivate::init()
{
2016-06-21 10:19:10 +00:00
Q_Q(CheckBox);
2016-06-13 11:49:43 +00:00
QPropertyAnimation *animation;
2016-06-21 10:19:10 +00:00
animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
2016-06-13 23:27:37 +00:00
animation->setStartValue(0);
animation->setEndValue(24);
2016-07-16 10:17:46 +00:00
animation->setDuration(280);
//animation->setDuration(6250);
2016-06-13 23:27:37 +00:00
uncheckedTransition->addAnimation(animation);
2016-04-14 13:47:27 +00:00
2016-06-21 10:19:10 +00:00
animation = new QPropertyAnimation(uncheckedIcon, "color", q);
2016-06-13 23:27:37 +00:00
animation->setDuration(250);
uncheckedTransition->addAnimation(animation);
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
//
2016-06-13 11:49:43 +00:00
2016-06-21 10:19:10 +00:00
animation = new QPropertyAnimation(uncheckedIcon, "color", q);
2016-07-16 10:17:46 +00:00
animation->setDuration(1550);
2016-06-13 23:27:37 +00:00
checkedTransition->addAnimation(animation);
2016-06-13 11:49:43 +00:00
2016-06-21 10:19:10 +00:00
animation = new QPropertyAnimation(checkedIcon, "opacity", q);
2016-07-16 10:17:46 +00:00
animation->setDuration(650);
2016-06-13 23:27:37 +00:00
checkedTransition->addAnimation(animation);
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
//
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
checkedState->assignProperty(checkedIcon, "iconSize", 24);
checkedState->assignProperty(checkedIcon, "opacity", 1);
2016-07-16 10:17:46 +00:00
checkedState->assignProperty(uncheckedIcon, "opacity", 0);
2016-06-13 23:27:37 +00:00
uncheckedState->assignProperty(checkedIcon, "opacity", 0);
2016-07-16 10:17:46 +00:00
uncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
2016-06-13 23:27:37 +00:00
disabledCheckedState->assignProperty(checkedIcon, "opacity", 1);
disabledUncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
2016-06-13 11:49:43 +00:00
}
2016-06-13 23:27:37 +00:00
CheckBox::CheckBox(QWidget *parent)
: Checkable(*new CheckBoxPrivate(this), parent)
2016-06-13 11:49:43 +00:00
{
2016-06-13 23:27:37 +00:00
Q_D(CheckBox);
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
d->init();
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
CheckBox::assignProperties();
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
d->machine->start();
QCoreApplication::processEvents();
2016-04-14 13:47:27 +00:00
}
2016-06-13 23:27:37 +00:00
CheckBox::~CheckBox()
2016-04-14 13:47:27 +00:00
{
2016-04-18 08:36:30 +00:00
}
2016-06-13 23:27:37 +00:00
void CheckBox::assignProperties()
2016-04-18 08:36:30 +00:00
{
2016-06-13 23:27:37 +00:00
Q_D(CheckBox);
2016-06-13 11:49:43 +00:00
2016-06-13 23:27:37 +00:00
d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
2016-06-13 11:49:43 +00:00
d->checkedState->assignProperty(d->uncheckedIcon, "color", checkedColor());
2016-06-13 23:27:37 +00:00
d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
d->disabledUncheckedState->assignProperty(d->uncheckedIcon, "color", disabledColor());
d->disabledCheckedState->assignProperty(d->checkedIcon, "color", disabledColor());
2016-04-14 13:47:27 +00:00
}