From 15b84c54f89b8c67f5484fa3a5c0952348989edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Tue, 19 Mar 2013 09:08:32 +0100 Subject: [PATCH] Support saturation/brightness in ThumbnailItem Two new properties saturation and brightness are added to the ThumbnailItem which can be set from QML. The properties are honoured by the Scene when rendering the thumbnail. --- scene.cpp | 2 ++ thumbnailitem.cpp | 22 ++++++++++++++++++++++ thumbnailitem.h | 25 +++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/scene.cpp b/scene.cpp index 939f000f0c..6a3aaeb26a 100644 --- a/scene.cpp +++ b/scene.cpp @@ -385,6 +385,8 @@ void Scene::paintWindow(Window* w, int mask, QRegion region, WindowQuadList quad EffectWindowImpl *thumb = it.value().data(); WindowPaintData thumbData(thumb); thumbData.setOpacity(data.opacity()); + thumbData.setBrightness(data.brightness() * item->brightness()); + thumbData.setSaturation(data.saturation() * item->saturation()); const QRect visualThumbRect(thumb->expandedGeometry()); diff --git a/thumbnailitem.cpp b/thumbnailitem.cpp index 66b665a685..4d10501f18 100644 --- a/thumbnailitem.cpp +++ b/thumbnailitem.cpp @@ -39,6 +39,8 @@ ThumbnailItem::ThumbnailItem(QDeclarativeItem* parent) , m_clip(true) , m_parent(QWeakPointer()) , m_parentWindow(0) + , m_brightness(1.0) + , m_saturation(1.0) { setFlags(flags() & ~QGraphicsItem::ItemHasNoContents); Q_ASSERT(Compositor::isCreated()); @@ -152,4 +154,24 @@ void ThumbnailItem::repaint(KWin::EffectWindow *w) } } +void ThumbnailItem::setBrightness(qreal brightness) +{ + if (qFuzzyCompare(brightness, m_brightness)) { + return; + } + m_brightness = brightness; + update(); + emit brightnessChanged(); +} + +void ThumbnailItem::setSaturation(qreal saturation) +{ + if (qFuzzyCompare(saturation, m_saturation)) { + return; + } + m_saturation = saturation; + update(); + emit saturationChanged(); +} + } // namespace KWin diff --git a/thumbnailitem.h b/thumbnailitem.h index f7dc4fe621..5be10754da 100644 --- a/thumbnailitem.h +++ b/thumbnailitem.h @@ -36,6 +36,8 @@ class ThumbnailItem : public QDeclarativeItem Q_PROPERTY(qulonglong wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true) Q_PROPERTY(bool clip READ isClip WRITE setClip NOTIFY clipChanged SCRIPTABLE true) Q_PROPERTY(qulonglong parentWindow READ parentWindow WRITE setParentWindow) + Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged) + Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged) public: explicit ThumbnailItem(QDeclarativeItem *parent = 0); virtual ~ThumbnailItem(); @@ -53,9 +55,18 @@ public: return m_parentWindow; } void setParentWindow(qulonglong parentWindow); + qreal brightness() const; + qreal saturation() const; + +public Q_SLOTS: + void setBrightness(qreal brightness); + void setSaturation(qreal saturation); + Q_SIGNALS: void wIdChanged(qulonglong wid); void clipChanged(bool clipped); + void brightnessChanged(); + void saturationChanged(); private Q_SLOTS: void init(); void effectWindowAdded(); @@ -67,8 +78,22 @@ private: bool m_clip; QWeakPointer m_parent; qulonglong m_parentWindow; + qreal m_brightness; + qreal m_saturation; }; +inline +qreal ThumbnailItem::brightness() const +{ + return m_brightness; +} + +inline +qreal ThumbnailItem::saturation() const +{ + return m_saturation; +} + } // KWin #endif // KWIN_THUMBNAILITEM_H