~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kwin/tools/decobenchmark/preview.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
 
4
 *
 
5
 *  This program is free software; you can redistribute it and/or modify
 
6
 *  it under the terms of the GNU General Public License as published by
 
7
 *  the Free Software Foundation; either version 2 of the License, or
 
8
 *  (at your option) any later version.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 
18
 */
 
19
 
 
20
#include "preview.h"
 
21
 
 
22
#include <kdebug.h>
 
23
 
 
24
#include <kapplication.h>
 
25
#include <klocale.h>
 
26
#include <kconfig.h>
 
27
#include <kglobal.h>
 
28
#include <QLabel>
 
29
#include <QStyle>
 
30
#include <QMouseEvent>
 
31
#include <QResizeEvent>
 
32
#include <QVector>
 
33
#include <kiconloader.h>
 
34
 
 
35
#include <X11/Xlib.h>
 
36
#include <X11/extensions/shape.h>
 
37
 
 
38
#include <kdecorationfactory.h>
 
39
#include <kdecoration_plugins_p.h>
 
40
#include <QX11Info>
 
41
 
 
42
// FRAME the preview doesn't update to reflect the changes done in the kcm
 
43
 
 
44
KDecorationPreview::KDecorationPreview(KDecorationPlugins* plugin, QWidget* parent, const char* name)
 
45
    :   QWidget(parent, name),
 
46
        m_plugin(plugin)
 
47
{
 
48
    options = new KDecorationPreviewOptions;
 
49
 
 
50
    bridge = new KDecorationPreviewBridge(this, true, "Deco Benchmark");
 
51
 
 
52
    deco = 0;
 
53
 
 
54
    setFixedSize(600, 500);
 
55
 
 
56
    positionPreviews();
 
57
}
 
58
 
 
59
KDecorationPreview::~KDecorationPreview()
 
60
{
 
61
    delete deco;
 
62
    delete bridge;
 
63
    delete options;
 
64
}
 
65
 
 
66
void KDecorationPreview::performRepaintTest(int n)
 
67
{
 
68
    kDebug(1212) << "start " << n << " repaints...";
 
69
    bridge->setCaption("Deco Benchmark");
 
70
    deco->captionChange();
 
71
    positionPreviews(0);
 
72
    for (int i = 0; i < n; ++i) {
 
73
        deco->widget()->repaint();
 
74
        kapp->processEvents();
 
75
    }
 
76
}
 
77
 
 
78
void KDecorationPreview::performCaptionTest(int n)
 
79
{
 
80
    kDebug(1212) << "start " << n << " caption changes...";
 
81
    QString caption = "Deco Benchmark %1";
 
82
    positionPreviews(0);
 
83
    for (int i = 0; i < n; ++i) {
 
84
        bridge->setCaption(caption.arg(i));
 
85
        deco->captionChange();
 
86
        deco->widget()->repaint();
 
87
        kapp->processEvents();
 
88
    }
 
89
}
 
90
 
 
91
void KDecorationPreview::performResizeTest(int n)
 
92
{
 
93
    kDebug(1212) << "start " << n << " resizes...";
 
94
    bridge->setCaption("Deco Benchmark");
 
95
    deco->captionChange();
 
96
    for (int i = 0; i < n; ++i) {
 
97
        positionPreviews(i % 200);
 
98
        kapp->processEvents();
 
99
    }
 
100
}
 
101
 
 
102
void KDecorationPreview::performRecreationTest(int n)
 
103
{
 
104
    kDebug(1212) << "start " << n << " resizes...";
 
105
    bridge->setCaption("Deco Benchmark");
 
106
    deco->captionChange();
 
107
    positionPreviews(0);
 
108
    for (int i = 0; i < n; ++i) {
 
109
        recreateDecoration();
 
110
        kapp->processEvents();
 
111
    }
 
112
}
 
113
 
 
114
bool KDecorationPreview::recreateDecoration()
 
115
{
 
116
    delete deco;
 
117
    deco = m_plugin->createDecoration(bridge);
 
118
    deco->init();
 
119
 
 
120
    if (!deco)
 
121
        return false;
 
122
 
 
123
    positionPreviews();
 
124
    deco->widget()->show();
 
125
 
 
126
    return true;
 
127
}
 
128
 
 
129
void KDecorationPreview::positionPreviews(int shrink)
 
130
{
 
131
    if (!deco)
 
132
        return;
 
133
 
 
134
    QSize size = QSize(width() - 2 * 10 - shrink, height() - 2 * 10 - shrink)/*.expandedTo(deco->minimumSize()*/;
 
135
 
 
136
    QRect geometry(QPoint(10, 10), size);
 
137
    deco->widget()->setGeometry(geometry);
 
138
}
 
139
 
 
140
void KDecorationPreview::setPreviewMask(const QRegion& reg, int mode)
 
141
{
 
142
    QWidget *widget = deco->widget();
 
143
 
 
144
    // FRAME duped from client.cpp
 
145
    if (mode == Unsorted) {
 
146
        XShapeCombineRegion(QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
 
147
                            reg.handle(), ShapeSet);
 
148
    } else {
 
149
        QVector< QRect > rects = reg.rects();
 
150
        XRectangle* xrects = new XRectangle[ rects.count()];
 
151
        for (unsigned int i = 0;
 
152
                i < rects.count();
 
153
                ++i) {
 
154
            xrects[ i ].x = rects[ i ].x();
 
155
            xrects[ i ].y = rects[ i ].y();
 
156
            xrects[ i ].width = rects[ i ].width();
 
157
            xrects[ i ].height = rects[ i ].height();
 
158
        }
 
159
        XShapeCombineRectangles(QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
 
160
                                xrects, rects.count(), ShapeSet, mode);
 
161
        delete[] xrects;
 
162
    }
 
163
}
 
164
 
 
165
QRect KDecorationPreview::windowGeometry(bool active) const
 
166
{
 
167
    QWidget *widget = deco->widget();
 
168
    return widget->geometry();
 
169
}
 
170
 
 
171
QRegion KDecorationPreview::unobscuredRegion(bool active, const QRegion& r) const
 
172
{
 
173
    return r;
 
174
}
 
175
 
 
176
KDecorationPreviewBridge::KDecorationPreviewBridge(KDecorationPreview* p, bool a, const QString &c)
 
177
    :   preview(p), active(a), m_caption(c)
 
178
{
 
179
}
 
180
 
 
181
void KDecorationPreviewBridge::setCaption(const QString &c)
 
182
{
 
183
    m_caption = c;
 
184
}
 
185
 
 
186
QWidget* KDecorationPreviewBridge::initialParentWidget() const
 
187
{
 
188
    return preview;
 
189
}
 
190
 
 
191
Qt::WFlags KDecorationPreviewBridge::initialWFlags() const
 
192
{
 
193
    return 0;
 
194
}
 
195
 
 
196
bool KDecorationPreviewBridge::isActive() const
 
197
{
 
198
    return active;
 
199
}
 
200
 
 
201
bool KDecorationPreviewBridge::isCloseable() const
 
202
{
 
203
    return true;
 
204
}
 
205
 
 
206
bool KDecorationPreviewBridge::isMaximizable() const
 
207
{
 
208
    return true;
 
209
}
 
210
 
 
211
KDecoration::MaximizeMode KDecorationPreviewBridge::maximizeMode() const
 
212
{
 
213
    return KDecoration::MaximizeRestore;
 
214
}
 
215
 
 
216
bool KDecorationPreviewBridge::isMinimizable() const
 
217
{
 
218
    return true;
 
219
}
 
220
 
 
221
bool KDecorationPreviewBridge::providesContextHelp() const
 
222
{
 
223
    return true;
 
224
}
 
225
 
 
226
int KDecorationPreviewBridge::desktop() const
 
227
{
 
228
    return 1;
 
229
}
 
230
 
 
231
bool KDecorationPreviewBridge::isModal() const
 
232
{
 
233
    return false;
 
234
}
 
235
 
 
236
bool KDecorationPreviewBridge::isShadeable() const
 
237
{
 
238
    return true;
 
239
}
 
240
 
 
241
bool KDecorationPreviewBridge::isShade() const
 
242
{
 
243
    return false;
 
244
}
 
245
 
 
246
bool KDecorationPreviewBridge::isSetShade() const
 
247
{
 
248
    return false;
 
249
}
 
250
 
 
251
bool KDecorationPreviewBridge::keepAbove() const
 
252
{
 
253
    return false;
 
254
}
 
255
 
 
256
bool KDecorationPreviewBridge::keepBelow() const
 
257
{
 
258
    return false;
 
259
}
 
260
 
 
261
bool KDecorationPreviewBridge::isMovable() const
 
262
{
 
263
    return true;
 
264
}
 
265
 
 
266
bool KDecorationPreviewBridge::isResizable() const
 
267
{
 
268
    return true;
 
269
}
 
270
 
 
271
NET::WindowType KDecorationPreviewBridge::windowType(unsigned long) const
 
272
{
 
273
    return NET::Normal;
 
274
}
 
275
 
 
276
QIcon KDecorationPreviewBridge::icon() const
 
277
{
 
278
    return QIcon(KGlobal::iconLoader()->loadIcon("xorg", KIconLoader::NoGroup, 32));
 
279
}
 
280
 
 
281
QString KDecorationPreviewBridge::caption() const
 
282
{
 
283
    return m_caption;
 
284
}
 
285
 
 
286
void KDecorationPreviewBridge::processMousePressEvent(QMouseEvent*)
 
287
{
 
288
}
 
289
 
 
290
void KDecorationPreviewBridge::showWindowMenu(const QRect &)
 
291
{
 
292
}
 
293
 
 
294
void KDecorationPreviewBridge::showWindowMenu(QPoint)
 
295
{
 
296
}
 
297
 
 
298
void KDecorationPreviewBridge::performWindowOperation(WindowOperation)
 
299
{
 
300
}
 
301
 
 
302
void KDecorationPreviewBridge::setMask(const QRegion& reg, int mode)
 
303
{
 
304
    preview->setPreviewMask(reg, mode);
 
305
}
 
306
 
 
307
bool KDecorationPreviewBridge::isPreview() const
 
308
{
 
309
    return false;
 
310
}
 
311
 
 
312
QRect KDecorationPreviewBridge::geometry() const
 
313
{
 
314
    return preview->windowGeometry(active);
 
315
}
 
316
 
 
317
QRect KDecorationPreviewBridge::iconGeometry() const
 
318
{
 
319
    return QRect();
 
320
}
 
321
 
 
322
QRegion KDecorationPreviewBridge::unobscuredRegion(const QRegion& r) const
 
323
{
 
324
    return preview->unobscuredRegion(active, r);
 
325
}
 
326
 
 
327
WId KDecorationPreviewBridge::windowId() const
 
328
{
 
329
    return 0; // no decorated window
 
330
}
 
331
 
 
332
void KDecorationPreviewBridge::closeWindow()
 
333
{
 
334
}
 
335
 
 
336
void KDecorationPreviewBridge::maximize(MaximizeMode)
 
337
{
 
338
}
 
339
 
 
340
void KDecorationPreviewBridge::minimize()
 
341
{
 
342
}
 
343
 
 
344
void KDecorationPreviewBridge::showContextHelp()
 
345
{
 
346
}
 
347
 
 
348
void KDecorationPreviewBridge::setDesktop(int)
 
349
{
 
350
}
 
351
 
 
352
void KDecorationPreviewBridge::titlebarDblClickOperation()
 
353
{
 
354
}
 
355
 
 
356
void KDecorationPreviewBridge::titlebarMouseWheelOperation(int)
 
357
{
 
358
}
 
359
 
 
360
void KDecorationPreviewBridge::setShade(bool)
 
361
{
 
362
}
 
363
 
 
364
void KDecorationPreviewBridge::setKeepAbove(bool)
 
365
{
 
366
}
 
367
 
 
368
void KDecorationPreviewBridge::setKeepBelow(bool)
 
369
{
 
370
}
 
371
 
 
372
int KDecorationPreviewBridge::currentDesktop() const
 
373
{
 
374
    return 1;
 
375
}
 
376
 
 
377
void KDecorationPreviewBridge::grabXServer(bool)
 
378
{
 
379
}
 
380
 
 
381
KDecorationPreviewOptions::KDecorationPreviewOptions()
 
382
{
 
383
    defaultKWinSettings();
 
384
    updateSettings();
 
385
}
 
386
 
 
387
KDecorationPreviewOptions::~KDecorationPreviewOptions()
 
388
{
 
389
}
 
390
 
 
391
unsigned long KDecorationPreviewOptions::updateSettings()
 
392
{
 
393
    KConfig cfg("kwinrc", true);
 
394
    unsigned long changed = 0;
 
395
    changed |= KDecorationOptions::updateKWinSettings(&cfg);
 
396
 
 
397
    return changed;
 
398
}
 
399
 
 
400
bool KDecorationPreviewPlugins::provides(Requirement)
 
401
{
 
402
    return false;
 
403
}
 
404
 
 
405
// #include "preview.moc"