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