1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
|
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include <qapplication.h>
#include <qstyle.h>
#include <qwidget.h>
#include <qpainter.h>
#include <qtimer.h>
#include <qwhatsthis.h>
#include "qcopenvelope_qws.h"
#include "qpedecoration_qws.h"
#include <qdialog.h>
#include <qdrawutil.h>
#include <qgfx_qws.h>
#include "qpeapplication.h"
#include "resource.h"
#include "global.h"
#include <qfile.h>
#include <qsignal.h>
#include <stdlib.h>
extern QRect qt_maxWindowRect;
//#define MINIMIZE_HELP_HACK // use minimize button when not a dialog
//#define WHATSTHIS_MODE
#ifndef QT_NO_QWS_QPE_WM_STYLE
#ifndef QT_NO_IMAGEIO_XPM
/* XPM */
static const char * const qpe_close_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
" ",
" ",
" ..... ",
" ..+++++.. ",
" .+++++++++. ",
" .+..+++..+. ",
" .++...+...++. ",
" .+++.....+++. ",
" .++++...++++. ",
" .+++.....+++. ",
" .++...+...++. ",
" .+..+++..+. ",
" .+++++++++. ",
" ..+++++.. ",
" ..... ",
" "};
/* XPM */
static const char * const qpe_accept_xpm[] = {
"16 16 3 1",
" c None",
". c #FFFFFF",
"+ c #000000",
" ",
" ",
" ..... ",
" ..+++++.. ",
" .+++++++++. ",
" .+++++++++. ",
" .+++++++..++. ",
" .++.+++...++. ",
" .+...+...+++. ",
" .+......++++. ",
" .++....+++++. ",
" .++..+++++. ",
" .+++++++++. ",
" ..+++++.. ",
" ..... ",
" "};
#endif // QT_NO_IMAGEIO_XPM
class TLWidget : public QWidget
{
public:
QWSManager *manager()
{
return topData()->qwsManager;
}
QTLWExtra *topExtra()
{
return topData();
}
};
QPEManager::QPEManager( QPEDecoration *d, QObject *parent )
: QObject( parent ), decoration( d ), helpState(0)
{
wtTimer = new QTimer( this );
connect( wtTimer, SIGNAL(timeout()), this, SLOT(whatsThisTimeout()) );
}
void QPEManager::updateActive()
{
QWidget *newActive = qApp->activeWindow();
if ( (QWidget*)active == newActive )
return;
if ( active ) {
((TLWidget *)(QWidget*)active)->manager()->removeEventFilter( this );
}
if ( newActive && ((TLWidget *)newActive)->manager() ) {
active = newActive;
((TLWidget *)(QWidget*)active)->manager()->installEventFilter( this );
} else {
active = 0;
}
}
int QPEManager::pointInQpeRegion( QWidget *w, const QPoint &p )
{
if ( decoration->region( w, w->geometry(),
(QWSDecoration::Region)QPEDecoration::Help ).contains(p) ) {
return QPEDecoration::Help;
}
return QWSDecoration::None;
}
bool QPEManager::eventFilter( QObject *o, QEvent *e )
{
QWSManager *mgr = (QWSManager *)o;
QWidget *w = mgr->widget();
switch ( e->type() ) {
case QEvent::MouseButtonPress:
{
if ( QWhatsThis::inWhatsThisMode() ) {
QWhatsThis::leaveWhatsThisMode();
return true;
}
pressTime = QTime::currentTime();
QPoint p = ((QMouseEvent*)e)->globalPos();
if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
helpState = QWSButton::Clicked|QWSButton::MouseOver;
drawButton( w, QPEDecoration::Help, helpState );
return true;
}
}
break;
case QEvent::MouseButtonRelease:
if ( helpState & QWSButton::Clicked ) {
helpState = 0;
drawButton( w, QPEDecoration::Help, helpState );
QPoint p = ((QMouseEvent*)e)->globalPos();
if ( pointInQpeRegion( w, p ) == QPEDecoration::Help ) {
#ifdef WHATSTHIS_MODE
if ( pressTime.msecsTo( QTime::currentTime() ) > 250 ) {
decoration->help( w );
} else {
QWhatsThis::enterWhatsThisMode();
wtTimer->start( 200 );
}
#else
decoration->help( w );
#endif
}
return true;
}
break;
case QEvent::MouseMove:
if ( helpState & QWSButton::Clicked ) {
int oldState = helpState;
QPoint p = ((QMouseEvent*)e)->globalPos();
if ( pointInQpeRegion( w, p ) == QPEDecoration::Help )
helpState = QWSButton::Clicked|QWSButton::MouseOver;
else
helpState = 0;
if ( helpState != oldState )
drawButton( w, QPEDecoration::Help, helpState );
}
break;
default:
break;
}
return QObject::eventFilter( o, e );
}
void QPEManager::drawButton( QWidget *w, QPEDecoration::QPERegion r, int state )
{
QPainter painter(w);
QRegion rgn = ((TLWidget *)w)->topExtra()->decor_allocated_region;
painter.internalGfx()->setWidgetDeviceRegion( rgn );
painter.setClipRegion(decoration->region(w, w->rect(),QWSDecoration::All));
decoration->paintButton( &painter, w, (QWSDecoration::Region)r, state );
}
void QPEManager::whatsThisTimeout()
{
if ( !QWhatsThis::inWhatsThisMode() ) {
wtTimer->stop();
if ( active )
drawButton( active, QPEDecoration::Help, 0 );
} else if ( active ) {
static int state = 0;
if ( !state )
state = QWSButton::Clicked|QWSButton::MouseOver;
else
state = 0;
drawButton( active, QPEDecoration::Help, state );
}
}
//=========
class HackWidget : public QWidget
{
public:
bool needsOk() { return (getWState() & WState_Reserved1 ); }
};
//===========================================================================
QPEDecoration::QPEDecoration()
: QWSDefaultDecoration()
{
imageOk = Resource::loadImage( "OKButton" );
imageClose = Resource::loadImage( "CloseButton" );
imageHelp = Resource::loadImage( "HelpButton" );
helpFile = QString(qApp->argv()[0]) + ".html";
QString lang = getenv( "LANG" );
helpExists = QFile::exists( QPEApplication::qpeDir() + "/help/" + lang + "/html/" + helpFile );
if ( !helpExists )
helpExists = QFile::exists( QPEApplication::qpeDir() + "/help/en/html/" + helpFile );
#ifndef MINIMIZE_HELP_HACK
qpeManager = new QPEManager( this );
#else
qpeManager = 0;
#endif
}
QPEDecoration::~QPEDecoration()
{
delete qpeManager;
}
const char **QPEDecoration::menuPixmap()
{
return (const char **)0;
}
const char **QPEDecoration::closePixmap()
{
return (const char **)qpe_close_xpm;
}
const char **QPEDecoration::minimizePixmap()
{
return (const char **)qpe_accept_xpm;
}
const char **QPEDecoration::maximizePixmap()
{
return (const char **)0;
}
const char **QPEDecoration::normalizePixmap()
{
return (const char **)0;
}
int QPEDecoration::getTitleHeight(const QWidget *)
{
return 15;
}
/*
If rect is empty, no frame is added. (a hack, really)
*/
QRegion QPEDecoration::region(const QWidget *widget, const QRect &rect, QWSDecoration::Region type)
{
int titleHeight = getTitleHeight(widget);
// int titleWidth = getTitleWidth(widget);
// int bw = rect.isEmpty() ? 0 : BORDER_WIDTH;
QRegion region;
#ifndef MINIMIZE_HELP_HACK
qpeManager->updateActive();
#endif
switch ((int)type) {
case Menu:
case Maximize:
break;
case Minimize: {
if ( ((HackWidget *)widget)->needsOk() ||
(widget->inherits( "QDialog" ) && !widget->inherits( "QMessageBox" ) ) ) {
QRect r(rect.right() - imageOk.width(),
rect.top() - titleHeight - 2,
imageOk.width(), titleHeight);
if (r.left() > rect.left() + titleHeight)
region = r;
}
#ifdef MINIMIZE_HELP_HACK
else if ( helpExists ) {
QRect r;
r = QRect(rect.right() - imageClose.width() - imageHelp.width(),
rect.top() - titleHeight - 2,
imageHelp.width(), titleHeight);
if (r.left() > rect.left() + titleHeight)
region = r;
}
#endif
}
break;
case Close: {
if ( ((HackWidget *)widget)->needsOk() ||
(widget->inherits( "QDialog" ) && !widget->inherits( "QMessageBox" ) ) ) {
QRect r;
r = QRect(rect.right() - imageOk.width() - imageClose.width(),
rect.top() - titleHeight - 2,
imageClose.width(), titleHeight);
if (r.left() > rect.left() + titleHeight)
region = r;
} else {
QRect r(rect.right() - imageClose.width(),
rect.top() - titleHeight - 2,
imageClose.width(), titleHeight);
if (r.left() > rect.left() + titleHeight)
region = r;
}
break;
}
case Title: {
if ( widget->isMaximized() ) {
region = QRegion();
} else {
int btnWidth = imageClose.width();
if ( ((HackWidget *)widget)->needsOk() ||
(widget->inherits( "QDialog" ) && !widget->inherits( "QMessageBox" ) ) )
btnWidth += imageOk.width();
QRect r(rect.left() + 1, rect.top() - titleHeight,
rect.width() - btnWidth - 2, titleHeight);
if (r.width() > 0)
region = r;
}
break;
}
case Help: {
if ( helpExists ) {
QRect r;
int l = rect.right() - imageClose.width() - imageHelp.width();
if ( ((HackWidget *)widget)->needsOk() ||
(widget->inherits( "QDialog" ) && !widget->inherits( "QMessageBox" ) ) )
l -= imageOk.width();
r = QRect(l, rect.top() - titleHeight - 2,
imageHelp.width(), titleHeight);
if (r.left() > rect.left() + titleHeight)
region = r;
}
break;
}
case Top:
case Left:
case Right:
case Bottom:
case TopLeft:
case TopRight:
case BottomLeft:
case BottomRight:
if ( widget->isMaximized() ) {
region = QRegion();
break;
}
//else fallthrough!!!
case All:
default:
region = QWSDefaultDecoration::region(widget, rect, type);
break;
}
return region;
}
void QPEDecoration::paint(QPainter *painter, const QWidget *widget)
{
#ifndef QT_NO_STYLE
// QStyle &style = QApplication::style();
#endif
int titleWidth = getTitleWidth(widget);
int titleHeight = getTitleHeight(widget);
QRect rect(widget->rect());
// Border rect
QRect br( rect.left() - BORDER_WIDTH,
rect.top() - BORDER_WIDTH - titleHeight,
rect.width() + 2 * BORDER_WIDTH,
rect.height() + BORDER_WIDTH + BOTTOM_BORDER_WIDTH + titleHeight );
// title bar rect
QRect tr;
tr = QRect( rect.left(), rect.top() - titleHeight, rect.width(), titleHeight );
QRegion oldClip = painter->clipRegion();
painter->setClipRegion( oldClip - QRegion( tr ) ); // reduce flicker
#ifndef QT_NO_PALETTE
// const QColorGroup &cg = QApplication::palette().active();
const QColorGroup &cg = widget->palette().active();
qDrawWinPanel(painter, br.x(), br.y(), br.width(),
br.height() - 4, cg, FALSE,
&cg.brush(QColorGroup::Background));
painter->setClipRegion( oldClip );
if (titleWidth > 0) {
QBrush titleBrush;
QPen titlePen;
QPen titleLines;
int titleLeft = titleHeight + 4;
if (widget == qApp->activeWindow()) {
titleBrush = cg.brush(QColorGroup::Highlight);
titlePen = cg.color(QColorGroup::HighlightedText);
} else {
titleBrush = cg.brush(QColorGroup::Background);
titlePen = cg.color(QColorGroup::Text);
}
titleLines = titleBrush.color().dark(150);
#define CLAMP(x, y) ( ((x) > (y)) ? (y) : (x) )
titleLeft = rect.left() + 5;
painter->setPen( cg.midlight() );
painter->drawLine( rect.left() - BORDER_WIDTH + 2,
rect.bottom() + 1, rect.right() + BORDER_WIDTH - 2,
rect.bottom() + 1 );
fillTitle( painter, widget, rect.left() - 2,
rect.top() - titleHeight - 2,
rect.width() + 3, titleHeight + 2 );
/*
painter->fillRect(rect.left() - 2,
rect.top() - titleHeight - 2,
rect.width() + 3, titleHeight + 2,
titleBrush);
painter->setPen( titleLines );
for ( int i = rect.top() - titleHeight - 2; i < rect.top(); i += 2 )
painter->drawLine( rect.left() - 2, i, rect.left() + rect.width() + 2, i );
*/
painter->setPen(titlePen);
QFont f( QApplication::font() );
f.setWeight( QFont::Bold );
painter->setFont(f);
painter->drawText( titleLeft, -titleHeight,
rect.width() - titleHeight - 10, titleHeight-1,
QPainter::AlignVCenter, widget->caption());
}
#endif //QT_NO_PALETTE
#ifndef MINIMIZE_HELP_HACK
paintButton( painter, widget, (QWSDecoration::Region)Help, 0 );
#endif
}
void QPEDecoration::paintButton(QPainter *painter, const QWidget *w,
QWSDecoration::Region type, int state)
{
#ifndef QT_NO_PALETTE
#ifndef QT_NO_STYLE
// QStyle &style = QApplication::style();
#endif
const QColorGroup &cg = w->palette().active();
QRect brect(region(w, w->rect(), type).boundingRect());
// int xoff=2;
// int yoff=2;
// const QPixmap *pm=pixmapFor(w,type,state & QWSButton::On, xoff, yoff);
const QImage *img = 0;
switch ((int)type) {
case Close:
img = &imageClose;
break;
case Minimize:
if ( ((HackWidget *)w)->needsOk() ||
(w->inherits( "QDialog" ) && !w->inherits( "QMessageBox" ) ) )
img = &imageOk;
else if ( helpExists )
img = &imageHelp;
break;
case Help:
img = &imageHelp;
break;
default:
return;
}
QBrush titleBrush;
if (w == qApp->activeWindow()) {
titleBrush = cg.brush(QColorGroup::Highlight);
} else {
titleBrush = cg.brush(QColorGroup::Background);
}
fillTitle( painter, w, brect.x(), brect.y(), brect.width()+1,
brect.height()+1 );
if ((state & QWSButton::MouseOver) && (state & QWSButton::Clicked)) {
if (img) painter->drawImage(brect.x()+1, brect.y()+3, *img);
} else {
if (img) painter->drawImage(brect.x(), brect.y()+2, *img);
}
#endif
}
void QPEDecoration::fillTitle( QPainter *p, const QWidget *widget,
int x, int y, int w, int h )
{
QBrush titleBrush;
QPen topLine;
QPen titleLines;
const QColorGroup &cg = widget->palette().active();
if (widget == qApp->activeWindow()) {
titleBrush = cg.brush(QColorGroup::Highlight);
titleLines = titleBrush.color().dark();
topLine = titleBrush.color().light();
} else {
titleBrush = cg.brush(QColorGroup::Background);
titleLines = titleBrush.color();
topLine = titleBrush.color();
}
p->fillRect( x, y, w, h, titleBrush);
p->setPen( topLine );
p->drawLine( x, y+1, x+w-1, y+1 );
p->setPen( titleLines );
for ( int i = y; i < y+h; i += 2 )
p->drawLine( x, i, x+w-1, i );
}
//#define QPE_DONT_SHOW_TITLEBAR
void QPEDecoration::maximize( QWidget *widget )
{
#ifdef QPE_DONT_SHOW_TITLEBAR
if ( !widget->inherits( "QDialog" ) ) {
widget->setGeometry( qt_maxWindowRect );
} else
#endif
{
QWSDecoration::maximize( widget );
}
}
#ifndef QT_NO_DIALOG
class HackDialog : public QDialog
{
public:
void acceptIt() {
if ( isA( "QMessageBox" ) )
qApp->postEvent( this, new QKeyEvent( QEvent::KeyPress, Key_Enter, '\n', 0, "\n" ) );
else
accept();
}
};
#endif
void QPEDecoration::minimize( QWidget *widget )
{
#ifndef QT_NO_DIALOG
// We use the minimize button as an "accept" button.
if ( widget->inherits( "QDialog" ) ) {
HackDialog *d = (HackDialog *)widget;
d->acceptIt();
}
#endif
else if ( ((HackWidget *)widget)->needsOk() ) {
QSignal s;
s.connect( widget, SLOT( accept() ) );
s.activate();
} else {
help( widget );
}
}
void QPEDecoration::help( QWidget * )
{
if ( helpExists ) {
Global::execute( "helpbrowser", helpFile );
}
}
/*
#ifndef QT_NO_POPUPMENU
QPopupMenu *QPEDecoration::menu(QWSManager*, const QWidget*, const QPoint&)
{
return 0;
}
#endif
*/
#endif // QT_NO_QWS_QPE_WM_STYLE
|