add more spacing
[personal-kdebase.git] / workspace / kwin / tools / decobenchmark / preview.cpp
blobfeb3eecef1dfad4de5b46b833d54dfbc9c68269d
1 /*
3 * Copyright (c) 2003 Lubos Lunak <l.lunak@kde.org>
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.
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.
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.
20 #include "preview.h"
22 #include <kdebug.h>
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>
35 #include <X11/Xlib.h>
36 #include <X11/extensions/shape.h>
38 #include <kdecorationfactory.h>
39 #include <kdecoration_plugins_p.h>
40 #include <QX11Info>
42 // FRAME the preview doesn't update to reflect the changes done in the kcm
44 KDecorationPreview::KDecorationPreview( KDecorationPlugins* plugin, QWidget* parent, const char* name )
45 : QWidget( parent, name ),
46 m_plugin(plugin)
48 options = new KDecorationPreviewOptions;
50 bridge = new KDecorationPreviewBridge( this, true, "Deco Benchmark" );
52 deco = 0;
54 setFixedSize( 600, 500 );
56 positionPreviews();
59 KDecorationPreview::~KDecorationPreview()
61 delete deco;
62 delete bridge;
63 delete options;
66 void KDecorationPreview::performRepaintTest(int n)
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();
78 void KDecorationPreview::performCaptionTest(int n)
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();
91 void KDecorationPreview::performResizeTest(int n)
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();
102 void KDecorationPreview::performRecreationTest(int n)
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();
114 bool KDecorationPreview::recreateDecoration()
116 delete deco;
117 deco = m_plugin->createDecoration(bridge);
118 deco->init();
120 if (!deco)
121 return false;
123 positionPreviews();
124 deco->widget()->show();
126 return true;
129 void KDecorationPreview::positionPreviews(int shrink)
131 if ( !deco )
132 return;
134 QSize size = QSize(width()-2*10-shrink, height()-2*10-shrink)/*.expandedTo(deco->minimumSize()*/;
136 QRect geometry(QPoint(10, 10), size);
137 deco->widget()->setGeometry(geometry);
140 void KDecorationPreview::setPreviewMask( const QRegion& reg, int mode )
142 QWidget *widget = deco->widget();
144 // FRAME duped from client.cpp
145 if( mode == Unsorted )
147 XShapeCombineRegion( QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
148 reg.handle(), ShapeSet );
150 else
152 QVector< QRect > rects = reg.rects();
153 XRectangle* xrects = new XRectangle[ rects.count() ];
154 for( unsigned int i = 0;
155 i < rects.count();
156 ++i )
158 xrects[ i ].x = rects[ i ].x();
159 xrects[ i ].y = rects[ i ].y();
160 xrects[ i ].width = rects[ i ].width();
161 xrects[ i ].height = rects[ i ].height();
163 XShapeCombineRectangles( QX11Info::display(), widget->winId(), ShapeBounding, 0, 0,
164 xrects, rects.count(), ShapeSet, mode );
165 delete[] xrects;
169 QRect KDecorationPreview::windowGeometry( bool active ) const
171 QWidget *widget = deco->widget();
172 return widget->geometry();
175 QRegion KDecorationPreview::unobscuredRegion( bool active, const QRegion& r ) const
177 return r;
180 KDecorationPreviewBridge::KDecorationPreviewBridge( KDecorationPreview* p, bool a, const QString &c )
181 : preview( p ), active( a ), m_caption( c )
185 void KDecorationPreviewBridge::setCaption(const QString &c)
187 m_caption = c;
190 QWidget* KDecorationPreviewBridge::initialParentWidget() const
192 return preview;
195 Qt::WFlags KDecorationPreviewBridge::initialWFlags() const
197 return 0;
200 bool KDecorationPreviewBridge::isActive() const
202 return active;
205 bool KDecorationPreviewBridge::isCloseable() const
207 return true;
210 bool KDecorationPreviewBridge::isMaximizable() const
212 return true;
215 KDecoration::MaximizeMode KDecorationPreviewBridge::maximizeMode() const
217 return KDecoration::MaximizeRestore;
220 bool KDecorationPreviewBridge::isMinimizable() const
222 return true;
225 bool KDecorationPreviewBridge::providesContextHelp() const
227 return true;
230 int KDecorationPreviewBridge::desktop() const
232 return 1;
235 bool KDecorationPreviewBridge::isModal() const
237 return false;
240 bool KDecorationPreviewBridge::isShadeable() const
242 return true;
245 bool KDecorationPreviewBridge::isShade() const
247 return false;
250 bool KDecorationPreviewBridge::isSetShade() const
252 return false;
255 bool KDecorationPreviewBridge::keepAbove() const
257 return false;
260 bool KDecorationPreviewBridge::keepBelow() const
262 return false;
265 bool KDecorationPreviewBridge::isMovable() const
267 return true;
270 bool KDecorationPreviewBridge::isResizable() const
272 return true;
275 NET::WindowType KDecorationPreviewBridge::windowType( unsigned long ) const
277 return NET::Normal;
280 QIcon KDecorationPreviewBridge::icon() const
282 return QIcon( KGlobal::iconLoader()->loadIcon( "xorg", KIconLoader::NoGroup, 32 ));
285 QString KDecorationPreviewBridge::caption() const
287 return m_caption;
290 void KDecorationPreviewBridge::processMousePressEvent( QMouseEvent* )
294 void KDecorationPreviewBridge::showWindowMenu( const QRect & )
298 void KDecorationPreviewBridge::showWindowMenu( QPoint )
302 void KDecorationPreviewBridge::performWindowOperation( WindowOperation )
306 void KDecorationPreviewBridge::setMask( const QRegion& reg, int mode )
308 preview->setPreviewMask( reg, mode );
311 bool KDecorationPreviewBridge::isPreview() const
313 return false;
316 QRect KDecorationPreviewBridge::geometry() const
318 return preview->windowGeometry( active );
321 QRect KDecorationPreviewBridge::iconGeometry() const
323 return QRect();
326 QRegion KDecorationPreviewBridge::unobscuredRegion( const QRegion& r ) const
328 return preview->unobscuredRegion( active, r );
331 WId KDecorationPreviewBridge::windowId() const
333 return 0; // no decorated window
336 void KDecorationPreviewBridge::closeWindow()
340 void KDecorationPreviewBridge::maximize( MaximizeMode )
344 void KDecorationPreviewBridge::minimize()
348 void KDecorationPreviewBridge::showContextHelp()
352 void KDecorationPreviewBridge::setDesktop( int )
356 void KDecorationPreviewBridge::titlebarDblClickOperation()
360 void KDecorationPreviewBridge::titlebarMouseWheelOperation( int )
364 void KDecorationPreviewBridge::setShade( bool )
368 void KDecorationPreviewBridge::setKeepAbove( bool )
372 void KDecorationPreviewBridge::setKeepBelow( bool )
376 int KDecorationPreviewBridge::currentDesktop() const
378 return 1;
381 void KDecorationPreviewBridge::grabXServer( bool )
385 KDecorationPreviewOptions::KDecorationPreviewOptions()
387 defaultKWinSettings();
388 updateSettings();
391 KDecorationPreviewOptions::~KDecorationPreviewOptions()
395 unsigned long KDecorationPreviewOptions::updateSettings()
397 KConfig cfg( "kwinrc", true );
398 unsigned long changed = 0;
399 changed |= KDecorationOptions::updateKWinSettings( &cfg );
401 return changed;
404 bool KDecorationPreviewPlugins::provides( Requirement )
406 return false;
409 // #include "preview.moc"