-rw-r--r-- | library/qpedecoration_qws.cpp | 23 |
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,206 +1,207 @@ | |||
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 | ||
43 | extern QRect qt_maxWindowRect; | 43 | extern 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 */ |
52 | static const char * const qpe_close_xpm[] = { | 52 | static 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 */ |
75 | static const char * const qpe_accept_xpm[] = { | 75 | static 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 | ||
99 | class HackWidget : public QWidget | 99 | class HackWidget : public QWidget |
100 | { | 100 | { |
101 | public: | 101 | public: |
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 | ||
108 | static QImage scaleButton( const QImage &img, int height ) | 108 | static 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 | ||
117 | class TLWidget : public QWidget | 118 | class TLWidget : public QWidget |
118 | { | 119 | { |
119 | public: | 120 | public: |
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 | ||
135 | QPEManager::QPEManager( QPEDecoration *d, QObject *parent ) | 136 | QPEManager::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 | ||
143 | void QPEManager::updateActive() | 144 | void 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 | ||
161 | int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p ) | 162 | int 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 | ||
177 | bool QPEManager::eventFilter( QObject *o, QEvent *e ) | 178 | bool 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: |
@@ -554,358 +555,358 @@ const char **QPEDecoration::minimizePixmap() | |||
554 | { | 555 | { |
555 | return (const char **)qpe_accept_xpm; | 556 | return (const char **)qpe_accept_xpm; |
556 | } | 557 | } |
557 | 558 | ||
558 | const char **QPEDecoration::maximizePixmap() | 559 | const char **QPEDecoration::maximizePixmap() |
559 | { | 560 | { |
560 | return (const char **)0; | 561 | return (const char **)0; |
561 | } | 562 | } |
562 | 563 | ||
563 | const char **QPEDecoration::normalizePixmap() | 564 | const char **QPEDecoration::normalizePixmap() |
564 | { | 565 | { |
565 | return (const char **)0; | 566 | return (const char **)0; |
566 | } | 567 | } |
567 | 568 | ||
568 | int QPEDecoration::getTitleHeight( const QWidget *w ) | 569 | int 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 | */ |
578 | QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type) | 579 | QRegion 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 | ||
728 | void QPEDecoration::paint(QPainter *painter, const QWidget *widget) | 729 | void 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 | ||
774 | void QPEDecoration::paintButton(QPainter *painter, const QWidget *w, | 775 | void 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 | ||
823 | void QPEDecoration::maximize( QWidget *widget ) | 824 | void 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 |
836 | class HackDialog : public QDialog | 837 | class HackDialog : public QDialog |
837 | { | 838 | { |
838 | public: | 839 | public: |
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 | ||
849 | void QPEDecoration::minimize( QWidget *widget ) | 850 | void 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 | ||
867 | void QPEDecoration::help( QWidget *w ) | 868 | void 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 | ||
882 | void QPEDecoration::windowData( const QWidget *w, WindowDecorationInterface::WindowData &wd ) const | 883 | void 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 |
900 | QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&) | 901 | QPopupMenu *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 |