2011-11-10 13:28:06 +00:00
|
|
|
/********************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*********************************************************************/
|
|
|
|
|
|
|
|
#include "thumbnailitem.h"
|
|
|
|
// KWin
|
|
|
|
#include "client.h"
|
|
|
|
#include "effects.h"
|
|
|
|
#include "workspace.h"
|
2013-03-06 08:46:25 +00:00
|
|
|
#include "composite.h"
|
2011-11-10 13:28:06 +00:00
|
|
|
// Qt
|
|
|
|
#include <QtDeclarative/QDeclarativeContext>
|
|
|
|
#include <QtDeclarative/QDeclarativeEngine>
|
|
|
|
#include <QtDeclarative/QDeclarativeView>
|
|
|
|
// KDE
|
|
|
|
#include <KDE/KDebug>
|
|
|
|
|
|
|
|
namespace KWin
|
|
|
|
{
|
|
|
|
ThumbnailItem::ThumbnailItem(QDeclarativeItem* parent)
|
|
|
|
: QDeclarativeItem(parent)
|
|
|
|
, m_wId(0)
|
2011-11-29 06:13:26 +00:00
|
|
|
, m_clip(true)
|
2011-11-10 13:28:06 +00:00
|
|
|
, m_parent(QWeakPointer<EffectWindowImpl>())
|
2012-03-24 07:12:29 +00:00
|
|
|
, m_parentWindow(0)
|
2013-03-19 08:08:32 +00:00
|
|
|
, m_brightness(1.0)
|
|
|
|
, m_saturation(1.0)
|
2011-11-10 13:28:06 +00:00
|
|
|
{
|
|
|
|
setFlags(flags() & ~QGraphicsItem::ItemHasNoContents);
|
2013-03-06 08:46:25 +00:00
|
|
|
Q_ASSERT(Compositor::isCreated());
|
|
|
|
connect(Compositor::self(), SIGNAL(compositingToggled(bool)), SLOT(compositingToggled()));
|
|
|
|
compositingToggled();
|
2011-11-10 13:28:06 +00:00
|
|
|
QTimer::singleShot(0, this, SLOT(init()));
|
|
|
|
}
|
|
|
|
|
|
|
|
ThumbnailItem::~ThumbnailItem()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-03-06 08:46:25 +00:00
|
|
|
void ThumbnailItem::compositingToggled()
|
|
|
|
{
|
|
|
|
m_parent.clear();
|
|
|
|
if (effects) {
|
|
|
|
connect(effects, SIGNAL(windowAdded(KWin::EffectWindow*)), SLOT(effectWindowAdded()));
|
|
|
|
connect(effects, SIGNAL(windowDamaged(KWin::EffectWindow*,QRect)), SLOT(repaint(KWin::EffectWindow*)));
|
|
|
|
effectWindowAdded();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:28:06 +00:00
|
|
|
void ThumbnailItem::init()
|
|
|
|
{
|
|
|
|
findParentEffectWindow();
|
|
|
|
if (!m_parent.isNull()) {
|
|
|
|
m_parent.data()->registerThumbnail(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-24 07:12:29 +00:00
|
|
|
void ThumbnailItem::setParentWindow(qulonglong parentWindow)
|
|
|
|
{
|
|
|
|
m_parentWindow = parentWindow;
|
|
|
|
findParentEffectWindow();
|
|
|
|
if (!m_parent.isNull()) {
|
|
|
|
m_parent.data()->registerThumbnail(this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:28:06 +00:00
|
|
|
void ThumbnailItem::findParentEffectWindow()
|
|
|
|
{
|
|
|
|
if (effects) {
|
2012-03-24 07:12:29 +00:00
|
|
|
if (m_parentWindow) {
|
|
|
|
if (EffectWindowImpl *w = static_cast<EffectWindowImpl*>(effects->findWindow(m_parentWindow))) {
|
|
|
|
m_parent = QWeakPointer<EffectWindowImpl>(w);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2011-11-10 13:28:06 +00:00
|
|
|
QDeclarativeContext *ctx = QDeclarativeEngine::contextForObject(this);
|
|
|
|
if (!ctx) {
|
|
|
|
kDebug(1212) << "No Context";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const QVariant variant = ctx->engine()->rootContext()->contextProperty("viewId");
|
|
|
|
if (!variant.isValid()) {
|
|
|
|
kDebug(1212) << "Required context property 'viewId' not found";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (EffectWindowImpl *w = static_cast<EffectWindowImpl*>(effects->findWindow(variant.value<qulonglong>()))) {
|
|
|
|
m_parent = QWeakPointer<EffectWindowImpl>(w);
|
2012-03-24 07:12:29 +00:00
|
|
|
m_parentWindow = variant.value<qulonglong>();
|
2011-11-10 13:28:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ThumbnailItem::setWId(qulonglong wId)
|
|
|
|
{
|
|
|
|
m_wId = wId;
|
|
|
|
emit wIdChanged(wId);
|
|
|
|
}
|
|
|
|
|
2011-11-29 06:13:26 +00:00
|
|
|
void ThumbnailItem::setClip(bool clip)
|
|
|
|
{
|
|
|
|
m_clip = clip;
|
|
|
|
emit clipChanged(clip);
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:28:06 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
if (effects) {
|
|
|
|
QDeclarativeItem::paint(painter, option, widget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Client *client = Workspace::self()->findClient(WindowMatchPredicate(m_wId));
|
|
|
|
if (!client) {
|
|
|
|
QDeclarativeItem::paint(painter, option, widget);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
QPixmap pixmap = client->icon(boundingRect().size().toSize());
|
|
|
|
const QSize size(boundingRect().size().toSize() - pixmap.size());
|
|
|
|
painter->drawPixmap(boundingRect().adjusted(size.width()/2.0, size.height()/2.0, -size.width()/2.0, -size.height()/2.0).toRect(),
|
|
|
|
pixmap);
|
|
|
|
}
|
|
|
|
|
2012-03-16 11:33:48 +00:00
|
|
|
void ThumbnailItem::repaint(KWin::EffectWindow *w)
|
|
|
|
{
|
|
|
|
if (static_cast<KWin::EffectWindowImpl*>(w)->window()->window() == m_wId) {
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-19 08:08:32 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-11-10 13:28:06 +00:00
|
|
|
} // namespace KWin
|