2016-06-19 14:27:21 +00:00
|
|
|
#include "rippleoverlay.h"
|
2016-03-18 14:36:02 +00:00
|
|
|
#include <QDebug>
|
|
|
|
#include <QPainter>
|
|
|
|
#include "ripple.h"
|
|
|
|
|
|
|
|
RippleOverlay::RippleOverlay(QWidget *parent)
|
2016-06-12 14:53:43 +00:00
|
|
|
: QWidget(parent),
|
|
|
|
useClip(false)
|
2016-03-18 14:36:02 +00:00
|
|
|
{
|
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
|
|
|
setAttribute(Qt::WA_NoSystemBackground);
|
|
|
|
}
|
|
|
|
|
|
|
|
RippleOverlay::~RippleOverlay()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-15 06:19:45 +00:00
|
|
|
void RippleOverlay::addRipple(const QPoint &position, qreal radius)
|
2016-03-18 14:36:02 +00:00
|
|
|
{
|
2016-06-20 19:02:24 +00:00
|
|
|
Ripple *ripple = new Ripple(position, this);
|
2016-03-18 14:36:02 +00:00
|
|
|
ripple->setRadiusEndValue(radius);
|
2016-05-15 06:19:45 +00:00
|
|
|
addRipple(ripple);
|
|
|
|
}
|
|
|
|
|
|
|
|
void RippleOverlay::addRipple(Ripple *ripple)
|
|
|
|
{
|
2016-06-20 19:02:24 +00:00
|
|
|
ripple->setOverlay(this);
|
2016-03-18 14:36:02 +00:00
|
|
|
ripples.push_back(ripple);
|
|
|
|
connect(ripple, SIGNAL(finished()), this, SLOT(deleteRipple()));
|
|
|
|
ripple->startAnimation();
|
|
|
|
}
|
|
|
|
|
2016-06-12 00:56:37 +00:00
|
|
|
void RippleOverlay::setColor(const QColor &color)
|
|
|
|
{
|
|
|
|
QList<Ripple *>::const_iterator i;
|
|
|
|
for (i = ripples.begin(); i != ripples.end(); ++i)
|
|
|
|
(*i)->setColor(color);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:36:02 +00:00
|
|
|
void RippleOverlay::paintEvent(QPaintEvent *event)
|
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
|
|
|
|
|
|
|
QPainter painter(this);
|
2016-05-29 13:42:13 +00:00
|
|
|
painter.setRenderHint(QPainter::Antialiasing);
|
2016-05-15 06:19:45 +00:00
|
|
|
painter.setPen(Qt::NoPen);
|
2016-03-18 14:36:02 +00:00
|
|
|
|
2016-06-12 14:53:43 +00:00
|
|
|
if (useClip) {
|
2016-06-12 15:17:27 +00:00
|
|
|
painter.setClipPath(clipPath);
|
2016-06-12 14:53:43 +00:00
|
|
|
}
|
|
|
|
|
2016-03-18 14:36:02 +00:00
|
|
|
QList<Ripple *>::const_iterator i;
|
|
|
|
for (i = ripples.begin(); i != ripples.end(); ++i)
|
|
|
|
{
|
|
|
|
const Ripple *ripple = *i;
|
|
|
|
const qreal radius = ripple->radius();
|
|
|
|
const QPointF ¢er = ripple->center();
|
|
|
|
painter.setOpacity(ripple->opacity());
|
2016-05-14 18:32:36 +00:00
|
|
|
painter.setBrush(ripple->brush());
|
2016-03-18 14:36:02 +00:00
|
|
|
painter.drawEllipse(center, radius, radius);
|
|
|
|
}
|
2016-03-19 20:32:07 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_LAYOUT
|
|
|
|
QPen pen;
|
|
|
|
pen.setColor(Qt::red);
|
|
|
|
pen.setWidth(2);
|
|
|
|
painter.setOpacity(1);
|
|
|
|
painter.setPen(pen);
|
|
|
|
painter.setBrush(Qt::NoBrush);
|
|
|
|
painter.drawRect(rect());
|
|
|
|
#endif
|
2016-03-18 14:36:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void RippleOverlay::deleteRipple()
|
|
|
|
{
|
|
|
|
if (ripples.isEmpty()) {
|
2016-05-01 17:05:48 +00:00
|
|
|
qWarning() << "RippleOverlay::deleteRipple was called when no ripples were active.";
|
2016-03-18 14:36:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ripples.takeFirst()->deleteLater();
|
|
|
|
}
|