diff --git a/effects.cpp b/effects.cpp index d4e76b4f73..2b48194b4f 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1789,11 +1789,13 @@ EffectWindow* effectWindow(Scene::Window* w) return ret; } -void EffectWindowImpl::registerThumbnail(ThumbnailItem *item) +void EffectWindowImpl::registerThumbnail(AbstractThumbnailItem *item) { - insertThumbnail(item); - connect(item, SIGNAL(destroyed(QObject*)), SLOT(thumbnailDestroyed(QObject*))); - connect(item, SIGNAL(wIdChanged(qulonglong)), SLOT(thumbnailTargetChanged())); + if (ThumbnailItem *thumb = qobject_cast(item)) { + insertThumbnail(thumb); + connect(thumb, SIGNAL(destroyed(QObject*)), SLOT(thumbnailDestroyed(QObject*))); + connect(thumb, SIGNAL(wIdChanged(qulonglong)), SLOT(thumbnailTargetChanged())); + } } void EffectWindowImpl::thumbnailDestroyed(QObject *object) diff --git a/effects.h b/effects.h index 2cd4c43021..4464775cf8 100644 --- a/effects.h +++ b/effects.h @@ -40,6 +40,7 @@ namespace KWin { typedef QPair< Effect*, xcb_window_t > InputWindowPair; +class AbstractThumbnailItem; class ThumbnailItem; class Client; @@ -286,7 +287,7 @@ public: void setData(int role, const QVariant &data); QVariant data(int role) const; - void registerThumbnail(ThumbnailItem *item); + void registerThumbnail(AbstractThumbnailItem *item); QHash > const &thumbnails() const { return m_thumbnails; } diff --git a/thumbnailitem.cpp b/thumbnailitem.cpp index 536b48eed7..4846962835 100644 --- a/thumbnailitem.cpp +++ b/thumbnailitem.cpp @@ -33,10 +33,9 @@ along with this program. If not, see . namespace KWin { -ThumbnailItem::ThumbnailItem(QDeclarativeItem* parent) + +AbstractThumbnailItem::AbstractThumbnailItem(QDeclarativeItem *parent) : QDeclarativeItem(parent) - , m_wId(0) - , m_client(NULL) , m_clip(true) , m_parent(QWeakPointer()) , m_parentWindow(0) @@ -50,11 +49,11 @@ ThumbnailItem::ThumbnailItem(QDeclarativeItem* parent) QTimer::singleShot(0, this, SLOT(init())); } -ThumbnailItem::~ThumbnailItem() +AbstractThumbnailItem::~AbstractThumbnailItem() { } -void ThumbnailItem::compositingToggled() +void AbstractThumbnailItem::compositingToggled() { m_parent.clear(); if (effects) { @@ -64,7 +63,7 @@ void ThumbnailItem::compositingToggled() } } -void ThumbnailItem::init() +void AbstractThumbnailItem::init() { findParentEffectWindow(); if (!m_parent.isNull()) { @@ -72,7 +71,7 @@ void ThumbnailItem::init() } } -void ThumbnailItem::setParentWindow(qulonglong parentWindow) +void AbstractThumbnailItem::setParentWindow(qulonglong parentWindow) { m_parentWindow = parentWindow; findParentEffectWindow(); @@ -81,7 +80,7 @@ void ThumbnailItem::setParentWindow(qulonglong parentWindow) } } -void ThumbnailItem::findParentEffectWindow() +void AbstractThumbnailItem::findParentEffectWindow() { if (effects) { if (m_parentWindow) { @@ -107,6 +106,59 @@ void ThumbnailItem::findParentEffectWindow() } } +void AbstractThumbnailItem::setClip(bool clip) +{ + m_clip = clip; + emit clipChanged(clip); +} + +void AbstractThumbnailItem::effectWindowAdded() +{ + // the window might be added before the EffectWindow is created + // by using this slot we can register the thumbnail when it is finally created + if (m_parent.isNull()) { + findParentEffectWindow(); + if (!m_parent.isNull()) { + m_parent.data()->registerThumbnail(this); + } + } +} + +void AbstractThumbnailItem::setBrightness(qreal brightness) +{ + if (qFuzzyCompare(brightness, m_brightness)) { + return; + } + m_brightness = brightness; + update(); + emit brightnessChanged(); +} + +void AbstractThumbnailItem::setSaturation(qreal saturation) +{ + if (qFuzzyCompare(saturation, m_saturation)) { + return; + } + m_saturation = saturation; + update(); + emit saturationChanged(); +} + + +ThumbnailItem::ThumbnailItem(QDeclarativeItem* parent) + : AbstractThumbnailItem(parent) + , m_wId(0) + , m_client(NULL) +{ + if (effects) { + connect(effects, SIGNAL(windowDamaged(KWin::EffectWindow*,QRect)), SLOT(repaint(KWin::EffectWindow*))); + } +} + +ThumbnailItem::~ThumbnailItem() +{ +} + void ThumbnailItem::setWId(qulonglong wId) { if (m_wId == wId) { @@ -136,23 +188,6 @@ void ThumbnailItem::setClient(Client *client) emit clientChanged(); } -void ThumbnailItem::setClip(bool clip) -{ - m_clip = clip; - emit clipChanged(clip); -} - -void ThumbnailItem::effectWindowAdded() -{ - // the window might be added before the EffectWindow is created - // by using this slot we can register the thumbnail when it is finally created - if (m_parent.isNull()) { - findParentEffectWindow(); - if (!m_parent.isNull()) { - m_parent.data()->registerThumbnail(this); - } - } -} void ThumbnailItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) { @@ -178,24 +213,4 @@ 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 d3462caf6b..f3382cd824 100644 --- a/thumbnailitem.h +++ b/thumbnailitem.h @@ -31,14 +31,56 @@ class Client; class EffectWindow; class EffectWindowImpl; -class ThumbnailItem : public QDeclarativeItem +class AbstractThumbnailItem : public QDeclarativeItem { Q_OBJECT - 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: + virtual ~AbstractThumbnailItem(); + bool isClip() const { + return m_clip; + } + void setClip(bool clip); + qulonglong parentWindow() const { + 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 clipChanged(bool clipped); + void brightnessChanged(); + void saturationChanged(); + +protected: + explicit AbstractThumbnailItem(QDeclarativeItem *parent = 0); + +private Q_SLOTS: + void init(); + void effectWindowAdded(); + void compositingToggled(); + +private: + void findParentEffectWindow(); + bool m_clip; + QWeakPointer m_parent; + qulonglong m_parentWindow; + qreal m_brightness; + qreal m_saturation; +}; + +class ThumbnailItem : public AbstractThumbnailItem +{ + Q_OBJECT + Q_PROPERTY(qulonglong wId READ wId WRITE setWId NOTIFY wIdChanged SCRIPTABLE true) Q_PROPERTY(KWin::Client *client READ client WRITE setClient NOTIFY clientChanged) public: explicit ThumbnailItem(QDeclarativeItem *parent = 0); @@ -48,54 +90,27 @@ public: return m_wId; } void setWId(qulonglong wId); - bool isClip() const { - return m_clip; - } - void setClip(bool clip); - virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - qulonglong parentWindow() const { - return m_parentWindow; - } - void setParentWindow(qulonglong parentWindow); - qreal brightness() const; - qreal saturation() const; Client *client() const; void setClient(Client *client); - -public Q_SLOTS: - void setBrightness(qreal brightness); - void setSaturation(qreal saturation); - + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); Q_SIGNALS: void wIdChanged(qulonglong wid); - void clipChanged(bool clipped); - void brightnessChanged(); - void saturationChanged(); void clientChanged(); private Q_SLOTS: - void init(); - void effectWindowAdded(); void repaint(KWin::EffectWindow* w); - void compositingToggled(); private: - void findParentEffectWindow(); qulonglong m_wId; Client *m_client; - bool m_clip; - QWeakPointer m_parent; - qulonglong m_parentWindow; - qreal m_brightness; - qreal m_saturation; }; inline -qreal ThumbnailItem::brightness() const +qreal AbstractThumbnailItem::brightness() const { return m_brightness; } inline -qreal ThumbnailItem::saturation() const +qreal AbstractThumbnailItem::saturation() const { return m_saturation; }