matrixion/src/ui/Ripple.cc

112 lines
1.8 KiB
C++
Raw Normal View History

2017-04-06 02:06:42 +03:00
#include "Ripple.h"
#include "RippleOverlay.h"
Ripple::Ripple(const QPoint &center, QObject *parent)
2017-08-20 13:47:22 +03:00
: QParallelAnimationGroup(parent)
, overlay_(0)
, radius_anim_(animate("radius"))
, opacity_anim_(animate("opacity"))
, radius_(0)
, opacity_(0)
, center_(center)
2017-04-06 02:06:42 +03:00
{
init();
}
Ripple::Ripple(const QPoint &center, RippleOverlay *overlay, QObject *parent)
2017-08-20 13:47:22 +03:00
: QParallelAnimationGroup(parent)
, overlay_(overlay)
, radius_anim_(animate("radius"))
, opacity_anim_(animate("opacity"))
, radius_(0)
, opacity_(0)
, center_(center)
2017-04-06 02:06:42 +03:00
{
init();
}
Ripple::~Ripple()
{
}
2017-08-20 13:47:22 +03:00
void
Ripple::setRadius(qreal radius)
2017-04-06 02:06:42 +03:00
{
Q_ASSERT(overlay_);
if (radius_ == radius)
return;
radius_ = radius;
overlay_->update();
}
2017-08-20 13:47:22 +03:00
void
Ripple::setOpacity(qreal opacity)
2017-04-06 02:06:42 +03:00
{
Q_ASSERT(overlay_);
if (opacity_ == opacity)
return;
opacity_ = opacity;
overlay_->update();
}
2017-08-20 13:47:22 +03:00
void
Ripple::setColor(const QColor &color)
2017-04-06 02:06:42 +03:00
{
if (brush_.color() == color)
return;
brush_.setColor(color);
if (overlay_)
overlay_->update();
}
2017-08-20 13:47:22 +03:00
void
Ripple::setBrush(const QBrush &brush)
2017-04-06 02:06:42 +03:00
{
brush_ = brush;
if (overlay_)
overlay_->update();
}
2017-08-20 13:47:22 +03:00
void
Ripple::destroy()
2017-04-06 02:06:42 +03:00
{
Q_ASSERT(overlay_);
overlay_->removeRipple(this);
}
2017-08-20 13:47:22 +03:00
QPropertyAnimation *
Ripple::animate(const QByteArray &property, const QEasingCurve &easing, int duration)
2017-04-06 02:06:42 +03:00
{
QPropertyAnimation *animation = new QPropertyAnimation;
animation->setTargetObject(this);
animation->setPropertyName(property);
animation->setEasingCurve(easing);
animation->setDuration(duration);
addAnimation(animation);
return animation;
}
2017-08-20 13:47:22 +03:00
void
Ripple::init()
2017-04-06 02:06:42 +03:00
{
setOpacityStartValue(0.5);
setOpacityEndValue(0);
setRadiusStartValue(0);
setRadiusEndValue(300);
brush_.setColor(Qt::black);
brush_.setStyle(Qt::SolidPattern);
connect(this, SIGNAL(finished()), this, SLOT(destroy()));
}