~ubuntu-branches/ubuntu/precise/kde-workspace/precise

« back to all changes in this revision

Viewing changes to .pc/enable_kwinactive.diff/kwin/tabbox/declarative.cpp

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac, Rodrigo Belem, Philip Muškovac
  • Date: 2012-04-10 19:37:37 UTC
  • Revision ID: package-import@ubuntu.com-20120410193737-rhsuhcb6mfsdom0f
Tags: 4:4.8.2a-0ubuntu2
[ Rodrigo Belem ]
* Move kwin4_effect_builtins.so to kde-window-manager
* Move libkwinnvidiahack4 to its own package
* Add breaks/replaces for kde-window-manager-common on
  libkwinnvidiahack4 and kde-window-manager << 4:4.8.2a-0ubuntu2~
* Enable kwinactive (LP: #956186)
* Build the source twice to create kwinactive binaries
* Add the packages
  - kde-window-manager-active
  - kde-window-manager-active-gles
  - libkwinactiveglutils1
  - libkwinactiveglesutils1
  - libkwinactiveeffects1abi3
  - libkwinactivenvidiahack4
* Fix kwinactive build failure with the patch
  kubuntu_active_fix_kwin_xrender_disable.diff

[ Philip Muškovac ]
* kde-window-manager/-gles depends on libkwinnvidiahack4
  kde-window-manager-active/-gles depends on libkwinactivenvidiahack4
* use ${allLibaries} to generate the library dependencies for
  kde-workspace-dev again

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/********************************************************************
 
2
 KWin - the KDE window manager
 
3
 This file is part of the KDE project.
 
4
 
 
5
Copyright (C) 2011 Martin Gräßlin <mgraesslin@kde.org>
 
6
 
 
7
This program is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or
 
10
(at your option) any later version.
 
11
 
 
12
This program is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
*********************************************************************/
 
20
// own
 
21
#include "declarative.h"
 
22
#include "tabboxhandler.h"
 
23
#include "clientmodel.h"
 
24
// Qt
 
25
#include <QtDeclarative/qdeclarative.h>
 
26
#include <QtDeclarative/QDeclarativeContext>
 
27
#include <QtDeclarative/QDeclarativeEngine>
 
28
#include <QtGui/QGraphicsObject>
 
29
#include <QtGui/QResizeEvent>
 
30
// include KDE
 
31
#include <KDE/KDebug>
 
32
#include <KDE/KIconEffect>
 
33
#include <KDE/KIconLoader>
 
34
#include <KDE/KStandardDirs>
 
35
#include <KDE/Plasma/FrameSvg>
 
36
#include <KDE/Plasma/Theme>
 
37
#include <KDE/Plasma/WindowEffects>
 
38
#include <kdeclarative.h>
 
39
#include <kephal/screens.h>
 
40
// KWin
 
41
#include "thumbnailitem.h"
 
42
 
 
43
namespace KWin
 
44
{
 
45
namespace TabBox
 
46
{
 
47
 
 
48
ImageProvider::ImageProvider(QAbstractItemModel *model)
 
49
    : QDeclarativeImageProvider(QDeclarativeImageProvider::Pixmap)
 
50
    , m_model(model)
 
51
{
 
52
}
 
53
 
 
54
QPixmap ImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
 
55
{
 
56
    bool ok = false;
 
57
    QStringList parts = id.split('/');
 
58
    const int row = parts.first().toInt(&ok);
 
59
    if (!ok) {
 
60
        return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
 
61
    }
 
62
    const QModelIndex index = m_model->index(row, 0);
 
63
    if (!index.isValid()) {
 
64
        return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
 
65
    }
 
66
    if (index.model()->data(index, ClientModel::EmptyRole).toBool()) {
 
67
        return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
 
68
    }
 
69
    TabBoxClient* client = static_cast< TabBoxClient* >(index.model()->data(index, ClientModel::ClientRole).value<void *>());
 
70
    if (!client) {
 
71
        return QDeclarativeImageProvider::requestPixmap(id, size, requestedSize);
 
72
    }
 
73
 
 
74
    QSize s(32, 32);
 
75
    if (requestedSize.isValid()) {
 
76
        s = requestedSize;
 
77
    }
 
78
    *size = s;
 
79
    QPixmap icon = client->icon(s);
 
80
    if (s.width() > icon.width() || s.height() > icon.height()) {
 
81
        // icon is smaller than what we requested - QML would scale it which looks bad
 
82
        QPixmap temp(s);
 
83
        temp.fill(Qt::transparent);
 
84
        QPainter p(&temp);
 
85
        p.drawPixmap(s.width()/2 - icon.width()/2, s.height()/2 - icon.height()/2, icon);
 
86
        icon = temp;
 
87
    }
 
88
    if (parts.size() > 2) {
 
89
        KIconEffect *effect = KIconLoader::global()->iconEffect();
 
90
        KIconLoader::States state = KIconLoader::DefaultState;
 
91
        if (parts.at(2) == QLatin1String("selected")) {
 
92
            state = KIconLoader::ActiveState;
 
93
        } else if (parts.at(2) == QLatin1String("disabled")) {
 
94
            state = KIconLoader::DisabledState;
 
95
        }
 
96
        icon = effect->apply(icon, KIconLoader::Desktop, state);
 
97
    }
 
98
    return icon;
 
99
}
 
100
 
 
101
DeclarativeView::DeclarativeView(QAbstractItemModel *model, QWidget *parent)
 
102
    : QDeclarativeView(parent)
 
103
    , m_model(model)
 
104
    , m_currentScreenGeometry()
 
105
    , m_frame(new Plasma::FrameSvg(this))
 
106
    , m_currentLayout()
 
107
{
 
108
    setAttribute(Qt::WA_TranslucentBackground);
 
109
    setWindowFlags(Qt::X11BypassWindowManagerHint);
 
110
    setResizeMode(QDeclarativeView::SizeViewToRootObject);
 
111
    QPalette pal = palette();
 
112
    pal.setColor(backgroundRole(), Qt::transparent);
 
113
    setPalette(pal);
 
114
    foreach (const QString &importPath, KGlobal::dirs()->findDirs("module", "imports")) {
 
115
        engine()->addImportPath(importPath);
 
116
    }
 
117
    engine()->addImageProvider(QLatin1String("client"), new ImageProvider(model));
 
118
    KDeclarative kdeclarative;
 
119
    kdeclarative.setDeclarativeEngine(engine());
 
120
    kdeclarative.initialize();
 
121
    kdeclarative.setupBindings();
 
122
    qmlRegisterType<ThumbnailItem>("org.kde.kwin", 0, 1, "ThumbnailItem");
 
123
    rootContext()->setContextProperty("viewId", static_cast<qulonglong>(winId()));
 
124
    rootContext()->setContextProperty("clientModel", model);
 
125
    setSource(QUrl(KStandardDirs::locate("data", "kwin/tabbox/tabbox.qml")));
 
126
 
 
127
    // FrameSvg
 
128
    m_frame->setImagePath("dialogs/background");
 
129
    m_frame->setCacheAllRenderedFrames(true);
 
130
    m_frame->setEnabledBorders(Plasma::FrameSvg::AllBorders);
 
131
 
 
132
    connect(tabBox, SIGNAL(configChanged()), SLOT(updateQmlSource()));
 
133
}
 
134
 
 
135
void DeclarativeView::showEvent(QShowEvent *event)
 
136
{
 
137
    updateQmlSource();
 
138
    m_currentScreenGeometry = Kephal::ScreenUtils::screenGeometry(tabBox->activeScreen());
 
139
    rootObject()->setProperty("screenWidth", m_currentScreenGeometry.width());
 
140
    rootObject()->setProperty("screenHeight", m_currentScreenGeometry.height());
 
141
    rootObject()->setProperty("allDesktops", tabBox->config().tabBoxMode() == TabBoxConfig::ClientTabBox &&
 
142
        ((tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsClientList) ||
 
143
        (tabBox->config().clientListMode() == TabBoxConfig::AllDesktopsApplicationList)));
 
144
    rootObject()->setProperty("longestCaption", static_cast<ClientModel*>(m_model)->longestCaption());
 
145
 
 
146
    if (QObject *item = rootObject()->findChild<QObject*>("listView")) {
 
147
        item->setProperty("currentIndex", tabBox->first().row());
 
148
        connect(item, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int)));
 
149
    }
 
150
    slotUpdateGeometry();
 
151
    QGraphicsView::showEvent(event);
 
152
}
 
153
 
 
154
void DeclarativeView::resizeEvent(QResizeEvent *event)
 
155
{
 
156
    m_frame->resizeFrame(event->size());
 
157
    if (Plasma::Theme::defaultTheme()->windowTranslucencyEnabled()) {
 
158
        // blur background
 
159
        Plasma::WindowEffects::enableBlurBehind(winId(), true, m_frame->mask());
 
160
        Plasma::WindowEffects::overrideShadow(winId(), true);
 
161
    } else {
 
162
        // do not trim to mask with compositing enabled, otherwise shadows are cropped
 
163
        setMask(m_frame->mask());
 
164
    }
 
165
    QDeclarativeView::resizeEvent(event);
 
166
}
 
167
 
 
168
void DeclarativeView::slotUpdateGeometry()
 
169
{
 
170
    const int width = rootObject()->property("width").toInt();
 
171
    const int height = rootObject()->property("height").toInt();
 
172
    setGeometry(m_currentScreenGeometry.x() + static_cast<qreal>(m_currentScreenGeometry.width()) * 0.5 - static_cast<qreal>(width) * 0.5,
 
173
        m_currentScreenGeometry.y() + static_cast<qreal>(m_currentScreenGeometry.height()) * 0.5 - static_cast<qreal>(height) * 0.5,
 
174
        width, height);
 
175
}
 
176
 
 
177
void DeclarativeView::setCurrentIndex(const QModelIndex &index, bool disableAnimation)
 
178
{
 
179
    if (QObject *item = rootObject()->findChild<QObject*>("listView")) {
 
180
        QVariant durationRestore;
 
181
        if (disableAnimation) {
 
182
            durationRestore = item->property("highlightMoveDuration");
 
183
            item->setProperty("highlightMoveDuration", QVariant(1));
 
184
        }
 
185
        item->setProperty("currentIndex", index.row());
 
186
        if (disableAnimation) {
 
187
            item->setProperty("highlightMoveDuration", durationRestore);
 
188
        }
 
189
    }
 
190
}
 
191
 
 
192
QModelIndex DeclarativeView::indexAt(const QPoint &pos) const
 
193
{
 
194
    if (QObject *item = rootObject()->findChild<QObject*>("listView")) {
 
195
        QVariant returnedValue;
 
196
        QVariant xPos(pos.x());
 
197
        QVariant yPos(pos.y());
 
198
        QMetaObject::invokeMethod(item, "indexAtMousePos", Q_RETURN_ARG(QVariant, returnedValue), Q_ARG(QVariant, QVariant(pos)));
 
199
        if (!returnedValue.canConvert<int>()) {
 
200
            return QModelIndex();
 
201
        }
 
202
        return m_model->index(returnedValue.toInt(), 0);
 
203
    }
 
204
    return QModelIndex();
 
205
}
 
206
 
 
207
void DeclarativeView::currentIndexChanged(int row)
 
208
{
 
209
    tabBox->setCurrentIndex(m_model->index(row, 0));
 
210
}
 
211
 
 
212
void DeclarativeView::updateQmlSource()
 
213
{
 
214
    if (tabBox->config().layoutName() == m_currentLayout) {
 
215
        return;
 
216
    }
 
217
    m_currentLayout = tabBox->config().layoutName();
 
218
    QString file = KStandardDirs::locate("data", "kwin/tabbox/" + m_currentLayout.toLower().replace(' ', '_') + ".qml");
 
219
    if (file.isNull()) {
 
220
        // fallback to default
 
221
        file = KStandardDirs::locate("data", "kwin/tabbox/informative.qml");
 
222
    }
 
223
    rootObject()->setProperty("source", QUrl(file));
 
224
}
 
225
 
 
226
} // namespace TabBox
 
227
} // namespace KWin