re-implement Raised Button animations as state machine
This commit is contained in:
parent
c2cc1af580
commit
6a27b85924
|
@ -1,5 +1,6 @@
|
|||
#include "raisedbutton.h"
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QEventTransition>
|
||||
#include "raisedbutton_p.h"
|
||||
|
||||
void RaisedButtonPrivate::init()
|
||||
|
@ -13,6 +14,34 @@ void RaisedButtonPrivate::init()
|
|||
q->setGraphicsEffect(effect);
|
||||
|
||||
q->setAutoFillBackground(true);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
RaisedButton::RaisedButton(QWidget *parent)
|
||||
|
@ -26,72 +55,3 @@ RaisedButton::RaisedButton(QWidget *parent)
|
|||
RaisedButton::~RaisedButton()
|
||||
{
|
||||
}
|
||||
|
||||
//#include <QDebug>
|
||||
//#include <QPropertyAnimation>
|
||||
//#include <QGraphicsDropShadowEffect>
|
||||
//#include <QStylePainter>
|
||||
//#include <QPaintEvent>
|
||||
//#include "raisedbutton.h"
|
||||
//
|
||||
//RaisedButton::RaisedButton(QWidget *parent)
|
||||
// : FlatButton(parent)
|
||||
//{
|
||||
// QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
|
||||
// effect->setBlurRadius(7);
|
||||
// effect->setOffset(QPoint(0, 0));
|
||||
// effect->setColor(QColor(0, 0, 0, 100));
|
||||
// setGraphicsEffect(effect);
|
||||
//
|
||||
// setAutoFillBackground(true);
|
||||
//
|
||||
// QPropertyAnimation *animation;
|
||||
//
|
||||
// animation = new QPropertyAnimation;
|
||||
// animation->setTargetObject(effect);
|
||||
// animation->setPropertyName("offset");
|
||||
// animation->setStartValue(QPoint(0, 6));
|
||||
// animation->setEndValue(QPoint(0, 0));
|
||||
// animation->setDuration(100);
|
||||
// _group.addAnimation(animation);
|
||||
//
|
||||
// animation = new QPropertyAnimation;
|
||||
// animation->setTargetObject(effect);
|
||||
// animation->setPropertyName("blurRadius");
|
||||
// animation->setStartValue(20);
|
||||
// animation->setEndValue(7);
|
||||
// animation->setDuration(100);
|
||||
// _group.addAnimation(animation);
|
||||
//
|
||||
// connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(update()));
|
||||
//}
|
||||
//
|
||||
//RaisedButton::~RaisedButton()
|
||||
//{
|
||||
//}
|
||||
//
|
||||
//void RaisedButton::mousePressEvent(QMouseEvent *event)
|
||||
//{
|
||||
// _group.setDirection(QAbstractAnimation::Backward);
|
||||
// _group.start();
|
||||
//
|
||||
// FlatButton::mousePressEvent(event);
|
||||
//}
|
||||
//
|
||||
//void RaisedButton::mouseReleaseEvent(QMouseEvent *event)
|
||||
//{
|
||||
// _group.setDirection(QAbstractAnimation::Forward);
|
||||
// _group.start();
|
||||
//
|
||||
// FlatButton::mouseReleaseEvent(event);
|
||||
//}
|
||||
//
|
||||
//void RaisedButton::paintEvent(QPaintEvent *event)
|
||||
//{
|
||||
// Q_UNUSED(event)
|
||||
//
|
||||
// QStylePainter painter(this);
|
||||
//
|
||||
//// painter.drawControl(QStyle::CE_PushButton, getStyleOption());
|
||||
//}
|
||||
//
|
||||
|
|
|
@ -19,31 +19,3 @@ private:
|
|||
};
|
||||
|
||||
#endif // RAISEDBUTTON_H
|
||||
|
||||
//#ifndef RAISEDBUTTON_H
|
||||
//#define RAISEDBUTTON_H
|
||||
//
|
||||
//#include <QParallelAnimationGroup>
|
||||
//#include "flatbutton.h"
|
||||
//
|
||||
//class QPropertyAnimation;
|
||||
//
|
||||
//class RaisedButton : public FlatButton
|
||||
//{
|
||||
// Q_OBJECT
|
||||
//
|
||||
//public:
|
||||
// explicit RaisedButton(QWidget *parent = 0);
|
||||
// ~RaisedButton();
|
||||
//
|
||||
//protected:
|
||||
// void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
// void mouseReleaseEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
|
||||
// void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||
//
|
||||
//private:
|
||||
// QParallelAnimationGroup _group;
|
||||
//};
|
||||
//
|
||||
//#endif // RAISEDBUTTON_H
|
||||
//
|
||||
|
|
|
@ -14,6 +14,8 @@ public:
|
|||
{}
|
||||
|
||||
void init();
|
||||
|
||||
QStateMachine machine;
|
||||
};
|
||||
|
||||
#endif // RAISEDBUTTON_P_H
|
||||
|
|
Loading…
Reference in New Issue