add support for clip region to Ripple
This commit is contained in:
parent
7b4ac5eb91
commit
369ed5adbb
|
@ -4,7 +4,8 @@
|
||||||
#include "ripple.h"
|
#include "ripple.h"
|
||||||
|
|
||||||
RippleOverlay::RippleOverlay(QWidget *parent)
|
RippleOverlay::RippleOverlay(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent),
|
||||||
|
useClip(false)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_TransparentForMouseEvents);
|
setAttribute(Qt::WA_TransparentForMouseEvents);
|
||||||
setAttribute(Qt::WA_NoSystemBackground);
|
setAttribute(Qt::WA_NoSystemBackground);
|
||||||
|
@ -44,6 +45,10 @@ void RippleOverlay::paintEvent(QPaintEvent *event)
|
||||||
painter.setRenderHint(QPainter::Antialiasing);
|
painter.setRenderHint(QPainter::Antialiasing);
|
||||||
painter.setPen(Qt::NoPen);
|
painter.setPen(Qt::NoPen);
|
||||||
|
|
||||||
|
if (useClip) {
|
||||||
|
painter.setClipRegion(clipRegion);
|
||||||
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -18,6 +18,11 @@ public:
|
||||||
|
|
||||||
void setColor(const QColor &color);
|
void setColor(const QColor &color);
|
||||||
|
|
||||||
|
inline void setClipping(bool enabled) { useClip = enabled; update(); }
|
||||||
|
inline bool hasClipping() const { return useClip; }
|
||||||
|
|
||||||
|
inline void setClipRegion(const QRegion ®ion) { clipRegion = region; update(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
@ -26,6 +31,8 @@ protected slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<Ripple *> ripples;
|
QList<Ripple *> ripples;
|
||||||
|
QRegion clipRegion;
|
||||||
|
bool useClip;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // RIPPLEOVERLAY_H
|
#endif // RIPPLEOVERLAY_H
|
||||||
|
|
Loading…
Reference in New Issue