qt-material-widgets/components/radiobutton.cpp

97 lines
3.2 KiB
C++
Raw Normal View History

2016-03-19 08:32:49 +00:00
#include "radiobutton.h"
2016-06-19 14:27:21 +00:00
#include "radiobutton_p.h"
2016-06-13 23:27:37 +00:00
#include <QStateMachine>
#include <QEvent>
2016-06-12 23:19:14 +00:00
#include <QSignalTransition>
2016-06-13 23:27:37 +00:00
#include <QEventTransition>
2016-06-12 23:19:14 +00:00
#include <QPropertyAnimation>
#include <QApplication>
#include <QDebug>
2016-06-12 16:02:45 +00:00
RadioButtonPrivate::RadioButtonPrivate(RadioButton *q)
2016-06-13 23:27:37 +00:00
: CheckablePrivate(q)
{
}
RadioButtonPrivate::~RadioButtonPrivate()
2016-06-12 16:02:45 +00:00
{
}
void RadioButtonPrivate::init()
{
Q_Q(RadioButton);
q->setAutoExclusive(true);
2016-06-13 23:27:37 +00:00
q->setCheckedIcon(QIcon("../qt-material-widgets/ic_radio_button_checked_black_24px.svg"));
q->setUncheckedIcon(QIcon("../qt-material-widgets/ic_radio_button_unchecked_black_24px.svg"));
2016-06-13 23:27:37 +00:00
uncheckedState->assignProperty(checkedIcon, "iconSize", 0);
uncheckedState->assignProperty(uncheckedIcon, "iconSize", 24);
disabledUncheckedState->assignProperty(checkedIcon, "iconSize", 0);
disabledUncheckedState->assignProperty(uncheckedIcon, "iconSize", 24);
2016-06-12 23:19:14 +00:00
2016-06-13 23:27:37 +00:00
checkedState->assignProperty(uncheckedIcon, "iconSize", 0);
checkedState->assignProperty(checkedIcon, "iconSize", 24);
disabledCheckedState->assignProperty(uncheckedIcon, "iconSize", 0);
disabledCheckedState->assignProperty(checkedIcon, "iconSize", 24);
2016-06-12 23:19:14 +00:00
2016-06-13 23:27:37 +00:00
uncheckedState->assignProperty(checkedIcon, "opacity", 0);
uncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
checkedState->assignProperty(uncheckedIcon, "opacity", 0);
checkedState->assignProperty(checkedIcon, "opacity", 1);
2016-06-12 23:19:14 +00:00
2016-06-13 23:27:37 +00:00
disabledUncheckedState->assignProperty(uncheckedIcon, "opacity", 1);
disabledCheckedState->assignProperty(checkedIcon, "opacity", 1);
2016-06-12 23:19:14 +00:00
QPropertyAnimation *animation;
2016-06-21 12:09:16 +00:00
animation = new QPropertyAnimation(checkedIcon, "iconSize", q);
2016-06-12 23:19:14 +00:00
animation->setDuration(250);
2016-06-13 23:27:37 +00:00
machine->addDefaultAnimation(animation);
2016-06-12 23:19:14 +00:00
2016-06-21 12:09:16 +00:00
animation = new QPropertyAnimation(uncheckedIcon, "iconSize", q);
2016-06-12 23:19:14 +00:00
animation->setDuration(250);
2016-06-13 23:27:37 +00:00
machine->addDefaultAnimation(animation);
2016-06-12 23:19:14 +00:00
2016-06-21 12:09:16 +00:00
animation = new QPropertyAnimation(uncheckedIcon, "opacity", q);
2016-06-12 23:19:14 +00:00
animation->setDuration(250);
2016-06-13 23:27:37 +00:00
machine->addDefaultAnimation(animation);
2016-06-12 23:19:14 +00:00
2016-06-21 12:09:16 +00:00
animation = new QPropertyAnimation(checkedIcon, "opacity", q);
2016-06-12 23:19:14 +00:00
animation->setDuration(250);
2016-06-13 23:27:37 +00:00
machine->addDefaultAnimation(animation);
2016-06-12 16:02:45 +00:00
}
2016-04-14 13:47:27 +00:00
RadioButton::RadioButton(QWidget *parent)
2016-06-13 23:27:37 +00:00
: Checkable(*new RadioButtonPrivate(this), parent)
2016-06-12 23:19:14 +00:00
{
Q_D(RadioButton);
2016-06-13 23:27:37 +00:00
d->init();
2016-06-12 23:19:14 +00:00
2016-06-13 23:27:37 +00:00
RadioButton::assignProperties();
2016-06-12 23:19:14 +00:00
2016-06-13 23:27:37 +00:00
d->machine->start();
QCoreApplication::processEvents();
}
2016-06-13 23:27:37 +00:00
RadioButton::~RadioButton()
{
}
2016-06-13 23:27:37 +00:00
void RadioButton::assignProperties()
2016-04-14 13:47:27 +00:00
{
2016-06-12 23:19:14 +00:00
Q_D(RadioButton);
2016-04-14 13:47:27 +00:00
2016-06-13 23:27:37 +00:00
d->disabledUncheckedState->assignProperty(d->uncheckedIcon, "color", disabledColor());
d->disabledUncheckedState->assignProperty(d->checkedIcon, "color", disabledColor());
d->disabledCheckedState->assignProperty(d->checkedIcon, "color", disabledColor());
d->disabledCheckedState->assignProperty(d->uncheckedIcon, "color", disabledColor());
2016-04-14 13:47:27 +00:00
2016-06-13 23:27:37 +00:00
d->uncheckedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
d->uncheckedState->assignProperty(d->checkedIcon, "color", checkedColor());
d->checkedState->assignProperty(d->uncheckedIcon, "color", uncheckedColor());
d->checkedState->assignProperty(d->checkedIcon, "color", checkedColor());
2016-04-14 13:47:27 +00:00
}