diff --git a/components/raisedbutton.cpp b/components/raisedbutton.cpp index 9f161a4..8636e2c 100644 --- a/components/raisedbutton.cpp +++ b/components/raisedbutton.cpp @@ -1,3 +1,7 @@ +#include +#include +#include +#include #include "raisedbutton.h" #include "lib/customshadoweffect.h" @@ -7,8 +11,55 @@ RaisedButton::RaisedButton(QWidget *parent) CustomShadowEffect *effect = new CustomShadowEffect; setGraphicsEffect(effect); 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() { } + +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()); +} diff --git a/components/raisedbutton.h b/components/raisedbutton.h index 6d54242..9a40674 100644 --- a/components/raisedbutton.h +++ b/components/raisedbutton.h @@ -1,8 +1,11 @@ #ifndef RAISEDBUTTON_H #define RAISEDBUTTON_H +#include #include "flatbutton.h" +class QPropertyAnimation; + class RaisedButton : public FlatButton { Q_OBJECT @@ -10,6 +13,14 @@ class RaisedButton : public FlatButton 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