add more spacing
[personal-kdebase.git] / workspace / kwin / clients / test / test.cpp
blob34439a4af7ce88071cc47114a4af13ab4356fa00
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, see <http://www.gnu.org/licenses/>.
17 *********************************************************************/
19 #include "test.h"
22 #include <kglobal.h>
23 #include <kdebug.h>
25 namespace KWinTest
28 Decoration::Decoration( KDecorationBridge* bridge, KDecorationFactory* factory )
29 : KDecoration( bridge, factory ),
30 button( NULL )
34 void Decoration::init()
36 createMainWidget();
37 widget()->setEraseColor( red );
38 widget()->installEventFilter( this );
39 if( isCloseable())
41 button = new QPushButton( widget());
42 button->show();
43 button->setCursor( arrowCursor );
44 button->move( 0, 0 );
45 connect( button, SIGNAL( clicked()), SLOT( closeWindow()));
46 button->setToolTip( "Zelva Mana" );
50 Decoration::MousePosition Decoration::mousePosition( const QPoint& p ) const
52 const int range = 16;
53 const int border = 4;
55 MousePosition m = Nowhere;
57 int width = widget()->width();
58 int height = widget()->height();
59 if ( ( p.x() > border && p.x() < width - border )
60 && ( p.y() > border && p.y() < height - border ) )
61 return Center;
63 if ( p.y() <= range && p.x() <= range)
64 m = TopLeft2;
65 else if ( p.y() >= height-range && p.x() >= width-range)
66 m = BottomRight2;
67 else if ( p.y() >= height-range && p.x() <= range)
68 m = BottomLeft2;
69 else if ( p.y() <= range && p.x() >= width-range)
70 m = TopRight2;
71 else if ( p.y() <= border )
72 m = Top;
73 else if ( p.y() >= height-border )
74 m = Bottom;
75 else if ( p.x() <= border )
76 m = Left;
77 else if ( p.x() >= width-border )
78 m = Right;
79 else
80 m = Center;
81 return m;
84 void Decoration::borders( int& left, int& right, int& top, int& bottom ) const
86 if( options()->preferredBorderSize( factory()) == BorderTiny )
88 left = right = bottom = 1;
89 top = 5;
91 else
93 left = right = options()->preferredBorderSize( factory()) * 5;
94 top = options()->preferredBorderSize( factory()) * 10;
95 bottom = options()->preferredBorderSize( factory()) * 2;
97 if( isShade())
98 bottom = 0;
99 if( ( maximizeMode() & MaximizeHorizontal ) && !options()->moveResizeMaximizedWindows())
100 left = right = 0;
101 if( ( maximizeMode() & MaximizeVertical ) && !options()->moveResizeMaximizedWindows())
102 bottom = 0;
105 void Decoration::reset( unsigned long )
109 void Decoration::resize( const QSize& s )
111 widget()->resize( s );
114 QSize Decoration::minimumSize() const
116 return QSize( 100, 50 );
119 bool Decoration::eventFilter( QObject* o, QEvent* e )
121 if( o == widget())
123 switch( e->type())
125 case QEvent::MouseButtonPress:
126 { // FRAME
127 processMousePressEvent( static_cast< QMouseEvent* >( e ));
128 return true;
130 case QEvent::Show:
131 break;
132 case QEvent::Hide:
133 break;
134 default:
135 break;
138 return false;
142 #include <QApplication>
143 #include <QPainter>
144 #include <X11/Xlib.h>
145 #include <math.h>
146 #include <unistd.h>
147 namespace KWinTest
150 // taken from riscos
151 bool Decoration::animateMinimize(bool iconify)
153 int style = 1;
154 switch (style) {
156 case 1:
158 // Double twisting double back, with pike ;)
160 if (!iconify) // No animation for restore.
161 return true;
163 // Go away quick.
164 helperShowHide( false );
165 qApp->syncX();
167 QRect r = iconGeometry();
169 if (!r.isValid())
170 return true;
172 // Algorithm taken from Window Maker (http://www.windowmaker.org)
174 int sx = geometry().x();
175 int sy = geometry().y();
176 int sw = width();
177 int sh = height();
178 int dx = r.x();
179 int dy = r.y();
180 int dw = r.width();
181 int dh = r.height();
183 double steps = 12;
185 double xstep = double((dx-sx)/steps);
186 double ystep = double((dy-sy)/steps);
187 double wstep = double((dw-sw)/steps);
188 double hstep = double((dh-sh)/steps);
190 double cx = sx;
191 double cy = sy;
192 double cw = sw;
193 double ch = sh;
195 double finalAngle = 3.14159265358979323846;
197 double delta = finalAngle / steps;
199 QPainter p( workspaceWidget());
200 p.setRasterOp(Qt::NotROP);
202 for (double angle = 0; ; angle += delta) {
204 if (angle > finalAngle)
205 angle = finalAngle;
207 double dx = (cw / 10) - ((cw / 5) * sin(angle));
208 double dch = (ch / 2) * cos(angle);
209 double midy = cy + (ch / 2);
211 QPoint p1(int(cx + dx), int(midy - dch));
212 QPoint p2(int(cx + cw - dx), p1.y());
213 QPoint p3(int(cx + dw + dx), int(midy + dch));
214 QPoint p4(int(cx - dx), p3.y());
216 grabXServer();
218 p.drawLine(p1, p2);
219 p.drawLine(p2, p3);
220 p.drawLine(p3, p4);
221 p.drawLine(p4, p1);
223 p.flush();
225 usleep(500);
227 p.drawLine(p1, p2);
228 p.drawLine(p2, p3);
229 p.drawLine(p3, p4);
230 p.drawLine(p4, p1);
232 ungrabXServer();
234 // FRAME qApp->processEvents(); // FRAME ???
236 cx += xstep;
237 cy += ystep;
238 cw += wstep;
239 ch += hstep;
241 if (angle >= finalAngle)
242 break;
245 break;
247 case 2:
249 // KVirc style ? Maybe. For qwertz.
251 if (!iconify) // No animation for restore.
252 return true;
254 // Go away quick.
255 helperShowHide( false );
257 qApp->syncX();
259 int stepCount = 12;
261 QRect r(geometry());
263 int dx = r.width() / (stepCount * 2);
264 int dy = r.height() / (stepCount * 2);
266 QPainter p( workspaceWidget());
267 p.setRasterOp(Qt::NotROP);
269 for (int step = 0; step < stepCount; step++) {
271 r.translate(dx, dy);
272 r.setWidth(r.width() - 2 * dx);
273 r.setHeight(r.height() - 2 * dy);
275 grabXServer();
277 p.drawRect(r);
278 p.flush();
279 usleep(200);
280 p.drawRect(r);
282 ungrabXServer();
284 // FRAME qApp->processEvents();
287 break;
290 default:
292 QRect icongeom = iconGeometry();
294 if (!icongeom.isValid())
295 return true;
297 QRect wingeom = geometry();
299 QPainter p( workspaceWidget());
301 p.setRasterOp(Qt::NotROP);
303 #if 0
304 if (iconify)
305 p.setClipRegion(
306 QRegion( workspaceWidget()->rect()) - wingeom
308 #endif
310 grabXServer();
312 p.drawLine(wingeom.bottomRight(), icongeom.bottomRight());
313 p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft());
314 p.drawLine(wingeom.topLeft(), icongeom.topLeft());
315 p.drawLine(wingeom.topRight(), icongeom.topRight());
317 p.flush();
319 qApp->syncX();
321 usleep(30000);
323 p.drawLine(wingeom.bottomRight(), icongeom.bottomRight());
324 p.drawLine(wingeom.bottomLeft(), icongeom.bottomLeft());
325 p.drawLine(wingeom.topLeft(), icongeom.topLeft());
326 p.drawLine(wingeom.topRight(), icongeom.topRight());
328 ungrabXServer();
330 break;
332 return true;
335 KDecoration* Factory::createDecoration( KDecorationBridge* bridge )
337 NET::WindowType type = windowType( SUPPORTED_WINDOW_TYPES_MASK, bridge );
338 if( type == NET::Dialog )
340 return new Decoration( bridge, this );
343 bool Factory::reset( unsigned long changed )
345 resetDecorations( changed );
346 return false;
349 } // namespace
351 extern "C"
354 KDE_EXPORT KDecorationFactory *create_factory()
356 return new KWinTest::Factory();
361 #include "test.moc"