~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/styles/qwindowsstyle.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the style module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
 
 
29
#include "qwindowsstyle.h"
 
30
 
 
31
#if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)
 
32
 
 
33
#include "qapplication.h"
 
34
#include "qbitmap.h"
 
35
#include "qdrawutil.h" // for now
 
36
#include "qevent.h"
 
37
#include "qmenu.h"
 
38
#include "qmenubar.h"
 
39
#include "qpaintengine.h"
 
40
#include "qpainter.h"
 
41
#include "qrubberband.h"
 
42
#include "qstyleoption.h"
 
43
#include "qtabbar.h"
 
44
#include "qwidget.h"
 
45
#include "qdebug.h"
 
46
 
 
47
#if defined(Q_WS_WIN)
 
48
#include "qt_windows.h"
 
49
#endif
 
50
 
 
51
#include <limits.h>
 
52
 
 
53
static const int windowsItemFrame        =  2; // menu item frame width
 
54
static const int windowsSepHeight        =  2; // separator item height
 
55
static const int windowsItemHMargin      =  3; // menu item hor text margin
 
56
static const int windowsItemVMargin      =  2; // menu item ver text margin
 
57
static const int windowsArrowHMargin     =  6; // arrow horizontal margin
 
58
static const int windowsTabSpacing       = 12; // space between text and tab
 
59
static const int windowsCheckMarkHMargin =  2; // horiz. margins of check mark
 
60
static const int windowsRightBorder      = 15; // right border on windows
 
61
static const int windowsCheckMarkWidth   = 12; // checkmarks width on windows
 
62
 
 
63
static bool use2000style = true;
 
64
 
 
65
enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
 
66
 
 
67
// Private class
 
68
class QWindowsStyle::Private : public QObject
 
69
{
 
70
public:
 
71
    Private(QWindowsStyle *parent);
 
72
 
 
73
    bool hasSeenAlt(const QWidget *widget) const;
 
74
    bool altDown() const { return alt_down; }
 
75
 
 
76
protected:
 
77
    bool eventFilter(QObject *o, QEvent *e);
 
78
 
 
79
private:
 
80
    QList<const QWidget *> seenAlt;
 
81
    bool alt_down;
 
82
    int menuBarTimer;
 
83
};
 
84
 
 
85
QWindowsStyle::Private::Private(QWindowsStyle *parent)
 
86
    : QObject(parent),
 
87
      alt_down(false), menuBarTimer(0)
 
88
{
 
89
}
 
90
 
 
91
// Returns true if the toplevel parent of \a widget has seen the Alt-key
 
92
bool QWindowsStyle::Private::hasSeenAlt(const QWidget *widget) const
 
93
{
 
94
    widget = widget->window();
 
95
    return seenAlt.contains(widget);
 
96
}
 
97
 
 
98
// Records Alt- and Focus events
 
99
bool QWindowsStyle::Private::eventFilter(QObject *o, QEvent *e)
 
100
{
 
101
    if (!o->isWidgetType())
 
102
        return QObject::eventFilter(o, e);
 
103
 
 
104
    QWidget *widget = ::qobject_cast<QWidget*>(o);
 
105
 
 
106
    switch(e->type()) {
 
107
    case QEvent::KeyPress:
 
108
        if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
 
109
            widget = widget->window();
 
110
 
 
111
            // Alt has been pressed - find all widgets that care
 
112
            QList<QWidget *> l = qFindChildren<QWidget *>(widget);
 
113
            for (int pos=0; pos<l.size(); ++pos) {
 
114
                QWidget *w = l.at(pos);
 
115
                if (w->isWindow() || !w->isVisible() ||
 
116
                    w->style()->styleHint(SH_UnderlineShortcut, 0, w))
 
117
                    l.removeAt(pos);
 
118
            }
 
119
            // Update states before repainting
 
120
            seenAlt.append(widget);
 
121
            alt_down = true;
 
122
 
 
123
            // Repaint all relevant widgets
 
124
            for (int pos = 0; pos<l.size(); ++pos)
 
125
                l.at(pos)->repaint();
 
126
        }
 
127
        break;
 
128
    case QEvent::KeyRelease:
 
129
        if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
 
130
            widget = widget->window();
 
131
 
 
132
            // Update state and repaint the menubars.
 
133
            alt_down = false;
 
134
            QList<QMenuBar *> l = qFindChildren<QMenuBar *>(widget);
 
135
            for (int i = 0; i < l.size(); ++i)
 
136
                l.at(i)->repaint();
 
137
        }
 
138
        break;
 
139
    case QEvent::Close:
 
140
        // Reset widget when closing
 
141
        seenAlt.removeAll(widget);
 
142
        seenAlt.removeAll(widget->window());
 
143
        break;
 
144
    default:
 
145
        break;
 
146
    }
 
147
 
 
148
    return QObject::eventFilter(o, e);
 
149
}
 
150
 
 
151
/*!
 
152
    \class QWindowsStyle qwindowsstyle.h
 
153
    \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.
 
154
 
 
155
    \ingroup appearance
 
156
 
 
157
    This style is Qt's default GUI style on Windows.
 
158
 
 
159
    \img qwindowsstyle.png
 
160
    \sa QWindowsXPStyle, QMacStyle, QPlastiqueStyle, QCDEStyle, QMotifStyle
 
161
*/
 
162
 
 
163
/*!
 
164
    Constructs a QWindowsStyle object.
 
165
*/
 
166
QWindowsStyle::QWindowsStyle() : QCommonStyle(), d(0)
 
167
{
 
168
#if defined(Q_OS_WIN32)
 
169
    use2000style = QSysInfo::WindowsVersion != QSysInfo::WV_NT && QSysInfo::WindowsVersion != QSysInfo::WV_95;
 
170
#endif
 
171
}
 
172
 
 
173
/*! Destroys the QWindowsStyle object. */
 
174
QWindowsStyle::~QWindowsStyle()
 
175
{
 
176
    delete d;
 
177
}
 
178
 
 
179
/*! \reimp */
 
180
void QWindowsStyle::polish(QApplication *app)
 
181
{
 
182
    // We only need the overhead when shortcuts are sometimes hidden
 
183
    if (!styleHint(SH_UnderlineShortcut, 0)) {
 
184
        d = new Private(this);
 
185
        app->installEventFilter(d);
 
186
    }
 
187
}
 
188
 
 
189
/*! \reimp */
 
190
void QWindowsStyle::unpolish(QApplication *)
 
191
{
 
192
    delete d;
 
193
    d = 0;
 
194
}
 
195
 
 
196
/*! \reimp */
 
197
void QWindowsStyle::polish(QWidget *widget)
 
198
{
 
199
    QCommonStyle::polish(widget);
 
200
    if (qobject_cast<QRubberBand*>(widget)) {
 
201
        widget->setWindowOpacity(0.7f);
 
202
        widget->setAttribute(Qt::WA_PaintOnScreen);
 
203
    }
 
204
}
 
205
 
 
206
/*! \reimp */
 
207
void QWindowsStyle::unpolish(QWidget *widget)
 
208
{
 
209
    QCommonStyle::polish(widget);
 
210
    if (qobject_cast<QRubberBand*>(widget)) {
 
211
        widget->setWindowOpacity(1.0);
 
212
        widget->setAttribute(Qt::WA_PaintOnScreen, false);
 
213
    }
 
214
}
 
215
 
 
216
/*! \reimp */
 
217
void QWindowsStyle::polish(QPalette &pal)
 
218
{
 
219
    QCommonStyle::polish(pal);
 
220
}
 
221
 
 
222
/*!
 
223
  \reimp
 
224
*/
 
225
int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
 
226
{
 
227
    int ret;
 
228
 
 
229
    switch (pm) {
 
230
    case PM_ButtonDefaultIndicator:
 
231
    case PM_ButtonShiftHorizontal:
 
232
    case PM_ButtonShiftVertical:
 
233
        ret = 1;
 
234
        break;
 
235
    case PM_TabBarTabShiftHorizontal:
 
236
        ret = 0;
 
237
        break;
 
238
    case PM_TabBarTabShiftVertical:
 
239
        ret = 2;
 
240
        break;
 
241
    case PM_MaximumDragDistance:
 
242
        ret = 60;
 
243
        break;
 
244
 
 
245
#ifndef QT_NO_SLIDER
 
246
    case PM_SliderLength:
 
247
        ret = 11;
 
248
        break;
 
249
 
 
250
        // Returns the number of pixels to use for the business part of the
 
251
        // slider (i.e., the non-tickmark portion). The remaining space is shared
 
252
        // equally between the tickmark regions.
 
253
    case PM_SliderControlThickness:
 
254
        if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
255
            int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
 
256
            int ticks = sl->tickPosition;
 
257
            int n = 0;
 
258
            if (ticks & QSlider::TicksAbove)
 
259
                ++n;
 
260
            if (ticks & QSlider::TicksBelow)
 
261
                ++n;
 
262
            if (!n) {
 
263
                ret = space;
 
264
                break;
 
265
            }
 
266
 
 
267
            int thick = 6;        // Magic constant to get 5 + 16 + 5
 
268
            if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
 
269
                thick += pixelMetric(PM_SliderLength, sl, widget) / 4;
 
270
 
 
271
            space -= thick;
 
272
            if (space > 0)
 
273
                thick += (space * 2) / (n + 2);
 
274
            ret = thick;
 
275
        } else {
 
276
            ret = 0;
 
277
        }
 
278
        break;
 
279
#endif // QT_NO_SLIDER
 
280
 
 
281
    case PM_MenuBarHMargin:
 
282
        ret = 0;
 
283
        break;
 
284
 
 
285
    case PM_MenuBarVMargin:
 
286
        ret = 1;
 
287
        break;
 
288
 
 
289
    case PM_MenuBarPanelWidth:
 
290
        ret = 0;
 
291
        break;
 
292
 
 
293
 
 
294
#if defined(Q_WS_WIN)
 
295
    case PM_TitleBarHeight:
 
296
        {
 
297
#if defined(Q_OS_TEMP)
 
298
            ret = GetSystemMetrics(SM_CYCAPTION) - 1;
 
299
#else
 
300
            ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
 
301
#endif
 
302
        }
 
303
 
 
304
        break;
 
305
 
 
306
    case PM_ScrollBarExtent:
 
307
        {
 
308
#ifndef Q_OS_TEMP
 
309
            NONCLIENTMETRICS ncm;
 
310
            ncm.cbSize = sizeof(NONCLIENTMETRICS);
 
311
            if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
 
312
                ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth);
 
313
            else
 
314
#endif
 
315
                ret = QCommonStyle::pixelMetric(pm, opt, widget);
 
316
        }
 
317
        break;
 
318
#endif
 
319
 
 
320
    case PM_SplitterWidth:
 
321
        ret = qMax(6, QApplication::globalStrut().width());
 
322
        break;
 
323
 
 
324
#if defined(Q_WS_WIN)
 
325
    case PM_MDIFrameWidth:
 
326
        ret = GetSystemMetrics(SM_CYFRAME);
 
327
        break;
 
328
#endif
 
329
 
 
330
    default:
 
331
        ret = QCommonStyle::pixelMetric(pm, opt, widget);
 
332
        break;
 
333
    }
 
334
 
 
335
    return ret;
 
336
}
 
337
 
 
338
#ifndef QT_NO_IMAGEIO_XPM
 
339
 
 
340
static const char * const qt_menu_xpm[] = {
 
341
"16 16 11 1",
 
342
"  c #000000",
 
343
", c #336600",
 
344
". c #99CC00",
 
345
"X c #666600",
 
346
"o c #999933",
 
347
"+ c #333300",
 
348
"@ c #669900",
 
349
"# c #999900",
 
350
"$ c #336633",
 
351
"% c #666633",
 
352
"& c #99CC33",
 
353
"................",
 
354
"................",
 
355
".....#,++X#.....",
 
356
"....X      X....",
 
357
"...X  Xo#%  X&..",
 
358
"..#  o..&@o  o..",
 
359
".., X..#+ @X X..",
 
360
"..+ o.o+ +o# +..",
 
361
"..+ #o+  +## +..",
 
362
".., %@ ++ +, X..",
 
363
"..#  o@oo+   #..",
 
364
"...X  X##$   o..",
 
365
"....X        X..",
 
366
"....&oX++X#oX...",
 
367
"................",
 
368
"................"};
 
369
 
 
370
static const char * const qt_close_xpm[] = {
 
371
"10 10 2 1",
 
372
"# c #000000",
 
373
". c None",
 
374
"..........",
 
375
".##....##.",
 
376
"..##..##..",
 
377
"...####...",
 
378
"....##....",
 
379
"...####...",
 
380
"..##..##..",
 
381
".##....##.",
 
382
"..........",
 
383
".........."};
 
384
 
 
385
static const char * const qt_maximize_xpm[]={
 
386
"10 10 2 1",
 
387
"# c #000000",
 
388
". c None",
 
389
"#########.",
 
390
"#########.",
 
391
"#.......#.",
 
392
"#.......#.",
 
393
"#.......#.",
 
394
"#.......#.",
 
395
"#.......#.",
 
396
"#.......#.",
 
397
"#########.",
 
398
".........."};
 
399
 
 
400
static const char * const qt_minimize_xpm[] = {
 
401
"10 10 2 1",
 
402
"# c #000000",
 
403
". c None",
 
404
"..........",
 
405
"..........",
 
406
"..........",
 
407
"..........",
 
408
"..........",
 
409
"..........",
 
410
"..........",
 
411
".#######..",
 
412
".#######..",
 
413
".........."};
 
414
 
 
415
static const char * const qt_normalizeup_xpm[] = {
 
416
"10 10 2 1",
 
417
"# c #000000",
 
418
". c None",
 
419
"...######.",
 
420
"...######.",
 
421
"...#....#.",
 
422
".######.#.",
 
423
".######.#.",
 
424
".#....###.",
 
425
".#....#...",
 
426
".#....#...",
 
427
".######...",
 
428
".........."};
 
429
 
 
430
static const char * const qt_help_xpm[] = {
 
431
"10 10 2 1",
 
432
". c None",
 
433
"# c #000000",
 
434
"..........",
 
435
"..######..",
 
436
".##....##.",
 
437
"......##..",
 
438
".....##...",
 
439
"....##....",
 
440
"....##....",
 
441
"..........",
 
442
"....##....",
 
443
".........."};
 
444
 
 
445
static const char * const qt_shade_xpm[] = {
 
446
"10 10 2 1",
 
447
"# c #000000",
 
448
". c None",
 
449
"..........",
 
450
"..........",
 
451
"..........",
 
452
"..........",
 
453
"....#.....",
 
454
"...###....",
 
455
"..#####...",
 
456
".#######..",
 
457
"..........",
 
458
".........."};
 
459
 
 
460
static const char * const qt_unshade_xpm[] = {
 
461
"10 10 2 1",
 
462
"# c #000000",
 
463
". c None",
 
464
"..........",
 
465
"..........",
 
466
"..........",
 
467
".#######..",
 
468
"..#####...",
 
469
"...###....",
 
470
"....#.....",
 
471
"..........",
 
472
"..........",
 
473
".........."};
 
474
 
 
475
static const char * dock_widget_close_xpm[] = {
 
476
"8 8 2 1",
 
477
"# c #000000",
 
478
". c None",
 
479
"........",
 
480
".##..##.",
 
481
"..####..",
 
482
"...##...",
 
483
"..####..",
 
484
".##..##.",
 
485
"........",
 
486
"........"};
 
487
 
 
488
/* XPM */
 
489
static const char * const information_xpm[]={
 
490
"32 32 5 1",
 
491
". c None",
 
492
"c c #000000",
 
493
"* c #999999",
 
494
"a c #ffffff",
 
495
"b c #0000ff",
 
496
"...........********.............",
 
497
"........***aaaaaaaa***..........",
 
498
"......**aaaaaaaaaaaaaa**........",
 
499
".....*aaaaaaaaaaaaaaaaaa*.......",
 
500
"....*aaaaaaaabbbbaaaaaaaac......",
 
501
"...*aaaaaaaabbbbbbaaaaaaaac.....",
 
502
"..*aaaaaaaaabbbbbbaaaaaaaaac....",
 
503
".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
 
504
".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
 
505
"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
 
506
"*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
 
507
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
508
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
509
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
510
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
511
"*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
 
512
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
 
513
".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
 
514
"..*aaaaaaaaaabbbbbaaaaaaaaac***.",
 
515
"...caaaaaaabbbbbbbbbaaaaaac****.",
 
516
"....caaaaaaaaaaaaaaaaaaaac****..",
 
517
".....caaaaaaaaaaaaaaaaaac****...",
 
518
"......ccaaaaaaaaaaaaaacc****....",
 
519
".......*cccaaaaaaaaccc*****.....",
 
520
"........***cccaaaac*******......",
 
521
"..........****caaac*****........",
 
522
".............*caaac**...........",
 
523
"...............caac**...........",
 
524
"................cac**...........",
 
525
".................cc**...........",
 
526
"..................***...........",
 
527
"...................**..........."};
 
528
/* XPM */
 
529
static const char* const warning_xpm[]={
 
530
"32 32 4 1",
 
531
". c None",
 
532
"a c #ffff00",
 
533
"* c #000000",
 
534
"b c #999999",
 
535
".............***................",
 
536
"............*aaa*...............",
 
537
"...........*aaaaa*b.............",
 
538
"...........*aaaaa*bb............",
 
539
"..........*aaaaaaa*bb...........",
 
540
"..........*aaaaaaa*bb...........",
 
541
".........*aaaaaaaaa*bb..........",
 
542
".........*aaaaaaaaa*bb..........",
 
543
"........*aaaaaaaaaaa*bb.........",
 
544
"........*aaaa***aaaa*bb.........",
 
545
".......*aaaa*****aaaa*bb........",
 
546
".......*aaaa*****aaaa*bb........",
 
547
"......*aaaaa*****aaaaa*bb.......",
 
548
"......*aaaaa*****aaaaa*bb.......",
 
549
".....*aaaaaa*****aaaaaa*bb......",
 
550
".....*aaaaaa*****aaaaaa*bb......",
 
551
"....*aaaaaaaa***aaaaaaaa*bb.....",
 
552
"....*aaaaaaaa***aaaaaaaa*bb.....",
 
553
"...*aaaaaaaaa***aaaaaaaaa*bb....",
 
554
"...*aaaaaaaaaa*aaaaaaaaaa*bb....",
 
555
"..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
 
556
"..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
 
557
".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
 
558
".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
 
559
"*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
 
560
"*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
 
561
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
 
562
"*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
 
563
".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
 
564
"..*************************bbbbb",
 
565
"....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
 
566
".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
 
567
/* XPM */
 
568
static const char* const critical_xpm[]={
 
569
"32 32 4 1",
 
570
". c None",
 
571
"a c #999999",
 
572
"* c #ff0000",
 
573
"b c #ffffff",
 
574
"...........********.............",
 
575
".........************...........",
 
576
".......****************.........",
 
577
"......******************........",
 
578
".....********************a......",
 
579
"....**********************a.....",
 
580
"...************************a....",
 
581
"..*******b**********b*******a...",
 
582
"..******bbb********bbb******a...",
 
583
".******bbbbb******bbbbb******a..",
 
584
".*******bbbbb****bbbbb*******a..",
 
585
"*********bbbbb**bbbbb*********a.",
 
586
"**********bbbbbbbbbb**********a.",
 
587
"***********bbbbbbbb***********aa",
 
588
"************bbbbbb************aa",
 
589
"************bbbbbb************aa",
 
590
"***********bbbbbbbb***********aa",
 
591
"**********bbbbbbbbbb**********aa",
 
592
"*********bbbbb**bbbbb*********aa",
 
593
".*******bbbbb****bbbbb*******aa.",
 
594
".******bbbbb******bbbbb******aa.",
 
595
"..******bbb********bbb******aaa.",
 
596
"..*******b**********b*******aa..",
 
597
"...************************aaa..",
 
598
"....**********************aaa...",
 
599
"....a********************aaa....",
 
600
".....a******************aaa.....",
 
601
"......a****************aaa......",
 
602
".......aa************aaaa.......",
 
603
".........aa********aaaaa........",
 
604
"...........aaaaaaaaaaa..........",
 
605
".............aaaaaaa............"};
 
606
/* XPM */
 
607
static const char *const question_xpm[] = {
 
608
"32 32 5 1",
 
609
". c None",
 
610
"c c #000000",
 
611
"* c #999999",
 
612
"a c #ffffff",
 
613
"b c #0000ff",
 
614
"...........********.............",
 
615
"........***aaaaaaaa***..........",
 
616
"......**aaaaaaaaaaaaaa**........",
 
617
".....*aaaaaaaaaaaaaaaaaa*.......",
 
618
"....*aaaaaaaaaaaaaaaaaaaac......",
 
619
"...*aaaaaaaabbbbbbaaaaaaaac.....",
 
620
"..*aaaaaaaabaaabbbbaaaaaaaac....",
 
621
".*aaaaaaaabbaaaabbbbaaaaaaaac...",
 
622
".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
 
623
"*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
 
624
"*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
 
625
"*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
 
626
"*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
 
627
"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
 
628
"*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
 
629
"*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
 
630
".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
 
631
".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
 
632
"..*aaaaaaaaaabbbbaaaaaaaaaac***.",
 
633
"...caaaaaaaaaabbaaaaaaaaaac****.",
 
634
"....caaaaaaaaaaaaaaaaaaaac****..",
 
635
".....caaaaaaaaaaaaaaaaaac****...",
 
636
"......ccaaaaaaaaaaaaaacc****....",
 
637
".......*cccaaaaaaaaccc*****.....",
 
638
"........***cccaaaac*******......",
 
639
"..........****caaac*****........",
 
640
".............*caaac**...........",
 
641
"...............caac**...........",
 
642
"................cac**...........",
 
643
".................cc**...........",
 
644
"..................***...........",
 
645
"...................**..........."};
 
646
/* XPM */
 
647
static const char* const dir_open_xpm[]={
 
648
    "16 16 6 1",
 
649
    ". c None",
 
650
    "b c #ffff00",
 
651
    "d c #000000",
 
652
    "* c #999999",
 
653
    "c c #cccccc",
 
654
    "a c #ffffff",
 
655
    "................",
 
656
    "................",
 
657
    "...*****........",
 
658
    "..*aaaaa*.......",
 
659
    ".*abcbcba******.",
 
660
    ".*acbcbcaaaaaa*d",
 
661
    ".*abcbcbcbcbcb*d",
 
662
    "*************b*d",
 
663
    "*aaaaaaaaaa**c*d",
 
664
    "*abcbcbcbcbbd**d",
 
665
    ".*abcbcbcbcbcd*d",
 
666
    ".*acbcbcbcbcbd*d",
 
667
    "..*acbcbcbcbb*dd",
 
668
    "..*************d",
 
669
    "...ddddddddddddd",
 
670
    "................"};
 
671
 
 
672
/* XPM */
 
673
static const char * const dir_closed_xpm[]={
 
674
    "16 16 6 1",
 
675
    ". c None",
 
676
    "b c #ffff00",
 
677
    "d c #000000",
 
678
    "* c #999999",
 
679
    "a c #cccccc",
 
680
    "c c #ffffff",
 
681
    "................",
 
682
    "................",
 
683
    "..*****.........",
 
684
    ".*ababa*........",
 
685
    "*abababa******..",
 
686
    "*cccccccccccc*d.",
 
687
    "*cbababababab*d.",
 
688
    "*cabababababa*d.",
 
689
    "*cbababababab*d.",
 
690
    "*cabababababa*d.",
 
691
    "*cbababababab*d.",
 
692
    "*cabababababa*d.",
 
693
    "*cbababababab*d.",
 
694
    "**************d.",
 
695
    ".dddddddddddddd.",
 
696
    "................"};
 
697
 
 
698
/* XPM */
 
699
static const char * const dir_link_xpm[]={
 
700
    "16 16 10 1",
 
701
    "h c #808080",
 
702
    "g c #a0a0a0",
 
703
    "d c #000000",
 
704
    "b c #ffff00",
 
705
    "f c #303030",
 
706
    "# c #999999",
 
707
    "a c #cccccc",
 
708
    "e c #585858",
 
709
    "c c #ffffff",
 
710
    ". c None",
 
711
    "................",
 
712
    "................",
 
713
    "..#####.........",
 
714
    ".#ababa#........",
 
715
    "#abababa######..",
 
716
    "#cccccccccccc#d.",
 
717
    "#cbababababab#d.",
 
718
    "#cabababababa#d.",
 
719
    "#cbababdddddddd.",
 
720
    "#cababadccccccd.",
 
721
    "#cbababdcececcd.",
 
722
    "#cababadcefdfcd.",
 
723
    "#cbababdccgdhcd.",
 
724
    "#######dccchccd.",
 
725
    ".dddddddddddddd.",
 
726
    "................"};
 
727
/* XPM */
 
728
static const char* const file_xpm[]={
 
729
    "16 16 5 1",
 
730
    ". c #7f7f7f",
 
731
    "# c None",
 
732
    "c c #000000",
 
733
    "b c #bfbfbf",
 
734
    "a c #ffffff",
 
735
    "################",
 
736
    "..........######",
 
737
    ".aaaaaaaab.#####",
 
738
    ".aaaaaaaaba.####",
 
739
    ".aaaaaaaacccc###",
 
740
    ".aaaaaaaaaabc###",
 
741
    ".aaaaaaaaaabc###",
 
742
    ".aaaaaaaaaabc###",
 
743
    ".aaaaaaaaaabc###",
 
744
    ".aaaaaaaaaabc###",
 
745
    ".aaaaaaaaaabc###",
 
746
    ".aaaaaaaaaabc###",
 
747
    ".aaaaaaaaaabc###",
 
748
    ".aaaaaaaaaabc###",
 
749
    ".bbbbbbbbbbbc###",
 
750
    "ccccccccccccc###"};
 
751
/* XPM */
 
752
static const char * const file_link_xpm[]={
 
753
    "16 16 10 1",
 
754
    "h c #808080",
 
755
    "g c #a0a0a0",
 
756
    "d c #c3c3c3",
 
757
    ". c #7f7f7f",
 
758
    "c c #000000",
 
759
    "b c #bfbfbf",
 
760
    "f c #303030",
 
761
    "e c #585858",
 
762
    "a c #ffffff",
 
763
    "# c None",
 
764
    "################",
 
765
    "..........######",
 
766
    ".aaaaaaaab.#####",
 
767
    ".aaaaaaaaba.####",
 
768
    ".aaaaaaaacccc###",
 
769
    ".aaaaaaaaaabc###",
 
770
    ".aaaaaaaaaabc###",
 
771
    ".aaaaaaaaaadc###",
 
772
    ".aaaaaaaaaadc###",
 
773
    ".aaaacccccccc###",
 
774
    ".aaaacaaaaaac###",
 
775
    ".aaaacaeaeaac###",
 
776
    ".aaaacaefcfac###",
 
777
    ".aaaacaagchac###",
 
778
    ".ddddcaaahaac###",
 
779
    "ccccccccccccc###"};
 
780
 
 
781
 
 
782
 
 
783
#endif //QT_NO_IMAGEIO_XPM
 
784
 
 
785
/*!
 
786
 \reimp
 
787
 */
 
788
QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
 
789
                                      const QWidget *widget) const
 
790
{
 
791
#ifndef QT_NO_IMAGEIO_XPM
 
792
    switch (standardPixmap) {
 
793
    case SP_TitleBarMenuButton:
 
794
        return QPixmap((const char **)qt_menu_xpm);
 
795
    case SP_TitleBarShadeButton:
 
796
        return QPixmap((const char **)qt_shade_xpm);
 
797
    case SP_TitleBarUnshadeButton:
 
798
        return QPixmap((const char **)qt_unshade_xpm);
 
799
    case SP_TitleBarNormalButton:
 
800
        return QPixmap((const char **)qt_normalizeup_xpm);
 
801
    case SP_TitleBarMinButton:
 
802
        return QPixmap((const char **)qt_minimize_xpm);
 
803
    case SP_TitleBarMaxButton:
 
804
        return QPixmap((const char **)qt_maximize_xpm);
 
805
    case SP_TitleBarCloseButton:
 
806
        return QPixmap((const char **)qt_close_xpm);
 
807
    case SP_TitleBarContextHelpButton:
 
808
        return QPixmap((const char **)qt_help_xpm);
 
809
    case SP_DockWidgetCloseButton:
 
810
        return QPixmap((const char **)dock_widget_close_xpm);
 
811
    case SP_MessageBoxInformation:
 
812
        return QPixmap((const char **)information_xpm);
 
813
    case SP_MessageBoxWarning:
 
814
        return QPixmap((const char **)warning_xpm);
 
815
    case SP_MessageBoxCritical:
 
816
        return QPixmap((const char **)critical_xpm);
 
817
    case SP_MessageBoxQuestion:
 
818
        return QPixmap((const char **)question_xpm);
 
819
    default:
 
820
        break;
 
821
    }
 
822
#endif //QT_NO_IMAGEIO_XPM
 
823
    return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
 
824
}
 
825
 
 
826
/*! \reimp */
 
827
int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
 
828
                             QStyleHintReturn *returnData) const
 
829
{
 
830
    int ret;
 
831
 
 
832
    switch (hint) {
 
833
    case SH_EtchDisabledText:
 
834
    case SH_Slider_SnapToValue:
 
835
    case SH_PrintDialog_RightAlignButtons:
 
836
    case SH_MainWindow_SpaceBelowMenuBar:
 
837
    case SH_FontDialog_SelectAssociatedText:
 
838
    case SH_Menu_AllowActiveAndDisabled:
 
839
    case SH_MenuBar_AltKeyNavigation:
 
840
    case SH_MenuBar_MouseTracking:
 
841
    case SH_Menu_MouseTracking:
 
842
    case SH_ComboBox_ListMouseTracking:
 
843
    case SH_ScrollBar_StopMouseOverSlider:
 
844
        ret = 1;
 
845
        break;
 
846
    case SH_ItemView_ChangeHighlightOnFocus:
 
847
#if defined(Q_WS_WIN)
 
848
        if (QSysInfo::WindowsVersion != QSysInfo::WV_95 && QSysInfo::WindowsVersion != QSysInfo::WV_NT)
 
849
            ret = 1;
 
850
        else
 
851
#endif
 
852
            ret = 0;
 
853
        break;
 
854
    case SH_ToolBox_SelectedPageTitleBold:
 
855
        ret = 0;
 
856
        break;
 
857
 
 
858
#if defined(Q_WS_WIN)
 
859
    case SH_UnderlineShortcut:
 
860
        ret = 1;
 
861
        if (QSysInfo::WindowsVersion != QSysInfo::WV_95
 
862
            && QSysInfo::WindowsVersion != QSysInfo::WV_98
 
863
            && QSysInfo::WindowsVersion != QSysInfo::WV_NT) {
 
864
            BOOL cues;
 
865
            SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
 
866
            ret = int(cues);
 
867
            // Do nothing if we always paint underlines
 
868
            if (!ret && widget && d) {
 
869
                const QMenuBar *menuBar = ::qobject_cast<const QMenuBar*>(widget);
 
870
                if (!menuBar && ::qobject_cast<const QMenu *>(widget)) {
 
871
                    QWidget *w = QApplication::activeWindow();
 
872
                    if (w && w != widget)
 
873
                        menuBar = qFindChild<QMenuBar *>(w);
 
874
                }
 
875
                // If we paint a menubar draw underlines if it has focus, or if alt is down,
 
876
                // or if a popup menu belonging to the menubar is active and paints underlines
 
877
                if (menuBar) {
 
878
                    if (menuBar->hasFocus() || d->altDown())
 
879
                        ret = 1;
 
880
                    // Otherwise draw underlines if the toplevel widget has seen an alt-press
 
881
                } else if (d->hasSeenAlt(widget)) {
 
882
                    ret = 1;
 
883
                }
 
884
            }
 
885
        }
 
886
        break;
 
887
#endif
 
888
    default:
 
889
        ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
 
890
        break;
 
891
    }
 
892
    return ret;
 
893
}
 
894
 
 
895
/*! \reimp */
 
896
void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
 
897
                                  const QWidget *w) const
 
898
{
 
899
    // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
 
900
    bool doRestore = false;
 
901
 
 
902
    switch (pe) {
 
903
    case PE_FrameButtonTool:
 
904
    case PE_PanelButtonTool: {
 
905
        QBrush fill;
 
906
        bool stippled;
 
907
        bool panel = (pe == PE_PanelButtonTool);
 
908
        if (!(opt->state & (State_Sunken | State_MouseOver)) && (opt->state & State_On)
 
909
                && use2000style) {
 
910
            fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
 
911
            stippled = true;
 
912
        } else {
 
913
            fill = opt->palette.brush(QPalette::Button);
 
914
            stippled = false;
 
915
        }
 
916
 
 
917
        if (opt->state & (State_Raised | State_Sunken | State_On)) {
 
918
            if (opt->state & State_AutoRaise) {
 
919
                if (panel)
 
920
                    qDrawShadePanel(p, opt->rect, opt->palette,
 
921
                            opt->state & (State_Sunken | State_On), 1, &fill);
 
922
                else
 
923
                    qDrawShadeRect(p, opt->rect, opt->palette,
 
924
                                   opt->state & (State_Sunken | State_On), 1);
 
925
                if (stippled) {
 
926
                    p->setPen(opt->palette.button().color());
 
927
                    p->drawRect(opt->rect.adjusted(1,1,-2,-2));
 
928
                }
 
929
            } else {
 
930
                qDrawWinButton(p, opt->rect, opt->palette,
 
931
                               opt->state & (State_Sunken | State_On), panel ? &fill : 0);
 
932
            }
 
933
        } else {
 
934
            p->fillRect(opt->rect, fill);
 
935
        }
 
936
        break; }
 
937
    case PE_PanelButtonCommand:
 
938
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
939
            QBrush fill;
 
940
            State flags = opt->state;
 
941
            QPalette pal = opt->palette;
 
942
            QRect r = opt->rect;
 
943
            if (! (flags & State_Sunken) && (flags & State_On))
 
944
                fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
 
945
            else
 
946
                fill = pal.brush(QPalette::Button);
 
947
 
 
948
            if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
 
949
                p->setPen(pal.dark().color());
 
950
                p->setBrush(fill);
 
951
                p->drawRect(r);
 
952
            } else if (flags & (State_Raised | State_Sunken | State_On | State_Sunken)) {
 
953
                qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
 
954
                               &fill);
 
955
            } else {
 
956
                p->fillRect(r, fill);
 
957
            }
 
958
        }
 
959
        break;
 
960
    case PE_FrameDefaultButton: {
 
961
        p->setPen(opt->palette.shadow().color());
 
962
        QRect rect = opt->rect;
 
963
        rect.adjust(0, 0, -1, -1);
 
964
        p->drawRect(rect);
 
965
        break;
 
966
    }
 
967
    case PE_IndicatorArrowUp:
 
968
    case PE_IndicatorArrowDown:
 
969
    case PE_IndicatorArrowRight:
 
970
    case PE_IndicatorArrowLeft: {
 
971
        QPoint points[7];
 
972
        switch (pe) {
 
973
            case PE_IndicatorArrowUp:
 
974
                points[0] = QPoint(-4, 1);
 
975
                points[1] = QPoint(2, 1);
 
976
                points[2] = QPoint(-3, 0);
 
977
                points[3] = QPoint(1, 0);
 
978
                points[4] = QPoint(-2, -1);
 
979
                points[5] = QPoint(0, -1);
 
980
                points[6] = QPoint(-1, -2);
 
981
                break;
 
982
            case PE_IndicatorArrowDown:
 
983
                points[0] = QPoint(-4, -2);
 
984
                points[1] = QPoint(2, -2);
 
985
                points[2] = QPoint(-3, -1);
 
986
                points[3] = QPoint(1, -1);
 
987
                points[4] = QPoint(-2, 0);
 
988
                points[5] = QPoint(0, 0);
 
989
                points[6] = QPoint(-1, 1);
 
990
                break;
 
991
            case PE_IndicatorArrowRight:
 
992
                points[0] = QPoint(-2, -3);
 
993
                points[1] = QPoint(-2, 3);
 
994
                points[2] = QPoint(-1, -2);
 
995
                points[3] = QPoint(-1, 2);
 
996
                points[4] = QPoint(0, -1);
 
997
                points[5] = QPoint(0, 1);
 
998
                points[6] = QPoint(1, 0);
 
999
                break;
 
1000
            case PE_IndicatorArrowLeft:
 
1001
                points[0] = QPoint(0, -3);
 
1002
                points[1] = QPoint(0, 3);
 
1003
                points[2] = QPoint(-1, -2);
 
1004
                points[3] = QPoint(-1, 2);
 
1005
                points[4] = QPoint(-2, -1);
 
1006
                points[5] = QPoint(-2, 1);
 
1007
                points[6] = QPoint(-3, 0);
 
1008
                break;
 
1009
            default:
 
1010
                break;
 
1011
        }
 
1012
        p->save();
 
1013
        if (opt->state & State_Sunken)
 
1014
            p->translate(pixelMetric(PM_ButtonShiftHorizontal),
 
1015
                         pixelMetric(PM_ButtonShiftVertical));
 
1016
        if (opt->state & State_Enabled) {
 
1017
            p->translate(opt->rect.x() + opt->rect.width() / 2,
 
1018
                         opt->rect.y() + opt->rect.height() / 2);
 
1019
            p->setPen(opt->palette.buttonText().color());
 
1020
            p->drawLine(points[0], points[1]);
 
1021
            p->drawLine(points[2], points[3]);
 
1022
            p->drawLine(points[4], points[5]);
 
1023
            p->drawPoint(points[6]);
 
1024
        } else {
 
1025
            p->translate(opt->rect.x() + opt->rect.width() / 2 + 1,
 
1026
                         opt->rect.y() + opt->rect.height() / 2 + 1);
 
1027
            p->setPen(opt->palette.light().color());
 
1028
            p->drawLine(points[0], points[1]);
 
1029
            p->drawLine(points[2], points[3]);
 
1030
            p->drawLine(points[4], points[5]);
 
1031
            p->drawPoint(points[6]);
 
1032
            p->translate(-1, -1);
 
1033
            p->setPen(opt->palette.mid().color());
 
1034
            p->drawLine(points[0], points[1]);
 
1035
            p->drawLine(points[2], points[3]);
 
1036
            p->drawLine(points[4], points[5]);
 
1037
            p->drawPoint(points[6]);
 
1038
        }
 
1039
        p->restore();
 
1040
        break; }
 
1041
    case PE_IndicatorCheckBox: {
 
1042
        QBrush fill;
 
1043
        if (opt->state & State_NoChange)
 
1044
            fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
 
1045
        else if (opt->state & State_Sunken)
 
1046
            fill = opt->palette.button();
 
1047
        else if (opt->state & State_Enabled)
 
1048
            fill = opt->palette.base();
 
1049
        else
 
1050
            fill = opt->palette.background();
 
1051
        p->save();
 
1052
        doRestore = true;
 
1053
        qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
 
1054
        if (opt->state & State_NoChange)
 
1055
            p->setPen(opt->palette.dark().color());
 
1056
        else
 
1057
            p->setPen(opt->palette.text().color());
 
1058
        } // Fall through!
 
1059
    case PE_IndicatorViewItemCheck:
 
1060
    case PE_Q3CheckListIndicator:
 
1061
        if (!doRestore) {
 
1062
            p->save();
 
1063
            doRestore = true;
 
1064
        }
 
1065
        if (pe == PE_Q3CheckListIndicator || pe == PE_IndicatorViewItemCheck) {
 
1066
            if (opt->state & State_Enabled)
 
1067
                p->setPen(QPen(opt->palette.text().color(), 1));
 
1068
            else
 
1069
                p->setPen(QPen(opt->palette.dark().color(), 1));
 
1070
            if (opt->state & State_NoChange)
 
1071
                p->setBrush(opt->palette.brush(QPalette::Button));
 
1072
            p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
 
1073
        }
 
1074
        if (!(opt->state & State_Off)) {
 
1075
            QLineF lines[7];
 
1076
            int i, xx, yy;
 
1077
            xx = opt->rect.x() + 3;
 
1078
            yy = opt->rect.y() + 5;
 
1079
            for (i = 0; i < 3; ++i) {
 
1080
                lines[i] = QLineF(xx, yy, xx, yy + 2);
 
1081
                ++xx;
 
1082
                ++yy;
 
1083
            }
 
1084
            yy -= 2;
 
1085
            for (i = 3; i < 7; ++i) {
 
1086
                lines[i] = QLineF(xx, yy, xx, yy + 2);
 
1087
                ++xx;
 
1088
                --yy;
 
1089
            }
 
1090
            p->drawLines(lines, 7);
 
1091
        }
 
1092
        if (doRestore)
 
1093
            p->restore();
 
1094
        break;
 
1095
    case PE_FrameFocusRect:
 
1096
        if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
 
1097
            if (!(fropt->state & State_KeyboardFocusChange))
 
1098
                return;
 
1099
            QRect r = opt->rect;
 
1100
            p->save();
 
1101
            p->setBackgroundMode(Qt::TransparentMode);
 
1102
            QColor bg_col = fropt->backgroundColor;
 
1103
            if (!bg_col.isValid())
 
1104
                bg_col = p->background().color();
 
1105
            // Create an "XOR" color.
 
1106
            QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
 
1107
                              (bg_col.green() ^ 0xff) & 0xff,
 
1108
                              (bg_col.blue() ^ 0xff) & 0xff);
 
1109
            p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
 
1110
            p->setBrushOrigin(r.topLeft());
 
1111
            p->setPen(Qt::NoPen);
 
1112
            p->drawRect(r.left(), r.top(), r.width(), 1);    // Top
 
1113
            p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
 
1114
            p->drawRect(r.left(), r.top(), 1, r.height());   // Left
 
1115
            p->drawRect(r.right(), r.top(), 1, r.height());  // Right
 
1116
            p->restore();
 
1117
        }
 
1118
        break;
 
1119
    case PE_IndicatorRadioButton:
 
1120
        {
 
1121
#define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
 
1122
            static const QPoint pts1[] = {              // dark lines
 
1123
                QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
 
1124
                QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)
 
1125
            };
 
1126
            static const QPoint pts2[] = {              // black lines
 
1127
                QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),
 
1128
                QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)
 
1129
            };
 
1130
            static const QPoint pts3[] = {              // background lines
 
1131
                QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),
 
1132
                QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)
 
1133
            };
 
1134
            static const QPoint pts4[] = {              // white lines
 
1135
                QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),
 
1136
                QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),
 
1137
                QPoint(10, 3), QPoint(10, 2)
 
1138
            };
 
1139
            static const QPoint pts5[] = {              // inner fill
 
1140
                QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),
 
1141
                QPoint(2, 7), QPoint(2, 4)
 
1142
            };
 
1143
 
 
1144
            // make sure the indicator is square
 
1145
            QRect ir = opt->rect;
 
1146
 
 
1147
            if (opt->rect.width() < opt->rect.height()) {
 
1148
                ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
 
1149
                ir.setHeight(opt->rect.width());
 
1150
            } else if (opt->rect.height() < opt->rect.width()) {
 
1151
                ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
 
1152
                ir.setWidth(opt->rect.height());
 
1153
            }
 
1154
 
 
1155
            p->save();
 
1156
            bool down = opt->state & State_Sunken;
 
1157
            bool enabled = opt->state & State_Enabled;
 
1158
            bool on = opt->state & State_On;
 
1159
            QPolygon a;
 
1160
            p->translate(ir.x(), ir.y());
 
1161
 
 
1162
            p->setPen(opt->palette.dark().color());
 
1163
            p->drawPolyline(pts1, PTSARRLEN(pts1));
 
1164
 
 
1165
            p->setPen(opt->palette.shadow().color());
 
1166
            p->drawPolyline(pts2, PTSARRLEN(pts2));
 
1167
 
 
1168
            p->setPen(opt->palette.midlight().color());
 
1169
            p->drawPolyline(pts3, PTSARRLEN(pts3));
 
1170
 
 
1171
            p->setPen(opt->palette.light().color());
 
1172
            p->drawPolyline(pts4, PTSARRLEN(pts4));
 
1173
 
 
1174
            QColor fillColor = (down || !enabled)
 
1175
                               ? opt->palette.button().color()
 
1176
                               : opt->palette.base().color();
 
1177
            p->setPen(fillColor);
 
1178
            p->setBrush(fillColor) ;
 
1179
            p->drawPolygon(pts5, PTSARRLEN(pts5));
 
1180
 
 
1181
            p->translate(-ir.x(), -ir.y()); // restore translate
 
1182
 
 
1183
            if (on) {
 
1184
                p->setPen(Qt::NoPen);
 
1185
                p->setBrush(opt->palette.text());
 
1186
                p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4);
 
1187
                p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2);
 
1188
            }
 
1189
            p->restore();
 
1190
            break;
 
1191
        }
 
1192
    case PE_Frame:
 
1193
    case PE_FrameMenu:
 
1194
        if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
 
1195
            if (frame->lineWidth == 2) {
 
1196
                QPalette popupPal = frame->palette;
 
1197
                if (pe == PE_FrameMenu) {
 
1198
                    popupPal.setColor(QPalette::Light, frame->palette.background().color());
 
1199
                    popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
 
1200
                }
 
1201
                qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
 
1202
            } else {
 
1203
                QCommonStyle::drawPrimitive(pe, opt, p, w);
 
1204
            }
 
1205
        }
 
1206
        break;
 
1207
    case PE_IndicatorBranch: {
 
1208
        // This is _way_ too similar to the common style.
 
1209
        static const int decoration_size = 9;
 
1210
        int mid_h = opt->rect.x() + opt->rect.width() / 2;
 
1211
        int mid_v = opt->rect.y() + opt->rect.height() / 2;
 
1212
        int bef_h = mid_h;
 
1213
        int bef_v = mid_v;
 
1214
        int aft_h = mid_h;
 
1215
        int aft_v = mid_v;
 
1216
        if (opt->state & State_Children) {
 
1217
            int delta = decoration_size / 2;
 
1218
            bef_h -= delta;
 
1219
            bef_v -= delta;
 
1220
            aft_h += delta;
 
1221
            aft_v += delta;
 
1222
            p->drawLine(bef_h + 2, bef_v + 4, bef_h + 6, bef_v + 4);
 
1223
            if (!(opt->state & State_Open))
 
1224
                p->drawLine(bef_h + 4, bef_v + 2, bef_h + 4, bef_v + 6);
 
1225
            QPen oldPen = p->pen();
 
1226
            p->setPen(opt->palette.dark().color());
 
1227
            p->drawRect(bef_h, bef_v, decoration_size - 1, decoration_size - 1);
 
1228
            p->setPen(oldPen);
 
1229
        }
 
1230
        QBrush brush(opt->palette.dark().color(), Qt::Dense4Pattern);
 
1231
        if (opt->state & State_Item) {
 
1232
            if (QApplication::isRightToLeft())
 
1233
                p->fillRect(opt->rect.left(), mid_v, bef_h - opt->rect.left(), 1, brush);
 
1234
            else
 
1235
                p->fillRect(aft_h, mid_v, opt->rect.right() - aft_h + 1, 1, brush);
 
1236
        }
 
1237
        if (opt->state & State_Sibling)
 
1238
            p->fillRect(mid_h, aft_v, 1, opt->rect.bottom() - aft_v + 1, brush);
 
1239
        if (opt->state & (State_Open | State_Children | State_Item | State_Sibling))
 
1240
            p->fillRect(mid_h, opt->rect.y(), 1, bef_v - opt->rect.y(), brush);
 
1241
        break; }
 
1242
    case PE_FrameButtonBevel:
 
1243
    case PE_PanelButtonBevel: {
 
1244
        QBrush fill;
 
1245
        bool panel = pe != PE_FrameButtonBevel;
 
1246
        p->setBrushOrigin(opt->rect.topLeft());
 
1247
        if (!(opt->state & State_Sunken) && (opt->state & State_On))
 
1248
            fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
 
1249
        else
 
1250
            fill = opt->palette.brush(QPalette::Button);
 
1251
 
 
1252
        if (opt->state & (State_Raised | State_On | State_Sunken)) {
 
1253
            qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
 
1254
                           panel ? &fill : 0);
 
1255
        } else {
 
1256
            if (panel)
 
1257
                p->fillRect(opt->rect, fill);
 
1258
            else
 
1259
                p->drawRect(opt->rect);
 
1260
        }
 
1261
        break; }
 
1262
    case PE_FrameWindow: {
 
1263
         QPalette popupPal = opt->palette;
 
1264
         popupPal.setColor(QPalette::Light, opt->palette.background().color());
 
1265
         popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
 
1266
         qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
 
1267
        break; }
 
1268
    case PE_IndicatorDockWidgetResizeHandle: {
 
1269
        QPen oldPen = p->pen();
 
1270
        p->setPen(opt->palette.light().color());
 
1271
        if (opt->state & State_Horizontal) {
 
1272
            p->drawLine(opt->rect.left(),          opt->rect.top(),
 
1273
                        opt->rect.right(), opt->rect.top());
 
1274
            p->setPen(opt->palette.dark().color());
 
1275
            p->drawLine(opt->rect.left(),          opt->rect.bottom() - 1,
 
1276
                        opt->rect.right(), opt->rect.bottom() - 1);
 
1277
            p->setPen(opt->palette.shadow().color());
 
1278
            p->drawLine(opt->rect.left(),          opt->rect.bottom(),
 
1279
                        opt->rect.right(), opt->rect.bottom());
 
1280
        } else {
 
1281
            p->drawLine(opt->rect.left(), opt->rect.top(),
 
1282
                        opt->rect.left(), opt->rect.bottom());
 
1283
            p->setPen(opt->palette.dark().color());
 
1284
            p->drawLine(opt->rect.right() - 1, opt->rect.top(),
 
1285
                        opt->rect.right() - 1, opt->rect.bottom());
 
1286
            p->setPen(opt->palette.shadow().color());
 
1287
            p->drawLine(opt->rect.right(), opt->rect.top(),
 
1288
                        opt->rect.right(), opt->rect.bottom());
 
1289
        }
 
1290
        p->setPen(oldPen);
 
1291
        break; }
 
1292
    default:
 
1293
        QCommonStyle::drawPrimitive(pe, opt, p, w);
 
1294
    }
 
1295
}
 
1296
 
 
1297
/*! \reimp */
 
1298
void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
 
1299
                                const QWidget *widget) const
 
1300
{
 
1301
    switch (ce) {
 
1302
    case CE_MenuItem:
 
1303
        if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
 
1304
            int x, y, w, h;
 
1305
            menuitem->rect.getRect(&x, &y, &w, &h);
 
1306
            int tab = menuitem->tabWidth;
 
1307
            bool dis = !(menuitem->state & State_Enabled);
 
1308
            bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
 
1309
                            ? menuitem->checked : false;
 
1310
            bool act = menuitem->state & State_Selected;
 
1311
 
 
1312
            // windows always has a check column, regardless whether we have an icon or not
 
1313
            int checkcol = qMax(menuitem->maxIconWidth, use2000style ? 20 : windowsCheckMarkWidth);
 
1314
 
 
1315
            if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
 
1316
                p->setPen(menuitem->palette.dark().color());
 
1317
                p->drawLine(x, y, x + w, y);
 
1318
                p->setPen(menuitem->palette.light().color());
 
1319
                p->drawLine(x, y + 1, x + w, y + 1);
 
1320
                return;
 
1321
            }
 
1322
 
 
1323
            QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
 
1324
            p->fillRect(menuitem->rect, fill);
 
1325
 
 
1326
            QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
 
1327
            if (checked) {
 
1328
                if (act && !dis) {
 
1329
                    qDrawShadePanel(p, vCheckRect,
 
1330
                                    menuitem->palette, true, 1,
 
1331
                                    &menuitem->palette.brush(QPalette::Button));
 
1332
                } else {
 
1333
                    QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
 
1334
                    qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
 
1335
                }
 
1336
            } else if (!act) {
 
1337
                p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
 
1338
            }
 
1339
 
 
1340
            // On Windows Style, if we have a checkable item and an icon we
 
1341
            // draw the icon recessed to indicate an item is checked. If we
 
1342
            // have no icon, we draw a checkmark instead.
 
1343
            if (!menuitem->icon.isNull()) {
 
1344
                QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
 
1345
                if (act && !dis)
 
1346
                    mode = QIcon::Active;
 
1347
                QPixmap pixmap;
 
1348
                if (checked)
 
1349
                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode, QIcon::On);
 
1350
                else
 
1351
                    pixmap = menuitem->icon.pixmap(pixelMetric(PM_SmallIconSize), mode);
 
1352
                int pixw = pixmap.width();
 
1353
                int pixh = pixmap.height();
 
1354
                if (act && !dis && !checked)
 
1355
                    qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
 
1356
                                    &menuitem->palette.brush(QPalette::Button));
 
1357
                QRect pmr(0, 0, pixw, pixh);
 
1358
                pmr.moveCenter(vCheckRect.center());
 
1359
                p->setPen(menuitem->palette.text().color());
 
1360
                p->drawPixmap(pmr.topLeft(), pixmap);
 
1361
            } else if (checked) {
 
1362
                QStyleOptionMenuItem newMi = *menuitem;
 
1363
                newMi.state = State_None;
 
1364
                if (!dis)
 
1365
                    newMi.state |= State_Enabled;
 
1366
                if (act)
 
1367
                    newMi.state |= State_On;
 
1368
                newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + windowsItemFrame, menuitem->rect.y() + windowsItemFrame,
 
1369
                                                                              checkcol - 2 * windowsItemFrame, menuitem->rect.height() - 2*windowsItemFrame));
 
1370
                drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
 
1371
            }
 
1372
            p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
 
1373
 
 
1374
            QColor discol;
 
1375
            if (dis) {
 
1376
                discol = menuitem->palette.text().color();
 
1377
                p->setPen(discol);
 
1378
            }
 
1379
 
 
1380
            int xm = windowsItemFrame + checkcol + windowsItemHMargin;
 
1381
            int xpos = menuitem->rect.x() + xm;
 
1382
            QRect textRect(xpos, y + windowsItemVMargin, w - xm - windowsRightBorder - tab + 1, h - 2 * windowsItemVMargin);
 
1383
            QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
 
1384
            QString s = menuitem->text;
 
1385
            if (!s.isEmpty()) {                     // draw text
 
1386
                p->save();
 
1387
                int t = s.indexOf('\t');
 
1388
                int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
 
1389
                if (!styleHint(SH_UnderlineShortcut, menuitem, widget))
 
1390
                    text_flags |= Qt::TextHideMnemonic;
 
1391
                text_flags |= Qt::AlignLeft;
 
1392
                if (t >= 0) {
 
1393
                    QRect vShortcutRect = visualRect(opt->direction, menuitem->rect, QRect(textRect.topRight(), menuitem->rect.bottomRight()));
 
1394
                    if (dis && !act) {
 
1395
                        p->setPen(menuitem->palette.light().color());
 
1396
                        p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
 
1397
                        p->setPen(discol);
 
1398
                    }
 
1399
                    p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
 
1400
                    s = s.left(t);
 
1401
                }
 
1402
                QFont font = menuitem->font;
 
1403
                if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
 
1404
                    font.setBold(true);
 
1405
                p->setFont(font);
 
1406
                if (dis && !act) {
 
1407
                    p->setPen(menuitem->palette.light().color());
 
1408
                    p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
 
1409
                    p->setPen(discol);
 
1410
                }
 
1411
                p->drawText(vTextRect, text_flags, s.left(t));
 
1412
                p->restore();
 
1413
            }
 
1414
            if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
 
1415
                int dim = (h - 2 * windowsItemFrame) / 2;
 
1416
                PrimitiveElement arrow;
 
1417
                arrow = QApplication::isRightToLeft() ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
 
1418
                xpos = x + w - windowsArrowHMargin - windowsItemFrame - dim;
 
1419
                QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
 
1420
                QStyleOptionMenuItem newMI = *menuitem;
 
1421
                newMI.rect = vSubMenuRect;
 
1422
                newMI.state = dis ? State_None : State_Enabled;
 
1423
                if (act)
 
1424
                    newMI.palette.setColor(QPalette::ButtonText,
 
1425
                                           newMI.palette.highlightedText().color());
 
1426
                drawPrimitive(arrow, &newMI, p, widget);
 
1427
            }
 
1428
 
 
1429
        }
 
1430
        break;
 
1431
    case CE_MenuBarItem:
 
1432
        if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
 
1433
            bool active = mbi->state & State_Selected;
 
1434
            bool hasFocus = mbi->state & State_HasFocus;
 
1435
            bool down = mbi->state & State_Sunken;
 
1436
            QStyleOptionMenuItem newMbi = *mbi;
 
1437
            p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button));
 
1438
            if (active || hasFocus) {
 
1439
                QBrush b = mbi->palette.brush(QPalette::Button);
 
1440
                if (active && down)
 
1441
                    p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
 
1442
                if (active && hasFocus)
 
1443
                    qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
 
1444
                                   mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
 
1445
                if (active && down) {
 
1446
                    newMbi.rect.translate(pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
 
1447
                                       pixelMetric(PM_ButtonShiftVertical, mbi, widget));
 
1448
                    p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
 
1449
                }
 
1450
            }
 
1451
            QCommonStyle::drawControl(ce, &newMbi, p, widget);
 
1452
        }
 
1453
        break;
 
1454
    case CE_TabBarTabShape:
 
1455
        if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
 
1456
            bool rtlHorTabs = (tab->direction == Qt::RightToLeft
 
1457
                               && (tab->shape == QTabBar::RoundedNorth
 
1458
                                   || tab->shape == QTabBar::RoundedSouth));
 
1459
            bool selected = tab->state & State_Selected;
 
1460
            bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
 
1461
                            || (rtlHorTabs
 
1462
                                && tab->position == QStyleOptionTab::Beginning));
 
1463
            bool firstTab = ((!rtlHorTabs
 
1464
                               && tab->position == QStyleOptionTab::Beginning)
 
1465
                             || (rtlHorTabs
 
1466
                                 && tab->position == QStyleOptionTab::End));
 
1467
            bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
 
1468
            bool previousSelected =
 
1469
                ((!rtlHorTabs
 
1470
                  && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
 
1471
                || (rtlHorTabs
 
1472
                    && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
 
1473
            bool nextSelected =
 
1474
                ((!rtlHorTabs
 
1475
                  && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
 
1476
                 || (rtlHorTabs
 
1477
                     && tab->selectedPosition
 
1478
                            == QStyleOptionTab::PreviousIsSelected));
 
1479
            int tabBarAlignment = styleHint(SH_TabBar_Alignment, tab, widget);
 
1480
            bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
 
1481
                                || (rtlHorTabs
 
1482
                                    && tabBarAlignment == Qt::AlignRight);
 
1483
 
 
1484
            bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
 
1485
                                 || (rtlHorTabs
 
1486
                                         && tabBarAlignment == Qt::AlignLeft);
 
1487
 
 
1488
            QColor light = tab->palette.light().color();
 
1489
            QColor midlight = tab->palette.midlight().color();
 
1490
            QColor dark = tab->palette.dark().color();
 
1491
            QColor shadow = tab->palette.shadow().color();
 
1492
            QColor background = tab->palette.background().color();
 
1493
            int borderThinkness = pixelMetric(PM_TabBarBaseOverlap, tab, widget);
 
1494
            if (selected)
 
1495
                borderThinkness /= 2;
 
1496
            QRect r2(opt->rect);
 
1497
            int x1 = r2.left();
 
1498
            int x2 = r2.right();
 
1499
            int y1 = r2.top();
 
1500
            int y2 = r2.bottom();
 
1501
            switch (tab->shape) {
 
1502
            default:
 
1503
                QCommonStyle::drawControl(ce, tab, p, widget);
 
1504
                break;
 
1505
            case QTabBar::RoundedNorth: {
 
1506
                if (!selected) {
 
1507
                    y1 += 2;
 
1508
                    x1 += firstTab ? borderThinkness : 0;
 
1509
                    x2 -= lastTab ? borderThinkness : 0;
 
1510
                }
 
1511
                // Delete border
 
1512
                if (selected) {
 
1513
                    p->setPen(background);
 
1514
                    p->drawLine(x1, y2 - 1, x2, y2 - 1);
 
1515
                    p->drawLine(x1, y2, x2, y2);
 
1516
                }
 
1517
                // Left
 
1518
                if (firstTab || selected || onlyOne || !previousSelected) {
 
1519
                    p->setPen(light);
 
1520
                    p->drawLine(x1, y1 + 2, x1, y2 - (firstTab && selected && leftAligned ? 0 : borderThinkness));
 
1521
                    p->drawPoint(x1 + 1, y1 + 1);
 
1522
                    p->setPen(midlight);
 
1523
                    p->drawLine(x1 + 1, y1 + 2, x1 + 1, y2 - (firstTab && selected && leftAligned ? 0 : borderThinkness));
 
1524
                }
 
1525
                // Top
 
1526
                {
 
1527
                    int beg = x1 + (previousSelected ? 0 : 2);
 
1528
                    int end = x2 - (nextSelected ? 0 : 2);
 
1529
                    p->setPen(light);
 
1530
                    p->drawLine(beg, y1, end, y1);
 
1531
                    p->setPen(midlight);
 
1532
                    p->drawLine(beg, y1 + 1, end, y1 + 1);
 
1533
                }
 
1534
                // Right
 
1535
                if (lastTab || selected || onlyOne || !nextSelected) {
 
1536
                    p->setPen(shadow);
 
1537
                    p->drawLine(x2, y1 + 2, x2, y2 - (lastTab && selected && rightAligned ? 0 : borderThinkness));
 
1538
                    p->drawPoint(x2 - 1, y1 + 1);
 
1539
                    p->setPen(dark);
 
1540
                    p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - (lastTab && selected && rightAligned ? 0 : borderThinkness));
 
1541
                }
 
1542
                break; }
 
1543
            case QTabBar::RoundedSouth: {
 
1544
                if (!selected) {
 
1545
                    y2 -= 2;
 
1546
                    x1 += firstTab ? borderThinkness : 0;
 
1547
                    x2 -= lastTab ? borderThinkness : 0;
 
1548
                }
 
1549
                // Delete border
 
1550
                if (selected) {
 
1551
                    p->setPen(background);
 
1552
                    p->drawLine(x1, y1 + 1, x2, y1 + 1);
 
1553
                    p->drawLine(x1, y1, x2, y1);
 
1554
                }
 
1555
                // Left
 
1556
                if (firstTab || selected || onlyOne || !previousSelected) {
 
1557
                    p->setPen(light);
 
1558
                    p->drawLine(x1, y2 - 2, x1, y1 + (firstTab && selected && leftAligned ? 0 : borderThinkness));
 
1559
                    p->drawPoint(x1 + 1, y2 - 1);
 
1560
                    p->setPen(midlight);
 
1561
                    p->drawLine(x1 + 1, y2 - 2, x1 + 1, y1 + (firstTab && selected && leftAligned ? 0 : borderThinkness));
 
1562
                }
 
1563
                // Bottom
 
1564
                {
 
1565
                    int beg = x1 + (previousSelected ? 0 : 2);
 
1566
                    int end = x2 - (nextSelected ? 0 : 2);
 
1567
                    p->setPen(shadow);
 
1568
                    p->drawLine(beg, y2, end, y2);
 
1569
                    p->setPen(dark);
 
1570
                    p->drawLine(beg, y2 - 1, end, y2 - 1);
 
1571
                }
 
1572
                // Right
 
1573
                if (lastTab || selected || onlyOne || !nextSelected) {
 
1574
                    p->setPen(shadow);
 
1575
                    p->drawLine(x2, y2 - 2, x2, y1 + (lastTab && selected && rightAligned ? 0 : borderThinkness));
 
1576
                    p->drawPoint(x2 - 1, y2 - 1);
 
1577
                    p->setPen(dark);
 
1578
                    p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + (lastTab && selected && rightAligned ? 0 : borderThinkness));
 
1579
                }
 
1580
                break; }
 
1581
            case QTabBar::RoundedWest: {
 
1582
                if (!selected) {
 
1583
                    x1 += 2;
 
1584
                    y1 += firstTab ? borderThinkness : 0;
 
1585
                    y2 -= lastTab ? borderThinkness : 0;
 
1586
                }
 
1587
                // Delete border
 
1588
                if (selected) {
 
1589
                    p->setPen(background);
 
1590
                    p->drawLine(x2 - 1, y1, x2 - 1, y2);
 
1591
                    p->drawLine(x2, y1, x2, y2);
 
1592
                }
 
1593
                // Top
 
1594
                if (firstTab || selected || onlyOne || !previousSelected) {
 
1595
                    p->setPen(light);
 
1596
                    p->drawLine(x1 + 2, y1, x2 - (firstTab && selected && leftAligned ? 0 : borderThinkness), y1);
 
1597
                    p->drawPoint(x1 + 1, y1 + 1);
 
1598
                    p->setPen(midlight);
 
1599
                    p->drawLine(x1 + 2, y1 + 1, x2 - (firstTab && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
 
1600
                }
 
1601
                // Left
 
1602
                {
 
1603
                    int beg = y1 + (previousSelected ? 0 : 2);
 
1604
                    int end = y2 - (nextSelected ? 0 : 2);
 
1605
                    p->setPen(light);
 
1606
                    p->drawLine(x1, beg, x1, end);
 
1607
                    p->setPen(midlight);
 
1608
                    p->drawLine(x1 + 1, beg, x1 + 1, end);
 
1609
                }
 
1610
                // Bottom
 
1611
                if (lastTab || selected || onlyOne || !nextSelected) {
 
1612
                    p->setPen(shadow);
 
1613
                    p->drawLine(x1 + 3, y2, x2 - (lastTab && selected && rightAligned ? 0 : borderThinkness), y2);
 
1614
                    p->drawPoint(x1 + 2, y2 - 1);
 
1615
                    p->setPen(dark);
 
1616
                    p->drawLine(x1 + 3, y2 - 1, x2 - (lastTab && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
 
1617
                    p->drawPoint(x1 + 1, y2 - 1);
 
1618
                    p->drawPoint(x1 + 2, y2);
 
1619
                }
 
1620
                break; }
 
1621
            case QTabBar::RoundedEast: {
 
1622
                if (!selected) {
 
1623
                    x2 -= 2;
 
1624
                    y1 += firstTab ? borderThinkness : 0;
 
1625
                    y2 -= lastTab ? borderThinkness : 0;
 
1626
                }
 
1627
                // Delete border
 
1628
                if (selected) {
 
1629
                    p->setPen(background);
 
1630
                    p->drawLine(x1 + 1, y1, x1 + 1, y2);
 
1631
                    p->drawLine(x1, y1, x1, y2);
 
1632
                }
 
1633
                // Top
 
1634
                if (firstTab || selected || onlyOne || !previousSelected) {
 
1635
                    p->setPen(light);
 
1636
                    p->drawLine(x2 - 2, y1, x1 + (firstTab && selected && leftAligned ? 0 : borderThinkness), y1);
 
1637
                    p->drawPoint(x2 - 1, y1 + 1);
 
1638
                    p->setPen(midlight);
 
1639
                    p->drawLine(x2 - 3, y1 + 1, x1 + (firstTab && selected && leftAligned ? 0 : borderThinkness), y1 + 1);
 
1640
                    p->drawPoint(x2 - 1, y1);
 
1641
                }
 
1642
                // Right
 
1643
                {
 
1644
                    int beg = y1 + (previousSelected ? 0 : 2);
 
1645
                    int end = y2 - (nextSelected ? 0 : 2);
 
1646
                    p->setPen(shadow);
 
1647
                    p->drawLine(x2, beg, x2, end);
 
1648
                    p->setPen(dark);
 
1649
                    p->drawLine(x2 - 1, beg, x2 - 1, end);
 
1650
                }
 
1651
                // Bottom
 
1652
                if (lastTab || selected || onlyOne || !nextSelected) {
 
1653
                    p->setPen(shadow);
 
1654
                    p->drawLine(x2 - 2, y2, x1 + (lastTab && selected && rightAligned ? 0 : borderThinkness), y2);
 
1655
                    p->drawPoint(x2 - 1, y2 - 1);
 
1656
                    p->setPen(dark);
 
1657
                    p->drawLine(x2 - 2, y2 - 1, x1 + (lastTab && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
 
1658
                }
 
1659
                break; }
 
1660
            }
 
1661
        }
 
1662
        break;
 
1663
    case CE_ToolBoxTab:
 
1664
        qDrawShadePanel(p, opt->rect, opt->palette,
 
1665
                        opt->state & (State_Sunken | State_On), 1,
 
1666
                        &opt->palette.brush(QPalette::Button));
 
1667
        break;
 
1668
    case CE_Splitter: {
 
1669
        QPen oldPen = p->pen();
 
1670
        p->setPen(opt->palette.light().color());
 
1671
        if (opt->state & State_Horizontal) {
 
1672
            p->drawLine(opt->rect.x() + 1, opt->rect.y(), opt->rect.x() + 1, opt->rect.height());
 
1673
            p->setPen(opt->palette.dark().color());
 
1674
            p->drawLine(opt->rect.x(), opt->rect.y(), opt->rect.x(), opt->rect.height());
 
1675
            p->drawLine(opt->rect.right() - 1, opt->rect.y(), opt->rect.right() - 1,
 
1676
                        opt->rect.height());
 
1677
            p->setPen(opt->palette.shadow().color());
 
1678
            p->drawLine(opt->rect.right(), opt->rect.y(), opt->rect.right(), opt->rect.height());
 
1679
        } else {
 
1680
            p->drawLine(opt->rect.x(), opt->rect.y() + 1, opt->rect.width(), opt->rect.y() + 1);
 
1681
            p->setPen(opt->palette.dark().color());
 
1682
            p->drawLine(opt->rect.x(), opt->rect.bottom() - 1, opt->rect.width(),
 
1683
                        opt->rect.bottom() - 1);
 
1684
            p->setPen(opt->palette.shadow().color());
 
1685
            p->drawLine(opt->rect.x(), opt->rect.bottom(), opt->rect.width(), opt->rect.bottom());
 
1686
        }
 
1687
        p->setPen(oldPen);
 
1688
        break; }
 
1689
    case CE_ScrollBarSubLine:
 
1690
    case CE_ScrollBarAddLine: {
 
1691
        if (use2000style && (opt->state & State_Sunken)) {
 
1692
            p->setPen(opt->palette.dark().color());
 
1693
            p->setBrush(opt->palette.brush(QPalette::Button));
 
1694
            p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
 
1695
        } else {
 
1696
            QStyleOption buttonOpt = *opt;
 
1697
            if (!(buttonOpt.state & State_Sunken))
 
1698
                buttonOpt.state |= State_Raised;
 
1699
            drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
 
1700
        }
 
1701
        PrimitiveElement arrow;
 
1702
        if (opt->state & State_Horizontal) {
 
1703
            if (ce == CE_ScrollBarAddLine)
 
1704
                arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
 
1705
            else
 
1706
                arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
 
1707
        } else {
 
1708
            if (ce == CE_ScrollBarAddLine)
 
1709
                arrow = PE_IndicatorArrowDown;
 
1710
            else
 
1711
                arrow = PE_IndicatorArrowUp;
 
1712
        }
 
1713
        drawPrimitive(arrow, opt, p, widget);
 
1714
        break; }
 
1715
    case CE_ScrollBarAddPage:
 
1716
    case CE_ScrollBarSubPage: {
 
1717
            QBrush br;
 
1718
            QBrush bg = p->background();
 
1719
            Qt::BGMode bg_mode = p->backgroundMode();
 
1720
            p->setPen(Qt::NoPen);
 
1721
            p->setBackgroundMode(Qt::OpaqueMode);
 
1722
 
 
1723
            if (opt->state & State_Sunken) {
 
1724
                br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
 
1725
                p->setBackground(opt->palette.dark().color());
 
1726
                p->setBrush(QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern));
 
1727
            } else {
 
1728
                QPixmap pm = opt->palette.brush(QPalette::Light).texture();
 
1729
                br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
 
1730
                p->setBackground(opt->palette.background().color());
 
1731
                p->setBrush(br);
 
1732
            }
 
1733
            p->drawRect(opt->rect);
 
1734
            p->setBackground(bg);
 
1735
            p->setBackgroundMode(bg_mode);
 
1736
            break; }
 
1737
    case CE_ScrollBarSlider:
 
1738
        if (!(opt->state & State_Enabled)) {
 
1739
            QPixmap pm = opt->palette.brush(QPalette::Light).texture();
 
1740
            QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
 
1741
            p->setPen(Qt::NoPen);
 
1742
            p->setBrush(br);
 
1743
            p->setBackgroundMode(Qt::OpaqueMode);
 
1744
            p->drawRect(opt->rect);
 
1745
        } else {
 
1746
            QStyleOptionButton buttonOpt;
 
1747
            buttonOpt.QStyleOption::operator=(*opt);
 
1748
            buttonOpt.state = State_Enabled | State_Raised;
 
1749
            drawPrimitive(PE_PanelButtonBevel, &buttonOpt, p, widget);
 
1750
        }
 
1751
        break;
 
1752
    case CE_HeaderSection: {
 
1753
        QBrush fill;
 
1754
        if (opt->state & State_On)
 
1755
            fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
 
1756
        else
 
1757
            fill = opt->palette.brush(QPalette::Button);
 
1758
 
 
1759
        if (opt->state & (State_Raised | State_Sunken)) {
 
1760
            qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
 
1761
        } else {
 
1762
            p->fillRect(opt->rect, fill);
 
1763
        }
 
1764
        break; }
 
1765
    default:
 
1766
        QCommonStyle::drawControl(ce, opt, p, widget);
 
1767
    }
 
1768
}
 
1769
 
 
1770
/*! \reimp */
 
1771
QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
 
1772
{
 
1773
    QRect r;
 
1774
    switch (sr) {
 
1775
    case SE_SliderFocusRect:
 
1776
    case SE_ToolBoxTabContents:
 
1777
        r = visualRect(opt->direction, opt->rect, opt->rect);
 
1778
        break;
 
1779
    default:
 
1780
        r = QCommonStyle::subElementRect(sr, opt, w);
 
1781
    }
 
1782
    return r;
 
1783
}
 
1784
 
 
1785
Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalVerticalLine, (1, 129))
 
1786
Q_GLOBAL_STATIC_WITH_ARGS(QBitmap, globalHorizontalLine, (128, 1))
 
1787
 
 
1788
/*! \reimp */
 
1789
void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
 
1790
                                       QPainter *p, const QWidget *widget) const
 
1791
{
 
1792
    switch (cc) {
 
1793
    case CC_Slider:
 
1794
        if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
 
1795
            int thickness  = pixelMetric(PM_SliderControlThickness, slider, widget);
 
1796
            int len        = pixelMetric(PM_SliderLength, slider, widget);
 
1797
            int ticks = slider->tickPosition;
 
1798
            QRect groove = QCommonStyle::subControlRect(CC_Slider, slider,
 
1799
                                                                SC_SliderGroove, widget);
 
1800
            QRect handle = QCommonStyle::subControlRect(CC_Slider, slider,
 
1801
                                                                SC_SliderHandle, widget);
 
1802
 
 
1803
            if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
 
1804
                int mid = thickness / 2;
 
1805
 
 
1806
                if (ticks & QSlider::TicksAbove)
 
1807
                    mid += len / 8;
 
1808
                if (ticks & QSlider::TicksBelow)
 
1809
                    mid -= len / 8;
 
1810
 
 
1811
                p->setPen(slider->palette.shadow().color());
 
1812
                if (slider->orientation == Qt::Horizontal) {
 
1813
                    qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
 
1814
                                   groove.width(), 4, slider->palette, true);
 
1815
                    p->drawLine(groove.x() + 1, groove.y() + mid - 1,
 
1816
                                groove.x() + groove.width() - 3, groove.y() + mid - 1);
 
1817
                } else {
 
1818
                    qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
 
1819
                                  4, groove.height(), slider->palette, true);
 
1820
                    p->drawLine(groove.x() + mid - 1, groove.y() + 1,
 
1821
                                groove.x() + mid - 1, groove.y() + groove.height() - 3);
 
1822
                }
 
1823
            }
 
1824
 
 
1825
            if (slider->subControls & SC_SliderTickmarks) {
 
1826
                QStyleOptionSlider tmpSlider = *slider;
 
1827
                tmpSlider.subControls = SC_SliderTickmarks;
 
1828
                QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
 
1829
            }
 
1830
 
 
1831
            if (slider->subControls & SC_SliderHandle) {
 
1832
                // 4444440
 
1833
                // 4333310
 
1834
                // 4322210
 
1835
                // 4322210
 
1836
                // 4322210
 
1837
                // 4322210
 
1838
                // *43210*
 
1839
                // **410**
 
1840
                // ***0***
 
1841
                const QColor c0 = slider->palette.shadow().color();
 
1842
                const QColor c1 = slider->palette.dark().color();
 
1843
                // const QColor c2 = g.button();
 
1844
                const QColor c3 = slider->palette.midlight().color();
 
1845
                const QColor c4 = slider->palette.light().color();
 
1846
 
 
1847
                int x = handle.x(), y = handle.y(),
 
1848
                   wi = handle.width(), he = handle.height();
 
1849
 
 
1850
                int x1 = x;
 
1851
                int x2 = x+wi-1;
 
1852
                int y1 = y;
 
1853
                int y2 = y+he-1;
 
1854
 
 
1855
                Qt::Orientation orient = slider->orientation;
 
1856
                bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
 
1857
                bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
 
1858
 
 
1859
                if (slider->state & State_HasFocus) {
 
1860
                    QStyleOptionFocusRect fropt;
 
1861
                    fropt.QStyleOption::operator=(*slider);
 
1862
                    fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
 
1863
                    drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
 
1864
                }
 
1865
 
 
1866
                if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
 
1867
                    qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
 
1868
                                   &slider->palette.brush(QPalette::Button));
 
1869
                    return;
 
1870
                }
 
1871
 
 
1872
                QSliderDirection dir;
 
1873
 
 
1874
                if (orient == Qt::Horizontal)
 
1875
                    if (tickAbove)
 
1876
                        dir = SlUp;
 
1877
                    else
 
1878
                        dir = SlDown;
 
1879
                else
 
1880
                    if (tickAbove)
 
1881
                        dir = SlLeft;
 
1882
                    else
 
1883
                        dir = SlRight;
 
1884
 
 
1885
                QPolygon a;
 
1886
 
 
1887
                int d = 0;
 
1888
                switch (dir) {
 
1889
                case SlUp:
 
1890
                    y1 = y1 + wi/2;
 
1891
                    d =  (wi + 1) / 2 - 1;
 
1892
                    a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
 
1893
                    break;
 
1894
                case SlDown:
 
1895
                    y2 = y2 - wi/2;
 
1896
                    d =  (wi + 1) / 2 - 1;
 
1897
                    a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
 
1898
                    break;
 
1899
                case SlLeft:
 
1900
                    d =  (he + 1) / 2 - 1;
 
1901
                    x1 = x1 + he/2;
 
1902
                    a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
 
1903
                    break;
 
1904
                case SlRight:
 
1905
                    d =  (he + 1) / 2 - 1;
 
1906
                    x2 = x2 - he/2;
 
1907
                    a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
 
1908
                    break;
 
1909
                }
 
1910
 
 
1911
                QBrush oldBrush = p->brush();
 
1912
                p->setBrush(slider->palette.brush(QPalette::Button));
 
1913
                p->setPen(Qt::NoPen);
 
1914
                p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
 
1915
                p->drawPolygon(a);
 
1916
                p->setBrush(oldBrush);
 
1917
 
 
1918
                if (dir != SlUp) {
 
1919
                    p->setPen(c4);
 
1920
                    p->drawLine(x1, y1, x2, y1);
 
1921
                    p->setPen(c3);
 
1922
                    p->drawLine(x1, y1+1, x2, y1+1);
 
1923
                }
 
1924
                if (dir != SlLeft) {
 
1925
                    p->setPen(c3);
 
1926
                    p->drawLine(x1+1, y1+1, x1+1, y2);
 
1927
                    p->setPen(c4);
 
1928
                    p->drawLine(x1, y1, x1, y2);
 
1929
                }
 
1930
                if (dir != SlRight) {
 
1931
                    p->setPen(c0);
 
1932
                    p->drawLine(x2, y1, x2, y2);
 
1933
                    p->setPen(c1);
 
1934
                    p->drawLine(x2-1, y1+1, x2-1, y2-1);
 
1935
                }
 
1936
                if (dir != SlDown) {
 
1937
                    p->setPen(c0);
 
1938
                    p->drawLine(x1, y2, x2, y2);
 
1939
                    p->setPen(c1);
 
1940
                    p->drawLine(x1+1, y2-1, x2-1, y2-1);
 
1941
                }
 
1942
 
 
1943
                switch (dir) {
 
1944
                case SlUp:
 
1945
                    p->setPen(c4);
 
1946
                    p->drawLine(x1, y1, x1+d, y1-d);
 
1947
                    p->setPen(c0);
 
1948
                    d = wi - d - 1;
 
1949
                    p->drawLine(x2, y1, x2-d, y1-d);
 
1950
                    d--;
 
1951
                    p->setPen(c3);
 
1952
                    p->drawLine(x1+1, y1, x1+1+d, y1-d);
 
1953
                    p->setPen(c1);
 
1954
                    p->drawLine(x2-1, y1, x2-1-d, y1-d);
 
1955
                    break;
 
1956
                case SlDown:
 
1957
                    p->setPen(c4);
 
1958
                    p->drawLine(x1, y2, x1+d, y2+d);
 
1959
                    p->setPen(c0);
 
1960
                    d = wi - d - 1;
 
1961
                    p->drawLine(x2, y2, x2-d, y2+d);
 
1962
                    d--;
 
1963
                    p->setPen(c3);
 
1964
                    p->drawLine(x1+1, y2, x1+1+d, y2+d);
 
1965
                    p->setPen(c1);
 
1966
                    p->drawLine(x2-1, y2, x2-1-d, y2+d);
 
1967
                    break;
 
1968
                case SlLeft:
 
1969
                    p->setPen(c4);
 
1970
                    p->drawLine(x1, y1, x1-d, y1+d);
 
1971
                    p->setPen(c0);
 
1972
                    d = he - d - 1;
 
1973
                    p->drawLine(x1, y2, x1-d, y2-d);
 
1974
                    d--;
 
1975
                    p->setPen(c3);
 
1976
                    p->drawLine(x1, y1+1, x1-d, y1+1+d);
 
1977
                    p->setPen(c1);
 
1978
                    p->drawLine(x1, y2-1, x1-d, y2-1-d);
 
1979
                    break;
 
1980
                case SlRight:
 
1981
                    p->setPen(c4);
 
1982
                    p->drawLine(x2, y1, x2+d, y1+d);
 
1983
                    p->setPen(c0);
 
1984
                    d = he - d - 1;
 
1985
                    p->drawLine(x2, y2, x2+d, y2-d);
 
1986
                    d--;
 
1987
                    p->setPen(c3);
 
1988
                    p->drawLine(x2, y1+1, x2+d, y1+1+d);
 
1989
                    p->setPen(c1);
 
1990
                    p->drawLine(x2, y2-1, x2+d, y2-1-d);
 
1991
                    break;
 
1992
                }
 
1993
            }
 
1994
        }
 
1995
        break;
 
1996
    case CC_Q3ListView:
 
1997
        if (const QStyleOptionQ3ListView *lv = qstyleoption_cast<const QStyleOptionQ3ListView *>(opt)) {
 
1998
            int i;
 
1999
            if (lv->subControls & SC_Q3ListView)
 
2000
                QCommonStyle::drawComplexControl(cc, lv, p, widget);
 
2001
            if (lv->subControls & (SC_Q3ListViewBranch | SC_Q3ListViewExpand)) {
 
2002
                if (lv->items.isEmpty())
 
2003
                    break;
 
2004
                QStyleOptionQ3ListViewItem item = lv->items.at(0);
 
2005
                int y = lv->rect.y();
 
2006
                int c;
 
2007
                int dotoffset = 0;
 
2008
                QPolygon dotlines;
 
2009
                if ((lv->activeSubControls & SC_All) && (lv->subControls & SC_Q3ListViewExpand)) {
 
2010
                    c = 2;
 
2011
                    dotlines.resize(2);
 
2012
                    dotlines[0] = QPoint(lv->rect.right(), lv->rect.top());
 
2013
                    dotlines[1] = QPoint(lv->rect.right(), lv->rect.bottom());
 
2014
                } else {
 
2015
                    int linetop = 0, linebot = 0;
 
2016
                    // each branch needs at most two lines, ie. four end points
 
2017
                    dotoffset = (item.itemY + item.height - y) % 2;
 
2018
                    dotlines.resize(item.childCount * 4);
 
2019
                    c = 0;
 
2020
 
 
2021
                    // skip the stuff above the exposed rectangle
 
2022
                    for (i = 1; i < lv->items.size(); ++i) {
 
2023
                        QStyleOptionQ3ListViewItem child = lv->items.at(i);
 
2024
                        if (child.height + y > 0)
 
2025
                            break;
 
2026
                        y += child.totalHeight;
 
2027
                    }
 
2028
                    int bx = lv->rect.width() / 2;
 
2029
 
 
2030
                    // paint stuff in the magical area
 
2031
                    while (i < lv->items.size() && y < lv->rect.height()) {
 
2032
                        QStyleOptionQ3ListViewItem child = lv->items.at(i);
 
2033
                        if (child.features & QStyleOptionQ3ListViewItem::Visible) {
 
2034
                            int lh;
 
2035
                            if (!(item.features & QStyleOptionQ3ListViewItem::MultiLine))
 
2036
                                lh = child.height;
 
2037
                            else
 
2038
                                lh = p->fontMetrics().height() + 2 * lv->itemMargin;
 
2039
                            lh = qMax(lh, QApplication::globalStrut().height());
 
2040
                            if (lh % 2 > 0)
 
2041
                                ++lh;
 
2042
                            linebot = y + lh / 2;
 
2043
                            if (child.features & QStyleOptionQ3ListViewItem::Expandable
 
2044
                                || child.childCount > 0 && child.height > 0) {
 
2045
                                // needs a box
 
2046
                                p->setPen(lv->palette.mid().color());
 
2047
                                p->drawRect(bx - 4, linebot - 4, 8, 8);
 
2048
                                // plus or minus
 
2049
                                p->setPen(lv->palette.text().color());
 
2050
                                p->drawLine(bx - 2, linebot, bx + 2, linebot);
 
2051
                                if (!(child.state & State_Open))
 
2052
                                    p->drawLine(bx, linebot - 2, bx, linebot + 2);
 
2053
                                // dotlinery
 
2054
                                p->setPen(lv->palette.mid().color());
 
2055
                                dotlines[c++] = QPoint(bx, linetop);
 
2056
                                dotlines[c++] = QPoint(bx, linebot - 4);
 
2057
                                dotlines[c++] = QPoint(bx + 5, linebot);
 
2058
                                dotlines[c++] = QPoint(lv->rect.width(), linebot);
 
2059
                                linetop = linebot + 5;
 
2060
                            } else {
 
2061
                                // just dotlinery
 
2062
                                dotlines[c++] = QPoint(bx+1, linebot -1);
 
2063
                                dotlines[c++] = QPoint(lv->rect.width(), linebot -1);
 
2064
                            }
 
2065
                            y += child.totalHeight;
 
2066
                        }
 
2067
                        ++i;
 
2068
                    }
 
2069
 
 
2070
                    // Expand line height to edge of rectangle if there's any
 
2071
                    // visible child below
 
2072
                    while (i < lv->items.size() && lv->items.at(i).height <= 0)
 
2073
                        ++i;
 
2074
                    if (i < lv->items.size())
 
2075
                        linebot = lv->rect.height();
 
2076
 
 
2077
                    if (linetop < linebot) {
 
2078
                        dotlines[c++] = QPoint(bx, linetop);
 
2079
                        dotlines[c++] = QPoint(bx, linebot);
 
2080
                    }
 
2081
                }
 
2082
                p->setPen(lv->palette.text().color());
 
2083
                QBitmap *verticalLine = globalVerticalLine();
 
2084
                QBitmap *horizontalLine = globalHorizontalLine();
 
2085
                static bool isInit = false;
 
2086
                if (!isInit) {
 
2087
                    isInit = true;
 
2088
                    // make 128*1 and 1*128 bitmaps that can be used for
 
2089
                    // drawing the right sort of lines.
 
2090
                    verticalLine->clear();
 
2091
                    horizontalLine->clear();
 
2092
                    QPolygon a(64);
 
2093
                    QPainter p;
 
2094
                    p.begin(verticalLine);
 
2095
                    for(i = 0; i < 64; ++i)
 
2096
                        a.setPoint(i, 0, i * 2 + 1);
 
2097
                    p.setPen(Qt::color1);
 
2098
                    p.drawPoints(a);
 
2099
                    p.end();
 
2100
                    QApplication::flush();
 
2101
                    verticalLine->setMask(*verticalLine);
 
2102
                    p.begin(horizontalLine);
 
2103
                    for(i = 0; i < 64; ++i)
 
2104
                        a.setPoint(i, i * 2 + 1, 0);
 
2105
                    p.setPen(Qt::color1);
 
2106
                    p.drawPoints(a);
 
2107
                    p.end();
 
2108
                    QApplication::flush();
 
2109
                    horizontalLine->setMask(*horizontalLine);
 
2110
                }
 
2111
 
 
2112
                int line; // index into dotlines
 
2113
                if (lv->subControls & SC_Q3ListViewBranch) for(line = 0; line < c; line += 2) {
 
2114
                    // assumptions here: lines are horizontal or vertical.
 
2115
                    // lines always start with the numerically lowest
 
2116
                    // coordinate.
 
2117
 
 
2118
                    // point ... relevant coordinate of current point
 
2119
                    // end ..... same coordinate of the end of the current line
 
2120
                    // other ... the other coordinate of the current point/line
 
2121
                    if (dotlines[line].y() == dotlines[line+1].y()) {
 
2122
                        int end = dotlines[line + 1].x();
 
2123
                        int point = dotlines[line].x();
 
2124
                        int other = dotlines[line].y();
 
2125
                        while (point < end) {
 
2126
                            int i = 128;
 
2127
                            if (i + point > end)
 
2128
                                i = end-point;
 
2129
                            p->drawPixmap(point, other, *horizontalLine, 0, 0, i, 1);
 
2130
                            point += i;
 
2131
                        }
 
2132
                    } else {
 
2133
                        int end = dotlines[line + 1].y();
 
2134
                        int point = dotlines[line].y();
 
2135
                        int other = dotlines[line].x();
 
2136
                        int pixmapoffset = ((point & 1) != dotoffset) ? 1 : 0;
 
2137
                        while(point < end) {
 
2138
                            int i = 128;
 
2139
                            if (i + point > end)
 
2140
                                i = end-point;
 
2141
                            p->drawPixmap(other, point, *verticalLine, 0, pixmapoffset, 1, i);
 
2142
                            point += i;
 
2143
                        }
 
2144
                    }
 
2145
                }
 
2146
            }
 
2147
        }
 
2148
        break;
 
2149
    case CC_ComboBox:
 
2150
        if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
 
2151
            if (cmb->subControls & SC_ComboBoxArrow) {
 
2152
                State flags = State_None;
 
2153
 
 
2154
                QBrush editBrush = (cmb->state & State_Enabled) ? cmb->palette.brush(QPalette::Base)
 
2155
                                   : cmb->palette.brush(QPalette::Background);
 
2156
                if (cmb->frame)
 
2157
                    qDrawWinPanel(p, opt->rect, opt->palette, true, &editBrush);
 
2158
                else
 
2159
                    p->fillRect(opt->rect, editBrush);
 
2160
 
 
2161
                QRect ar = subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
 
2162
                if (cmb->activeSubControls == SC_ComboBoxArrow) {
 
2163
                    p->setPen(cmb->palette.dark().color());
 
2164
                    p->setBrush(cmb->palette.brush(QPalette::Button));
 
2165
                    p->drawRect(ar.adjusted(0,0,-1,-1));
 
2166
                } else {
 
2167
                    qDrawWinPanel(p, ar, cmb->palette, false,
 
2168
                                  &cmb->palette.brush(QPalette::Button));
 
2169
                }
 
2170
 
 
2171
                ar.adjust(2, 2, -2, -2);
 
2172
                if (opt->state & State_Enabled)
 
2173
                    flags |= State_Enabled;
 
2174
 
 
2175
                if (cmb->activeSubControls == SC_ComboBoxArrow)
 
2176
                    flags |= State_Sunken;
 
2177
                QStyleOption arrowOpt(0);
 
2178
                arrowOpt.rect = ar;
 
2179
                arrowOpt.palette = cmb->palette;
 
2180
                arrowOpt.state = flags;
 
2181
                drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
 
2182
            }
 
2183
            if (cmb->subControls & SC_ComboBoxEditField) {
 
2184
                QRect re = subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
 
2185
                if (cmb->state & State_HasFocus && !cmb->editable)
 
2186
                    p->fillRect(re.x(), re.y(), re.width(), re.height(),
 
2187
                                cmb->palette.brush(QPalette::Highlight));
 
2188
 
 
2189
                if (cmb->state & State_HasFocus) {
 
2190
                    p->setPen(cmb->palette.highlightedText().color());
 
2191
                    p->setBackground(cmb->palette.highlight());
 
2192
 
 
2193
                } else {
 
2194
                    p->setPen(cmb->palette.text().color());
 
2195
                    p->setBackground(cmb->palette.background());
 
2196
                }
 
2197
 
 
2198
                if (cmb->state & State_HasFocus && !cmb->editable) {
 
2199
                    QStyleOptionFocusRect focus;
 
2200
                    focus.QStyleOption::operator=(*cmb);
 
2201
                    focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
 
2202
                    focus.state |= State_FocusAtBorder;
 
2203
                    focus.backgroundColor = cmb->palette.highlight().color();
 
2204
                    drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
 
2205
                }
 
2206
            }
 
2207
        }
 
2208
        break;
 
2209
    default:
 
2210
        QCommonStyle::drawComplexControl(cc, opt, p, widget);
 
2211
    }
 
2212
}
 
2213
 
 
2214
/*! \reimp */
 
2215
QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
 
2216
                                      const QSize &csz, const QWidget *widget) const
 
2217
{
 
2218
    QSize sz(csz);
 
2219
    switch (ct) {
 
2220
    case CT_PushButton:
 
2221
        if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
 
2222
            sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
 
2223
            int w = sz.width(),
 
2224
                h = sz.height();
 
2225
            int defwidth = 0;
 
2226
            if (btn->features & QStyleOptionButton::AutoDefaultButton)
 
2227
                defwidth = 2 * pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
 
2228
            if (w < 75 + defwidth && btn->icon.isNull())
 
2229
                w = 75 + defwidth;
 
2230
            if (h < 23 + defwidth)
 
2231
                h = 23 + defwidth;
 
2232
            sz = QSize(w, h);
 
2233
        }
 
2234
        break;
 
2235
    case CT_MenuItem:
 
2236
        if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
 
2237
            int w = sz.width();
 
2238
            sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
 
2239
            if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull())
 
2240
                 sz.setHeight(qMax(sz.height(),
 
2241
                              mi->icon.pixmap(pixelMetric(PM_SmallIconSize), QIcon::Normal).height()
 
2242
                              + 2 * windowsItemFrame));
 
2243
            int maxpmw = mi->maxIconWidth;
 
2244
            int tabSpacing = use2000style ? 20 :windowsTabSpacing;
 
2245
            if (mi->text.contains('\t'))
 
2246
                w += tabSpacing;
 
2247
            else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
 
2248
                w += 2 * windowsArrowHMargin;
 
2249
            else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
 
2250
                // adjust the font and add the difference in size.
 
2251
                // it would be better if the font could be adjusted in the getStyleOptions qmenu func!!
 
2252
                QFontMetrics fm(mi->font);
 
2253
                QFont fontBold = mi->font;
 
2254
                fontBold.setBold(true);
 
2255
                QFontMetrics fmBold(fontBold);
 
2256
                w += fmBold.width(mi->text) - fm.width(mi->text);
 
2257
            }
 
2258
 
 
2259
            int checkcol = qMax(maxpmw, use2000style ? 20 : windowsCheckMarkWidth); // Windows always shows a check column
 
2260
            w += checkcol;
 
2261
            w += windowsRightBorder + 10;
 
2262
            sz.setWidth(w);
 
2263
        }
 
2264
        break;
 
2265
    case CT_MenuBarItem:
 
2266
        if (!sz.isEmpty())
 
2267
            sz += QSize(windowsItemHMargin * 5 + 1, windowsItemVMargin * 2);
 
2268
        break;
 
2269
    default:
 
2270
        sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
 
2271
    }
 
2272
    return sz;
 
2273
}
 
2274
#endif