add support for clip region to Ripple

This commit is contained in:
laserpants 2016-06-12 17:53:43 +03:00
parent 7b4ac5eb91
commit 369ed5adbb
2 changed files with 13 additions and 1 deletions

View File

@ -4,7 +4,8 @@
#include "ripple.h"
RippleOverlay::RippleOverlay(QWidget *parent)
: QWidget(parent)
: QWidget(parent),
useClip(false)
{
setAttribute(Qt::WA_TransparentForMouseEvents);
setAttribute(Qt::WA_NoSystemBackground);
@ -44,6 +45,10 @@ void RippleOverlay::paintEvent(QPaintEvent *event)
painter.setRenderHint(QPainter::Antialiasing);
painter.setPen(Qt::NoPen);
if (useClip) {
painter.setClipRegion(clipRegion);
}
QList<Ripple *>::const_iterator i;
for (i = ripples.begin(); i != ripples.end(); ++i)
{

View File

@ -18,6 +18,11 @@ public:
void setColor(const QColor &color);
inline void setClipping(bool enabled) { useClip = enabled; update(); }
inline bool hasClipping() const { return useClip; }
inline void setClipRegion(const QRegion &region) { clipRegion = region; update(); }
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
@ -26,6 +31,8 @@ protected slots:
private:
QList<Ripple *> ripples;
QRegion clipRegion;
bool useClip;
};
#endif // RIPPLEOVERLAY_H