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 *********************************************************************/
28 Decoration::Decoration( KDecorationBridge
* bridge
, KDecorationFactory
* factory
)
29 : KDecoration( bridge
, factory
),
34 void Decoration::init()
37 widget()->setEraseColor( red
);
38 widget()->installEventFilter( this );
41 button
= new QPushButton( widget());
43 button
->setCursor( arrowCursor
);
45 connect( button
, SIGNAL( clicked()), SLOT( closeWindow()));
46 button
->setToolTip( "Zelva Mana" );
50 Decoration::MousePosition
Decoration::mousePosition( const QPoint
& p
) const
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
) )
63 if ( p
.y() <= range
&& p
.x() <= range
)
65 else if ( p
.y() >= height
-range
&& p
.x() >= width
-range
)
67 else if ( p
.y() >= height
-range
&& p
.x() <= range
)
69 else if ( p
.y() <= range
&& p
.x() >= width
-range
)
71 else if ( p
.y() <= border
)
73 else if ( p
.y() >= height
-border
)
75 else if ( p
.x() <= border
)
77 else if ( p
.x() >= width
-border
)
84 void Decoration::borders( int& left
, int& right
, int& top
, int& bottom
) const
86 if( options()->preferredBorderSize( factory()) == BorderTiny
)
88 left
= right
= bottom
= 1;
93 left
= right
= options()->preferredBorderSize( factory()) * 5;
94 top
= options()->preferredBorderSize( factory()) * 10;
95 bottom
= options()->preferredBorderSize( factory()) * 2;
99 if( ( maximizeMode() & MaximizeHorizontal
) && !options()->moveResizeMaximizedWindows())
101 if( ( maximizeMode() & MaximizeVertical
) && !options()->moveResizeMaximizedWindows())
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
)
125 case QEvent::MouseButtonPress
:
127 processMousePressEvent( static_cast< QMouseEvent
* >( e
));
142 #include <QApplication>
144 #include <X11/Xlib.h>
151 bool Decoration::animateMinimize(bool iconify
)
158 // Double twisting double back, with pike ;)
160 if (!iconify
) // No animation for restore.
164 helperShowHide( false );
167 QRect r
= iconGeometry();
172 // Algorithm taken from Window Maker (http://www.windowmaker.org)
174 int sx
= geometry().x();
175 int sy
= geometry().y();
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
);
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
)
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());
234 // FRAME qApp->processEvents(); // FRAME ???
241 if (angle
>= finalAngle
)
249 // KVirc style ? Maybe. For qwertz.
251 if (!iconify
) // No animation for restore.
255 helperShowHide( false );
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
++) {
272 r
.setWidth(r
.width() - 2 * dx
);
273 r
.setHeight(r
.height() - 2 * dy
);
284 // FRAME qApp->processEvents();
292 QRect icongeom
= iconGeometry();
294 if (!icongeom
.isValid())
297 QRect wingeom
= geometry();
299 QPainter
p( workspaceWidget());
301 p
.setRasterOp(Qt::NotROP
);
306 QRegion( workspaceWidget()->rect()) - wingeom
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());
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());
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
);
354 KDE_EXPORT KDecorationFactory
*create_factory()
356 return new KWinTest::Factory();