4df68a76adb396d64c62903db8be9a71907ba062
[profile/ivi/qtbase.git] / src / widgets / styles / qwindowsstyle.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwindowsstyle.h"
43 #include "qwindowsstyle_p.h"
44
45 #if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)
46
47 #include <private/qsystemlibrary_p.h>
48 #include "qapplication.h"
49 #include "qbitmap.h"
50 #include "qdrawutil.h" // for now
51 #include "qevent.h"
52 #include "qmenu.h"
53 #include "qmenubar.h"
54 #include <private/qmenubar_p.h>
55 #include "qpaintengine.h"
56 #include "qpainter.h"
57 #include "qrubberband.h"
58 #include "qstyleoption.h"
59 #include "qtabbar.h"
60 #include "qwidget.h"
61 #include "qdebug.h"
62 #include "qmainwindow.h"
63 #include "qfile.h"
64 #include "qtextstream.h"
65 #include "qpixmapcache.h"
66 #include "qwizard.h"
67 #include "qlistview.h"
68 #include <private/qmath_p.h>
69 #include <qmath.h>
70 #include <qpa/qplatformtheme.h>
71 #include <private/qguiapplication_p.h>
72
73 #include <private/qstylehelper_p.h>
74 #include <private/qstyleanimation_p.h>
75
76 QT_BEGIN_NAMESPACE
77
78 #if defined(Q_OS_WIN)
79
80 QT_BEGIN_INCLUDE_NAMESPACE
81 #include "qt_windows.h"
82 QT_END_INCLUDE_NAMESPACE
83 #  ifndef COLOR_GRADIENTACTIVECAPTION
84 #    define COLOR_GRADIENTACTIVECAPTION     27
85 #  endif
86 #  ifndef COLOR_GRADIENTINACTIVECAPTION
87 #    define COLOR_GRADIENTINACTIVECAPTION   28
88 #  endif
89
90
91 typedef struct
92 {
93     DWORD cbSize;
94     HICON hIcon;
95     int   iSysImageIndex;
96     int   iIcon;
97     WCHAR szPath[MAX_PATH];
98 } QSHSTOCKICONINFO;
99
100 #define _SHGFI_SMALLICON         0x000000001
101 #define _SHGFI_LARGEICON         0x000000000
102 #define _SHGFI_ICON              0x000000100
103 #define _SIID_SHIELD             77
104
105 typedef HRESULT (WINAPI *PtrSHGetStockIconInfo)(int siid, int uFlags, QSHSTOCKICONINFO *psii);
106 static PtrSHGetStockIconInfo pSHGetStockIconInfo = 0;
107
108 Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &);
109 Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon);
110 #endif //Q_OS_WIN
111
112 QT_BEGIN_INCLUDE_NAMESPACE
113 #include <limits.h>
114 QT_END_INCLUDE_NAMESPACE
115
116 enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
117
118 /*
119     \internal
120 */
121 QWindowsStylePrivate::QWindowsStylePrivate()
122     : alt_down(false), menuBarTimer(0)
123 {
124 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
125     if ((QSysInfo::WindowsVersion >= QSysInfo::WV_VISTA
126         && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) {
127         QSystemLibrary shellLib(QLatin1String("shell32"));
128         pSHGetStockIconInfo = (PtrSHGetStockIconInfo)shellLib.resolve("SHGetStockIconInfo");
129     }
130 #endif
131 }
132
133 // Returns true if the toplevel parent of \a widget has seen the Alt-key
134 bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const
135 {
136     widget = widget->window();
137     return seenAlt.contains(widget);
138 }
139
140 /*!
141     \reimp
142 */
143 bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
144 {
145     // Records Alt- and Focus events
146     if (!o->isWidgetType())
147         return QObject::eventFilter(o, e);
148
149     QWidget *widget = qobject_cast<QWidget*>(o);
150     Q_D(QWindowsStyle);
151     switch(e->type()) {
152     case QEvent::KeyPress:
153         if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
154             widget = widget->window();
155
156             // Alt has been pressed - find all widgets that care
157             QList<QWidget *> l = widget->findChildren<QWidget *>();
158             for (int pos=0 ; pos < l.size() ; ++pos) {
159                 QWidget *w = l.at(pos);
160                 if (w->isWindow() || !w->isVisible() ||
161                     w->style()->styleHint(SH_UnderlineShortcut, 0, w))
162                     l.removeAt(pos);
163             }
164             // Update states before repainting
165             d->seenAlt.append(widget);
166             d->alt_down = true;
167
168             // Repaint all relevant widgets
169             for (int pos = 0; pos < l.size(); ++pos)
170                 l.at(pos)->update();
171         }
172         break;
173     case QEvent::KeyRelease:
174         if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
175             widget = widget->window();
176
177             // Update state and repaint the menu bars.
178             d->alt_down = false;
179 #ifndef QT_NO_MENUBAR
180             QList<QMenuBar *> l = widget->findChildren<QMenuBar *>();
181             for (int i = 0; i < l.size(); ++i)
182                 l.at(i)->update();
183 #endif
184         }
185         break;
186     case QEvent::Close:
187         // Reset widget when closing
188         d->seenAlt.removeAll(widget);
189         d->seenAlt.removeAll(widget->window());
190         break;
191     default:
192         break;
193     }
194     return QCommonStyle::eventFilter(o, e);
195 }
196
197 /*!
198     \class QWindowsStyle
199     \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.
200
201     \ingroup appearance
202     \inmodule QtWidgets
203
204     This style is Qt's default GUI style on Windows.
205
206     \image qwindowsstyle.png
207     \sa QWindowsXPStyle, QMacStyle, QPlastiqueStyle
208 */
209
210 /*!
211     Constructs a QWindowsStyle object.
212 */
213 QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate)
214 {
215 }
216
217 /*!
218     \internal
219
220     Constructs a QWindowsStyle object.
221 */
222 QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
223 {
224 }
225
226
227 /*! Destroys the QWindowsStyle object. */
228 QWindowsStyle::~QWindowsStyle()
229 {
230 }
231
232 #ifdef Q_OS_WIN
233 static inline QRgb colorref2qrgb(COLORREF col)
234 {
235     return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
236 }
237 #endif
238
239 /*! \reimp */
240 void QWindowsStyle::polish(QApplication *app)
241 {
242     QCommonStyle::polish(app);
243     QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func());
244     // We only need the overhead when shortcuts are sometimes hidden
245     if (!proxy()->styleHint(SH_UnderlineShortcut, 0) && app)
246         app->installEventFilter(this);
247
248     d->activeCaptionColor = app->palette().highlight().color();
249     d->activeGradientCaptionColor = app->palette().highlight() .color();
250     d->inactiveCaptionColor = app->palette().dark().color();
251     d->inactiveGradientCaptionColor = app->palette().dark().color();
252     d->inactiveCaptionText = app->palette().background().color();
253
254 #if defined(Q_OS_WIN) //fetch native title bar colors
255     if(app->desktopSettingsAware()){
256         DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);
257         DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
258         DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);
259         DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
260         DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
261         d->activeCaptionColor = colorref2qrgb(activeCaption);
262         d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);
263         d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);
264         d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);
265         d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);
266     }
267 #endif
268 }
269
270 /*! \reimp */
271 void QWindowsStyle::unpolish(QApplication *app)
272 {
273     QCommonStyle::unpolish(app);
274     app->removeEventFilter(this);
275 }
276
277 /*! \reimp */
278 void QWindowsStyle::polish(QWidget *widget)
279 {
280     QCommonStyle::polish(widget);
281 }
282
283 /*! \reimp */
284 void QWindowsStyle::unpolish(QWidget *widget)
285 {
286     QCommonStyle::unpolish(widget);
287 }
288
289 /*!
290   \reimp
291 */
292 void QWindowsStyle::polish(QPalette &pal)
293 {
294     QCommonStyle::polish(pal);
295 }
296
297 /*!
298   \reimp
299 */
300 int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
301 {
302     int ret;
303
304     switch (pm) {
305     case PM_ButtonDefaultIndicator:
306     case PM_ButtonShiftHorizontal:
307     case PM_ButtonShiftVertical:
308     case PM_MenuHMargin:
309     case PM_MenuVMargin:
310         ret = 1;
311         break;
312     case PM_DockWidgetSeparatorExtent:
313         ret = int(QStyleHelper::dpiScaled(4.));
314         break;
315 #ifndef QT_NO_TABBAR
316     case PM_TabBarTabShiftHorizontal:
317         ret = 0;
318         break;
319     case PM_TabBarTabShiftVertical:
320         ret = 2;
321         break;
322 #endif
323     case PM_MaximumDragDistance:
324         ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance);
325         if (ret == -1)
326             ret = 60;
327         break;
328
329 #ifndef QT_NO_SLIDER
330     case PM_SliderLength:
331         ret = int(QStyleHelper::dpiScaled(11.));
332         break;
333
334         // Returns the number of pixels to use for the business part of the
335         // slider (i.e., the non-tickmark portion). The remaining space is shared
336         // equally between the tickmark regions.
337     case PM_SliderControlThickness:
338         if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
339             int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
340             int ticks = sl->tickPosition;
341             int n = 0;
342             if (ticks & QSlider::TicksAbove)
343                 ++n;
344             if (ticks & QSlider::TicksBelow)
345                 ++n;
346             if (!n) {
347                 ret = space;
348                 break;
349             }
350
351             int thick = 6;        // Magic constant to get 5 + 16 + 5
352             if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
353                 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;
354
355             space -= thick;
356             if (space > 0)
357                 thick += (space * 2) / (n + 2);
358             ret = thick;
359         } else {
360             ret = 0;
361         }
362         break;
363 #endif // QT_NO_SLIDER
364
365 #ifndef QT_NO_MENU
366     case PM_MenuBarHMargin:
367         ret = 0;
368         break;
369
370     case PM_MenuBarVMargin:
371         ret = 0;
372         break;
373
374     case PM_MenuBarPanelWidth:
375         ret = 0;
376         break;
377
378     case PM_SmallIconSize:
379         ret = int(QStyleHelper::dpiScaled(16.));
380         break;
381
382     case PM_LargeIconSize:
383         ret = int(QStyleHelper::dpiScaled(32.));
384         break;
385
386     case PM_IconViewIconSize:
387         ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
388         break;
389
390     case PM_DockWidgetTitleMargin:
391         ret = int(QStyleHelper::dpiScaled(2.));
392         break;
393     case PM_DockWidgetTitleBarButtonMargin:
394         ret = int(QStyleHelper::dpiScaled(4.));
395         break;
396 #if defined(Q_WS_WIN)
397     case PM_DockWidgetFrameWidth:
398 #if defined(Q_OS_WINCE)
399         ret = GetSystemMetrics(SM_CXDLGFRAME);
400 #else
401         ret = GetSystemMetrics(SM_CXFRAME);
402 #endif
403         break;
404 #else
405     case PM_DockWidgetFrameWidth:
406         ret = 4;
407         break;
408 #endif // Q_WS_WIN
409     break;
410
411 #endif // QT_NO_MENU
412
413
414 #if defined(Q_OS_WIN)
415     case PM_TitleBarHeight:
416         if (widget && (widget->windowType() == Qt::Tool)) {
417             // MS always use one less than they say
418 #if defined(Q_OS_WINCE)
419             ret = GetSystemMetrics(SM_CYCAPTION) - 1;
420 #else
421             ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
422 #endif
423         } else {
424             ret = GetSystemMetrics(SM_CYCAPTION) - 1;
425         }
426
427         break;
428
429     case PM_ScrollBarExtent:
430         {
431 #ifndef Q_OS_WINCE
432             NONCLIENTMETRICS ncm;
433             ncm.cbSize = FIELD_OFFSET(NONCLIENTMETRICS, lfMessageFont) + sizeof(LOGFONT);
434             if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0))
435                 ret = qMax(ncm.iScrollHeight, ncm.iScrollWidth);
436             else
437 #endif
438                 ret = QCommonStyle::pixelMetric(pm, opt, widget);
439         }
440         break;
441 #endif // Q_OS_WIN
442
443     case PM_SplitterWidth:
444         ret = qMax(4, QApplication::globalStrut().width());
445         break;
446
447 #if defined(Q_OS_WIN)
448     case PM_MdiSubWindowFrameWidth:
449 #if defined(Q_OS_WINCE)
450         ret = GetSystemMetrics(SM_CYDLGFRAME);
451 #else
452         ret = GetSystemMetrics(SM_CYFRAME);
453 #endif
454         break;
455 #endif
456     case PM_ToolBarItemMargin:
457         ret = 1;
458         break;
459     case PM_ToolBarItemSpacing:
460         ret = 0;
461         break;
462     case PM_ToolBarHandleExtent:
463         ret = int(QStyleHelper::dpiScaled(10.));
464         break;
465     default:
466         ret = QCommonStyle::pixelMetric(pm, opt, widget);
467         break;
468     }
469
470     return ret;
471 }
472
473 #ifndef QT_NO_IMAGEFORMAT_XPM
474
475 /* XPM */
476 static const char * const qt_menu_xpm[] = {
477 "16 16 72 1",
478 "  c None",
479 ". c #65AF36",
480 "+ c #66B036",
481 "@ c #77B94C",
482 "# c #A7D28C",
483 "$ c #BADBA4",
484 "% c #A4D088",
485 "& c #72B646",
486 "* c #9ACB7A",
487 "= c #7FBD56",
488 "- c #85C05F",
489 "; c #F4F9F0",
490 "> c #FFFFFF",
491 ", c #E5F1DC",
492 "' c #ECF5E7",
493 ") c #7ABA50",
494 "! c #83BF5C",
495 "~ c #AED595",
496 "{ c #D7EACA",
497 "] c #A9D28D",
498 "^ c #BCDDA8",
499 "/ c #C4E0B1",
500 "( c #81BE59",
501 "_ c #D0E7C2",
502 ": c #D4E9C6",
503 "< c #6FB542",
504 "[ c #6EB440",
505 "} c #88C162",
506 "| c #98CA78",
507 "1 c #F4F9F1",
508 "2 c #8FC56C",
509 "3 c #F1F8EC",
510 "4 c #E8F3E1",
511 "5 c #D4E9C7",
512 "6 c #74B748",
513 "7 c #80BE59",
514 "8 c #73B747",
515 "9 c #6DB43F",
516 "0 c #CBE4BA",
517 "a c #80BD58",
518 "b c #6DB33F",
519 "c c #FEFFFE",
520 "d c #68B138",
521 "e c #F9FCF7",
522 "f c #91C66F",
523 "g c #E8F3E0",
524 "h c #DCEDD0",
525 "i c #91C66E",
526 "j c #A3CF86",
527 "k c #C9E3B8",
528 "l c #B0D697",
529 "m c #E3F0DA",
530 "n c #95C873",
531 "o c #E6F2DE",
532 "p c #9ECD80",
533 "q c #BEDEAA",
534 "r c #C7E2B6",
535 "s c #79BA4F",
536 "t c #6EB441",
537 "u c #BCDCA7",
538 "v c #FAFCF8",
539 "w c #F6FAF3",
540 "x c #84BF5D",
541 "y c #EDF6E7",
542 "z c #FAFDF9",
543 "A c #88C263",
544 "B c #98CA77",
545 "C c #CDE5BE",
546 "D c #67B037",
547 "E c #D9EBCD",
548 "F c #6AB23C",
549 "G c #77B94D",
550 " .++++++++++++++",
551 ".+++++++++++++++",
552 "+++@#$%&+++*=+++",
553 "++-;>,>')+!>~+++",
554 "++{>]+^>/(_>:~<+",
555 "+[>>}+|>123>456+",
556 "+7>>8+->>90>~+++",
557 "+a>>b+a>c[0>~+++",
558 "+de>=+f>g+0>~+++",
559 "++h>i+j>k+0>~+++",
560 "++l>mno>p+q>rst+",
561 "++duv>wl++xy>zA+",
562 "++++B>Cb++++&D++",
563 "+++++0zE++++++++",
564 "++++++FG+++++++.",
565 "++++++++++++++. "};
566
567 static const char * const qt_close_xpm[] = {
568 "10 10 2 1",
569 "# c #000000",
570 ". c None",
571 "..........",
572 ".##....##.",
573 "..##..##..",
574 "...####...",
575 "....##....",
576 "...####...",
577 "..##..##..",
578 ".##....##.",
579 "..........",
580 ".........."};
581
582 static const char * const qt_maximize_xpm[]={
583 "10 10 2 1",
584 "# c #000000",
585 ". c None",
586 "#########.",
587 "#########.",
588 "#.......#.",
589 "#.......#.",
590 "#.......#.",
591 "#.......#.",
592 "#.......#.",
593 "#.......#.",
594 "#########.",
595 ".........."};
596
597 static const char * const qt_minimize_xpm[] = {
598 "10 10 2 1",
599 "# c #000000",
600 ". c None",
601 "..........",
602 "..........",
603 "..........",
604 "..........",
605 "..........",
606 "..........",
607 "..........",
608 ".#######..",
609 ".#######..",
610 ".........."};
611
612 static const char * const qt_normalizeup_xpm[] = {
613 "10 10 2 1",
614 "# c #000000",
615 ". c None",
616 "...######.",
617 "...######.",
618 "...#....#.",
619 ".######.#.",
620 ".######.#.",
621 ".#....###.",
622 ".#....#...",
623 ".#....#...",
624 ".######...",
625 ".........."};
626
627 static const char * const qt_help_xpm[] = {
628 "10 10 2 1",
629 ". c None",
630 "# c #000000",
631 "..........",
632 "..######..",
633 ".##....##.",
634 "......##..",
635 ".....##...",
636 "....##....",
637 "....##....",
638 "..........",
639 "....##....",
640 ".........."};
641
642 static const char * const qt_shade_xpm[] = {
643 "10 10 2 1",
644 "# c #000000",
645 ". c None",
646 "..........",
647 "..........",
648 "..........",
649 "..........",
650 "....#.....",
651 "...###....",
652 "..#####...",
653 ".#######..",
654 "..........",
655 ".........."};
656
657 static const char * const qt_unshade_xpm[] = {
658 "10 10 2 1",
659 "# c #000000",
660 ". c None",
661 "..........",
662 "..........",
663 "..........",
664 ".#######..",
665 "..#####...",
666 "...###....",
667 "....#.....",
668 "..........",
669 "..........",
670 ".........."};
671
672 static const char * dock_widget_close_xpm[] = {
673 "8 8 2 1",
674 "# c #000000",
675 ". c None",
676 "........",
677 ".##..##.",
678 "..####..",
679 "...##...",
680 "..####..",
681 ".##..##.",
682 "........",
683 "........"};
684
685 /* XPM */
686 static const char * const information_xpm[]={
687 "32 32 5 1",
688 ". c None",
689 "c c #000000",
690 "* c #999999",
691 "a c #ffffff",
692 "b c #0000ff",
693 "...........********.............",
694 "........***aaaaaaaa***..........",
695 "......**aaaaaaaaaaaaaa**........",
696 ".....*aaaaaaaaaaaaaaaaaa*.......",
697 "....*aaaaaaaabbbbaaaaaaaac......",
698 "...*aaaaaaaabbbbbbaaaaaaaac.....",
699 "..*aaaaaaaaabbbbbbaaaaaaaaac....",
700 ".*aaaaaaaaaaabbbbaaaaaaaaaaac...",
701 ".*aaaaaaaaaaaaaaaaaaaaaaaaaac*..",
702 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac*.",
703 "*aaaaaaaaaabbbbbbbaaaaaaaaaaac*.",
704 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
705 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
706 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
707 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
708 "*aaaaaaaaaaaabbbbbaaaaaaaaaaac**",
709 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
710 ".*aaaaaaaaaaabbbbbaaaaaaaaaac***",
711 "..*aaaaaaaaaabbbbbaaaaaaaaac***.",
712 "...caaaaaaabbbbbbbbbaaaaaac****.",
713 "....caaaaaaaaaaaaaaaaaaaac****..",
714 ".....caaaaaaaaaaaaaaaaaac****...",
715 "......ccaaaaaaaaaaaaaacc****....",
716 ".......*cccaaaaaaaaccc*****.....",
717 "........***cccaaaac*******......",
718 "..........****caaac*****........",
719 ".............*caaac**...........",
720 "...............caac**...........",
721 "................cac**...........",
722 ".................cc**...........",
723 "..................***...........",
724 "...................**..........."};
725 /* XPM */
726 static const char* const warning_xpm[]={
727 "32 32 4 1",
728 ". c None",
729 "a c #ffff00",
730 "* c #000000",
731 "b c #999999",
732 ".............***................",
733 "............*aaa*...............",
734 "...........*aaaaa*b.............",
735 "...........*aaaaa*bb............",
736 "..........*aaaaaaa*bb...........",
737 "..........*aaaaaaa*bb...........",
738 ".........*aaaaaaaaa*bb..........",
739 ".........*aaaaaaaaa*bb..........",
740 "........*aaaaaaaaaaa*bb.........",
741 "........*aaaa***aaaa*bb.........",
742 ".......*aaaa*****aaaa*bb........",
743 ".......*aaaa*****aaaa*bb........",
744 "......*aaaaa*****aaaaa*bb.......",
745 "......*aaaaa*****aaaaa*bb.......",
746 ".....*aaaaaa*****aaaaaa*bb......",
747 ".....*aaaaaa*****aaaaaa*bb......",
748 "....*aaaaaaaa***aaaaaaaa*bb.....",
749 "....*aaaaaaaa***aaaaaaaa*bb.....",
750 "...*aaaaaaaaa***aaaaaaaaa*bb....",
751 "...*aaaaaaaaaa*aaaaaaaaaa*bb....",
752 "..*aaaaaaaaaaa*aaaaaaaaaaa*bb...",
753 "..*aaaaaaaaaaaaaaaaaaaaaaa*bb...",
754 ".*aaaaaaaaaaaa**aaaaaaaaaaa*bb..",
755 ".*aaaaaaaaaaa****aaaaaaaaaa*bb..",
756 "*aaaaaaaaaaaa****aaaaaaaaaaa*bb.",
757 "*aaaaaaaaaaaaa**aaaaaaaaaaaa*bb.",
758 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
759 "*aaaaaaaaaaaaaaaaaaaaaaaaaaa*bbb",
760 ".*aaaaaaaaaaaaaaaaaaaaaaaaa*bbbb",
761 "..*************************bbbbb",
762 "....bbbbbbbbbbbbbbbbbbbbbbbbbbb.",
763 ".....bbbbbbbbbbbbbbbbbbbbbbbbb.."};
764 /* XPM */
765 static const char* const critical_xpm[]={
766 "32 32 4 1",
767 ". c None",
768 "a c #999999",
769 "* c #ff0000",
770 "b c #ffffff",
771 "...........********.............",
772 ".........************...........",
773 ".......****************.........",
774 "......******************........",
775 ".....********************a......",
776 "....**********************a.....",
777 "...************************a....",
778 "..*******b**********b*******a...",
779 "..******bbb********bbb******a...",
780 ".******bbbbb******bbbbb******a..",
781 ".*******bbbbb****bbbbb*******a..",
782 "*********bbbbb**bbbbb*********a.",
783 "**********bbbbbbbbbb**********a.",
784 "***********bbbbbbbb***********aa",
785 "************bbbbbb************aa",
786 "************bbbbbb************aa",
787 "***********bbbbbbbb***********aa",
788 "**********bbbbbbbbbb**********aa",
789 "*********bbbbb**bbbbb*********aa",
790 ".*******bbbbb****bbbbb*******aa.",
791 ".******bbbbb******bbbbb******aa.",
792 "..******bbb********bbb******aaa.",
793 "..*******b**********b*******aa..",
794 "...************************aaa..",
795 "....**********************aaa...",
796 "....a********************aaa....",
797 ".....a******************aaa.....",
798 "......a****************aaa......",
799 ".......aa************aaaa.......",
800 ".........aa********aaaaa........",
801 "...........aaaaaaaaaaa..........",
802 ".............aaaaaaa............"};
803 /* XPM */
804 static const char *const question_xpm[] = {
805 "32 32 5 1",
806 ". c None",
807 "c c #000000",
808 "* c #999999",
809 "a c #ffffff",
810 "b c #0000ff",
811 "...........********.............",
812 "........***aaaaaaaa***..........",
813 "......**aaaaaaaaaaaaaa**........",
814 ".....*aaaaaaaaaaaaaaaaaa*.......",
815 "....*aaaaaaaaaaaaaaaaaaaac......",
816 "...*aaaaaaaabbbbbbaaaaaaaac.....",
817 "..*aaaaaaaabaaabbbbaaaaaaaac....",
818 ".*aaaaaaaabbaaaabbbbaaaaaaaac...",
819 ".*aaaaaaaabbbbaabbbbaaaaaaaac*..",
820 "*aaaaaaaaabbbbaabbbbaaaaaaaaac*.",
821 "*aaaaaaaaaabbaabbbbaaaaaaaaaac*.",
822 "*aaaaaaaaaaaaabbbbaaaaaaaaaaac**",
823 "*aaaaaaaaaaaaabbbaaaaaaaaaaaac**",
824 "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
825 "*aaaaaaaaaaaaabbaaaaaaaaaaaaac**",
826 "*aaaaaaaaaaaaaaaaaaaaaaaaaaaac**",
827 ".*aaaaaaaaaaaabbaaaaaaaaaaaac***",
828 ".*aaaaaaaaaaabbbbaaaaaaaaaaac***",
829 "..*aaaaaaaaaabbbbaaaaaaaaaac***.",
830 "...caaaaaaaaaabbaaaaaaaaaac****.",
831 "....caaaaaaaaaaaaaaaaaaaac****..",
832 ".....caaaaaaaaaaaaaaaaaac****...",
833 "......ccaaaaaaaaaaaaaacc****....",
834 ".......*cccaaaaaaaaccc*****.....",
835 "........***cccaaaac*******......",
836 "..........****caaac*****........",
837 ".............*caaac**...........",
838 "...............caac**...........",
839 "................cac**...........",
840 ".................cc**...........",
841 "..................***...........",
842 "...................**..........."};
843
844 #endif //QT_NO_IMAGEFORMAT_XPM
845
846 /*!
847  \reimp
848  */
849 QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
850                                       const QWidget *widget) const
851 {
852 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
853     QPixmap desktopIcon;
854     switch(standardPixmap) {
855     case SP_DriveCDIcon:
856     case SP_DriveDVDIcon:
857     case SP_DriveNetIcon:
858     case SP_DriveHDIcon:
859     case SP_DriveFDIcon:
860     case SP_FileIcon:
861     case SP_FileLinkIcon:
862     case SP_DirLinkIcon:
863     case SP_DirClosedIcon:
864     case SP_DesktopIcon:
865     case SP_ComputerIcon:
866     case SP_DirOpenIcon:
867     case SP_FileDialogNewFolder:
868     case SP_DirHomeIcon:
869     case SP_TrashIcon:
870     case SP_VistaShield:
871         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
872             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap);
873             desktopIcon = theme->standardPixmap(sp, QSizeF(16, 16));
874         }
875         break;
876     case SP_MessageBoxInformation:
877     case SP_MessageBoxWarning:
878     case SP_MessageBoxCritical:
879     case SP_MessageBoxQuestion:
880         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
881             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap);
882             desktopIcon = theme->standardPixmap(sp, QSizeF());
883         }
884         break;
885     default:
886         break;
887     }
888     if (!desktopIcon.isNull()) {
889         return desktopIcon;
890     }
891 #endif
892 #ifndef QT_NO_IMAGEFORMAT_XPM
893     switch (standardPixmap) {
894     case SP_TitleBarMenuButton:
895         return QPixmap(qt_menu_xpm);
896     case SP_TitleBarShadeButton:
897         return QPixmap(qt_shade_xpm);
898     case SP_TitleBarUnshadeButton:
899         return QPixmap(qt_unshade_xpm);
900     case SP_TitleBarNormalButton:
901         return QPixmap(qt_normalizeup_xpm);
902     case SP_TitleBarMinButton:
903         return QPixmap(qt_minimize_xpm);
904     case SP_TitleBarMaxButton:
905         return QPixmap(qt_maximize_xpm);
906     case SP_TitleBarCloseButton:
907         return QPixmap(qt_close_xpm);
908     case SP_TitleBarContextHelpButton:
909         return QPixmap(qt_help_xpm);
910     case SP_DockWidgetCloseButton:
911         return QPixmap(dock_widget_close_xpm);
912     case SP_MessageBoxInformation:
913         return QPixmap(information_xpm);
914     case SP_MessageBoxWarning:
915         return QPixmap(warning_xpm);
916     case SP_MessageBoxCritical:
917         return QPixmap(critical_xpm);
918     case SP_MessageBoxQuestion:
919         return QPixmap(question_xpm);
920     default:
921         break;
922     }
923 #endif //QT_NO_IMAGEFORMAT_XPM
924     return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
925 }
926
927 /*! \reimp */
928 int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
929                              QStyleHintReturn *returnData) const
930 {
931     int ret = 0;
932
933     switch (hint) {
934     case SH_EtchDisabledText:
935     case SH_Slider_SnapToValue:
936     case SH_PrintDialog_RightAlignButtons:
937     case SH_FontDialog_SelectAssociatedText:
938     case SH_Menu_AllowActiveAndDisabled:
939     case SH_MenuBar_AltKeyNavigation:
940     case SH_MenuBar_MouseTracking:
941     case SH_Menu_MouseTracking:
942     case SH_ComboBox_ListMouseTracking:
943     case SH_ScrollBar_StopMouseOverSlider:
944     case SH_MainWindow_SpaceBelowMenuBar:
945         ret = 1;
946
947         break;
948     case SH_ItemView_ShowDecorationSelected:
949 #ifndef QT_NO_LISTVIEW
950         if (qobject_cast<const QListView*>(widget))
951             ret = 1;
952 #endif
953         break;
954     case SH_ItemView_ChangeHighlightOnFocus:
955         ret = 1;
956         break;
957     case SH_ToolBox_SelectedPageTitleBold:
958         ret = 0;
959         break;
960
961 #if defined(Q_OS_WIN)
962     case SH_UnderlineShortcut:
963     {
964         ret = 1;
965         BOOL cues = false;
966         SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
967         ret = int(cues);
968         // Do nothing if we always paint underlines
969         Q_D(const QWindowsStyle);
970         if (!ret && widget && d) {
971 #ifndef QT_NO_MENUBAR
972             const QMenuBar *menuBar = qobject_cast<const QMenuBar *>(widget);
973             if (!menuBar && qobject_cast<const QMenu *>(widget)) {
974                 QWidget *w = QApplication::activeWindow();
975                 if (w && w != widget)
976                     menuBar = w->findChild<QMenuBar *>();
977             }
978             // If we paint a menu bar draw underlines if is in the keyboardState
979             if (menuBar) {
980                 if (menuBar->d_func()->keyboardState || d->altDown())
981                     ret = 1;
982                 // Otherwise draw underlines if the toplevel widget has seen an alt-press
983             } else
984 #endif // QT_NO_MENUBAR
985             if (d->hasSeenAlt(widget)) {
986                 ret = 1;
987             }
988         }
989         break;
990     }
991 #endif
992 #ifndef QT_NO_RUBBERBAND
993     case SH_RubberBand_Mask:
994         if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
995             ret = 0;
996             if (rbOpt->shape == QRubberBand::Rectangle) {
997                 ret = true;
998                 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
999                     mask->region = opt->rect;
1000                     int size = 1;
1001                     if (widget && widget->isWindow())
1002                         size = 4;
1003                     mask->region -= opt->rect.adjusted(size, size, -size, -size);
1004                 }
1005             }
1006         }
1007         break;
1008 #endif // QT_NO_RUBBERBAND
1009     case SH_LineEdit_PasswordCharacter:
1010         {
1011 #ifdef Q_OS_WIN
1012             if (widget && (QSysInfo::WindowsVersion >= QSysInfo::WV_XP && (QSysInfo::WindowsVersion & QSysInfo::WV_NT_based))) {
1013                 const QFontMetrics &fm = widget->fontMetrics();
1014                 if (fm.inFont(QChar(0x25CF)))
1015                     ret = 0x25CF;
1016                 else if (fm.inFont(QChar(0x2022)))
1017                     ret = 0x2022;
1018             }
1019 #endif
1020             if (!ret)
1021                 ret = '*';
1022         }
1023         break;
1024 #ifndef QT_NO_WIZARD
1025     case SH_WizardStyle:
1026         ret = QWizard::ModernStyle;
1027         break;
1028 #endif
1029     case SH_ItemView_ArrowKeysNavigateIntoChildren:
1030         ret = true;
1031         break;
1032     case SH_DialogButtonBox_ButtonsHaveIcons:
1033         ret = 0;
1034         break;
1035     default:
1036         ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
1037         break;
1038     }
1039     return ret;
1040 }
1041
1042 /*! \reimp */
1043 void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
1044                                   const QWidget *w) const
1045 {
1046     // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
1047     bool doRestore = false;
1048
1049     switch (pe) {
1050 #ifndef QT_NO_TOOLBAR
1051   case PE_IndicatorToolBarSeparator:
1052         {
1053             QRect rect = opt->rect;
1054             const int margin = 2;
1055             QPen oldPen = p->pen();
1056             if(opt->state & State_Horizontal){
1057                 const int offset = rect.width()/2;
1058                 p->setPen(QPen(opt->palette.dark().color()));
1059                 p->drawLine(rect.bottomLeft().x() + offset,
1060                             rect.bottomLeft().y() - margin,
1061                             rect.topLeft().x() + offset,
1062                             rect.topLeft().y() + margin);
1063                 p->setPen(QPen(opt->palette.light().color()));
1064                 p->drawLine(rect.bottomLeft().x() + offset + 1,
1065                             rect.bottomLeft().y() - margin,
1066                             rect.topLeft().x() + offset + 1,
1067                             rect.topLeft().y() + margin);
1068             }
1069             else{ //Draw vertical separator
1070                 const int offset = rect.height()/2;
1071                 p->setPen(QPen(opt->palette.dark().color()));
1072                 p->drawLine(rect.topLeft().x() + margin ,
1073                             rect.topLeft().y() + offset,
1074                             rect.topRight().x() - margin,
1075                             rect.topRight().y() + offset);
1076                 p->setPen(QPen(opt->palette.light().color()));
1077                 p->drawLine(rect.topLeft().x() + margin ,
1078                             rect.topLeft().y() + offset + 1,
1079                             rect.topRight().x() - margin,
1080                             rect.topRight().y() + offset + 1);
1081             }
1082             p->setPen(oldPen);
1083         }
1084         break;
1085     case PE_IndicatorToolBarHandle:
1086         p->save();
1087         p->translate(opt->rect.x(), opt->rect.y());
1088         if (opt->state & State_Horizontal) {
1089             int x = opt->rect.width() / 2 - 4;
1090             if (opt->direction == Qt::RightToLeft)
1091                 x -= 2;
1092             if (opt->rect.height() > 4) {
1093                 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
1094                                 opt->palette, false, 1, 0);
1095                 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
1096                                 opt->palette, false, 1, 0);
1097             }
1098         } else {
1099             if (opt->rect.width() > 4) {
1100                 int y = opt->rect.height() / 2 - 4;
1101                 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
1102                                 opt->palette, false, 1, 0);
1103                 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
1104                                 opt->palette, false, 1, 0);
1105             }
1106         }
1107         p->restore();
1108         break;
1109
1110 #endif // QT_NO_TOOLBAR
1111     case PE_FrameButtonTool:
1112     case PE_PanelButtonTool: {
1113         QPen oldPen = p->pen();
1114 #ifndef QT_NO_DOCKWIDGET
1115         if (w && w->inherits("QDockWidgetTitleButton")) {
1116            if (const QWidget *dw = w->parentWidget())
1117                 if (dw->isWindow()){
1118                     qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),
1119                            &opt->palette.button());
1120
1121                     return;
1122                 }
1123         }
1124 #endif // QT_NO_DOCKWIDGET
1125         QBrush fill;
1126         bool stippled;
1127         bool panel = (pe == PE_PanelButtonTool);
1128         if ((!(opt->state & State_Sunken ))
1129             && (!(opt->state & State_Enabled)
1130                 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))
1131             && (opt->state & State_On)) {
1132             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1133             stippled = true;
1134         } else {
1135             fill = opt->palette.brush(QPalette::Button);
1136             stippled = false;
1137         }
1138
1139         if (opt->state & (State_Raised | State_Sunken | State_On)) {
1140             if (opt->state & State_AutoRaise) {
1141                 if(opt->state & (State_Enabled | State_Sunken | State_On)){
1142                     if (panel)
1143                         qDrawShadePanel(p, opt->rect, opt->palette,
1144                                         opt->state & (State_Sunken | State_On), 1, &fill);
1145                     else
1146                         qDrawShadeRect(p, opt->rect, opt->palette,
1147                                        opt->state & (State_Sunken | State_On), 1);
1148                 }
1149                 if (stippled) {
1150                     p->setPen(opt->palette.button().color());
1151                     p->drawRect(opt->rect.adjusted(1,1,-2,-2));
1152                 }
1153             } else {
1154                 qDrawWinButton(p, opt->rect, opt->palette,
1155                                opt->state & (State_Sunken | State_On), panel ? &fill : 0);
1156             }
1157         } else {
1158             p->fillRect(opt->rect, fill);
1159         }
1160         p->setPen(oldPen);
1161         break; }
1162     case PE_PanelButtonCommand:
1163         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
1164             QBrush fill;
1165             State flags = opt->state;
1166             QPalette pal = opt->palette;
1167             QRect r = opt->rect;
1168             if (! (flags & State_Sunken) && (flags & State_On))
1169                 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
1170             else
1171                 fill = pal.brush(QPalette::Button);
1172
1173             if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
1174                 p->setPen(pal.dark().color());
1175                 p->setBrush(fill);
1176                 p->drawRect(r.adjusted(0, 0, -1, -1));
1177             } else if (flags & (State_Raised | State_On | State_Sunken)) {
1178                 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
1179                                &fill);
1180             } else {
1181                 p->fillRect(r, fill);
1182             }
1183         }
1184         break;
1185     case PE_FrameDefaultButton: {
1186         QPen oldPen = p->pen();
1187         p->setPen(opt->palette.shadow().color());
1188         QRect rect = opt->rect;
1189         rect.adjust(0, 0, -1, -1);
1190         p->drawRect(rect);
1191         p->setPen(oldPen);
1192         break;
1193     }
1194     case PE_IndicatorArrowUp:
1195     case PE_IndicatorArrowDown:
1196     case PE_IndicatorArrowRight:
1197     case PE_IndicatorArrowLeft:
1198         {
1199             if (opt->rect.width() <= 1 || opt->rect.height() <= 1)
1200                 break;
1201             QRect r = opt->rect;
1202             int size = qMin(r.height(), r.width());
1203             QPixmap pixmap;
1204             QString pixmapName = QStyleHelper::uniqueName(QLatin1String("$qt_ia-")
1205                                                           % QLatin1String(metaObject()->className()), opt, QSize(size, size))
1206                                  % HexString<uint>(pe);
1207             if (!QPixmapCache::find(pixmapName, pixmap)) {
1208                 int border = size/5;
1209                 int sqsize = 2*(size/2);
1210                 QImage image(sqsize, sqsize, QImage::Format_ARGB32_Premultiplied);
1211                 image.fill(0);
1212                 QPainter imagePainter(&image);
1213
1214                 QPolygon a;
1215                 switch (pe) {
1216                     case PE_IndicatorArrowUp:
1217                         a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize - border, sqsize/2);
1218                         break;
1219                     case PE_IndicatorArrowDown:
1220                         a.setPoints(3, border, sqsize/2,  sqsize/2, sqsize - border,  sqsize - border, sqsize/2);
1221                         break;
1222                     case PE_IndicatorArrowRight:
1223                         a.setPoints(3, sqsize - border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
1224                         break;
1225                     case PE_IndicatorArrowLeft:
1226                         a.setPoints(3, border, sqsize/2,  sqsize/2, border,  sqsize/2, sqsize - border);
1227                         break;
1228                     default:
1229                         break;
1230                 }
1231
1232                 int bsx = 0;
1233                 int bsy = 0;
1234
1235                 if (opt->state & State_Sunken) {
1236                     bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, w);
1237                     bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, w);
1238                 }
1239
1240                 QRect bounds = a.boundingRect();
1241                 int sx = sqsize / 2 - bounds.center().x() - 1;
1242                 int sy = sqsize / 2 - bounds.center().y() - 1;
1243                 imagePainter.translate(sx + bsx, sy + bsy);
1244                 imagePainter.setPen(opt->palette.buttonText().color());
1245                 imagePainter.setBrush(opt->palette.buttonText());
1246
1247                 if (!(opt->state & State_Enabled)) {
1248                     imagePainter.translate(1, 1);
1249                     imagePainter.setBrush(opt->palette.light().color());
1250                     imagePainter.setPen(opt->palette.light().color());
1251                     imagePainter.drawPolygon(a);
1252                     imagePainter.translate(-1, -1);
1253                     imagePainter.setBrush(opt->palette.mid().color());
1254                     imagePainter.setPen(opt->palette.mid().color());
1255                 }
1256
1257                 imagePainter.drawPolygon(a);
1258                 imagePainter.end();
1259                 pixmap = QPixmap::fromImage(image);
1260                 QPixmapCache::insert(pixmapName, pixmap);
1261             }
1262             int xOffset = r.x() + (r.width() - size)/2;
1263             int yOffset = r.y() + (r.height() - size)/2;
1264             p->drawPixmap(xOffset, yOffset, pixmap);
1265         }
1266         break;
1267     case PE_IndicatorCheckBox: {
1268         QBrush fill;
1269         if (opt->state & State_NoChange)
1270             fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
1271         else if (opt->state & State_Sunken)
1272             fill = opt->palette.button();
1273         else if (opt->state & State_Enabled)
1274             fill = opt->palette.base();
1275         else
1276             fill = opt->palette.background();
1277         p->save();
1278         doRestore = true;
1279         qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
1280         if (opt->state & State_NoChange)
1281             p->setPen(opt->palette.dark().color());
1282         else
1283             p->setPen(opt->palette.text().color());
1284         } // Fall through!
1285     case PE_IndicatorViewItemCheck:
1286         if (!doRestore) {
1287             p->save();
1288             doRestore = true;
1289         }
1290         if (pe == PE_IndicatorViewItemCheck) {
1291             const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
1292             p->setPen(itemViewOpt
1293                       && itemViewOpt->showDecorationSelected
1294                       && opt->state & State_Selected
1295                         ? opt->palette.highlightedText().color()
1296                         : opt->palette.text().color());
1297             if (opt->state & State_NoChange)
1298                 p->setBrush(opt->palette.brush(QPalette::Button));
1299             p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
1300         }
1301         if (!(opt->state & State_Off)) {
1302             QLineF lines[7];
1303             int i, xx, yy;
1304             xx = opt->rect.x() + 3;
1305             yy = opt->rect.y() + 5;
1306             for (i = 0; i < 3; ++i) {
1307                 lines[i] = QLineF(xx, yy, xx, yy + 2);
1308                 ++xx;
1309                 ++yy;
1310             }
1311             yy -= 2;
1312             for (i = 3; i < 7; ++i) {
1313                 lines[i] = QLineF(xx, yy, xx, yy + 2);
1314                 ++xx;
1315                 --yy;
1316             }
1317             p->drawLines(lines, 7);
1318         }
1319         if (doRestore)
1320             p->restore();
1321         break;
1322     case PE_FrameFocusRect:
1323         if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
1324             //### check for d->alt_down
1325             if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt))
1326                 return;
1327             QRect r = opt->rect;
1328             p->save();
1329             p->setBackgroundMode(Qt::TransparentMode);
1330             QColor bg_col = fropt->backgroundColor;
1331             if (!bg_col.isValid())
1332                 bg_col = p->background().color();
1333             // Create an "XOR" color.
1334             QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
1335                               (bg_col.green() ^ 0xff) & 0xff,
1336                               (bg_col.blue() ^ 0xff) & 0xff);
1337             p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
1338             p->setBrushOrigin(r.topLeft());
1339             p->setPen(Qt::NoPen);
1340             p->drawRect(r.left(), r.top(), r.width(), 1);    // Top
1341             p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
1342             p->drawRect(r.left(), r.top(), 1, r.height());   // Left
1343             p->drawRect(r.right(), r.top(), 1, r.height());  // Right
1344             p->restore();
1345         }
1346         break;
1347     case PE_IndicatorRadioButton:
1348         {
1349 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
1350             static const QPoint pts1[] = {              // dark lines
1351                 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
1352                 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)
1353             };
1354             static const QPoint pts2[] = {              // black lines
1355                 QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),
1356                 QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)
1357             };
1358             static const QPoint pts3[] = {              // background lines
1359                 QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),
1360                 QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)
1361             };
1362             static const QPoint pts4[] = {              // white lines
1363                 QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),
1364                 QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),
1365                 QPoint(10, 3), QPoint(10, 2)
1366             };
1367             static const QPoint pts5[] = {              // inner fill
1368                 QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),
1369                 QPoint(2, 7), QPoint(2, 4)
1370             };
1371
1372             // make sure the indicator is square
1373             QRect ir = opt->rect;
1374
1375             if (opt->rect.width() < opt->rect.height()) {
1376                 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1377                 ir.setHeight(opt->rect.width());
1378             } else if (opt->rect.height() < opt->rect.width()) {
1379                 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1380                 ir.setWidth(opt->rect.height());
1381             }
1382
1383             p->save();
1384             bool down = opt->state & State_Sunken;
1385             bool enabled = opt->state & State_Enabled;
1386             bool on = opt->state & State_On;
1387             QPolygon a;
1388
1389             //center when rect is larger than indicator size
1390             int xOffset = 0;
1391             int yOffset = 0;
1392             int indicatorWidth = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth);
1393             int indicatorHeight = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth);
1394             if (ir.width() > indicatorWidth)
1395                 xOffset += (ir.width() - indicatorWidth)/2;
1396             if (ir.height() > indicatorHeight)
1397                 yOffset += (ir.height() - indicatorHeight)/2;
1398             p->translate(xOffset, yOffset);
1399
1400             p->translate(ir.x(), ir.y());
1401
1402             p->setPen(opt->palette.dark().color());
1403             p->drawPolyline(pts1, PTSARRLEN(pts1));
1404
1405             p->setPen(opt->palette.shadow().color());
1406             p->drawPolyline(pts2, PTSARRLEN(pts2));
1407
1408             p->setPen(opt->palette.midlight().color());
1409             p->drawPolyline(pts3, PTSARRLEN(pts3));
1410
1411             p->setPen(opt->palette.light().color());
1412             p->drawPolyline(pts4, PTSARRLEN(pts4));
1413
1414             QColor fillColor = (down || !enabled)
1415                                ? opt->palette.button().color()
1416                                : opt->palette.base().color();
1417             p->setPen(fillColor);
1418             p->setBrush(fillColor) ;
1419             p->drawPolygon(pts5, PTSARRLEN(pts5));
1420
1421             p->translate(-ir.x(), -ir.y()); // restore translate
1422
1423             if (on) {
1424                 p->setPen(Qt::NoPen);
1425                 p->setBrush(opt->palette.text());
1426                 p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4);
1427                 p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2);
1428             }
1429             p->restore();
1430             break;
1431         }
1432 #ifndef QT_NO_FRAME
1433     case PE_Frame:
1434     case PE_FrameMenu:
1435         if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1436             if (frame->lineWidth == 2 || pe == PE_Frame) {
1437                 QPalette popupPal = frame->palette;
1438                 if (pe == PE_FrameMenu) {
1439                     popupPal.setColor(QPalette::Light, frame->palette.background().color());
1440                     popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
1441                 }
1442                 if (pe == PE_Frame && (frame->state & State_Raised))
1443                     qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
1444                 else if (pe == PE_Frame && (frame->state & State_Sunken))
1445                 {
1446                     popupPal.setColor(QPalette::Midlight, frame->palette.background().color());
1447                     qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1448                 }
1449                 else
1450                     qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1451             } else {
1452                 QCommonStyle::drawPrimitive(pe, opt, p, w);
1453             }
1454         } else {
1455             QPalette popupPal = opt->palette;
1456             popupPal.setColor(QPalette::Light, opt->palette.background().color());
1457             popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
1458             qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
1459         }
1460         break;
1461 #endif // QT_NO_FRAME
1462     case PE_FrameButtonBevel:
1463     case PE_PanelButtonBevel: {
1464         QBrush fill;
1465         bool panel = pe != PE_FrameButtonBevel;
1466         p->setBrushOrigin(opt->rect.topLeft());
1467         if (!(opt->state & State_Sunken) && (opt->state & State_On))
1468             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1469         else
1470             fill = opt->palette.brush(QPalette::Button);
1471
1472         if (opt->state & (State_Raised | State_On | State_Sunken)) {
1473             qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
1474                            panel ? &fill : 0);
1475         } else {
1476             if (panel)
1477                 p->fillRect(opt->rect, fill);
1478             else
1479                 p->drawRect(opt->rect);
1480         }
1481         break; }
1482     case PE_FrameWindow: {
1483          QPalette popupPal = opt->palette;
1484          popupPal.setColor(QPalette::Light, opt->palette.background().color());
1485          popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
1486          qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
1487         break; }
1488 #ifndef QT_NO_DOCKWIDGET
1489     case PE_IndicatorDockWidgetResizeHandle:
1490         break;
1491     case PE_FrameDockWidget:
1492         if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1493             proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
1494         }
1495     break;
1496 #endif // QT_NO_DOCKWIDGET
1497
1498     case PE_FrameStatusBarItem:
1499         qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0);
1500         break;
1501
1502     case PE_IndicatorProgressChunk:
1503         {
1504             bool vertical = false, inverted = false;
1505             if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
1506                 vertical = (pb2->orientation == Qt::Vertical);
1507                 inverted = pb2->invertedAppearance;
1508             }
1509
1510             int space = 2;
1511             int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
1512             if (!vertical) {
1513                 if (opt->rect.width() <= chunksize)
1514                     space = 0;
1515
1516                 if (inverted)
1517                     p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1518                             opt->palette.brush(QPalette::Highlight));
1519                 else
1520                     p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1521                                 opt->palette.brush(QPalette::Highlight));
1522             } else {
1523                 if (opt->rect.height() <= chunksize)
1524                     space = 0;
1525
1526                 if (inverted)
1527                     p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
1528                             opt->palette.brush(QPalette::Highlight));
1529                 else
1530                     p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
1531                                 opt->palette.brush(QPalette::Highlight));
1532             }
1533         }
1534         break;
1535
1536     case PE_FrameTabWidget: {
1537         qDrawWinButton(p, opt->rect, opt->palette, false, 0);
1538         break;
1539     }
1540     default:
1541         QCommonStyle::drawPrimitive(pe, opt, p, w);
1542     }
1543 }
1544
1545 /*! \reimp */
1546 void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
1547                                 const QWidget *widget) const
1548 {
1549     switch (ce) {
1550 #ifndef QT_NO_RUBBERBAND
1551     case CE_RubberBand:
1552         if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
1553             // ### workaround for slow general painter path
1554             QPixmap tiledPixmap(16, 16);
1555             QPainter pixmapPainter(&tiledPixmap);
1556             pixmapPainter.setPen(Qt::NoPen);
1557             pixmapPainter.setBrush(Qt::Dense4Pattern);
1558             pixmapPainter.setBackground(Qt::white);
1559             pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1560             pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1561             pixmapPainter.end();
1562             tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1563             p->save();
1564             QRect r = opt->rect;
1565             QStyleHintReturnMask mask;
1566             if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1567                 p->setClipRegion(mask.region);
1568             p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1569             p->restore();
1570             return;
1571         }
1572         break;
1573 #endif // QT_NO_RUBBERBAND
1574
1575 #if !defined(QT_NO_MENU) && !defined(QT_NO_MAINWINDOW)
1576     case CE_MenuBarEmptyArea:
1577         if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
1578             p->fillRect(opt->rect, opt->palette.button());
1579             QPen oldPen = p->pen();
1580             p->setPen(QPen(opt->palette.dark().color()));
1581             p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1582             p->setPen(oldPen);
1583         }
1584         break;
1585 #endif
1586 #ifndef QT_NO_MENU
1587     case CE_MenuItem:
1588         if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1589             int x, y, w, h;
1590             menuitem->rect.getRect(&x, &y, &w, &h);
1591             int tab = menuitem->tabWidth;
1592             bool dis = !(menuitem->state & State_Enabled);
1593             bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1594                             ? menuitem->checked : false;
1595             bool act = menuitem->state & State_Selected;
1596
1597             // windows always has a check column, regardless whether we have an icon or not
1598             int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1599
1600             QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1601             p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1602
1603             if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1604                 int yoff = y-1 + h / 2;
1605                 p->setPen(menuitem->palette.dark().color());
1606                 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1607                 p->setPen(menuitem->palette.light().color());
1608                 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1609                 return;
1610             }
1611
1612             QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1613             if (!menuitem->icon.isNull() && checked) {
1614                 if (act) {
1615                     qDrawShadePanel(p, vCheckRect,
1616                                     menuitem->palette, true, 1,
1617                                     &menuitem->palette.brush(QPalette::Button));
1618                 } else {
1619                     QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1620                     qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1621                 }
1622             } else if (!act) {
1623                 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1624             }
1625
1626             // On Windows Style, if we have a checkable item and an icon we
1627             // draw the icon recessed to indicate an item is checked. If we
1628             // have no icon, we draw a checkmark instead.
1629             if (!menuitem->icon.isNull()) {
1630                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1631                 if (act && !dis)
1632                     mode = QIcon::Active;
1633                 QPixmap pixmap;
1634                 if (checked)
1635                     pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On);
1636                 else
1637                     pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode);
1638                 int pixw = pixmap.width();
1639                 int pixh = pixmap.height();
1640                 if (act && !dis && !checked)
1641                     qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
1642                                     &menuitem->palette.brush(QPalette::Button));
1643                 QRect pmr(0, 0, pixw, pixh);
1644                 pmr.moveCenter(vCheckRect.center());
1645                 p->setPen(menuitem->palette.text().color());
1646                 p->drawPixmap(pmr.topLeft(), pixmap);
1647             } else if (checked) {
1648                 QStyleOptionMenuItem newMi = *menuitem;
1649                 newMi.state = State_None;
1650                 if (!dis)
1651                     newMi.state |= State_Enabled;
1652                 if (act)
1653                     newMi.state |= State_On;
1654                 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1655                                                                               menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1656                                                                               checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1657                                                                               menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1658                 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1659             }
1660             p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1661
1662             QColor discol;
1663             if (dis) {
1664                 discol = menuitem->palette.text().color();
1665                 p->setPen(discol);
1666             }
1667
1668             int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin);
1669             int xpos = menuitem->rect.x() + xm;
1670             QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1671                            w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1672             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1673             QString s = menuitem->text;
1674             if (!s.isEmpty()) {                     // draw text
1675                 p->save();
1676                 int t = s.indexOf(QLatin1Char('\t'));
1677                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1678                 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1679                     text_flags |= Qt::TextHideMnemonic;
1680                 text_flags |= Qt::AlignLeft;
1681                 if (t >= 0) {
1682                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1683                         QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1684                     if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1685                         p->setPen(menuitem->palette.light().color());
1686                         p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1687                         p->setPen(discol);
1688                     }
1689                     p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1690                     s = s.left(t);
1691                 }
1692                 QFont font = menuitem->font;
1693                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1694                     font.setBold(true);
1695                 p->setFont(font);
1696                 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1697                     p->setPen(menuitem->palette.light().color());
1698                     p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1699                     p->setPen(discol);
1700                 }
1701                 p->drawText(vTextRect, text_flags, s.left(t));
1702                 p->restore();
1703             }
1704             if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1705                 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1706                 PrimitiveElement arrow;
1707                 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1708                 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1709                 QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1710                 QStyleOptionMenuItem newMI = *menuitem;
1711                 newMI.rect = vSubMenuRect;
1712                 newMI.state = dis ? State_None : State_Enabled;
1713                 if (act)
1714                     newMI.palette.setColor(QPalette::ButtonText,
1715                                            newMI.palette.highlightedText().color());
1716                 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1717             }
1718
1719         }
1720         break;
1721 #endif // QT_NO_MENU
1722 #ifndef QT_NO_MENUBAR
1723     case CE_MenuBarItem:
1724         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1725             bool active = mbi->state & State_Selected;
1726             bool hasFocus = mbi->state & State_HasFocus;
1727             bool down = mbi->state & State_Sunken;
1728             QStyleOptionMenuItem newMbi = *mbi;
1729             p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button));
1730             if (active || hasFocus) {
1731                 QBrush b = mbi->palette.brush(QPalette::Button);
1732                 if (active && down)
1733                     p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
1734                 if (active && hasFocus)
1735                     qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1736                                    mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
1737                 if (active && down) {
1738                     newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1739                                        proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1740                     p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
1741                 }
1742             }
1743             QCommonStyle::drawControl(ce, &newMbi, p, widget);
1744         }
1745         break;
1746 #endif // QT_NO_MENUBAR
1747 #ifndef QT_NO_TABBAR
1748     case CE_TabBarTabShape:
1749         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1750             bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1751                                && (tab->shape == QTabBar::RoundedNorth
1752                                    || tab->shape == QTabBar::RoundedSouth));
1753             bool selected = tab->state & State_Selected;
1754             bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1755                             || (rtlHorTabs
1756                                 && tab->position == QStyleOptionTab::Beginning));
1757             bool firstTab = ((!rtlHorTabs
1758                                && tab->position == QStyleOptionTab::Beginning)
1759                              || (rtlHorTabs
1760                                  && tab->position == QStyleOptionTab::End));
1761             bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1762             bool previousSelected =
1763                 ((!rtlHorTabs
1764                   && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1765                 || (rtlHorTabs
1766                     && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1767             bool nextSelected =
1768                 ((!rtlHorTabs
1769                   && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1770                  || (rtlHorTabs
1771                      && tab->selectedPosition
1772                             == QStyleOptionTab::PreviousIsSelected));
1773             int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1774             bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1775                                 || (rtlHorTabs
1776                                     && tabBarAlignment == Qt::AlignRight);
1777
1778             bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1779                                  || (rtlHorTabs
1780                                          && tabBarAlignment == Qt::AlignLeft);
1781
1782             QColor light = tab->palette.light().color();
1783             QColor dark = tab->palette.dark().color();
1784             QColor shadow = tab->palette.shadow().color();
1785             int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1786             if (selected)
1787                 borderThinkness /= 2;
1788             QRect r2(opt->rect);
1789             int x1 = r2.left();
1790             int x2 = r2.right();
1791             int y1 = r2.top();
1792             int y2 = r2.bottom();
1793             switch (tab->shape) {
1794             default:
1795                 QCommonStyle::drawControl(ce, tab, p, widget);
1796                 break;
1797             case QTabBar::RoundedNorth: {
1798                 if (!selected) {
1799                     y1 += 2;
1800                     x1 += onlyOne || firstTab ? borderThinkness : 0;
1801                     x2 -= onlyOne || lastTab ? borderThinkness : 0;
1802                 }
1803
1804                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
1805
1806                 // Delete border
1807                 if (selected) {
1808                     p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background());
1809                     p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background());
1810                 }
1811                 // Left
1812                 if (firstTab || selected || onlyOne || !previousSelected) {
1813                     p->setPen(light);
1814                     p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1815                     p->drawPoint(x1 + 1, y1 + 1);
1816                 }
1817                 // Top
1818                 {
1819                     int beg = x1 + (previousSelected ? 0 : 2);
1820                     int end = x2 - (nextSelected ? 0 : 2);
1821                     p->setPen(light);
1822                     p->drawLine(beg, y1, end, y1);
1823                 }
1824                 // Right
1825                 if (lastTab || selected || onlyOne || !nextSelected) {
1826                     p->setPen(shadow);
1827                     p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1828                     p->drawPoint(x2 - 1, y1 + 1);
1829                     p->setPen(dark);
1830                     p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1831                 }
1832                 break; }
1833             case QTabBar::RoundedSouth: {
1834                 if (!selected) {
1835                     y2 -= 2;
1836                     x1 += firstTab ? borderThinkness : 0;
1837                     x2 -= lastTab ? borderThinkness : 0;
1838                 }
1839
1840                 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
1841
1842                 // Delete border
1843                 if (selected) {
1844                     p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background());
1845                     p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background());
1846                 }
1847                 // Left
1848                 if (firstTab || selected || onlyOne || !previousSelected) {
1849                     p->setPen(light);
1850                     p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1851                     p->drawPoint(x1 + 1, y2 - 1);
1852                 }
1853                 // Bottom
1854                 {
1855                     int beg = x1 + (previousSelected ? 0 : 2);
1856                     int end = x2 - (nextSelected ? 0 : 2);
1857                     p->setPen(shadow);
1858                     p->drawLine(beg, y2, end, y2);
1859                     p->setPen(dark);
1860                     p->drawLine(beg, y2 - 1, end, y2 - 1);
1861                 }
1862                 // Right
1863                 if (lastTab || selected || onlyOne || !nextSelected) {
1864                     p->setPen(shadow);
1865                     p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1866                     p->drawPoint(x2 - 1, y2 - 1);
1867                     p->setPen(dark);
1868                     p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1869                 }
1870                 break; }
1871             case QTabBar::RoundedWest: {
1872                 if (!selected) {
1873                     x1 += 2;
1874                     y1 += firstTab ? borderThinkness : 0;
1875                     y2 -= lastTab ? borderThinkness : 0;
1876                 }
1877
1878                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
1879
1880                 // Delete border
1881                 if (selected) {
1882                     p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background());
1883                     p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background());
1884                 }
1885                 // Top
1886                 if (firstTab || selected || onlyOne || !previousSelected) {
1887                     p->setPen(light);
1888                     p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1889                     p->drawPoint(x1 + 1, y1 + 1);
1890                 }
1891                 // Left
1892                 {
1893                     int beg = y1 + (previousSelected ? 0 : 2);
1894                     int end = y2 - (nextSelected ? 0 : 2);
1895                     p->setPen(light);
1896                     p->drawLine(x1, beg, x1, end);
1897                 }
1898                 // Bottom
1899                 if (lastTab || selected || onlyOne || !nextSelected) {
1900                     p->setPen(shadow);
1901                     p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1902                     p->drawPoint(x1 + 2, y2 - 1);
1903                     p->setPen(dark);
1904                     p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1905                     p->drawPoint(x1 + 1, y2 - 1);
1906                     p->drawPoint(x1 + 2, y2);
1907                 }
1908                 break; }
1909             case QTabBar::RoundedEast: {
1910                 if (!selected) {
1911                     x2 -= 2;
1912                     y1 += firstTab ? borderThinkness : 0;
1913                     y2 -= lastTab ? borderThinkness : 0;
1914                 }
1915
1916                 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
1917
1918                 // Delete border
1919                 if (selected) {
1920                     p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background());
1921                     p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background());
1922                 }
1923                 // Top
1924                 if (firstTab || selected || onlyOne || !previousSelected) {
1925                     p->setPen(light);
1926                     p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1927                     p->drawPoint(x2 - 1, y1 + 1);
1928                 }
1929                 // Right
1930                 {
1931                     int beg = y1 + (previousSelected ? 0 : 2);
1932                     int end = y2 - (nextSelected ? 0 : 2);
1933                     p->setPen(shadow);
1934                     p->drawLine(x2, beg, x2, end);
1935                     p->setPen(dark);
1936                     p->drawLine(x2 - 1, beg, x2 - 1, end);
1937                 }
1938                 // Bottom
1939                 if (lastTab || selected || onlyOne || !nextSelected) {
1940                     p->setPen(shadow);
1941                     p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1942                     p->drawPoint(x2 - 1, y2 - 1);
1943                     p->setPen(dark);
1944                     p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1945                 }
1946                 break; }
1947             }
1948         }
1949         break;
1950 #endif // QT_NO_TABBAR
1951     case CE_ToolBoxTabShape:
1952         qDrawShadePanel(p, opt->rect, opt->palette,
1953                         opt->state & (State_Sunken | State_On), 1,
1954                         &opt->palette.brush(QPalette::Button));
1955         break;
1956 #ifndef QT_NO_SPLITTER
1957     case CE_Splitter:
1958         p->eraseRect(opt->rect);
1959         break;
1960 #endif // QT_NO_SPLITTER
1961 #ifndef QT_NO_SCROLLBAR
1962     case CE_ScrollBarSubLine:
1963     case CE_ScrollBarAddLine: {
1964         if ((opt->state & State_Sunken)) {
1965             p->setPen(opt->palette.dark().color());
1966             p->setBrush(opt->palette.brush(QPalette::Button));
1967             p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1968         } else {
1969             QStyleOption buttonOpt = *opt;
1970             if (!(buttonOpt.state & State_Sunken))
1971                 buttonOpt.state |= State_Raised;
1972             QPalette pal(opt->palette);
1973             pal.setColor(QPalette::Button, opt->palette.light().color());
1974             pal.setColor(QPalette::Light, opt->palette.button().color());
1975             qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1976                            &opt->palette.brush(QPalette::Button));
1977         }
1978         PrimitiveElement arrow;
1979         if (opt->state & State_Horizontal) {
1980             if (ce == CE_ScrollBarAddLine)
1981                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1982             else
1983                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1984         } else {
1985             if (ce == CE_ScrollBarAddLine)
1986                 arrow = PE_IndicatorArrowDown;
1987             else
1988                 arrow = PE_IndicatorArrowUp;
1989         }
1990         QStyleOption arrowOpt = *opt;
1991         arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1992         proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1993         break; }
1994     case CE_ScrollBarAddPage:
1995     case CE_ScrollBarSubPage: {
1996             QBrush br;
1997             QBrush bg = p->background();
1998             Qt::BGMode bg_mode = p->backgroundMode();
1999             p->setPen(Qt::NoPen);
2000             p->setBackgroundMode(Qt::OpaqueMode);
2001
2002             if (opt->state & State_Sunken) {
2003                 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
2004                 p->setBackground(opt->palette.dark().color());
2005                 p->setBrush(br);
2006             } else {
2007                 QPixmap pm = opt->palette.brush(QPalette::Light).texture();
2008                 br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2009                 p->setBackground(opt->palette.background().color());
2010                 p->setBrush(br);
2011             }
2012             p->drawRect(opt->rect);
2013             p->setBackground(bg);
2014             p->setBackgroundMode(bg_mode);
2015             break; }
2016     case CE_ScrollBarSlider:
2017         if (!(opt->state & State_Enabled)) {
2018             QPixmap pm = opt->palette.brush(QPalette::Light).texture();
2019             QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2020             p->setPen(Qt::NoPen);
2021             p->setBrush(br);
2022             p->setBackgroundMode(Qt::OpaqueMode);
2023             p->drawRect(opt->rect);
2024         } else {
2025             QStyleOptionButton buttonOpt;
2026             buttonOpt.QStyleOption::operator=(*opt);
2027             buttonOpt.state = State_Enabled | State_Raised;
2028
2029             QPalette pal(opt->palette);
2030             pal.setColor(QPalette::Button, opt->palette.light().color());
2031             pal.setColor(QPalette::Light, opt->palette.button().color());
2032             qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button));
2033         }
2034         break;
2035 #endif // QT_NO_SCROLLBAR
2036     case CE_HeaderSection: {
2037         QBrush fill;
2038         if (opt->state & State_On)
2039             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2040         else
2041             fill = opt->palette.brush(QPalette::Button);
2042
2043         if (opt->state & (State_Raised | State_Sunken)) {
2044             qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
2045         } else {
2046             p->fillRect(opt->rect, fill);
2047         }
2048         break; }
2049 #ifndef QT_NO_TOOLBAR
2050     case CE_ToolBar:
2051         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
2052             // Reserve the beveled appearance only for mainwindow toolbars
2053             if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
2054                 break;
2055
2056             QRect rect = opt->rect;
2057             bool paintLeftBorder = true;
2058             bool paintRightBorder = true;
2059             bool paintBottomBorder = true;
2060
2061             switch (toolbar->toolBarArea){
2062             case Qt::BottomToolBarArea :
2063                 switch(toolbar->positionOfLine){
2064                 case QStyleOptionToolBar::Beginning:
2065                 case QStyleOptionToolBar::OnlyOne:
2066                     paintBottomBorder = false;
2067                 default:
2068                     break;
2069                 }
2070             case Qt::TopToolBarArea :
2071                 switch(toolbar->positionWithinLine){
2072                 case QStyleOptionToolBar::Beginning:
2073                     paintLeftBorder = false;
2074                     break;
2075                 case QStyleOptionToolBar::End:
2076                     paintRightBorder = false;
2077                     break;
2078                 case QStyleOptionToolBar::OnlyOne:
2079                     paintRightBorder = false;
2080                     paintLeftBorder = false;
2081                 default:
2082                     break;
2083                 }
2084                 if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
2085                     bool tmp = paintLeftBorder;
2086                     paintRightBorder=paintLeftBorder;
2087                     paintLeftBorder=tmp;
2088                 }
2089                 break;
2090             case Qt::RightToolBarArea :
2091                 switch (toolbar->positionOfLine){
2092                 case QStyleOptionToolBar::Beginning:
2093                 case QStyleOptionToolBar::OnlyOne:
2094                     paintRightBorder = false;
2095                     break;
2096                 default:
2097                     break;
2098                 }
2099                 break;
2100             case Qt::LeftToolBarArea :
2101                 switch (toolbar->positionOfLine){
2102                 case QStyleOptionToolBar::Beginning:
2103                 case QStyleOptionToolBar::OnlyOne:
2104                     paintLeftBorder = false;
2105                     break;
2106                 default:
2107                     break;
2108                 }
2109                 break;
2110             default:
2111                 break;
2112             }
2113
2114
2115             //draw top border
2116             p->setPen(QPen(opt->palette.light().color()));
2117             p->drawLine(rect.topLeft().x(),
2118                         rect.topLeft().y(),
2119                         rect.topRight().x(),
2120                         rect.topRight().y());
2121
2122             if (paintLeftBorder){
2123                 p->setPen(QPen(opt->palette.light().color()));
2124                 p->drawLine(rect.topLeft().x(),
2125                             rect.topLeft().y(),
2126                             rect.bottomLeft().x(),
2127                             rect.bottomLeft().y());
2128             }
2129
2130             if (paintRightBorder){
2131                 p->setPen(QPen(opt->palette.dark().color()));
2132                 p->drawLine(rect.topRight().x(),
2133                             rect.topRight().y(),
2134                             rect.bottomRight().x(),
2135                             rect.bottomRight().y());
2136             }
2137
2138             if (paintBottomBorder){
2139                 p->setPen(QPen(opt->palette.dark().color()));
2140                 p->drawLine(rect.bottomLeft().x(),
2141                             rect.bottomLeft().y(),
2142                             rect.bottomRight().x(),
2143                             rect.bottomRight().y());
2144             }
2145         }
2146         break;
2147
2148
2149 #endif // QT_NO_TOOLBAR
2150
2151     case CE_ProgressBarContents:
2152         if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
2153             QRect rect = pb->rect;
2154             if (!rect.isValid())
2155                 return;
2156
2157             bool vertical = false;
2158             bool inverted = false;
2159
2160             // Get extra style options if version 2
2161             const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
2162             if (pb2) {
2163                 vertical = (pb2->orientation == Qt::Vertical);
2164                 inverted = pb2->invertedAppearance;
2165             }
2166             QMatrix m;
2167             if (vertical) {
2168                 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height
2169                 m.rotate(90);
2170                 m.translate(0, -(rect.height() + rect.y()*2));
2171             }
2172             QPalette pal2 = pb->palette;
2173             // Correct the highlight color if it is the same as the background
2174             if (pal2.highlight() == pal2.background())
2175                 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
2176                                                                      QPalette::Highlight));
2177             bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
2178             if (inverted)
2179                 reverse = !reverse;
2180             int w = rect.width();
2181             Q_D(const QWindowsStyle);
2182             if (pb->minimum == 0 && pb->maximum == 0) {
2183                 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
2184                 QStyleOptionProgressBarV2 pbBits = *pb;
2185                 Q_ASSERT(unit_width >0);
2186
2187                 pbBits.rect = rect;
2188                 pbBits.palette = pal2;
2189
2190                 int step = 0;
2191                 int chunkCount = w / unit_width + 1;
2192                 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
2193                     step = (animation->animationStep() / 3) % chunkCount;
2194                 else
2195                     d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject));
2196                 int chunksInRow = 5;
2197                 int myY = pbBits.rect.y();
2198                 int myHeight = pbBits.rect.height();
2199                 int chunksToDraw = chunksInRow;
2200
2201                 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step);
2202                 p->save();
2203                 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
2204
2205                 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width  : rect.left() + unit_width * step;
2206                 int x = 0;
2207
2208                 for (int i = 0; i < chunksToDraw ; ++i) {
2209                     pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
2210                     pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
2211                     proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
2212                     x += reverse ? -unit_width : unit_width;
2213                 }
2214                 //Draw wrap-around chunks
2215                 if( step > chunkCount-5){
2216                     x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
2217                     x = 0;
2218                     int chunksToDraw = step - (chunkCount - chunksInRow);
2219                     for (int i = 0; i < chunksToDraw ; ++i) {
2220                         pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
2221                         pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
2222                         proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
2223                         x += reverse ? -unit_width : unit_width;
2224                     }
2225                 }
2226                 p->restore(); //restore state
2227             }
2228             else {
2229                 d->stopAnimation(opt->styleObject);
2230                 QCommonStyle::drawControl(ce, opt, p, widget);
2231             }
2232         }
2233         break;
2234
2235 #ifndef QT_NO_DOCKWIDGET
2236     case CE_DockWidgetTitle:
2237
2238         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
2239             Q_D(const QWindowsStyle);
2240
2241             const QStyleOptionDockWidgetV2 *v2
2242                 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
2243             bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2244
2245             QRect rect = dwOpt->rect;
2246             QRect r = rect;
2247
2248             if (verticalTitleBar) {
2249                 QSize s = r.size();
2250                 s.transpose();
2251                 r.setSize(s);
2252
2253                 p->save();
2254                 p->translate(r.left(), r.top() + r.width());
2255                 p->rotate(-90);
2256                 p->translate(-r.left(), -r.top());
2257             }
2258
2259             bool floating = false;
2260             bool active = dwOpt->state & State_Active;
2261             QColor inactiveCaptionTextColor = d->inactiveCaptionText;
2262             if (dwOpt->movable) {
2263                 QColor left, right;
2264
2265                 //Titlebar gradient
2266                 if (widget && widget->isWindow()) {
2267                     floating = true;
2268                     if (active) {
2269                         left = d->activeCaptionColor;
2270                         right = d->activeGradientCaptionColor;
2271                     } else {
2272                         left = d->inactiveCaptionColor;
2273                         right = d->inactiveGradientCaptionColor;
2274                     }
2275                     QBrush fillBrush(left);
2276                     if (left != right) {
2277                         QPoint p1(r.x(), r.top() + r.height()/2);
2278                         QPoint p2(rect.right(), r.top() + r.height()/2);
2279                         QLinearGradient lg(p1, p2);
2280                         lg.setColorAt(0, left);
2281                         lg.setColorAt(1, right);
2282                         fillBrush = lg;
2283                     }
2284                     p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
2285                 }
2286             }
2287             if (!dwOpt->title.isEmpty()) {
2288                 QFont oldFont = p->font();
2289                 if (floating) {
2290                     QFont font = oldFont;
2291                     font.setBold(true);
2292                     p->setFont(font);
2293                 }
2294                 QPalette palette = dwOpt->palette;
2295                 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
2296                 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
2297                 if (verticalTitleBar) {
2298                     titleRect = QRect(r.left() + rect.bottom()
2299                                         - titleRect.bottom(),
2300                                     r.top() + titleRect.left() - rect.left(),
2301                                     titleRect.height(), titleRect.width());
2302                 }
2303                 proxy()->drawItemText(p, titleRect,
2304                             Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette,
2305                             dwOpt->state & State_Enabled, dwOpt->title,
2306                             floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
2307                 p->setFont(oldFont);
2308             }
2309             if (verticalTitleBar)
2310                 p->restore();
2311         }
2312         return;
2313 #endif // QT_NO_DOCKWIDGET
2314     default:
2315         QCommonStyle::drawControl(ce, opt, p, widget);
2316     }
2317 }
2318
2319 /*! \reimp */
2320 QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
2321 {
2322     QRect r;
2323     switch (sr) {
2324     case SE_SliderFocusRect:
2325     case SE_ToolBoxTabContents:
2326         r = visualRect(opt->direction, opt->rect, opt->rect);
2327         break;
2328     case SE_DockWidgetTitleBarText: {
2329         r = QCommonStyle::subElementRect(sr, opt, w);
2330         const QStyleOptionDockWidgetV2 *v2
2331             = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
2332         bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2333         int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
2334         if (verticalTitleBar) {
2335             r.adjust(0, 0, 0, -m);
2336         } else {
2337             if (opt->direction == Qt::LeftToRight)
2338                 r.adjust(m, 0, 0, 0);
2339             else
2340                 r.adjust(0, 0, -m, 0);
2341         }
2342         break;
2343     }
2344     case SE_ProgressBarContents:
2345         r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
2346         r.adjust(3, 3, -3, -3);
2347         break;
2348     default:
2349         r = QCommonStyle::subElementRect(sr, opt, w);
2350     }
2351     return r;
2352 }
2353
2354
2355 /*! \reimp */
2356 void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
2357                                        QPainter *p, const QWidget *widget) const
2358 {
2359     switch (cc) {
2360 #ifndef QT_NO_SLIDER
2361     case CC_Slider:
2362         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2363             int thickness  = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
2364             int len        = proxy()->pixelMetric(PM_SliderLength, slider, widget);
2365             int ticks = slider->tickPosition;
2366             QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
2367             QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
2368
2369             if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
2370                 int mid = thickness / 2;
2371
2372                 if (ticks & QSlider::TicksAbove)
2373                     mid += len / 8;
2374                 if (ticks & QSlider::TicksBelow)
2375                     mid -= len / 8;
2376
2377                 p->setPen(slider->palette.shadow().color());
2378                 if (slider->orientation == Qt::Horizontal) {
2379                     qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
2380                                    groove.width(), 4, slider->palette, true);
2381                     p->drawLine(groove.x() + 1, groove.y() + mid - 1,
2382                                 groove.x() + groove.width() - 3, groove.y() + mid - 1);
2383                 } else {
2384                     qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
2385                                   4, groove.height(), slider->palette, true);
2386                     p->drawLine(groove.x() + mid - 1, groove.y() + 1,
2387                                 groove.x() + mid - 1, groove.y() + groove.height() - 3);
2388                 }
2389             }
2390
2391             if (slider->subControls & SC_SliderTickmarks) {
2392                 QStyleOptionSlider tmpSlider = *slider;
2393                 tmpSlider.subControls = SC_SliderTickmarks;
2394                 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
2395             }
2396
2397             if (slider->subControls & SC_SliderHandle) {
2398                 // 4444440
2399                 // 4333310
2400                 // 4322210
2401                 // 4322210
2402                 // 4322210
2403                 // 4322210
2404                 // *43210*
2405                 // **410**
2406                 // ***0***
2407                 const QColor c0 = slider->palette.shadow().color();
2408                 const QColor c1 = slider->palette.dark().color();
2409                 // const QColor c2 = g.button();
2410                 const QColor c3 = slider->palette.midlight().color();
2411                 const QColor c4 = slider->palette.light().color();
2412                 QBrush handleBrush;
2413
2414                 if (slider->state & State_Enabled) {
2415                     handleBrush = slider->palette.color(QPalette::Button);
2416                 } else {
2417                     handleBrush = QBrush(slider->palette.color(QPalette::Button),
2418                                          Qt::Dense4Pattern);
2419                 }
2420
2421
2422                 int x = handle.x(), y = handle.y(),
2423                    wi = handle.width(), he = handle.height();
2424
2425                 int x1 = x;
2426                 int x2 = x+wi-1;
2427                 int y1 = y;
2428                 int y2 = y+he-1;
2429
2430                 Qt::Orientation orient = slider->orientation;
2431                 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
2432                 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
2433
2434                 if (slider->state & State_HasFocus) {
2435                     QStyleOptionFocusRect fropt;
2436                     fropt.QStyleOption::operator=(*slider);
2437                     fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
2438                     proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
2439                 }
2440
2441                 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
2442                     Qt::BGMode oldMode = p->backgroundMode();
2443                     p->setBackgroundMode(Qt::OpaqueMode);
2444                     qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
2445                                    &handleBrush);
2446                     p->setBackgroundMode(oldMode);
2447                     return;
2448                 }
2449
2450                 QSliderDirection dir;
2451
2452                 if (orient == Qt::Horizontal)
2453                     if (tickAbove)
2454                         dir = SlUp;
2455                     else
2456                         dir = SlDown;
2457                 else
2458                     if (tickAbove)
2459                         dir = SlLeft;
2460                     else
2461                         dir = SlRight;
2462
2463                 QPolygon a;
2464
2465                 int d = 0;
2466                 switch (dir) {
2467                 case SlUp:
2468                     y1 = y1 + wi/2;
2469                     d =  (wi + 1) / 2 - 1;
2470                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
2471                     break;
2472                 case SlDown:
2473                     y2 = y2 - wi/2;
2474                     d =  (wi + 1) / 2 - 1;
2475                     a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
2476                     break;
2477                 case SlLeft:
2478                     d =  (he + 1) / 2 - 1;
2479                     x1 = x1 + he/2;
2480                     a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
2481                     break;
2482                 case SlRight:
2483                     d =  (he + 1) / 2 - 1;
2484                     x2 = x2 - he/2;
2485                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
2486                     break;
2487                 }
2488
2489                 QBrush oldBrush = p->brush();
2490                 p->setPen(Qt::NoPen);
2491                 p->setBrush(handleBrush);
2492                 Qt::BGMode oldMode = p->backgroundMode();
2493                 p->setBackgroundMode(Qt::OpaqueMode);
2494                 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
2495                 p->drawPolygon(a);
2496                 p->setBrush(oldBrush);
2497                 p->setBackgroundMode(oldMode);
2498
2499                 if (dir != SlUp) {
2500                     p->setPen(c4);
2501                     p->drawLine(x1, y1, x2, y1);
2502                     p->setPen(c3);
2503                     p->drawLine(x1, y1+1, x2, y1+1);
2504                 }
2505                 if (dir != SlLeft) {
2506                     p->setPen(c3);
2507                     p->drawLine(x1+1, y1+1, x1+1, y2);
2508                     p->setPen(c4);
2509                     p->drawLine(x1, y1, x1, y2);
2510                 }
2511                 if (dir != SlRight) {
2512                     p->setPen(c0);
2513                     p->drawLine(x2, y1, x2, y2);
2514                     p->setPen(c1);
2515                     p->drawLine(x2-1, y1+1, x2-1, y2-1);
2516                 }
2517                 if (dir != SlDown) {
2518                     p->setPen(c0);
2519                     p->drawLine(x1, y2, x2, y2);
2520                     p->setPen(c1);
2521                     p->drawLine(x1+1, y2-1, x2-1, y2-1);
2522                 }
2523
2524                 switch (dir) {
2525                 case SlUp:
2526                     p->setPen(c4);
2527                     p->drawLine(x1, y1, x1+d, y1-d);
2528                     p->setPen(c0);
2529                     d = wi - d - 1;
2530                     p->drawLine(x2, y1, x2-d, y1-d);
2531                     d--;
2532                     p->setPen(c3);
2533                     p->drawLine(x1+1, y1, x1+1+d, y1-d);
2534                     p->setPen(c1);
2535                     p->drawLine(x2-1, y1, x2-1-d, y1-d);
2536                     break;
2537                 case SlDown:
2538                     p->setPen(c4);
2539                     p->drawLine(x1, y2, x1+d, y2+d);
2540                     p->setPen(c0);
2541                     d = wi - d - 1;
2542                     p->drawLine(x2, y2, x2-d, y2+d);
2543                     d--;
2544                     p->setPen(c3);
2545                     p->drawLine(x1+1, y2, x1+1+d, y2+d);
2546                     p->setPen(c1);
2547                     p->drawLine(x2-1, y2, x2-1-d, y2+d);
2548                     break;
2549                 case SlLeft:
2550                     p->setPen(c4);
2551                     p->drawLine(x1, y1, x1-d, y1+d);
2552                     p->setPen(c0);
2553                     d = he - d - 1;
2554                     p->drawLine(x1, y2, x1-d, y2-d);
2555                     d--;
2556                     p->setPen(c3);
2557                     p->drawLine(x1, y1+1, x1-d, y1+1+d);
2558                     p->setPen(c1);
2559                     p->drawLine(x1, y2-1, x1-d, y2-1-d);
2560                     break;
2561                 case SlRight:
2562                     p->setPen(c4);
2563                     p->drawLine(x2, y1, x2+d, y1+d);
2564                     p->setPen(c0);
2565                     d = he - d - 1;
2566                     p->drawLine(x2, y2, x2+d, y2-d);
2567                     d--;
2568                     p->setPen(c3);
2569                     p->drawLine(x2, y1+1, x2+d, y1+1+d);
2570                     p->setPen(c1);
2571                     p->drawLine(x2, y2-1, x2+d, y2-1-d);
2572                     break;
2573                 }
2574             }
2575         }
2576         break;
2577 #endif // QT_NO_SLIDER
2578 #ifndef QT_NO_SCROLLBAR
2579     case CC_ScrollBar:
2580         if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2581             QStyleOptionSlider newScrollbar = *scrollbar;
2582             if (scrollbar->minimum == scrollbar->maximum)
2583                 newScrollbar.state &= ~State_Enabled; //do not draw the slider.
2584             QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2585         }
2586         break;
2587 #endif // QT_NO_SCROLLBAR
2588 #ifndef QT_NO_COMBOBOX
2589     case CC_ComboBox:
2590         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2591             QBrush editBrush = cmb->palette.brush(QPalette::Base);
2592             if ((cmb->subControls & SC_ComboBoxFrame)) {
2593                 if (cmb->frame) {
2594                     QPalette shadePal = opt->palette;
2595                     shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2596                     qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush);
2597                 }
2598                 else {
2599                     p->fillRect(opt->rect, editBrush);
2600                 }
2601             }
2602             if (cmb->subControls & SC_ComboBoxArrow) {
2603                 State flags = State_None;
2604
2605                 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2606                 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2607                                    && cmb->state & State_Sunken;
2608                 if (sunkenArrow) {
2609                     p->setPen(cmb->palette.dark().color());
2610                     p->setBrush(cmb->palette.brush(QPalette::Button));
2611                     p->drawRect(ar.adjusted(0,0,-1,-1));
2612                 } else {
2613                     // Make qDrawWinButton use the right colors for drawing the shade of the button
2614                     QPalette pal(cmb->palette);
2615                     pal.setColor(QPalette::Button, cmb->palette.light().color());
2616                     pal.setColor(QPalette::Light, cmb->palette.button().color());
2617                     qDrawWinButton(p, ar, pal, false,
2618                                    &cmb->palette.brush(QPalette::Button));
2619                 }
2620
2621                 ar.adjust(2, 2, -2, -2);
2622                 if (opt->state & State_Enabled)
2623                     flags |= State_Enabled;
2624                 if (opt->state & State_HasFocus)
2625                     flags |= State_HasFocus;
2626
2627                 if (sunkenArrow)
2628                     flags |= State_Sunken;
2629                 QStyleOption arrowOpt(0);
2630                 arrowOpt.rect = ar.adjusted(1, 1, -1, -1);
2631                 arrowOpt.palette = cmb->palette;
2632                 arrowOpt.state = flags;
2633                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2634             }
2635
2636             if (cmb->subControls & SC_ComboBoxEditField) {
2637                 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2638                 if (cmb->state & State_HasFocus && !cmb->editable)
2639                     p->fillRect(re.x(), re.y(), re.width(), re.height(),
2640                                 cmb->palette.brush(QPalette::Highlight));
2641
2642                 if (cmb->state & State_HasFocus) {
2643                     p->setPen(cmb->palette.highlightedText().color());
2644                     p->setBackground(cmb->palette.highlight());
2645
2646                 } else {
2647                     p->setPen(cmb->palette.text().color());
2648                     p->setBackground(cmb->palette.background());
2649                 }
2650
2651                 if (cmb->state & State_HasFocus && !cmb->editable) {
2652                     QStyleOptionFocusRect focus;
2653                     focus.QStyleOption::operator=(*cmb);
2654                     focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2655                     focus.state |= State_FocusAtBorder;
2656                     focus.backgroundColor = cmb->palette.highlight().color();
2657                     proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2658                 }
2659             }
2660         }
2661         break;
2662 #endif // QT_NO_COMBOBOX
2663 #ifndef QT_NO_SPINBOX
2664     case CC_SpinBox:
2665         if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2666             QStyleOptionSpinBox copy = *sb;
2667             PrimitiveElement pe;
2668             bool enabled = opt->state & State_Enabled;
2669             if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2670                 QBrush editBrush = sb->palette.brush(QPalette::Base);
2671                 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2672                 QPalette shadePal = sb->palette;
2673                 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2674                 qDrawWinPanel(p, r, shadePal, true, &editBrush);
2675             }
2676
2677             QPalette shadePal(opt->palette);
2678             shadePal.setColor(QPalette::Button, opt->palette.light().color());
2679             shadePal.setColor(QPalette::Light, opt->palette.button().color());
2680
2681             if (sb->subControls & SC_SpinBoxUp) {
2682                 copy.subControls = SC_SpinBoxUp;
2683                 QPalette pal2 = sb->palette;
2684                 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2685                     pal2.setCurrentColorGroup(QPalette::Disabled);
2686                     copy.state &= ~State_Enabled;
2687                 }
2688
2689                 copy.palette = pal2;
2690
2691                 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2692                     copy.state |= State_On;
2693                     copy.state |= State_Sunken;
2694                 } else {
2695                     copy.state |= State_Raised;
2696                     copy.state &= ~State_Sunken;
2697                 }
2698                 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2699                                                                        : PE_IndicatorSpinUp);
2700
2701                 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2702                 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2703                                 &copy.palette.brush(QPalette::Button));
2704                 copy.rect.adjust(4, 1, -5, -1);
2705                 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2706                     && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2707                 {
2708                     QStyleOptionSpinBox lightCopy = copy;
2709                     lightCopy.rect.adjust(1, 1, 1, 1);
2710                     lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2711                     proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2712                 }
2713                 proxy()->drawPrimitive(pe, &copy, p, widget);
2714             }
2715
2716             if (sb->subControls & SC_SpinBoxDown) {
2717                 copy.subControls = SC_SpinBoxDown;
2718                 copy.state = sb->state;
2719                 QPalette pal2 = sb->palette;
2720                 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2721                     pal2.setCurrentColorGroup(QPalette::Disabled);
2722                     copy.state &= ~State_Enabled;
2723                 }
2724                 copy.palette = pal2;
2725
2726                 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2727                     copy.state |= State_On;
2728                     copy.state |= State_Sunken;
2729                 } else {
2730                     copy.state |= State_Raised;
2731                     copy.state &= ~State_Sunken;
2732                 }
2733                 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2734                                                                        : PE_IndicatorSpinDown);
2735
2736                 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2737                 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2738                                 &copy.palette.brush(QPalette::Button));
2739                 copy.rect.adjust(4, 0, -5, -1);
2740                 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2741                     && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2742                 {
2743                     QStyleOptionSpinBox lightCopy = copy;
2744                     lightCopy.rect.adjust(1, 1, 1, 1);
2745                     lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2746                     proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2747                 }
2748                 proxy()->drawPrimitive(pe, &copy, p, widget);
2749             }
2750         }
2751         break;
2752 #endif // QT_NO_SPINBOX
2753
2754     default:
2755         QCommonStyle::drawComplexControl(cc, opt, p, widget);
2756     }
2757 }
2758
2759 /*! \reimp */
2760 QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2761                                       const QSize &csz, const QWidget *widget) const
2762 {
2763     QSize sz(csz);
2764     switch (ct) {
2765     case CT_PushButton:
2766         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2767             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2768             int w = sz.width(),
2769                 h = sz.height();
2770             int defwidth = 0;
2771             if (btn->features & QStyleOptionButton::AutoDefaultButton)
2772                 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2773             int minwidth = int(QStyleHelper::dpiScaled(75.));
2774             int minheight = int(QStyleHelper::dpiScaled(23.));
2775
2776 #ifndef QT_QWS_SMALL_PUSHBUTTON
2777             if (w < minwidth + defwidth && !btn->text.isEmpty())
2778                 w = minwidth + defwidth;
2779             if (h < minheight + defwidth)
2780                 h = minheight + defwidth;
2781 #endif
2782             sz = QSize(w, h);
2783         }
2784         break;
2785 #ifndef QT_NO_MENU
2786     case CT_MenuItem:
2787         if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2788             int w = sz.width();
2789             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2790
2791             if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2792                 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2793             }
2794             else if (mi->icon.isNull()) {
2795                 sz.setHeight(sz.height() - 2);
2796                 w -= 6;
2797             }
2798
2799             if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2800                 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2801                 sz.setHeight(qMax(sz.height(),
2802                                   mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2803                                   + 2 * QWindowsStylePrivate::windowsItemFrame));
2804             }
2805             int maxpmw = mi->maxIconWidth;
2806             int tabSpacing = 20;
2807             if (mi->text.contains(QLatin1Char('\t')))
2808                 w += tabSpacing;
2809             else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2810                 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2811             else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2812                 // adjust the font and add the difference in size.
2813                 // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
2814                 QFontMetrics fm(mi->font);
2815                 QFont fontBold = mi->font;
2816                 fontBold.setBold(true);
2817                 QFontMetrics fmBold(fontBold);
2818                 w += fmBold.width(mi->text) - fm.width(mi->text);
2819             }
2820
2821             int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
2822             w += checkcol;
2823             w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
2824             sz.setWidth(w);
2825         }
2826         break;
2827 #endif // QT_NO_MENU
2828 #ifndef QT_NO_MENUBAR
2829     case CT_MenuBarItem:
2830         if (!sz.isEmpty())
2831             sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2832         break;
2833 #endif
2834                 // Otherwise, fall through
2835     case CT_ToolButton:
2836         if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
2837             return sz += QSize(7, 6);
2838         // Otherwise, fall through
2839
2840     default:
2841         sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2842     }
2843     return sz;
2844 }
2845
2846 /*!
2847     \reimp
2848 */
2849 QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option,
2850                                   const QWidget *widget) const
2851 {
2852     QIcon icon;
2853 #ifdef Q_OS_WIN
2854     QPixmap pixmap;
2855     switch (standardIcon) {
2856     case SP_DriveCDIcon:
2857     case SP_DriveDVDIcon:
2858     case SP_DriveNetIcon:
2859     case SP_DriveHDIcon:
2860     case SP_DriveFDIcon:
2861     case SP_FileIcon:
2862     case SP_FileLinkIcon:
2863     case SP_DesktopIcon:
2864     case SP_ComputerIcon:
2865         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2866             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2867             for (int size = 16 ; size <= 32 ; size += 16) {
2868                 pixmap = theme->standardPixmap(sp, QSizeF(size, size));
2869                 icon.addPixmap(pixmap, QIcon::Normal);
2870             }
2871         }
2872         break;
2873     case SP_DirIcon:
2874     case SP_DirLinkIcon:
2875         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2876             QPlatformTheme::StandardPixmap spOff = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2877             QPlatformTheme::StandardPixmap spOn = standardIcon == SP_DirIcon ? QPlatformTheme::DirOpenIcon :
2878                                                                                  QPlatformTheme::DirLinkOpenIcon;
2879             for (int size = 16 ; size <= 32 ; size += 16) {
2880                 QSizeF pixSize(size, size);
2881                 pixmap = theme->standardPixmap(spOff, pixSize);
2882                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::Off);
2883                 pixmap = theme->standardPixmap(spOn, pixSize);
2884                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::On);
2885             }
2886         }
2887         break;
2888     case SP_VistaShield:
2889         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2890             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2891             pixmap = theme->standardPixmap(sp, QSizeF(32, 32));
2892         }
2893         break;
2894     default:
2895         break;
2896     }
2897 #endif
2898
2899     if (icon.isNull())
2900         icon = QCommonStyle::standardIcon(standardIcon, option, widget);
2901     return icon;
2902 }
2903
2904
2905
2906 QT_END_NAMESPACE
2907
2908 #endif // QT_NO_STYLE_WINDOWS