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 <QPainter>
|
|
|
|
|
|
|
|
#include "Ripple.h"
|
|
|
|
#include "RippleOverlay.h"
|
|
|
|
|
|
|
|
RippleOverlay::RippleOverlay(QWidget *parent)
|
2017-08-20 13:47:22 +03:00
|
|
|
: OverlayWidget(parent)
|
|
|
|
, use_clip_(false)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RippleOverlay::addRipple(Ripple *ripple)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
ripple->setOverlay(this);
|
|
|
|
ripples_.push_back(ripple);
|
|
|
|
ripple->start();
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RippleOverlay::addRipple(const QPoint &position, qreal radius)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Ripple *ripple = new Ripple(position);
|
|
|
|
ripple->setRadiusEndValue(radius);
|
|
|
|
addRipple(ripple);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RippleOverlay::removeRipple(Ripple *ripple)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
if (ripples_.removeOne(ripple))
|
|
|
|
delete ripple;
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RippleOverlay::paintEvent(QPaintEvent *event)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
Q_UNUSED(event)
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
QPainter painter(this);
|
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
|
|
|
painter.setPen(Qt::NoPen);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (use_clip_)
|
|
|
|
painter.setClipPath(clip_path_);
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
for (auto it = ripples_.constBegin(); it != ripples_.constEnd(); ++it)
|
|
|
|
paintRipple(&painter, *it);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|
|
|
|
|
2017-08-20 13:47:22 +03:00
|
|
|
void
|
|
|
|
RippleOverlay::paintRipple(QPainter *painter, Ripple *ripple)
|
2017-04-06 02:06:42 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
const qreal radius = ripple->radius();
|
|
|
|
const QPointF center = ripple->center();
|
2017-04-06 02:06:42 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
painter->setOpacity(ripple->opacity());
|
|
|
|
painter->setBrush(ripple->brush());
|
|
|
|
painter->drawEllipse(center, radius, radius);
|
2017-04-06 02:06:42 +03:00
|
|
|
}
|