2021-03-05 02:35:15 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2017-04-06 02:06:42 +03:00
|
|
|
#include "Ripple.h"
|
|
|
|
#include "RippleOverlay.h"
|
|
|
|
|
|
|
|
Ripple::Ripple(const QPoint ¢er, QObject *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: QParallelAnimationGroup(parent)
|
2020-02-04 06:58:43 +03:00
|
|
|
, overlay_(nullptr)
|
2017-08-20 13:47:22 +03:00
|
|
|
, radius_anim_(animate("radius"))
|
|
|
|
, opacity_anim_(animate("opacity"))
|
|
|
|
, radius_(0)
|
|
|
|
, opacity_(0)
|
|
|
|
, center_(center)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
init();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Ripple::Ripple(const QPoint ¢er, 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
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
init();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::setRadius(qreal radius)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_ASSERT(overlay_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (radius_ == radius)
|
|
|
|
return;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
radius_ = radius;
|
|
|
|
overlay_->update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::setOpacity(qreal opacity)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_ASSERT(overlay_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (opacity_ == opacity)
|
|
|
|
return;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
opacity_ = opacity;
|
|
|
|
overlay_->update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::setColor(const QColor &color)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
if (brush_.color() == color)
|
|
|
|
return;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
brush_.setColor(color);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (overlay_)
|
|
|
|
overlay_->update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::setBrush(const QBrush &brush)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
brush_ = brush;
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
if (overlay_)
|
|
|
|
overlay_->update();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::destroy()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
Q_ASSERT(overlay_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
overlay_->removeRipple(this);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
QPropertyAnimation *animation = new QPropertyAnimation;
|
|
|
|
animation->setTargetObject(this);
|
|
|
|
animation->setPropertyName(property);
|
|
|
|
animation->setEasingCurve(easing);
|
|
|
|
animation->setDuration(duration);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
addAnimation(animation);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
return animation;
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
Ripple::init()
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2017-09-10 12:59:21 +03:00
|
|
|
setOpacityStartValue(0.5);
|
|
|
|
setOpacityEndValue(0);
|
|
|
|
setRadiusStartValue(0);
|
|
|
|
setRadiusEndValue(300);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
brush_.setColor(Qt::black);
|
|
|
|
brush_.setStyle(Qt::SolidPattern);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2017-09-10 12:59:21 +03:00
|
|
|
connect(this, SIGNAL(finished()), this, SLOT(destroy()));
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|