summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--library/qpedecoration_qws.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/library/qpedecoration_qws.cpp b/library/qpedecoration_qws.cpp
index 222d906..c2eb751 100644
--- a/library/qpedecoration_qws.cpp
+++ b/library/qpedecoration_qws.cpp
@@ -1,911 +1,912 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifdef QWS 20#ifdef QWS
21#define QTOPIA_INTERNAL_LANGLIST 21#define QTOPIA_INTERNAL_LANGLIST
22#include <qapplication.h> 22#include <qapplication.h>
23#include <qstyle.h> 23#include <qstyle.h>
24#include <qwidget.h> 24#include <qwidget.h>
25#include <qpainter.h> 25#include <qpainter.h>
26#include <qtimer.h> 26#include <qtimer.h>
27#include <qwhatsthis.h> 27#include <qwhatsthis.h>
28#include "qcopenvelope_qws.h" 28#include "qcopenvelope_qws.h"
29#include "qpedecoration_qws.h" 29#include "qpedecoration_qws.h"
30#include <qdialog.h> 30#include <qdialog.h>
31#include <qdrawutil.h> 31#include <qdrawutil.h>
32#include <qgfx_qws.h> 32#include <qgfx_qws.h>
33#include "qpeapplication.h" 33#include "qpeapplication.h"
34#include "resource.h" 34#include "resource.h"
35#include "global.h" 35#include "global.h"
36#include "qlibrary.h" 36#include "qlibrary.h"
37#include "windowdecorationinterface.h" 37#include "windowdecorationinterface.h"
38#include <qfile.h> 38#include <qfile.h>
39#include <qsignal.h> 39#include <qsignal.h>
40 40
41#include <stdlib.h> 41#include <stdlib.h>
42 42
43extern QRect qt_maxWindowRect; 43extern QRect qt_maxWindowRect;
44 44
45#define WHATSTHIS_MODE 45#define WHATSTHIS_MODE
46 46
47#ifndef QT_NO_QWS_QPE_WM_STYLE 47#ifndef QT_NO_QWS_QPE_WM_STYLE
48 48
49#ifndef QT_NO_IMAGEIO_XPM 49#ifndef QT_NO_IMAGEIO_XPM
50 50
51/* XPM */ 51/* XPM */
52static const char * const qpe_close_xpm[] = { 52static const char * const qpe_close_xpm[] = {
53"16 16 3 1", 53"16 16 3 1",
54" c None", 54" c None",
55". c #FFFFFF", 55". c #FFFFFF",
56"+ c #000000", 56"+ c #000000",
57" ", 57" ",
58" ", 58" ",
59" ..... ", 59" ..... ",
60" ..+++++.. ", 60" ..+++++.. ",
61" .+++++++++. ", 61" .+++++++++. ",
62" .+..+++..+. ", 62" .+..+++..+. ",
63" .++...+...++. ", 63" .++...+...++. ",
64" .+++.....+++. ", 64" .+++.....+++. ",
65" .++++...++++. ", 65" .++++...++++. ",
66" .+++.....+++. ", 66" .+++.....+++. ",
67" .++...+...++. ", 67" .++...+...++. ",
68" .+..+++..+. ", 68" .+..+++..+. ",
69" .+++++++++. ", 69" .+++++++++. ",
70" ..+++++.. ", 70" ..+++++.. ",
71" ..... ", 71" ..... ",
72" "}; 72" "};
73 73
74/* XPM */ 74/* XPM */
75static const char * const qpe_accept_xpm[] = { 75static const char * const qpe_accept_xpm[] = {
76"16 16 3 1", 76"16 16 3 1",
77" c None", 77" c None",
78". c #FFFFFF", 78". c #FFFFFF",
79"+ c #000000", 79"+ c #000000",
80" ", 80" ",
81" ", 81" ",
82" ..... ", 82" ..... ",
83" ..+++++.. ", 83" ..+++++.. ",
84" .+++++++++. ", 84" .+++++++++. ",
85" .+++++++++. ", 85" .+++++++++. ",
86" .+++++++..++. ", 86" .+++++++..++. ",
87" .++.+++...++. ", 87" .++.+++...++. ",
88" .+...+...+++. ", 88" .+...+...+++. ",
89" .+......++++. ", 89" .+......++++. ",
90" .++....+++++. ", 90" .++....+++++. ",
91" .++..+++++. ", 91" .++..+++++. ",
92" .+++++++++. ", 92" .+++++++++. ",
93" ..+++++.. ", 93" ..+++++.. ",
94" ..... ", 94" ..... ",
95" "}; 95" "};
96 96
97#endif // QT_NO_IMAGEIO_XPM 97#endif // QT_NO_IMAGEIO_XPM
98 98
99class HackWidget : public QWidget 99class HackWidget : public QWidget
100{ 100{
101public: 101public:
102 bool needsOk() { 102 bool needsOk() {
103 return (getWState() & WState_Reserved1 ) || 103 return (getWState() & WState_Reserved1 ) ||
104 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) ); 104 (inherits( "QDialog" ) && !inherits( "QMessageBox" ) );
105 } 105 }
106}; 106};
107 107
108static QImage scaleButton( const QImage &img, int height ) 108static QImage scaleButton( const QImage &img, int height )
109{ 109{
110 if ( img.height() != height ) { 110 qWarning("Height %d %d", height, img.height() );
111 if ( img.height()!=0 && img.height() != height ) {
111 return img.smoothScale( img.width()*height/img.height(), height ); 112 return img.smoothScale( img.width()*height/img.height(), height );
112 } else { 113 } else {
113 return img; 114 return img;
114 } 115 }
115} 116}
116 117
117class TLWidget : public QWidget 118class TLWidget : public QWidget
118{ 119{
119public: 120public:
120 QWSManager *manager() 121 QWSManager *manager()
121 { 122 {
122 return topData()->qwsManager; 123 return topData()->qwsManager;
123 } 124 }
124 125
125 QTLWExtra *topExtra() 126 QTLWExtra *topExtra()
126 { 127 {
127 return topData(); 128 return topData();
128 } 129 }
129 130
130 void setWState( uint s ) { QWidget::setWState( s ); } 131 void setWState( uint s ) { QWidget::setWState( s ); }
131 void clearWState( uint s ) { QWidget::clearWState( s ); } 132 void clearWState( uint s ) { QWidget::clearWState( s ); }
132}; 133};
133 134
134 135
135QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) 136QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
136 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE) 137 : QObject( parent ), decoration( d ), helpState(0), inWhatsThis(FALSE)
137{ 138{
138 wtTimer = new QTimer( this ); 139 wtTimer = new QTimer( this );
139 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) ); 140 connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
140} 141}
141 142
142 143
143void QPEManager::updateActive() 144void QPEManager::updateActive()
144{ 145{
145 QWidget *newActive = qApp->activeWindow(); 146 QWidget *newActive = qApp->activeWindow();
146 if ( newActive && (QWidget*)active == newActive ) 147 if ( newActive && (QWidget*)active == newActive )
147 return; 148 return;
148 149
149 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) { 150 if ( active && (!newActive || ((TLWidget *)newActive)->manager()) ) {
150 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this ); 151 ((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
151 } 152 }
152 153
153 if ( newActive && ((TLWidget *)newActive)->manager() ) { 154 if ( newActive && ((TLWidget *)newActive)->manager() ) {
154 active = newActive; 155 active = newActive;
155 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this ); 156 ((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
156 } else if ( !newActive ) { 157 } else if ( !newActive ) {
157 active = 0; 158 active = 0;
158 } 159 }
159} 160}
160 161
161int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) 162int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
162{ 163{
163 QRect rect(w->geometry()); 164 QRect rect(w->geometry());
164 165
165 if ( decoration->region( w, rect, 166 if ( decoration->region( w, rect,
166 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) 167 (QWSDecoration::Region)QPEDecoration::Help ).contains(p) )
167 return QPEDecoration::Help; 168 return QPEDecoration::Help;
168 169
169 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) { 170 for (int i = QWSDecoration::LastRegion; i >= QWSDecoration::Title; i--) {
170 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p)) 171 if (decoration->region(w, rect, (QWSDecoration::Region)i).contains(p))
171 return (QWSDecoration::Region)i; 172 return (QWSDecoration::Region)i;
172 } 173 }
173 174
174 return QWSDecoration::None; 175 return QWSDecoration::None;
175} 176}
176 177
177bool QPEManager::eventFilter( QObject *o, QEvent *e ) 178bool QPEManager::eventFilter( QObject *o, QEvent *e )
178{ 179{
179 QWSManager *mgr = (QWSManager *)o; 180 QWSManager *mgr = (QWSManager *)o;
180 QWidget *w = mgr->widget(); 181 QWidget *w = mgr->widget();
181 switch ( e->type() ) { 182 switch ( e->type() ) {
182 case QEvent::MouseButtonPress: 183 case QEvent::MouseButtonPress:
183 { 184 {
184 pressTime = QTime::currentTime(); 185 pressTime = QTime::currentTime();
185 QPoint p = ((QMouseEvent*)e)->globalPos(); 186 QPoint p = ((QMouseEvent*)e)->globalPos();
186 int inRegion = pointInQpeRegion( w, p ); 187 int inRegion = pointInQpeRegion( w, p );
187#ifdef WHATSTHIS_MODE 188#ifdef WHATSTHIS_MODE
188 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) { 189 if ( !w->geometry().contains(p) && QWhatsThis::inWhatsThisMode() ) {
189 QString text; 190 QString text;
190 switch ( inRegion ) { 191 switch ( inRegion ) {
191 case QWSDecoration::Close: 192 case QWSDecoration::Close:
192 if ( ((HackWidget*)w)->needsOk() ) 193 if ( ((HackWidget*)w)->needsOk() )
193 text = tr("Click to close this window, discarding changes."); 194 text = tr("Click to close this window, discarding changes.");
194 else 195 else
195 text = tr("Click to close this window."); 196 text = tr("Click to close this window.");
196 break; 197 break;
197 case QWSDecoration::Minimize: 198 case QWSDecoration::Minimize:
198 text = tr("Click to close this window and apply changes."); 199 text = tr("Click to close this window and apply changes.");
199 break; 200 break;
200 case QWSDecoration::Maximize: 201 case QWSDecoration::Maximize:
201 if ( w->isMaximized() ) 202 if ( w->isMaximized() )
202 text = tr("Click to make this window moveable."); 203 text = tr("Click to make this window moveable.");
203 else 204 else
204 text = tr("Click to make this window use all available screen area."); 205 text = tr("Click to make this window use all available screen area.");
205 break; 206 break;
206 default: 207 default:
207 break; 208 break;
208 } 209 }
209 QWhatsThis::leaveWhatsThisMode( text ); 210 QWhatsThis::leaveWhatsThisMode( text );
210 whatsThisTimeout(); 211 whatsThisTimeout();
211 helpState = 0; 212 helpState = 0;
212 return true; 213 return true;
213 } 214 }
214#endif 215#endif
215 if ( inRegion == QPEDecoration::Help ) { 216 if ( inRegion == QPEDecoration::Help ) {
216#ifdef WHATSTHIS_MODE 217#ifdef WHATSTHIS_MODE
217 wtTimer->start( 400, TRUE ); 218 wtTimer->start( 400, TRUE );
218#endif 219#endif
219 helpState = QWSButton::Clicked|QWSButton::MouseOver; 220 helpState = QWSButton::Clicked|QWSButton::MouseOver;
220 drawButton( w, QPEDecoration::Help, helpState ); 221 drawButton( w, QPEDecoration::Help, helpState );
221 return true; 222 return true;
222 } 223 }
223 } 224 }
224 break; 225 break;
225 case QEvent::MouseButtonRelease: 226 case QEvent::MouseButtonRelease:
226 if ( helpState & QWSButton::Clicked ) { 227 if ( helpState & QWSButton::Clicked ) {
227 wtTimer->stop(); 228 wtTimer->stop();
228 helpState = 0; 229 helpState = 0;
229 drawButton( w, QPEDecoration::Help, helpState ); 230 drawButton( w, QPEDecoration::Help, helpState );
230 QPoint p = ((QMouseEvent*)e)->globalPos(); 231 QPoint p = ((QMouseEvent*)e)->globalPos();
231 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 232 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
232 decoration->help( w ); 233 decoration->help( w );
233 } 234 }
234 return true; 235 return true;
235 } 236 }
236 break; 237 break;
237 case QEvent::MouseMove: 238 case QEvent::MouseMove:
238 if ( helpState & QWSButton::Clicked ) { 239 if ( helpState & QWSButton::Clicked ) {
239 int oldState = helpState; 240 int oldState = helpState;
240 QPoint p = ((QMouseEvent*)e)->globalPos(); 241 QPoint p = ((QMouseEvent*)e)->globalPos();
241 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) { 242 if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
242 helpState = QWSButton::Clicked|QWSButton::MouseOver; 243 helpState = QWSButton::Clicked|QWSButton::MouseOver;
243 } else { 244 } else {
244 helpState = 0; 245 helpState = 0;
245 } 246 }
246 if ( helpState != oldState ) 247 if ( helpState != oldState )
247 drawButton( w, QPEDecoration::Help, helpState ); 248 drawButton( w, QPEDecoration::Help, helpState );
248 } 249 }
249 break; 250 break;
250 default: 251 default:
251 break; 252 break;
252 } 253 }
253 return QObject::eventFilter( o, e ); 254 return QObject::eventFilter( o, e );
254} 255}
255 256
256void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) 257void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
257{ 258{
258 QPainter painter(w); 259 QPainter painter(w);
259 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 260 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
260 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 261 painter.internalGfx()->setWidgetDeviceRegion( rgn );
261 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 262 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
262 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state ); 263 decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
263} 264}
264 265
265void QPEManager::drawTitle( QWidget *w ) 266void QPEManager::drawTitle( QWidget *w )
266{ 267{
267 QPainter painter(w); 268 QPainter painter(w);
268 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region; 269 QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
269 painter.internalGfx()->setWidgetDeviceRegion( rgn ); 270 painter.internalGfx()->setWidgetDeviceRegion( rgn );
270 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All)); 271 painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
271 decoration->paint( &painter, w ); 272 decoration->paint( &painter, w );
272 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0); 273 decoration->paintButton(&painter, w, QWSDecoration::Menu, 0);
273 decoration->paintButton(&painter, w, QWSDecoration::Close, 0); 274 decoration->paintButton(&painter, w, QWSDecoration::Close, 0);
274 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0); 275 decoration->paintButton(&painter, w, QWSDecoration::Minimize, 0);
275 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0); 276 decoration->paintButton(&painter, w, QWSDecoration::Maximize, 0);
276} 277}
277 278
278void QPEManager::whatsThisTimeout() 279void QPEManager::whatsThisTimeout()
279{ 280{
280 if ( !QWhatsThis::inWhatsThisMode() ) { 281 if ( !QWhatsThis::inWhatsThisMode() ) {
281 if ( inWhatsThis ) { 282 if ( inWhatsThis ) {
282 if ( whatsThis ) { 283 if ( whatsThis ) {
283 QWidget *w = whatsThis; 284 QWidget *w = whatsThis;
284 whatsThis = 0; 285 whatsThis = 0;
285 drawTitle( w ); 286 drawTitle( w );
286 } 287 }
287 wtTimer->stop(); 288 wtTimer->stop();
288 } else { 289 } else {
289 QWhatsThis::enterWhatsThisMode(); 290 QWhatsThis::enterWhatsThisMode();
290 helpState = 0; 291 helpState = 0;
291 updateActive(); 292 updateActive();
292 if ( active ) { 293 if ( active ) {
293 whatsThis = active; 294 whatsThis = active;
294 drawTitle( active ); 295 drawTitle( active );
295 // check periodically to see if we've left whats this mode 296 // check periodically to see if we've left whats this mode
296 wtTimer->start( 250 ); 297 wtTimer->start( 250 );
297 } 298 }
298 } 299 }
299 inWhatsThis = !inWhatsThis; 300 inWhatsThis = !inWhatsThis;
300 } 301 }
301} 302}
302 303
303//=========================================================================== 304//===========================================================================
304 305
305static QImage *okImage( int th ) 306static QImage *okImage( int th )
306{ 307{
307 static QImage *i = 0; 308 static QImage *i = 0;
308 if ( !i || i->height() != th ) { 309 if ( !i || i->height() != th ) {
309 delete i; 310 delete i;
310 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th)); 311 i = new QImage(scaleButton(Resource::loadImage("OKButton"),th));
311 } 312 }
312 return i; 313 return i;
313} 314}
314 315
315static QImage *closeImage( int th ) 316static QImage *closeImage( int th )
316{ 317{
317 static QImage *i = 0; 318 static QImage *i = 0;
318 if ( !i || i->height() != th ) { 319 if ( !i || i->height() != th ) {
319 delete i; 320 delete i;
320 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th)); 321 i = new QImage(scaleButton(Resource::loadImage("CloseButton"),th));
321 } 322 }
322 return i; 323 return i;
323} 324}
324 325
325static QImage *helpImage( int th ) 326static QImage *helpImage( int th )
326{ 327{
327 static QImage *i = 0; 328 static QImage *i = 0;
328 if ( !i || i->height() != th ) { 329 if ( !i || i->height() != th ) {
329 delete i; 330 delete i;
330 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th)); 331 i = new QImage(scaleButton(Resource::loadImage("HelpButton"),th));
331 } 332 }
332 return i; 333 return i;
333} 334}
334 335
335static QImage *maximizeImage( int th ) 336static QImage *maximizeImage( int th )
336{ 337{
337 static QImage *i = 0; 338 static QImage *i = 0;
338 if ( !i || i->height() != th ) { 339 if ( !i || i->height() != th ) {
339 delete i; 340 delete i;
340 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th)); 341 i = new QImage(scaleButton(Resource::loadImage("MaximizeButton"),th));
341 } 342 }
342 return i; 343 return i;
343} 344}
344 345
345int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const 346int WindowDecorationInterface::metric( Metric m, const WindowData *wd ) const
346{ 347{
347 switch ( m ) { 348 switch ( m ) {
348 case TitleHeight: 349 case TitleHeight:
349 if ( QApplication::desktop()->height() > 320 ) 350 if ( QApplication::desktop()->height() > 320 )
350 return 19; 351 return 19;
351 else 352 else
352 return 15; 353 return 15;
353 case LeftBorder: 354 case LeftBorder:
354 case RightBorder: 355 case RightBorder:
355 case TopBorder: 356 case TopBorder:
356 case BottomBorder: 357 case BottomBorder:
357 return 4; 358 return 4;
358 case OKWidth: 359 case OKWidth:
359 return okImage(metric(TitleHeight,wd))->width(); 360 return okImage(metric(TitleHeight,wd))->width();
360 case CloseWidth: 361 case CloseWidth:
361 return closeImage(metric(TitleHeight,wd))->width(); 362 return closeImage(metric(TitleHeight,wd))->width();
362 case HelpWidth: 363 case HelpWidth:
363 return helpImage(metric(TitleHeight,wd))->width(); 364 return helpImage(metric(TitleHeight,wd))->width();
364 case MaximizeWidth: 365 case MaximizeWidth:
365 return maximizeImage(metric(TitleHeight,wd))->width(); 366 return maximizeImage(metric(TitleHeight,wd))->width();
366 case CornerGrabSize: 367 case CornerGrabSize:
367 return 16; 368 return 16;
368 } 369 }
369 370
370 return 0; 371 return 0;
371} 372}
372 373
373void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const 374void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const
374{ 375{
375 int th = metric( TitleHeight, wd ); 376 int th = metric( TitleHeight, wd );
376 QRect r = wd->rect; 377 QRect r = wd->rect;
377 378
378 switch ( a ) { 379 switch ( a ) {
379 case Border: 380 case Border:
380 { 381 {
381 const QColorGroup &cg = wd->palette.active(); 382 const QColorGroup &cg = wd->palette.active();
382 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd), 383 qDrawWinPanel(p, r.x()-metric(LeftBorder,wd),
383 r.y()-th-metric(TopBorder,wd), 384 r.y()-th-metric(TopBorder,wd),
384 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd), 385 r.width()+metric(LeftBorder,wd)+metric(RightBorder,wd),
385 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd), 386 r.height()+th+metric(TopBorder,wd)+metric(BottomBorder,wd),
386 cg, FALSE, &cg.brush(QColorGroup::Background)); 387 cg, FALSE, &cg.brush(QColorGroup::Background));
387 } 388 }
388 break; 389 break;
389 case Title: 390 case Title:
390 { 391 {
391 const QColorGroup &cg = wd->palette.active(); 392 const QColorGroup &cg = wd->palette.active();
392 QBrush titleBrush; 393 QBrush titleBrush;
393 QPen titleLines; 394 QPen titleLines;
394 395
395 if ( wd->flags & WindowData::Active ) { 396 if ( wd->flags & WindowData::Active ) {
396 titleBrush = cg.brush(QColorGroup::Highlight); 397 titleBrush = cg.brush(QColorGroup::Highlight);
397 titleLines = titleBrush.color().dark(); 398 titleLines = titleBrush.color().dark();
398 } else { 399 } else {
399 titleBrush = cg.brush(QColorGroup::Background); 400 titleBrush = cg.brush(QColorGroup::Background);
400 titleLines = titleBrush.color(); 401 titleLines = titleBrush.color();
401 } 402 }
402 403
403 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush); 404 p->fillRect( r.x(), r.y()-th, r.width(), th, titleBrush);
404 405
405 p->setPen( titleLines ); 406 p->setPen( titleLines );
406 for ( int i = r.y()-th; i < r.y(); i += 2 ) 407 for ( int i = r.y()-th; i < r.y(); i += 2 )
407 p->drawLine( r.left(), i, r.right(), i ); 408 p->drawLine( r.left(), i, r.right(), i );
408 } 409 }
409 break; 410 break;
410 case TitleText: 411 case TitleText:
411 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th, 412 p->drawText( r.x()+3+metric(HelpWidth,wd), r.top()-th,
412 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd), 413 r.width()-metric(OKWidth,wd)-metric(CloseWidth,wd),
413 th, QPainter::AlignVCenter, wd->caption); 414 th, QPainter::AlignVCenter, wd->caption);
414 break; 415 break;
415 } 416 }
416} 417}
417 418
418void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const 419void WindowDecorationInterface::drawButton( Button b, QPainter *p, const WindowData *wd, int x, int y, int, int, QWSButton::State state ) const
419{ 420{
420 QImage *img = 0; 421 QImage *img = 0;
421 switch ( b ) { 422 switch ( b ) {
422 case OK: 423 case OK:
423 img = okImage(metric(TitleHeight,wd)); 424 img = okImage(metric(TitleHeight,wd));
424 break; 425 break;
425 case Close: 426 case Close:
426 img = closeImage(metric(TitleHeight,wd)); 427 img = closeImage(metric(TitleHeight,wd));
427 break; 428 break;
428 case Help: 429 case Help:
429 img = helpImage(metric(TitleHeight,wd)); 430 img = helpImage(metric(TitleHeight,wd));
430 break; 431 break;
431 case Maximize: 432 case Maximize:
432 img = maximizeImage(metric(TitleHeight,wd)); 433 img = maximizeImage(metric(TitleHeight,wd));
433 break; 434 break;
434 } 435 }
435 436
436 if ( img ) { 437 if ( img ) {
437 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) 438 if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked))
438 p->drawImage(x+2, y+2, *img); 439 p->drawImage(x+2, y+2, *img);
439 else 440 else
440 p->drawImage(x+1, y+1, *img); 441 p->drawImage(x+1, y+1, *img);
441 } 442 }
442} 443}
443 444
444QRegion WindowDecorationInterface::mask( const WindowData *wd ) const 445QRegion WindowDecorationInterface::mask( const WindowData *wd ) const
445{ 446{
446 int th = metric(TitleHeight,wd); 447 int th = metric(TitleHeight,wd);
447 QRect rect( wd->rect ); 448 QRect rect( wd->rect );
448 QRect r(rect.left() - metric(LeftBorder,wd), 449 QRect r(rect.left() - metric(LeftBorder,wd),
449 rect.top() - th - metric(TopBorder,wd), 450 rect.top() - th - metric(TopBorder,wd),
450 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd), 451 rect.width() + metric(LeftBorder,wd) + metric(RightBorder,wd),
451 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd)); 452 rect.height() + th + metric(TopBorder,wd) + metric(BottomBorder,wd));
452 return QRegion(r) - rect; 453 return QRegion(r) - rect;
453} 454}
454 455
455class DefaultWindowDecoration : public WindowDecorationInterface 456class DefaultWindowDecoration : public WindowDecorationInterface
456{ 457{
457public: 458public:
458 DefaultWindowDecoration() : ref(0) {} 459 DefaultWindowDecoration() : ref(0) {}
459 QString name() const { 460 QString name() const {
460 return "Default"; 461 return "Default";
461 } 462 }
462 QPixmap icon() const { 463 QPixmap icon() const {
463 return QPixmap(); 464 return QPixmap();
464 } 465 }
465 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) { 466 QRESULT queryInterface( const QUuid &uuid, QUnknownInterface **iface ) {
466 *iface = 0; 467 *iface = 0;
467 if ( uuid == IID_QUnknown ) 468 if ( uuid == IID_QUnknown )
468 *iface = this; 469 *iface = this;
469 else if ( uuid == IID_WindowDecoration ) 470 else if ( uuid == IID_WindowDecoration )
470 *iface = this; 471 *iface = this;
471 472
472 if ( *iface ) 473 if ( *iface )
473 (*iface)->addRef(); 474 (*iface)->addRef();
474 return QS_OK; 475 return QS_OK;
475 } 476 }
476 Q_REFCOUNT 477 Q_REFCOUNT
477 478
478private: 479private:
479 ulong ref; 480 ulong ref;
480}; 481};
481 482
482static WindowDecorationInterface *wdiface = 0; 483static WindowDecorationInterface *wdiface = 0;
483static QLibrary *wdlib = 0; 484static QLibrary *wdlib = 0;
484 485
485//=========================================================================== 486//===========================================================================
486 487
487QPEDecoration::QPEDecoration() 488QPEDecoration::QPEDecoration()
488 : QWSDefaultDecoration() 489 : QWSDefaultDecoration()
489{ 490{
490 if ( wdlib ) { 491 if ( wdlib ) {
491 wdiface->release(); 492 wdiface->release();
492 wdlib->unload(); 493 wdlib->unload();
493 delete wdlib; 494 delete wdlib;
494 wdlib = 0; 495 wdlib = 0;
495 } else { 496 } else {
496 delete wdiface; 497 delete wdiface;
497 } 498 }
498 wdiface = new DefaultWindowDecoration; 499 wdiface = new DefaultWindowDecoration;
499 500
500 helpFile = QString(qApp->argv()[0]) + ".html"; 501 helpFile = QString(qApp->argv()[0]) + ".html";
501 QStringList helpPath = Global::helpPath(); 502 QStringList helpPath = Global::helpPath();
502 helpExists = FALSE; 503 helpExists = FALSE;
503 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) 504 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it)
504 helpExists = QFile::exists( *it + "/" + helpFile ); 505 helpExists = QFile::exists( *it + "/" + helpFile );
505 qpeManager = new QPEManager( this ); 506 qpeManager = new QPEManager( this );
506} 507}
507 508
508QPEDecoration::QPEDecoration( const QString &plugin ) 509QPEDecoration::QPEDecoration( const QString &plugin )
509 : QWSDefaultDecoration() 510 : QWSDefaultDecoration()
510{ 511{
511 if ( wdlib ) { 512 if ( wdlib ) {
512 wdiface->release(); 513 wdiface->release();
513 wdlib->unload(); 514 wdlib->unload();
514 delete wdlib; 515 delete wdlib;
515 wdlib = 0; 516 wdlib = 0;
516 } else { 517 } else {
517 delete wdiface; 518 delete wdiface;
518 } 519 }
519 WindowDecorationInterface *iface = 0; 520 WindowDecorationInterface *iface = 0;
520 QString path = QPEApplication::qpeDir() + "/plugins/decorations"; 521 QString path = QPEApplication::qpeDir() + "/plugins/decorations";
521 QLibrary *lib = new QLibrary( path + "/" + plugin ); 522 QLibrary *lib = new QLibrary( path + "/" + plugin );
522 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) { 523 if ( lib->queryInterface( IID_WindowDecoration, (QUnknownInterface**)&iface ) == QS_OK && iface ) {
523 wdiface = iface; 524 wdiface = iface;
524 wdlib = lib; 525 wdlib = lib;
525 } else { 526 } else {
526 delete lib; 527 delete lib;
527 wdiface = new DefaultWindowDecoration; 528 wdiface = new DefaultWindowDecoration;
528 } 529 }
529 530
530 helpFile = QString(qApp->argv()[0]) + ".html"; 531 helpFile = QString(qApp->argv()[0]) + ".html";
531 QStringList helpPath = Global::helpPath(); 532 QStringList helpPath = Global::helpPath();
532 helpExists = FALSE; 533 helpExists = FALSE;
533 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it) 534 for (QStringList::ConstIterator it=helpPath.begin(); it!=helpPath.end() && !helpExists; ++it)
534 helpExists = QFile::exists( *it + "/" + helpFile ); 535 helpExists = QFile::exists( *it + "/" + helpFile );
535 qpeManager = new QPEManager( this ); 536 qpeManager = new QPEManager( this );
536} 537}
537 538
538QPEDecoration::~QPEDecoration() 539QPEDecoration::~QPEDecoration()
539{ 540{
540 delete qpeManager; 541 delete qpeManager;
541} 542}
542 543
543const char **QPEDecoration::menuPixmap() 544const char **QPEDecoration::menuPixmap()
544{ 545{
545 return (const char **)0; 546 return (const char **)0;
546} 547}
547 548
548const char **QPEDecoration::closePixmap() 549const char **QPEDecoration::closePixmap()
549{ 550{
550 return (const char **)qpe_close_xpm; 551 return (const char **)qpe_close_xpm;
551} 552}
552 553
553const char **QPEDecoration::minimizePixmap() 554const char **QPEDecoration::minimizePixmap()
554{ 555{
555 return (const char **)qpe_accept_xpm; 556 return (const char **)qpe_accept_xpm;
556} 557}
557 558
558const char **QPEDecoration::maximizePixmap() 559const char **QPEDecoration::maximizePixmap()
559{ 560{
560 return (const char **)0; 561 return (const char **)0;
561} 562}
562 563
563const char **QPEDecoration::normalizePixmap() 564const char **QPEDecoration::normalizePixmap()
564{ 565{
565 return (const char **)0; 566 return (const char **)0;
566} 567}
567 568
568int QPEDecoration::getTitleHeight( const QWidget *w ) 569int QPEDecoration::getTitleHeight( const QWidget *w )
569{ 570{
570 WindowDecorationInterface::WindowData wd; 571 WindowDecorationInterface::WindowData wd;
571 windowData( w, wd ); 572 windowData( w, wd );
572 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 573 return wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
573} 574}
574 575
575/* 576/*
576 If rect is empty, no frame is added. (a hack, really) 577 If rect is empty, no frame is added. (a hack, really)
577*/ 578*/
578QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) 579QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
579{ 580{
580 qpeManager->updateActive(); 581 qpeManager->updateActive();
581 582
582 WindowDecorationInterface::WindowData wd; 583 WindowDecorationInterface::WindowData wd;
583 windowData( widget, wd ); 584 windowData( widget, wd );
584 wd.rect = rect; 585 wd.rect = rect;
585 586
586 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 587 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
587 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd); 588 int okWidth = wdiface->metric(WindowDecorationInterface::OKWidth,&wd);
588 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd); 589 int closeWidth = wdiface->metric(WindowDecorationInterface::CloseWidth,&wd);
589 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd); 590 int helpWidth = wdiface->metric(WindowDecorationInterface::HelpWidth,&wd);
590 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd); 591 int grab = wdiface->metric(WindowDecorationInterface::CornerGrabSize,&wd);
591 592
592 QRegion region; 593 QRegion region;
593 594
594 switch ((int)type) { 595 switch ((int)type) {
595 case Menu: 596 case Menu:
596 break; 597 break;
597 case Maximize: 598 case Maximize:
598 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) { 599 if ( !widget->inherits( "QDialog" ) && qApp->desktop()->width() > 350 ) {
599 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd); 600 int maximizeWidth = wdiface->metric(WindowDecorationInterface::MaximizeWidth,&wd);
600 int left = rect.right() - maximizeWidth - closeWidth; 601 int left = rect.right() - maximizeWidth - closeWidth;
601 if ( ((HackWidget *)widget)->needsOk() ) 602 if ( ((HackWidget *)widget)->needsOk() )
602 left -= okWidth; 603 left -= okWidth;
603 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 604 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
604 region = r; 605 region = r;
605 } 606 }
606 break; 607 break;
607 case Minimize: 608 case Minimize:
608 if ( ((HackWidget *)widget)->needsOk() ) { 609 if ( ((HackWidget *)widget)->needsOk() ) {
609 QRect r(rect.right() - okWidth, 610 QRect r(rect.right() - okWidth,
610 rect.top() - titleHeight, okWidth, titleHeight); 611 rect.top() - titleHeight, okWidth, titleHeight);
611 if (r.left() > rect.left() + titleHeight) 612 if (r.left() > rect.left() + titleHeight)
612 region = r; 613 region = r;
613 } 614 }
614 break; 615 break;
615 case Close: 616 case Close:
616 { 617 {
617 int left = rect.right() - closeWidth; 618 int left = rect.right() - closeWidth;
618 if ( ((HackWidget *)widget)->needsOk() ) 619 if ( ((HackWidget *)widget)->needsOk() )
619 left -= okWidth; 620 left -= okWidth;
620 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); 621 QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight);
621 region = r; 622 region = r;
622 } 623 }
623 break; 624 break;
624 case Title: 625 case Title:
625 if ( !widget->isMaximized() ) { 626 if ( !widget->isMaximized() ) {
626 int width = rect.width() - helpWidth - closeWidth; 627 int width = rect.width() - helpWidth - closeWidth;
627 if ( ((HackWidget *)widget)->needsOk() ) 628 if ( ((HackWidget *)widget)->needsOk() )
628 width -= okWidth; 629 width -= okWidth;
629 QRect r(rect.left()+helpWidth, rect.top() - titleHeight, 630 QRect r(rect.left()+helpWidth, rect.top() - titleHeight,
630 width, titleHeight); 631 width, titleHeight);
631 if (r.width() > 0) 632 if (r.width() > 0)
632 region = r; 633 region = r;
633 } 634 }
634 break; 635 break;
635 case Help: 636 case Help:
636 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) { 637 if ( helpExists || widget->testWFlags(Qt::WStyle_ContextHelp) ) {
637 QRect r(rect.left(), rect.top() - titleHeight, 638 QRect r(rect.left(), rect.top() - titleHeight,
638 helpWidth, titleHeight); 639 helpWidth, titleHeight);
639 region = r; 640 region = r;
640 } 641 }
641 break; 642 break;
642 case Top: 643 case Top:
643 if ( !widget->isMaximized() ) { 644 if ( !widget->isMaximized() ) {
644 QRegion m = wdiface->mask(&wd); 645 QRegion m = wdiface->mask(&wd);
645 QRect br = m.boundingRect(); 646 QRect br = m.boundingRect();
646 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 647 int b = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
647 region = m & QRect( br.left()+grab, br.top(), 648 region = m & QRect( br.left()+grab, br.top(),
648 br.width()-2*grab, b ); 649 br.width()-2*grab, b );
649 } 650 }
650 break; 651 break;
651 case Left: 652 case Left:
652 if ( !widget->isMaximized() ) { 653 if ( !widget->isMaximized() ) {
653 QRegion m = wdiface->mask(&wd); 654 QRegion m = wdiface->mask(&wd);
654 QRect br = m.boundingRect(); 655 QRect br = m.boundingRect();
655 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 656 int b = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
656 region = m & QRect( br.left(), br.top()+grab, 657 region = m & QRect( br.left(), br.top()+grab,
657 b, br.height()-2*grab ); 658 b, br.height()-2*grab );
658 } 659 }
659 break; 660 break;
660 case Right: 661 case Right:
661 if ( !widget->isMaximized() ) { 662 if ( !widget->isMaximized() ) {
662 QRegion m = wdiface->mask(&wd); 663 QRegion m = wdiface->mask(&wd);
663 QRect br = m.boundingRect(); 664 QRect br = m.boundingRect();
664 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 665 int b = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
665 region = m & QRect( rect.right(), br.top()+grab, 666 region = m & QRect( rect.right(), br.top()+grab,
666 b, br.height()-2*grab ); 667 b, br.height()-2*grab );
667 } 668 }
668 break; 669 break;
669 case Bottom: 670 case Bottom:
670 if ( !widget->isMaximized() ) { 671 if ( !widget->isMaximized() ) {
671 QRegion m = wdiface->mask(&wd); 672 QRegion m = wdiface->mask(&wd);
672 QRect br = m.boundingRect(); 673 QRect br = m.boundingRect();
673 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd); 674 int b = wdiface->metric(WindowDecorationInterface::BottomBorder,&wd);
674 region = m & QRect( br.left()+grab, rect.bottom(), 675 region = m & QRect( br.left()+grab, rect.bottom(),
675 br.width()-2*grab, b ); 676 br.width()-2*grab, b );
676 } 677 }
677 break; 678 break;
678 case TopLeft: 679 case TopLeft:
679 if ( !widget->isMaximized() ) { 680 if ( !widget->isMaximized() ) {
680 QRegion m = wdiface->mask(&wd); 681 QRegion m = wdiface->mask(&wd);
681 QRect br = m.boundingRect(); 682 QRect br = m.boundingRect();
682 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 683 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
683 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd); 684 int lb = wdiface->metric(WindowDecorationInterface::LeftBorder,&wd);
684 QRegion crgn( br.left(), br.top(), grab, tb ); 685 QRegion crgn( br.left(), br.top(), grab, tb );
685 crgn |= QRect( br.left(), br.top(), lb, grab ); 686 crgn |= QRect( br.left(), br.top(), lb, grab );
686 region = m & crgn; 687 region = m & crgn;
687 } 688 }
688 break; 689 break;
689 case TopRight: 690 case TopRight:
690 if ( !widget->isMaximized() ) { 691 if ( !widget->isMaximized() ) {
691 QRegion m = wdiface->mask(&wd); 692 QRegion m = wdiface->mask(&wd);
692 QRect br = m.boundingRect(); 693 QRect br = m.boundingRect();
693 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd); 694 int tb = wdiface->metric(WindowDecorationInterface::TopBorder,&wd);
694 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd); 695 int rb = wdiface->metric(WindowDecorationInterface::RightBorder,&wd);
695 QRegion crgn( br.right()-grab, br.top(), grab, tb ); 696 QRegion crgn( br.right()-grab, br.top(), grab, tb );
696 crgn |= QRect( br.right()-rb, br.top(), rb, grab ); 697 crgn |= QRect( br.right()-rb, br.top(), rb, grab );
697 region = m & crgn; 698 region = m & crgn;
698 } 699 }
699 break; 700 break;
700 case BottomLeft: 701 case BottomLeft:
701 if ( !widget->isMaximized() ) { 702 if ( !widget->isMaximized() ) {
702 QRegion m = wdiface->mask(&wd); 703 QRegion m = wdiface->mask(&wd);
703 QRect br = m.boundingRect(); 704 QRect br = m.boundingRect();
704 region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); 705 region = m & QRect( br.left(), br.bottom()-grab, grab, grab );
705 } 706 }
706 break; 707 break;
707 case BottomRight: 708 case BottomRight:
708 if ( !widget->isMaximized() ) { 709 if ( !widget->isMaximized() ) {
709 QRegion m = wdiface->mask(&wd); 710 QRegion m = wdiface->mask(&wd);
710 QRect br = m.boundingRect(); 711 QRect br = m.boundingRect();
711 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab ); 712 region = m & QRect( br.right()-grab, br.bottom()-grab, grab, grab );
712 } 713 }
713 break; 714 break;
714 case All: 715 case All:
715 if ( widget->isMaximized() ) 716 if ( widget->isMaximized() )
716 region = QWSDefaultDecoration::region(widget, rect, type); 717 region = QWSDefaultDecoration::region(widget, rect, type);
717 else 718 else
718 region = wdiface->mask(&wd) - rect; 719 region = wdiface->mask(&wd) - rect;
719 break; 720 break;
720 default: 721 default:
721 region = QWSDefaultDecoration::region(widget, rect, type); 722 region = QWSDefaultDecoration::region(widget, rect, type);
722 break; 723 break;
723 } 724 }
724 725
725 return region; 726 return region;
726} 727}
727 728
728void QPEDecoration::paint(QPainter *painter, const QWidget *widget) 729void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
729{ 730{
730 WindowDecorationInterface::WindowData wd; 731 WindowDecorationInterface::WindowData wd;
731 windowData( widget, wd ); 732 windowData( widget, wd );
732 733
733 int titleWidth = getTitleWidth(widget); 734 int titleWidth = getTitleWidth(widget);
734 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 735 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
735 736
736 QRect rect(widget->rect()); 737 QRect rect(widget->rect());
737 738
738 // title bar rect 739 // title bar rect
739 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 740 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
740 741
741#ifndef QT_NO_PALETTE 742#ifndef QT_NO_PALETTE
742 QRegion oldClip = painter->clipRegion(); 743 QRegion oldClip = painter->clipRegion();
743 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker 744 painter->setClipRegion( oldClip - QRegion( tr ) );// reduce flicker
744 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd ); 745 wdiface->drawArea( WindowDecorationInterface::Border, painter, &wd );
745 painter->setClipRegion( oldClip ); 746 painter->setClipRegion( oldClip );
746 747
747 if (titleWidth > 0) { 748 if (titleWidth > 0) {
748 const QColorGroup &cg = widget->palette().active(); 749 const QColorGroup &cg = widget->palette().active();
749 QBrush titleBrush; 750 QBrush titleBrush;
750 QPen titlePen; 751 QPen titlePen;
751 752
752 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) { 753 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) {
753 titleBrush = cg.brush(QColorGroup::Highlight); 754 titleBrush = cg.brush(QColorGroup::Highlight);
754 titlePen = cg.color(QColorGroup::HighlightedText); 755 titlePen = cg.color(QColorGroup::HighlightedText);
755 } else { 756 } else {
756 titleBrush = cg.brush(QColorGroup::Background); 757 titleBrush = cg.brush(QColorGroup::Background);
757 titlePen = cg.color(QColorGroup::Text); 758 titlePen = cg.color(QColorGroup::Text);
758 } 759 }
759 760
760 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 761 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
761 762
762 // Draw caption 763 // Draw caption
763 painter->setPen(titlePen); 764 painter->setPen(titlePen);
764 QFont f( QApplication::font() ); 765 QFont f( QApplication::font() );
765 f.setWeight( QFont::Bold ); 766 f.setWeight( QFont::Bold );
766 painter->setFont(f); 767 painter->setFont(f);
767 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd ); 768 wdiface->drawArea( WindowDecorationInterface::TitleText, painter, &wd );
768 } 769 }
769#endif //QT_NO_PALETTE 770#endif //QT_NO_PALETTE
770 771
771 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 ); 772 paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
772} 773}
773 774
774void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, 775void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
775 QWSDecoration::Region type, int state) 776 QWSDecoration::Region type, int state)
776{ 777{
777 WindowDecorationInterface::Button b; 778 WindowDecorationInterface::Button b;
778 switch ((int)type) { 779 switch ((int)type) {
779 case Close: 780 case Close:
780 b = WindowDecorationInterface::Close; 781 b = WindowDecorationInterface::Close;
781 break; 782 break;
782 case Minimize: 783 case Minimize:
783 if ( ((HackWidget *)w)->needsOk() ) 784 if ( ((HackWidget *)w)->needsOk() )
784 b = WindowDecorationInterface::OK; 785 b = WindowDecorationInterface::OK;
785 else if ( helpExists ) 786 else if ( helpExists )
786 b = WindowDecorationInterface::Help; 787 b = WindowDecorationInterface::Help;
787 else 788 else
788 return; 789 return;
789 break; 790 break;
790 case Help: 791 case Help:
791 b = WindowDecorationInterface::Help; 792 b = WindowDecorationInterface::Help;
792 break; 793 break;
793 case Maximize: 794 case Maximize:
794 b = WindowDecorationInterface::Maximize; 795 b = WindowDecorationInterface::Maximize;
795 break; 796 break;
796 default: 797 default:
797 return; 798 return;
798 } 799 }
799 800
800 WindowDecorationInterface::WindowData wd; 801 WindowDecorationInterface::WindowData wd;
801 windowData( w, wd ); 802 windowData( w, wd );
802 803
803 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); 804 int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd);
804 QRect rect(w->rect()); 805 QRect rect(w->rect());
805 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); 806 QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
806 QRect brect(region(w, w->rect(), type).boundingRect()); 807 QRect brect(region(w, w->rect(), type).boundingRect());
807 808
808 const QColorGroup &cg = w->palette().active(); 809 const QColorGroup &cg = w->palette().active();
809 if ( wd.flags & WindowDecorationInterface::WindowData::Active ) 810 if ( wd.flags & WindowDecorationInterface::WindowData::Active )
810 painter->setPen( cg.color(QColorGroup::HighlightedText) ); 811 painter->setPen( cg.color(QColorGroup::HighlightedText) );
811 else 812 else
812 painter->setPen( cg.color(QColorGroup::Text) ); 813 painter->setPen( cg.color(QColorGroup::Text) );
813 814
814 QRegion oldClip = painter->clipRegion(); 815 QRegion oldClip = painter->clipRegion();
815 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker 816 painter->setClipRegion( QRect(brect.x(), tr.y(), brect.width(), tr.height()) ); // reduce flicker
816 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd ); 817 wdiface->drawArea( WindowDecorationInterface::Title, painter, &wd );
817 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state ); 818 wdiface->drawButton( b, painter, &wd, brect.x(), brect.y(), brect.width(), brect.height(), (QWSButton::State)state );
818 painter->setClipRegion( oldClip ); 819 painter->setClipRegion( oldClip );
819} 820}
820 821
821//#define QPE_DONT_SHOW_TITLEBAR 822//#define QPE_DONT_SHOW_TITLEBAR
822 823
823void QPEDecoration::maximize( QWidget *widget ) 824void QPEDecoration::maximize( QWidget *widget )
824{ 825{
825#ifdef QPE_DONT_SHOW_TITLEBAR 826#ifdef QPE_DONT_SHOW_TITLEBAR
826 if ( !widget->inherits( "QDialog" ) ) { 827 if ( !widget->inherits( "QDialog" ) ) {
827 widget->setGeometry( qt_maxWindowRect ); 828 widget->setGeometry( qt_maxWindowRect );
828 } else 829 } else
829 #endif 830#endif
830 { 831 {
831 QWSDecoration::maximize( widget ); 832 QWSDecoration::maximize( widget );
832 } 833 }
833} 834}
834 835
835#ifndef QT_NO_DIALOG 836#ifndef QT_NO_DIALOG
836class HackDialog : public QDialog 837class HackDialog : public QDialog
837{ 838{
838public: 839public:
839 void acceptIt() { 840 void acceptIt() {
840 if ( isA( "QMessageBox" ) ) 841 if ( isA( "QMessageBox" ) )
841 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) ); 842 qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
842 else 843 else
843 accept(); 844 accept();
844 } 845 }
845}; 846};
846#endif 847#endif
847 848
848 849
849void QPEDecoration::minimize( QWidget *widget ) 850void QPEDecoration::minimize( QWidget *widget )
850{ 851{
851#ifndef QT_NO_DIALOG 852#ifndef QT_NO_DIALOG
852 // We use the minimize button as an "accept" button. 853 // We use the minimize button as an "accept" button.
853 if ( widget->inherits( "QDialog" ) ) { 854 if ( widget->inherits( "QDialog" ) ) {
854 HackDialog *d = (HackDialog *)widget; 855 HackDialog *d = (HackDialog *)widget;
855 d->acceptIt(); 856 d->acceptIt();
856 } 857 }
857#endif 858#endif
858 else if ( ((HackWidget *)widget)->needsOk() ) { 859 else if ( ((HackWidget *)widget)->needsOk() ) {
859 QSignal s; 860 QSignal s;
860 s.connect( widget, SLOT( accept() ) ); 861 s.connect( widget, SLOT( accept() ) );
861 s.activate(); 862 s.activate();
862 } else { 863 } else {
863 help( widget ); 864 help( widget );
864 } 865 }
865} 866}
866 867
867void QPEDecoration::help( QWidget *w ) 868void QPEDecoration::help( QWidget *w )
868{ 869{
869 if ( helpExists ) { 870 if ( helpExists ) {
870 Global::execute( "helpbrowser", helpFile ); 871 Global::execute( "helpbrowser", helpFile );
871 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) { 872 } else if ( w && w->testWFlags(Qt::WStyle_ContextHelp) ) {
872 QWhatsThis::enterWhatsThisMode(); 873 QWhatsThis::enterWhatsThisMode();
873 QWhatsThis::leaveWhatsThisMode( qApp->tr( 874 QWhatsThis::leaveWhatsThisMode( qApp->tr(
874 "<Qt>Comprehensive help is not available for this application, " 875 "<Qt>Comprehensive help is not available for this application, "
875 "however there is context-sensitive help.<p>To use context-sensitive help:<p>" 876 "however there is context-sensitive help.<p>To use context-sensitive help:<p>"
876 "<ol><li>click and hold the help button." 877 "<ol><li>click and hold the help button."
877 "<li>when the title bar shows <b>What's this...</b>, " 878 "<li>when the title bar shows <b>What's this...</b>, "
878 "click on any control.</ol></Qt>" ) ); 879 "click on any control.</ol></Qt>" ) );
879 } 880 }
880} 881}
881 882
882void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const 883void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const
883{ 884{
884 wd.rect = w->rect(); 885 wd.rect = w->rect();
885 if ( qpeManager->whatsThisWidget() == w ) 886 if ( qpeManager->whatsThisWidget() == w )
886 wd.caption = qApp->tr("What's this..." ); 887 wd.caption = qApp->tr("What's this..." );
887 else 888 else
888 wd.caption = w->caption(); 889 wd.caption = w->caption();
889 wd.palette = qApp->palette(); 890 wd.palette = qApp->palette();
890 wd.flags = 0; 891 wd.flags = 0;
891 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0; 892 wd.flags |= w->isMaximized() ? WindowDecorationInterface::WindowData::Maximized : 0;
892 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0; 893 wd.flags |= w->testWFlags(Qt::WStyle_Dialog) ? WindowDecorationInterface::WindowData::Dialog : 0;
893 const QWidget *active = qpeManager->activeWidget(); 894 const QWidget *active = qpeManager->activeWidget();
894 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0; 895 wd.flags |= w == active ? WindowDecorationInterface::WindowData::Active : 0;
895 wd.reserved = 1; 896 wd.reserved = 1;
896} 897}
897 898
898/* 899/*
899#ifndef QT_NO_POPUPMENU 900#ifndef QT_NO_POPUPMENU
900QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) 901QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
901{ 902{
902 return 0; 903 return 0;
903} 904}
904#endif 905#endif
905*/ 906*/
906 907
907 908
908 909
909 910
910#endif // QT_NO_QWS_QPE_WM_STYLE 911#endif // QT_NO_QWS_QPE_WM_STYLE
911#endif 912#endif