2016-03-22 08:50:48 +00:00
|
|
|
#include "raisedbutton.h"
|
2016-05-17 13:43:46 +00:00
|
|
|
#include <QGraphicsDropShadowEffect>
|
2016-05-17 13:58:46 +00:00
|
|
|
#include <QEventTransition>
|
2016-05-17 12:26:50 +00:00
|
|
|
#include "raisedbutton_p.h"
|
|
|
|
|
2016-05-17 13:43:46 +00:00
|
|
|
void RaisedButtonPrivate::init()
|
|
|
|
{
|
|
|
|
Q_Q(RaisedButton);
|
|
|
|
|
|
|
|
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
|
|
|
|
effect->setBlurRadius(7);
|
|
|
|
effect->setOffset(QPoint(0, 0));
|
|
|
|
effect->setColor(QColor(0, 0, 0, 100));
|
|
|
|
q->setGraphicsEffect(effect);
|
|
|
|
|
|
|
|
q->setAutoFillBackground(true);
|
2016-05-17 13:58:46 +00:00
|
|
|
|
|
|
|
QState *normalState = new QState;
|
|
|
|
QState *pressedState = new QState;
|
|
|
|
|
|
|
|
machine.addState(normalState);
|
|
|
|
machine.addState(pressedState);
|
|
|
|
|
|
|
|
normalState->assignProperty(effect, "offset", QPoint(0, 0));
|
|
|
|
normalState->assignProperty(effect, "blurRadius", 7);
|
|
|
|
|
|
|
|
pressedState->assignProperty(effect, "offset", QPoint(0, 6));
|
|
|
|
pressedState->assignProperty(effect, "blurRadius", 20);
|
|
|
|
|
|
|
|
QAbstractTransition *transition;
|
|
|
|
|
|
|
|
transition = new QEventTransition(q, QEvent::MouseButtonPress);
|
|
|
|
transition->setTargetState(pressedState);
|
|
|
|
normalState->addTransition(transition);
|
|
|
|
|
|
|
|
transition = new QEventTransition(q, QEvent::MouseButtonRelease);
|
|
|
|
transition->setTargetState(normalState);
|
|
|
|
pressedState->addTransition(transition);
|
|
|
|
|
|
|
|
machine.setInitialState(normalState);
|
|
|
|
|
|
|
|
// add animation.. duration: 100 !!!
|
|
|
|
|
|
|
|
machine.start();
|
2016-05-17 13:43:46 +00:00
|
|
|
}
|
|
|
|
|
2016-03-22 08:50:48 +00:00
|
|
|
RaisedButton::RaisedButton(QWidget *parent)
|
2016-05-17 12:26:50 +00:00
|
|
|
: FlatButton(*new RaisedButtonPrivate(this), parent)
|
2016-03-22 08:50:48 +00:00
|
|
|
{
|
2016-05-17 13:43:46 +00:00
|
|
|
Q_D(RaisedButton);
|
|
|
|
|
|
|
|
d->init();
|
2016-03-22 08:50:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RaisedButton::~RaisedButton()
|
|
|
|
{
|
|
|
|
}
|