add ripple brush accessors
This commit is contained in:
parent
3d2084d99e
commit
2601b2e39e
|
@ -14,6 +14,9 @@ Ripple::Ripple(const QPoint ¢er, QObject *parent)
|
||||||
setOpacityEndValue(0);
|
setOpacityEndValue(0);
|
||||||
setRadiusStartValue(0);
|
setRadiusStartValue(0);
|
||||||
setRadiusEndValue(300);
|
setRadiusEndValue(300);
|
||||||
|
|
||||||
|
_brush.setColor(Qt::black);
|
||||||
|
_brush.setStyle(Qt::SolidPattern);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ripple::~Ripple()
|
Ripple::~Ripple()
|
||||||
|
@ -38,6 +41,14 @@ void Ripple::setOpacity(qreal opacity)
|
||||||
emit changed();
|
emit changed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ripple::setColor(const QColor &color)
|
||||||
|
{
|
||||||
|
if (color == _brush.color())
|
||||||
|
return;
|
||||||
|
|
||||||
|
_brush.setColor(color);
|
||||||
|
}
|
||||||
|
|
||||||
QPropertyAnimation *Ripple::animate(const QByteArray &property)
|
QPropertyAnimation *Ripple::animate(const QByteArray &property)
|
||||||
{
|
{
|
||||||
QPropertyAnimation *animation = new QPropertyAnimation;
|
QPropertyAnimation *animation = new QPropertyAnimation;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
#include <QParallelAnimationGroup>
|
#include <QParallelAnimationGroup>
|
||||||
#include <QPropertyAnimation>
|
#include <QPropertyAnimation>
|
||||||
|
#include <QBrush>
|
||||||
|
|
||||||
class Ripple : public QObject
|
class Ripple : public QObject
|
||||||
{
|
{
|
||||||
|
@ -23,6 +24,12 @@ public:
|
||||||
void setOpacity(qreal opacity);
|
void setOpacity(qreal opacity);
|
||||||
inline qreal opacity() const { return _opacity; }
|
inline qreal opacity() const { return _opacity; }
|
||||||
|
|
||||||
|
void setColor(const QColor &color);
|
||||||
|
inline QColor color() const { return _brush.color(); }
|
||||||
|
|
||||||
|
inline void setBrush(const QBrush &brush) { _brush = brush; }
|
||||||
|
inline QBrush brush() const { return _brush; }
|
||||||
|
|
||||||
inline const QPoint ¢er() const { return _center; }
|
inline const QPoint ¢er() const { return _center; }
|
||||||
|
|
||||||
inline void setDuration(int duration)
|
inline void setDuration(int duration)
|
||||||
|
@ -51,6 +58,7 @@ private:
|
||||||
qreal _radius;
|
qreal _radius;
|
||||||
qreal _opacity;
|
qreal _opacity;
|
||||||
QPoint _center;
|
QPoint _center;
|
||||||
|
QBrush _brush;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RIPPLE_H
|
#endif // RIPPLE_H
|
||||||
|
|
|
@ -14,10 +14,11 @@ RippleOverlay::~RippleOverlay()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void RippleOverlay::addRipple(const QPoint &position, qreal radius)
|
void RippleOverlay::addRipple(const QPoint &position, const QColor &color, qreal radius)
|
||||||
{
|
{
|
||||||
Ripple *ripple = new Ripple(position);
|
Ripple *ripple = new Ripple(position);
|
||||||
ripple->setRadiusEndValue(radius);
|
ripple->setRadiusEndValue(radius);
|
||||||
|
ripple->setColor(color);
|
||||||
ripples.push_back(ripple);
|
ripples.push_back(ripple);
|
||||||
connect(ripple, SIGNAL(changed()), this, SLOT(update()));
|
connect(ripple, SIGNAL(changed()), this, SLOT(update()));
|
||||||
connect(ripple, SIGNAL(finished()), this, SLOT(deleteRipple()));
|
connect(ripple, SIGNAL(finished()), this, SLOT(deleteRipple()));
|
||||||
|
@ -31,11 +32,6 @@ void RippleOverlay::paintEvent(QPaintEvent *event)
|
||||||
QPainter painter(this);
|
QPainter painter(this);
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
|
|
||||||
QBrush brush;
|
|
||||||
brush.setColor(Qt::black);
|
|
||||||
brush.setStyle(Qt::SolidPattern);
|
|
||||||
painter.setBrush(brush);
|
|
||||||
|
|
||||||
QList<Ripple *>::const_iterator i;
|
QList<Ripple *>::const_iterator i;
|
||||||
for (i = ripples.begin(); i != ripples.end(); ++i)
|
for (i = ripples.begin(); i != ripples.end(); ++i)
|
||||||
{
|
{
|
||||||
|
@ -43,6 +39,7 @@ void RippleOverlay::paintEvent(QPaintEvent *event)
|
||||||
const qreal radius = ripple->radius();
|
const qreal radius = ripple->radius();
|
||||||
const QPointF ¢er = ripple->center();
|
const QPointF ¢er = ripple->center();
|
||||||
painter.setOpacity(ripple->opacity());
|
painter.setOpacity(ripple->opacity());
|
||||||
|
painter.setBrush(ripple->brush());
|
||||||
painter.drawEllipse(center, radius, radius);
|
painter.drawEllipse(center, radius, radius);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,8 @@ public:
|
||||||
explicit RippleOverlay(QWidget *parent = 0);
|
explicit RippleOverlay(QWidget *parent = 0);
|
||||||
~RippleOverlay();
|
~RippleOverlay();
|
||||||
|
|
||||||
void addRipple(const QPoint &position, qreal radius = 300);
|
void addRipple(const QPoint &position, const QColor &color = Qt::black,
|
||||||
|
qreal radius = 300);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
Loading…
Reference in New Issue