animate drop shadow on RaisedButton
This commit is contained in:
parent
7a04426900
commit
28b063e591
|
@ -1,3 +1,7 @@
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QPropertyAnimation>
|
||||||
|
#include <QStylePainter>
|
||||||
|
#include <QPaintEvent>
|
||||||
#include "raisedbutton.h"
|
#include "raisedbutton.h"
|
||||||
#include "lib/customshadoweffect.h"
|
#include "lib/customshadoweffect.h"
|
||||||
|
|
||||||
|
@ -7,8 +11,55 @@ RaisedButton::RaisedButton(QWidget *parent)
|
||||||
CustomShadowEffect *effect = new CustomShadowEffect;
|
CustomShadowEffect *effect = new CustomShadowEffect;
|
||||||
setGraphicsEffect(effect);
|
setGraphicsEffect(effect);
|
||||||
setAutoFillBackground(true);
|
setAutoFillBackground(true);
|
||||||
|
|
||||||
|
QPropertyAnimation *animation;
|
||||||
|
|
||||||
|
animation = new QPropertyAnimation;
|
||||||
|
animation->setTargetObject(effect);
|
||||||
|
animation->setPropertyName("distance");
|
||||||
|
animation->setStartValue(2);
|
||||||
|
animation->setEndValue(6);
|
||||||
|
animation->setDuration(100);
|
||||||
|
_group.addAnimation(animation);
|
||||||
|
|
||||||
|
animation = new QPropertyAnimation;
|
||||||
|
animation->setTargetObject(effect);
|
||||||
|
animation->setPropertyName("blurRadius");
|
||||||
|
animation->setStartValue(10);
|
||||||
|
animation->setEndValue(20);
|
||||||
|
animation->setDuration(100);
|
||||||
|
_group.addAnimation(animation);
|
||||||
|
|
||||||
|
connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(update()));
|
||||||
}
|
}
|
||||||
|
|
||||||
RaisedButton::~RaisedButton()
|
RaisedButton::~RaisedButton()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RaisedButton::mousePressEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
_group.setDirection(QAbstractAnimation::Forward);
|
||||||
|
_group.start();
|
||||||
|
|
||||||
|
FlatButton::mousePressEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RaisedButton::mouseReleaseEvent(QMouseEvent *event)
|
||||||
|
{
|
||||||
|
Q_UNUSED(event)
|
||||||
|
|
||||||
|
_group.setDirection(QAbstractAnimation::Backward);
|
||||||
|
_group.start();
|
||||||
|
|
||||||
|
FlatButton::mouseReleaseEvent(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void RaisedButton::paintEvent(QPaintEvent *event)
|
||||||
|
{
|
||||||
|
QStylePainter painter(this);
|
||||||
|
|
||||||
|
painter.drawControl(QStyle::CE_PushButton, getStyleOption());
|
||||||
|
}
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
#ifndef RAISEDBUTTON_H
|
#ifndef RAISEDBUTTON_H
|
||||||
#define RAISEDBUTTON_H
|
#define RAISEDBUTTON_H
|
||||||
|
|
||||||
|
#include <QParallelAnimationGroup>
|
||||||
#include "flatbutton.h"
|
#include "flatbutton.h"
|
||||||
|
|
||||||
|
class QPropertyAnimation;
|
||||||
|
|
||||||
class RaisedButton : public FlatButton
|
class RaisedButton : public FlatButton
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -10,6 +13,14 @@ class RaisedButton : public FlatButton
|
||||||
public:
|
public:
|
||||||
explicit RaisedButton(QWidget *parent = 0);
|
explicit RaisedButton(QWidget *parent = 0);
|
||||||
~RaisedButton();
|
~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
|
#endif // RAISEDBUTTON_H
|
||||||
|
|
Loading…
Reference in New Issue