author | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
---|---|---|
committer | zecke <zecke> | 2002-09-10 12:09:49 (UTC) |
commit | 6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4 (patch) (unidiff) | |
tree | 6ebc93c6432f4ed9d00ef1448b6a047ef522a79a /library/qpedecoration_qws.cpp | |
parent | d10cddb3c9ce75bc90b14add14bc133737fe35aa (diff) | |
download | opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.zip opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.gz opie-6b77a1cdb9536b1c135eb86d53a6b2c22c19b0a4.tar.bz2 |
Qtopia1-6 merge
still to test
bic changes to be resolved
more changes to be made?
-rw-r--r-- | library/qpedecoration_qws.cpp | 733 |
1 files changed, 502 insertions, 231 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,5 +1,5 @@ | |||
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 | ** |
@@ -19,2 +19,3 @@ | |||
19 | **********************************************************************/ | 19 | **********************************************************************/ |
20 | #ifdef QWS | ||
20 | #define QTOPIA_INTERNAL_LANGLIST | 21 | #define QTOPIA_INTERNAL_LANGLIST |
@@ -34,2 +35,4 @@ | |||
34 | #include "global.h" | 35 | #include "global.h" |
36 | #include "qlibrary.h" | ||
37 | #include "windowdecorationinterface.h" | ||
35 | #include <qfile.h> | 38 | #include <qfile.h> |
@@ -41,5 +44,3 @@ 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 | ||
@@ -97,2 +98,20 @@ static const char * const qpe_accept_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 |
@@ -109,6 +128,10 @@ public: | |||
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 | { |
@@ -122,6 +145,6 @@ void QPEManager::updateActive() | |||
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 ); |
@@ -132,3 +155,3 @@ void QPEManager::updateActive() | |||
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; |
@@ -139,5 +162,11 @@ 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 | } |
@@ -154,9 +183,37 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e ) | |||
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; |
@@ -169,2 +226,3 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e ) | |||
169 | if ( helpState & QWSButton::Clicked ) { | 226 | if ( helpState & QWSButton::Clicked ) { |
227 | wtTimer->stop(); | ||
170 | helpState = 0; | 228 | helpState = 0; |
@@ -173,12 +231,3 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e ) | |||
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 ); | 232 | decoration->help( w ); |
177 | } else { | ||
178 | QWhatsThis::enterWhatsThisMode(); | ||
179 | wtTimer->start( 200 ); | ||
180 | } | ||
181 | #else | ||
182 | decoration->help( w ); | ||
183 | #endif | ||
184 | } | 233 | } |
@@ -191,6 +240,7 @@ bool QPEManager::eventFilter( QObject *o, QEvent *e ) | |||
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 ) |
@@ -214,2 +264,15 @@ void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state ) | |||
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() |
@@ -217,23 +280,206 @@ void QPEManager::whatsThisTimeout() | |||
217 | if ( !QWhatsThis::inWhatsThisMode() ) { | 280 | if ( !QWhatsThis::inWhatsThisMode() ) { |
281 | if ( inWhatsThis ) { | ||
282 | if ( whatsThis ) { | ||
283 | QWidget *w = whatsThis; | ||
284 | whatsThis = 0; | ||
285 | drawTitle( w ); | ||
286 | } | ||
218 | wtTimer->stop(); | 287 | wtTimer->stop(); |
219 | if ( active ) | 288 | } else { |
220 | drawButton( active, QPEDecoration::Help, 0 ); | 289 | QWhatsThis::enterWhatsThisMode(); |
221 | } else if ( active ) { | 290 | helpState = 0; |
222 | static int state = 0; | 291 | updateActive(); |
223 | if ( !state ) | 292 | if ( active ) { |
224 | state = QWSButton::Clicked|QWSButton::MouseOver; | 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; | ||
225 | else | 351 | else |
226 | state = 0; | 352 | return 15; |
227 | drawButton( active, QPEDecoration::Help, state ); | 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; | ||
228 | } | 368 | } |
369 | |||
370 | return 0; | ||
229 | } | 371 | } |
230 | 372 | ||
231 | //========= | 373 | void WindowDecorationInterface::drawArea( Area a, QPainter *p, const WindowData *wd ) const |
374 | { | ||
375 | int th = metric( TitleHeight, wd ); | ||
376 | QRect r = wd->rect; | ||
232 | 377 | ||
233 | class HackWidget : public QWidget | 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); | ||
439 | else | ||
440 | p->drawImage(x+1, y+1, *img); | ||
441 | } | ||
442 | } | ||
443 | |||
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 | } | ||
454 | |||
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 | //=========================================================================== |
@@ -243,15 +489,48 @@ QPEDecoration::QPEDecoration() | |||
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 | } |
@@ -288,5 +567,7 @@ const char **QPEDecoration::normalizePixmap() | |||
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 | } |
@@ -298,10 +579,15 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
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 | ||
@@ -309,19 +595,17 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
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) |
@@ -329,19 +613,9 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
329 | } | 613 | } |
330 | #endif | ||
331 | } | ||
332 | break; | 614 | break; |
333 | case Close: { | 615 | case Close: |
334 | if ( ((HackWidget *)widget)->needsOk() || | 616 | { |
335 | (widget->inherits( "QDialog" ) && !widget->inherits( "QMessageBox" ) ) ) { | 617 | int left = rect.right() - closeWidth; |
336 | QRect r; | 618 | if ( ((HackWidget *)widget)->needsOk() ) |
337 | r = QRect(rect.right() - imageOk.width() - imageClose.width(), | 619 | left -= okWidth; |
338 | rect.top() - titleHeight - 2, | 620 | QRect r(left, rect.top() - titleHeight, closeWidth, titleHeight); |
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; | 621 | region = r; |
@@ -349,13 +623,9 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
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) |
@@ -364,13 +634,6 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
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(); | ||
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; | 639 | region = r; |
@@ -378,17 +641,80 @@ QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecor | |||
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: |
387 | case BottomRight: | 701 | if ( !widget->isMaximized() ) { |
388 | if ( widget->isMaximized() ) { | 702 | QRegion m = wdiface->mask(&wd); |
389 | region = QRegion(); | 703 | QRect br = m.boundingRect(); |
704 | region = m & QRect( br.left(), br.bottom()-grab, grab, grab ); | ||
705 | } | ||
390 | break; | 706 | break; |
707 | case BottomRight: | ||
708 | if ( !widget->isMaximized() ) { | ||
709 | QRegion m = wdiface->mask(&wd); | ||
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: |
@@ -403,8 +729,7 @@ 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 | ||
@@ -412,24 +737,9 @@ void QPEDecoration::paint(QPainter *painter, const QWidget *widget) | |||
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 ); |
@@ -437,8 +747,7 @@ void QPEDecoration::paint(QPainter *painter, const QWidget *widget) | |||
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); |
@@ -450,25 +759,5 @@ void QPEDecoration::paint(QPainter *painter, const QWidget *widget) | |||
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); |
@@ -477,12 +766,7 @@ void QPEDecoration::paint(QPainter *painter, const QWidget *widget) | |||
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 | } |
@@ -492,30 +776,20 @@ void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, | |||
492 | { | 776 | { |
493 | #ifndef QT_NO_PALETTE | 777 | WindowDecorationInterface::Button b; |
494 | #ifndef QT_NO_STYLE | ||
495 | // QStyle &style = QApplication::style(); | ||
496 | #endif | ||
497 | const QColorGroup &cg = w->palette().active(); | ||
498 | |||
499 | QRect brect(region(w, w->rect(), type).boundingRect()); | ||
500 | |||
501 | // int xoff=2; | ||
502 | // int yoff=2; | ||
503 | |||
504 | // const QPixmap *pm=pixmapFor(w,type,state & QWSButton::On, xoff, yoff); | ||
505 | |||
506 | const QImage *img = 0; | ||
507 | |||
508 | switch ((int)type) { | 778 | switch ((int)type) { |
509 | case Close: | 779 | case Close: |
510 | img = &imageClose; | 780 | b = WindowDecorationInterface::Close; |
511 | break; | 781 | break; |
512 | case Minimize: | 782 | case Minimize: |
513 | if ( ((HackWidget *)w)->needsOk() || | 783 | if ( ((HackWidget *)w)->needsOk() ) |
514 | (w->inherits( "QDialog" ) && !w->inherits( "QMessageBox" ) ) ) | 784 | b = WindowDecorationInterface::OK; |
515 | img = &imageOk; | ||
516 | else if ( helpExists ) | 785 | else if ( helpExists ) |
517 | img = &imageHelp; | 786 | b = WindowDecorationInterface::Help; |
787 | else | ||
788 | return; | ||
518 | break; | 789 | break; |
519 | case Help: | 790 | case Help: |
520 | img = &imageHelp; | 791 | b = WindowDecorationInterface::Help; |
792 | break; | ||
793 | case Maximize: | ||
794 | b = WindowDecorationInterface::Maximize; | ||
521 | break; | 795 | break; |
@@ -525,48 +799,21 @@ void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, | |||
525 | 799 | ||
526 | QBrush titleBrush; | 800 | WindowDecorationInterface::WindowData wd; |
801 | windowData( w, wd ); | ||
527 | 802 | ||
528 | if (w == qApp->activeWindow()) { | 803 | int titleHeight = wdiface->metric(WindowDecorationInterface::TitleHeight,&wd); |
529 | titleBrush = cg.brush(QColorGroup::Highlight); | 804 | QRect rect(w->rect()); |
530 | } else { | 805 | QRect tr( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight ); |
531 | titleBrush = cg.brush(QColorGroup::Background); | 806 | QRect brect(region(w, w->rect(), type).boundingRect()); |
532 | } | ||
533 | |||
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 | |||
553 | const QColorGroup &cg = widget->palette().active(); | ||
554 | |||
555 | if (widget == qApp->activeWindow()) { | ||
556 | titleBrush = cg.brush(QColorGroup::Highlight); | ||
557 | titleLines = titleBrush.color().dark(); | ||
558 | topLine = titleBrush.color().light(); | ||
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 | } |
@@ -619,3 +866,3 @@ void QPEDecoration::minimize( QWidget *widget ) | |||
619 | 866 | ||
620 | void QPEDecoration::help( QWidget * ) | 867 | void QPEDecoration::help( QWidget *w ) |
621 | { | 868 | { |
@@ -623,2 +870,10 @@ void QPEDecoration::help( QWidget * ) | |||
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 | } |
@@ -626,2 +881,17 @@ void QPEDecoration::help( QWidget * ) | |||
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 | ||
@@ -640 +910,2 @@ QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) | |||
640 | #endif // QT_NO_QWS_QPE_WM_STYLE | 910 | #endif // QT_NO_QWS_QPE_WM_STYLE |
911 | #endif | ||