qt-material-widgets/components/raisedbutton.cpp

67 lines
1.6 KiB
C++
Raw Normal View History

2016-03-22 09:48:59 +00:00
#include <QDebug>
#include <QPropertyAnimation>
#include <QGraphicsDropShadowEffect>
2016-03-22 09:48:59 +00:00
#include <QStylePainter>
#include <QPaintEvent>
2016-03-22 08:50:48 +00:00
#include "raisedbutton.h"
RaisedButton::RaisedButton(QWidget *parent)
: FlatButton(parent)
{
QGraphicsDropShadowEffect *effect = new QGraphicsDropShadowEffect;
effect->setBlurRadius(7);
effect->setOffset(QPoint(0, 0));
2016-03-22 08:50:48 +00:00
setGraphicsEffect(effect);
2016-03-22 08:54:01 +00:00
setAutoFillBackground(true);
2016-03-22 09:48:59 +00:00
QPropertyAnimation *animation;
animation = new QPropertyAnimation;
animation->setTargetObject(effect);
animation->setPropertyName("offset");
animation->setStartValue(QPoint(0, 6));
animation->setEndValue(QPoint(0, 0));
2016-03-22 09:48:59 +00:00
animation->setDuration(100);
_group.addAnimation(animation);
animation = new QPropertyAnimation;
animation->setTargetObject(effect);
animation->setPropertyName("blurRadius");
animation->setStartValue(20);
animation->setEndValue(7);
2016-03-22 09:48:59 +00:00
animation->setDuration(100);
_group.addAnimation(animation);
connect(animation, SIGNAL(valueChanged(QVariant)), this, SLOT(update()));
2016-03-22 08:50:48 +00:00
}
RaisedButton::~RaisedButton()
{
}
2016-03-22 09:48:59 +00:00
void RaisedButton::mousePressEvent(QMouseEvent *event)
{
_group.setDirection(QAbstractAnimation::Backward);
2016-03-22 09:48:59 +00:00
_group.start();
FlatButton::mousePressEvent(event);
}
void RaisedButton::mouseReleaseEvent(QMouseEvent *event)
{
_group.setDirection(QAbstractAnimation::Forward);
2016-03-22 09:48:59 +00:00
_group.start();
FlatButton::mouseReleaseEvent(event);
}
void RaisedButton::paintEvent(QPaintEvent *event)
{
2016-03-22 09:53:10 +00:00
Q_UNUSED(event)
2016-03-22 09:48:59 +00:00
QStylePainter painter(this);
painter.drawControl(QStyle::CE_PushButton, getStyleOption());
}