make animation in Raised Button consistent with Material style
This commit is contained in:
parent
a963401861
commit
d2add935b0
|
@ -1,34 +1,35 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
#include <QGraphicsDropShadowEffect>
|
||||||
#include <QStylePainter>
|
#include <QStylePainter>
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include "raisedbutton.h"
|
#include "raisedbutton.h"
|
||||||
#include "lib/customshadoweffect.h"
|
|
||||||
|
|
||||||
RaisedButton::RaisedButton(QWidget *parent)
|
RaisedButton::RaisedButton(QWidget *parent)
|
||||||
: FlatButton(parent)
|
: FlatButton(parent)
|
||||||
{
|
{
|
||||||
CustomShadowEffect *effect = new CustomShadowEffect;
|
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
|
||||||
effect->setBlurRadius(17);
|
effect->setBlurRadius(7);
|
||||||
effect->setDistance(6);
|
effect->setOffset(QPoint(0, 0));
|
||||||
setGraphicsEffect(effect);
|
setGraphicsEffect(effect);
|
||||||
|
|
||||||
setAutoFillBackground(true);
|
setAutoFillBackground(true);
|
||||||
|
|
||||||
QPropertyAnimation *animation;
|
QPropertyAnimation *animation;
|
||||||
|
|
||||||
animation = new QPropertyAnimation;
|
animation = new QPropertyAnimation;
|
||||||
animation->setTargetObject(effect);
|
animation->setTargetObject(effect);
|
||||||
animation->setPropertyName("distance");
|
animation->setPropertyName("offset");
|
||||||
animation->setStartValue(effect->distance());
|
animation->setStartValue(QPoint(0, 6));
|
||||||
animation->setEndValue(1);
|
animation->setEndValue(QPoint(0, 0));
|
||||||
animation->setDuration(100);
|
animation->setDuration(100);
|
||||||
_group.addAnimation(animation);
|
_group.addAnimation(animation);
|
||||||
|
|
||||||
animation = new QPropertyAnimation;
|
animation = new QPropertyAnimation;
|
||||||
animation->setTargetObject(effect);
|
animation->setTargetObject(effect);
|
||||||
animation->setPropertyName("blurRadius");
|
animation->setPropertyName("blurRadius");
|
||||||
animation->setStartValue(effect->blurRadius());
|
animation->setStartValue(20);
|
||||||
animation->setEndValue(9);
|
animation->setEndValue(7);
|
||||||
animation->setDuration(100);
|
animation->setDuration(100);
|
||||||
_group.addAnimation(animation);
|
_group.addAnimation(animation);
|
||||||
|
|
||||||
|
@ -41,9 +42,7 @@ RaisedButton::~RaisedButton()
|
||||||
|
|
||||||
void RaisedButton::mousePressEvent(QMouseEvent *event)
|
void RaisedButton::mousePressEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
_group.setDirection(QAbstractAnimation::Backward);
|
||||||
|
|
||||||
_group.setDirection(QAbstractAnimation::Forward);
|
|
||||||
_group.start();
|
_group.start();
|
||||||
|
|
||||||
FlatButton::mousePressEvent(event);
|
FlatButton::mousePressEvent(event);
|
||||||
|
@ -51,9 +50,7 @@ void RaisedButton::mousePressEvent(QMouseEvent *event)
|
||||||
|
|
||||||
void RaisedButton::mouseReleaseEvent(QMouseEvent *event)
|
void RaisedButton::mouseReleaseEvent(QMouseEvent *event)
|
||||||
{
|
{
|
||||||
Q_UNUSED(event)
|
_group.setDirection(QAbstractAnimation::Forward);
|
||||||
|
|
||||||
_group.setDirection(QAbstractAnimation::Backward);
|
|
||||||
_group.start();
|
_group.start();
|
||||||
|
|
||||||
FlatButton::mouseReleaseEvent(event);
|
FlatButton::mouseReleaseEvent(event);
|
||||||
|
|
Loading…
Reference in New Issue