Fixed inconsistent QPainter fill rules for aliased painting.
[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                 imagePainter.setRenderHint(QPainter::Qt4CompatiblePainting);
1247
1248                 if (!(opt->state & State_Enabled)) {
1249                     imagePainter.translate(1, 1);
1250                     imagePainter.setBrush(opt->palette.light().color());
1251                     imagePainter.setPen(opt->palette.light().color());
1252                     imagePainter.drawPolygon(a);
1253                     imagePainter.translate(-1, -1);
1254                     imagePainter.setBrush(opt->palette.mid().color());
1255                     imagePainter.setPen(opt->palette.mid().color());
1256                 }
1257
1258                 imagePainter.drawPolygon(a);
1259                 imagePainter.end();
1260                 pixmap = QPixmap::fromImage(image);
1261                 QPixmapCache::insert(pixmapName, pixmap);
1262             }
1263             int xOffset = r.x() + (r.width() - size)/2;
1264             int yOffset = r.y() + (r.height() - size)/2;
1265             p->drawPixmap(xOffset, yOffset, pixmap);
1266         }
1267         break;
1268     case PE_IndicatorCheckBox: {
1269         QBrush fill;
1270         if (opt->state & State_NoChange)
1271             fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
1272         else if (opt->state & State_Sunken)
1273             fill = opt->palette.button();
1274         else if (opt->state & State_Enabled)
1275             fill = opt->palette.base();
1276         else
1277             fill = opt->palette.background();
1278         p->save();
1279         doRestore = true;
1280         qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
1281         if (opt->state & State_NoChange)
1282             p->setPen(opt->palette.dark().color());
1283         else
1284             p->setPen(opt->palette.text().color());
1285         } // Fall through!
1286     case PE_IndicatorViewItemCheck:
1287         if (!doRestore) {
1288             p->save();
1289             doRestore = true;
1290         }
1291         if (pe == PE_IndicatorViewItemCheck) {
1292             const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
1293             p->setPen(itemViewOpt
1294                       && itemViewOpt->showDecorationSelected
1295                       && opt->state & State_Selected
1296                         ? opt->palette.highlightedText().color()
1297                         : opt->palette.text().color());
1298             if (opt->state & State_NoChange)
1299                 p->setBrush(opt->palette.brush(QPalette::Button));
1300             p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, 11, 11);
1301         }
1302         if (!(opt->state & State_Off)) {
1303             QLineF lines[7];
1304             int i, xx, yy;
1305             xx = opt->rect.x() + 3;
1306             yy = opt->rect.y() + 5;
1307             for (i = 0; i < 3; ++i) {
1308                 lines[i] = QLineF(xx, yy, xx, yy + 2);
1309                 ++xx;
1310                 ++yy;
1311             }
1312             yy -= 2;
1313             for (i = 3; i < 7; ++i) {
1314                 lines[i] = QLineF(xx, yy, xx, yy + 2);
1315                 ++xx;
1316                 --yy;
1317             }
1318             p->drawLines(lines, 7);
1319         }
1320         if (doRestore)
1321             p->restore();
1322         break;
1323     case PE_FrameFocusRect:
1324         if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
1325             //### check for d->alt_down
1326             if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt))
1327                 return;
1328             QRect r = opt->rect;
1329             p->save();
1330             p->setBackgroundMode(Qt::TransparentMode);
1331             QColor bg_col = fropt->backgroundColor;
1332             if (!bg_col.isValid())
1333                 bg_col = p->background().color();
1334             // Create an "XOR" color.
1335             QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
1336                               (bg_col.green() ^ 0xff) & 0xff,
1337                               (bg_col.blue() ^ 0xff) & 0xff);
1338             p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
1339             p->setBrushOrigin(r.topLeft());
1340             p->setPen(Qt::NoPen);
1341             p->drawRect(r.left(), r.top(), r.width(), 1);    // Top
1342             p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
1343             p->drawRect(r.left(), r.top(), 1, r.height());   // Left
1344             p->drawRect(r.right(), r.top(), 1, r.height());  // Right
1345             p->restore();
1346         }
1347         break;
1348     case PE_IndicatorRadioButton:
1349         {
1350 #define PTSARRLEN(x) sizeof(x)/(sizeof(QPoint))
1351             static const QPoint pts1[] = {              // dark lines
1352                 QPoint(1, 9), QPoint(1, 8), QPoint(0, 7), QPoint(0, 4), QPoint(1, 3), QPoint(1, 2),
1353                 QPoint(2, 1), QPoint(3, 1), QPoint(4, 0), QPoint(7, 0), QPoint(8, 1), QPoint(9, 1)
1354             };
1355             static const QPoint pts2[] = {              // black lines
1356                 QPoint(2, 8), QPoint(1, 7), QPoint(1, 4), QPoint(2, 3), QPoint(2, 2), QPoint(3, 2),
1357                 QPoint(4, 1), QPoint(7, 1), QPoint(8, 2), QPoint(9, 2)
1358             };
1359             static const QPoint pts3[] = {              // background lines
1360                 QPoint(2, 9), QPoint(3, 9), QPoint(4, 10), QPoint(7, 10), QPoint(8, 9), QPoint(9, 9),
1361                 QPoint(9, 8), QPoint(10, 7), QPoint(10, 4), QPoint(9, 3)
1362             };
1363             static const QPoint pts4[] = {              // white lines
1364                 QPoint(2, 10), QPoint(3, 10), QPoint(4, 11), QPoint(7, 11), QPoint(8, 10),
1365                 QPoint(9, 10), QPoint(10, 9), QPoint(10, 8), QPoint(11, 7), QPoint(11, 4),
1366                 QPoint(10, 3), QPoint(10, 2)
1367             };
1368             static const QPoint pts5[] = {              // inner fill
1369                 QPoint(4, 2), QPoint(7, 2), QPoint(9, 4), QPoint(9, 7), QPoint(7, 9), QPoint(4, 9),
1370                 QPoint(2, 7), QPoint(2, 4)
1371             };
1372
1373             // make sure the indicator is square
1374             QRect ir = opt->rect;
1375
1376             if (opt->rect.width() < opt->rect.height()) {
1377                 ir.setTop(opt->rect.top() + (opt->rect.height() - opt->rect.width()) / 2);
1378                 ir.setHeight(opt->rect.width());
1379             } else if (opt->rect.height() < opt->rect.width()) {
1380                 ir.setLeft(opt->rect.left() + (opt->rect.width() - opt->rect.height()) / 2);
1381                 ir.setWidth(opt->rect.height());
1382             }
1383
1384             p->save();
1385             p->setRenderHint(QPainter::Qt4CompatiblePainting);
1386             bool down = opt->state & State_Sunken;
1387             bool enabled = opt->state & State_Enabled;
1388             bool on = opt->state & State_On;
1389             QPolygon a;
1390
1391             //center when rect is larger than indicator size
1392             int xOffset = 0;
1393             int yOffset = 0;
1394             int indicatorWidth = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth);
1395             int indicatorHeight = proxy()->pixelMetric(PM_ExclusiveIndicatorWidth);
1396             if (ir.width() > indicatorWidth)
1397                 xOffset += (ir.width() - indicatorWidth)/2;
1398             if (ir.height() > indicatorHeight)
1399                 yOffset += (ir.height() - indicatorHeight)/2;
1400             p->translate(xOffset, yOffset);
1401
1402             p->translate(ir.x(), ir.y());
1403
1404             p->setPen(opt->palette.dark().color());
1405             p->drawPolyline(pts1, PTSARRLEN(pts1));
1406
1407             p->setPen(opt->palette.shadow().color());
1408             p->drawPolyline(pts2, PTSARRLEN(pts2));
1409
1410             p->setPen(opt->palette.midlight().color());
1411             p->drawPolyline(pts3, PTSARRLEN(pts3));
1412
1413             p->setPen(opt->palette.light().color());
1414             p->drawPolyline(pts4, PTSARRLEN(pts4));
1415
1416             QColor fillColor = (down || !enabled)
1417                                ? opt->palette.button().color()
1418                                : opt->palette.base().color();
1419             p->setPen(fillColor);
1420             p->setBrush(fillColor) ;
1421             p->drawPolygon(pts5, PTSARRLEN(pts5));
1422
1423             p->translate(-ir.x(), -ir.y()); // restore translate
1424
1425             if (on) {
1426                 p->setPen(Qt::NoPen);
1427                 p->setBrush(opt->palette.text());
1428                 p->drawRect(ir.x() + 5, ir.y() + 4, 2, 4);
1429                 p->drawRect(ir.x() + 4, ir.y() + 5, 4, 2);
1430             }
1431             p->restore();
1432             break;
1433         }
1434 #ifndef QT_NO_FRAME
1435     case PE_Frame:
1436     case PE_FrameMenu:
1437         if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1438             if (frame->lineWidth == 2 || pe == PE_Frame) {
1439                 QPalette popupPal = frame->palette;
1440                 if (pe == PE_FrameMenu) {
1441                     popupPal.setColor(QPalette::Light, frame->palette.background().color());
1442                     popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
1443                 }
1444                 if (pe == PE_Frame && (frame->state & State_Raised))
1445                     qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
1446                 else if (pe == PE_Frame && (frame->state & State_Sunken))
1447                 {
1448                     popupPal.setColor(QPalette::Midlight, frame->palette.background().color());
1449                     qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1450                 }
1451                 else
1452                     qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1453             } else {
1454                 QCommonStyle::drawPrimitive(pe, opt, p, w);
1455             }
1456         } else {
1457             QPalette popupPal = opt->palette;
1458             popupPal.setColor(QPalette::Light, opt->palette.background().color());
1459             popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
1460             qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
1461         }
1462         break;
1463 #endif // QT_NO_FRAME
1464     case PE_FrameButtonBevel:
1465     case PE_PanelButtonBevel: {
1466         QBrush fill;
1467         bool panel = pe != PE_FrameButtonBevel;
1468         p->setBrushOrigin(opt->rect.topLeft());
1469         if (!(opt->state & State_Sunken) && (opt->state & State_On))
1470             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1471         else
1472             fill = opt->palette.brush(QPalette::Button);
1473
1474         if (opt->state & (State_Raised | State_On | State_Sunken)) {
1475             qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
1476                            panel ? &fill : 0);
1477         } else {
1478             if (panel)
1479                 p->fillRect(opt->rect, fill);
1480             else
1481                 p->drawRect(opt->rect);
1482         }
1483         break; }
1484     case PE_FrameWindow: {
1485          QPalette popupPal = opt->palette;
1486          popupPal.setColor(QPalette::Light, opt->palette.background().color());
1487          popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
1488          qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
1489         break; }
1490 #ifndef QT_NO_DOCKWIDGET
1491     case PE_IndicatorDockWidgetResizeHandle:
1492         break;
1493     case PE_FrameDockWidget:
1494         if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1495             proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
1496         }
1497     break;
1498 #endif // QT_NO_DOCKWIDGET
1499
1500     case PE_FrameStatusBarItem:
1501         qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0);
1502         break;
1503
1504     case PE_IndicatorProgressChunk:
1505         {
1506             bool vertical = false, inverted = false;
1507             if (const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt)) {
1508                 vertical = (pb2->orientation == Qt::Vertical);
1509                 inverted = pb2->invertedAppearance;
1510             }
1511
1512             int space = 2;
1513             int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
1514             if (!vertical) {
1515                 if (opt->rect.width() <= chunksize)
1516                     space = 0;
1517
1518                 if (inverted)
1519                     p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1520                             opt->palette.brush(QPalette::Highlight));
1521                 else
1522                     p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1523                                 opt->palette.brush(QPalette::Highlight));
1524             } else {
1525                 if (opt->rect.height() <= chunksize)
1526                     space = 0;
1527
1528                 if (inverted)
1529                     p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
1530                             opt->palette.brush(QPalette::Highlight));
1531                 else
1532                     p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
1533                                 opt->palette.brush(QPalette::Highlight));
1534             }
1535         }
1536         break;
1537
1538     case PE_FrameTabWidget: {
1539         qDrawWinButton(p, opt->rect, opt->palette, false, 0);
1540         break;
1541     }
1542     default:
1543         QCommonStyle::drawPrimitive(pe, opt, p, w);
1544     }
1545 }
1546
1547 /*! \reimp */
1548 void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
1549                                 const QWidget *widget) const
1550 {
1551     switch (ce) {
1552 #ifndef QT_NO_RUBBERBAND
1553     case CE_RubberBand:
1554         if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
1555             // ### workaround for slow general painter path
1556             QPixmap tiledPixmap(16, 16);
1557             QPainter pixmapPainter(&tiledPixmap);
1558             pixmapPainter.setPen(Qt::NoPen);
1559             pixmapPainter.setBrush(Qt::Dense4Pattern);
1560             pixmapPainter.setBackground(Qt::white);
1561             pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1562             pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1563             pixmapPainter.end();
1564             tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1565             p->save();
1566             QRect r = opt->rect;
1567             QStyleHintReturnMask mask;
1568             if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1569                 p->setClipRegion(mask.region);
1570             p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1571             p->restore();
1572             return;
1573         }
1574         break;
1575 #endif // QT_NO_RUBBERBAND
1576
1577 #if !defined(QT_NO_MENU) && !defined(QT_NO_MAINWINDOW)
1578     case CE_MenuBarEmptyArea:
1579         if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
1580             p->fillRect(opt->rect, opt->palette.button());
1581             QPen oldPen = p->pen();
1582             p->setPen(QPen(opt->palette.dark().color()));
1583             p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1584             p->setPen(oldPen);
1585         }
1586         break;
1587 #endif
1588 #ifndef QT_NO_MENU
1589     case CE_MenuItem:
1590         if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1591             int x, y, w, h;
1592             menuitem->rect.getRect(&x, &y, &w, &h);
1593             int tab = menuitem->tabWidth;
1594             bool dis = !(menuitem->state & State_Enabled);
1595             bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1596                             ? menuitem->checked : false;
1597             bool act = menuitem->state & State_Selected;
1598
1599             // windows always has a check column, regardless whether we have an icon or not
1600             int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1601
1602             QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1603             p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1604
1605             if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1606                 int yoff = y-1 + h / 2;
1607                 p->setPen(menuitem->palette.dark().color());
1608                 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1609                 p->setPen(menuitem->palette.light().color());
1610                 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1611                 return;
1612             }
1613
1614             QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1615             if (!menuitem->icon.isNull() && checked) {
1616                 if (act) {
1617                     qDrawShadePanel(p, vCheckRect,
1618                                     menuitem->palette, true, 1,
1619                                     &menuitem->palette.brush(QPalette::Button));
1620                 } else {
1621                     QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1622                     qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1623                 }
1624             } else if (!act) {
1625                 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1626             }
1627
1628             // On Windows Style, if we have a checkable item and an icon we
1629             // draw the icon recessed to indicate an item is checked. If we
1630             // have no icon, we draw a checkmark instead.
1631             if (!menuitem->icon.isNull()) {
1632                 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1633                 if (act && !dis)
1634                     mode = QIcon::Active;
1635                 QPixmap pixmap;
1636                 if (checked)
1637                     pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On);
1638                 else
1639                     pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode);
1640                 int pixw = pixmap.width();
1641                 int pixh = pixmap.height();
1642                 if (act && !dis && !checked)
1643                     qDrawShadePanel(p, vCheckRect,  menuitem->palette, false, 1,
1644                                     &menuitem->palette.brush(QPalette::Button));
1645                 QRect pmr(0, 0, pixw, pixh);
1646                 pmr.moveCenter(vCheckRect.center());
1647                 p->setPen(menuitem->palette.text().color());
1648                 p->drawPixmap(pmr.topLeft(), pixmap);
1649             } else if (checked) {
1650                 QStyleOptionMenuItem newMi = *menuitem;
1651                 newMi.state = State_None;
1652                 if (!dis)
1653                     newMi.state |= State_Enabled;
1654                 if (act)
1655                     newMi.state |= State_On;
1656                 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1657                                                                               menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1658                                                                               checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1659                                                                               menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1660                 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1661             }
1662             p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1663
1664             QColor discol;
1665             if (dis) {
1666                 discol = menuitem->palette.text().color();
1667                 p->setPen(discol);
1668             }
1669
1670             int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin);
1671             int xpos = menuitem->rect.x() + xm;
1672             QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1673                            w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1674             QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1675             QString s = menuitem->text;
1676             if (!s.isEmpty()) {                     // draw text
1677                 p->save();
1678                 int t = s.indexOf(QLatin1Char('\t'));
1679                 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1680                 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1681                     text_flags |= Qt::TextHideMnemonic;
1682                 text_flags |= Qt::AlignLeft;
1683                 if (t >= 0) {
1684                     QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1685                         QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1686                     if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1687                         p->setPen(menuitem->palette.light().color());
1688                         p->drawText(vShortcutRect.adjusted(1,1,1,1), text_flags, s.mid(t + 1));
1689                         p->setPen(discol);
1690                     }
1691                     p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1692                     s = s.left(t);
1693                 }
1694                 QFont font = menuitem->font;
1695                 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1696                     font.setBold(true);
1697                 p->setFont(font);
1698                 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1699                     p->setPen(menuitem->palette.light().color());
1700                     p->drawText(vTextRect.adjusted(1,1,1,1), text_flags, s.left(t));
1701                     p->setPen(discol);
1702                 }
1703                 p->drawText(vTextRect, text_flags, s.left(t));
1704                 p->restore();
1705             }
1706             if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1707                 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1708                 PrimitiveElement arrow;
1709                 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1710                 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1711                 QRect  vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1712                 QStyleOptionMenuItem newMI = *menuitem;
1713                 newMI.rect = vSubMenuRect;
1714                 newMI.state = dis ? State_None : State_Enabled;
1715                 if (act)
1716                     newMI.palette.setColor(QPalette::ButtonText,
1717                                            newMI.palette.highlightedText().color());
1718                 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1719             }
1720
1721         }
1722         break;
1723 #endif // QT_NO_MENU
1724 #ifndef QT_NO_MENUBAR
1725     case CE_MenuBarItem:
1726         if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1727             bool active = mbi->state & State_Selected;
1728             bool hasFocus = mbi->state & State_HasFocus;
1729             bool down = mbi->state & State_Sunken;
1730             QStyleOptionMenuItem newMbi = *mbi;
1731             p->fillRect(mbi->rect, mbi->palette.brush(QPalette::Button));
1732             if (active || hasFocus) {
1733                 QBrush b = mbi->palette.brush(QPalette::Button);
1734                 if (active && down)
1735                     p->setBrushOrigin(p->brushOrigin() + QPoint(1, 1));
1736                 if (active && hasFocus)
1737                     qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1738                                    mbi->rect.height(), mbi->palette, active && down, 1, 0, &b);
1739                 if (active && down) {
1740                     newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1741                                        proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1742                     p->setBrushOrigin(p->brushOrigin() - QPoint(1, 1));
1743                 }
1744             }
1745             QCommonStyle::drawControl(ce, &newMbi, p, widget);
1746         }
1747         break;
1748 #endif // QT_NO_MENUBAR
1749 #ifndef QT_NO_TABBAR
1750     case CE_TabBarTabShape:
1751         if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1752             bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1753                                && (tab->shape == QTabBar::RoundedNorth
1754                                    || tab->shape == QTabBar::RoundedSouth));
1755             bool selected = tab->state & State_Selected;
1756             bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1757                             || (rtlHorTabs
1758                                 && tab->position == QStyleOptionTab::Beginning));
1759             bool firstTab = ((!rtlHorTabs
1760                                && tab->position == QStyleOptionTab::Beginning)
1761                              || (rtlHorTabs
1762                                  && tab->position == QStyleOptionTab::End));
1763             bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1764             bool previousSelected =
1765                 ((!rtlHorTabs
1766                   && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1767                 || (rtlHorTabs
1768                     && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1769             bool nextSelected =
1770                 ((!rtlHorTabs
1771                   && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1772                  || (rtlHorTabs
1773                      && tab->selectedPosition
1774                             == QStyleOptionTab::PreviousIsSelected));
1775             int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1776             bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1777                                 || (rtlHorTabs
1778                                     && tabBarAlignment == Qt::AlignRight);
1779
1780             bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1781                                  || (rtlHorTabs
1782                                          && tabBarAlignment == Qt::AlignLeft);
1783
1784             QColor light = tab->palette.light().color();
1785             QColor dark = tab->palette.dark().color();
1786             QColor shadow = tab->palette.shadow().color();
1787             int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1788             if (selected)
1789                 borderThinkness /= 2;
1790             QRect r2(opt->rect);
1791             int x1 = r2.left();
1792             int x2 = r2.right();
1793             int y1 = r2.top();
1794             int y2 = r2.bottom();
1795             switch (tab->shape) {
1796             default:
1797                 QCommonStyle::drawControl(ce, tab, p, widget);
1798                 break;
1799             case QTabBar::RoundedNorth: {
1800                 if (!selected) {
1801                     y1 += 2;
1802                     x1 += onlyOne || firstTab ? borderThinkness : 0;
1803                     x2 -= onlyOne || lastTab ? borderThinkness : 0;
1804                 }
1805
1806                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
1807
1808                 // Delete border
1809                 if (selected) {
1810                     p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.background());
1811                     p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.background());
1812                 }
1813                 // Left
1814                 if (firstTab || selected || onlyOne || !previousSelected) {
1815                     p->setPen(light);
1816                     p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1817                     p->drawPoint(x1 + 1, y1 + 1);
1818                 }
1819                 // Top
1820                 {
1821                     int beg = x1 + (previousSelected ? 0 : 2);
1822                     int end = x2 - (nextSelected ? 0 : 2);
1823                     p->setPen(light);
1824                     p->drawLine(beg, y1, end, y1);
1825                 }
1826                 // Right
1827                 if (lastTab || selected || onlyOne || !nextSelected) {
1828                     p->setPen(shadow);
1829                     p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1830                     p->drawPoint(x2 - 1, y1 + 1);
1831                     p->setPen(dark);
1832                     p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1833                 }
1834                 break; }
1835             case QTabBar::RoundedSouth: {
1836                 if (!selected) {
1837                     y2 -= 2;
1838                     x1 += firstTab ? borderThinkness : 0;
1839                     x2 -= lastTab ? borderThinkness : 0;
1840                 }
1841
1842                 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
1843
1844                 // Delete border
1845                 if (selected) {
1846                     p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.background());
1847                     p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.background());
1848                 }
1849                 // Left
1850                 if (firstTab || selected || onlyOne || !previousSelected) {
1851                     p->setPen(light);
1852                     p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1853                     p->drawPoint(x1 + 1, y2 - 1);
1854                 }
1855                 // Bottom
1856                 {
1857                     int beg = x1 + (previousSelected ? 0 : 2);
1858                     int end = x2 - (nextSelected ? 0 : 2);
1859                     p->setPen(shadow);
1860                     p->drawLine(beg, y2, end, y2);
1861                     p->setPen(dark);
1862                     p->drawLine(beg, y2 - 1, end, y2 - 1);
1863                 }
1864                 // Right
1865                 if (lastTab || selected || onlyOne || !nextSelected) {
1866                     p->setPen(shadow);
1867                     p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1868                     p->drawPoint(x2 - 1, y2 - 1);
1869                     p->setPen(dark);
1870                     p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1871                 }
1872                 break; }
1873             case QTabBar::RoundedWest: {
1874                 if (!selected) {
1875                     x1 += 2;
1876                     y1 += firstTab ? borderThinkness : 0;
1877                     y2 -= lastTab ? borderThinkness : 0;
1878                 }
1879
1880                 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
1881
1882                 // Delete border
1883                 if (selected) {
1884                     p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.background());
1885                     p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.background());
1886                 }
1887                 // Top
1888                 if (firstTab || selected || onlyOne || !previousSelected) {
1889                     p->setPen(light);
1890                     p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1891                     p->drawPoint(x1 + 1, y1 + 1);
1892                 }
1893                 // Left
1894                 {
1895                     int beg = y1 + (previousSelected ? 0 : 2);
1896                     int end = y2 - (nextSelected ? 0 : 2);
1897                     p->setPen(light);
1898                     p->drawLine(x1, beg, x1, end);
1899                 }
1900                 // Bottom
1901                 if (lastTab || selected || onlyOne || !nextSelected) {
1902                     p->setPen(shadow);
1903                     p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1904                     p->drawPoint(x1 + 2, y2 - 1);
1905                     p->setPen(dark);
1906                     p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1907                     p->drawPoint(x1 + 1, y2 - 1);
1908                     p->drawPoint(x1 + 2, y2);
1909                 }
1910                 break; }
1911             case QTabBar::RoundedEast: {
1912                 if (!selected) {
1913                     x2 -= 2;
1914                     y1 += firstTab ? borderThinkness : 0;
1915                     y2 -= lastTab ? borderThinkness : 0;
1916                 }
1917
1918                 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
1919
1920                 // Delete border
1921                 if (selected) {
1922                     p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.background());
1923                     p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.background());
1924                 }
1925                 // Top
1926                 if (firstTab || selected || onlyOne || !previousSelected) {
1927                     p->setPen(light);
1928                     p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1929                     p->drawPoint(x2 - 1, y1 + 1);
1930                 }
1931                 // Right
1932                 {
1933                     int beg = y1 + (previousSelected ? 0 : 2);
1934                     int end = y2 - (nextSelected ? 0 : 2);
1935                     p->setPen(shadow);
1936                     p->drawLine(x2, beg, x2, end);
1937                     p->setPen(dark);
1938                     p->drawLine(x2 - 1, beg, x2 - 1, end);
1939                 }
1940                 // Bottom
1941                 if (lastTab || selected || onlyOne || !nextSelected) {
1942                     p->setPen(shadow);
1943                     p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1944                     p->drawPoint(x2 - 1, y2 - 1);
1945                     p->setPen(dark);
1946                     p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1947                 }
1948                 break; }
1949             }
1950         }
1951         break;
1952 #endif // QT_NO_TABBAR
1953     case CE_ToolBoxTabShape:
1954         qDrawShadePanel(p, opt->rect, opt->palette,
1955                         opt->state & (State_Sunken | State_On), 1,
1956                         &opt->palette.brush(QPalette::Button));
1957         break;
1958 #ifndef QT_NO_SPLITTER
1959     case CE_Splitter:
1960         p->eraseRect(opt->rect);
1961         break;
1962 #endif // QT_NO_SPLITTER
1963 #ifndef QT_NO_SCROLLBAR
1964     case CE_ScrollBarSubLine:
1965     case CE_ScrollBarAddLine: {
1966         if ((opt->state & State_Sunken)) {
1967             p->setPen(opt->palette.dark().color());
1968             p->setBrush(opt->palette.brush(QPalette::Button));
1969             p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1970         } else {
1971             QStyleOption buttonOpt = *opt;
1972             if (!(buttonOpt.state & State_Sunken))
1973                 buttonOpt.state |= State_Raised;
1974             QPalette pal(opt->palette);
1975             pal.setColor(QPalette::Button, opt->palette.light().color());
1976             pal.setColor(QPalette::Light, opt->palette.button().color());
1977             qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1978                            &opt->palette.brush(QPalette::Button));
1979         }
1980         PrimitiveElement arrow;
1981         if (opt->state & State_Horizontal) {
1982             if (ce == CE_ScrollBarAddLine)
1983                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1984             else
1985                 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1986         } else {
1987             if (ce == CE_ScrollBarAddLine)
1988                 arrow = PE_IndicatorArrowDown;
1989             else
1990                 arrow = PE_IndicatorArrowUp;
1991         }
1992         QStyleOption arrowOpt = *opt;
1993         arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1994         proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1995         break; }
1996     case CE_ScrollBarAddPage:
1997     case CE_ScrollBarSubPage: {
1998             QBrush br;
1999             QBrush bg = p->background();
2000             Qt::BGMode bg_mode = p->backgroundMode();
2001             p->setPen(Qt::NoPen);
2002             p->setBackgroundMode(Qt::OpaqueMode);
2003
2004             if (opt->state & State_Sunken) {
2005                 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
2006                 p->setBackground(opt->palette.dark().color());
2007                 p->setBrush(br);
2008             } else {
2009                 QPixmap pm = opt->palette.brush(QPalette::Light).texture();
2010                 br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2011                 p->setBackground(opt->palette.background().color());
2012                 p->setBrush(br);
2013             }
2014             p->drawRect(opt->rect);
2015             p->setBackground(bg);
2016             p->setBackgroundMode(bg_mode);
2017             break; }
2018     case CE_ScrollBarSlider:
2019         if (!(opt->state & State_Enabled)) {
2020             QPixmap pm = opt->palette.brush(QPalette::Light).texture();
2021             QBrush br = !pm.isNull() ? QBrush(pm) : QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2022             p->setPen(Qt::NoPen);
2023             p->setBrush(br);
2024             p->setBackgroundMode(Qt::OpaqueMode);
2025             p->drawRect(opt->rect);
2026         } else {
2027             QStyleOptionButton buttonOpt;
2028             buttonOpt.QStyleOption::operator=(*opt);
2029             buttonOpt.state = State_Enabled | State_Raised;
2030
2031             QPalette pal(opt->palette);
2032             pal.setColor(QPalette::Button, opt->palette.light().color());
2033             pal.setColor(QPalette::Light, opt->palette.button().color());
2034             qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button));
2035         }
2036         break;
2037 #endif // QT_NO_SCROLLBAR
2038     case CE_HeaderSection: {
2039         QBrush fill;
2040         if (opt->state & State_On)
2041             fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2042         else
2043             fill = opt->palette.brush(QPalette::Button);
2044
2045         if (opt->state & (State_Raised | State_Sunken)) {
2046             qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
2047         } else {
2048             p->fillRect(opt->rect, fill);
2049         }
2050         break; }
2051 #ifndef QT_NO_TOOLBAR
2052     case CE_ToolBar:
2053         if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
2054             // Reserve the beveled appearance only for mainwindow toolbars
2055             if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
2056                 break;
2057
2058             QRect rect = opt->rect;
2059             bool paintLeftBorder = true;
2060             bool paintRightBorder = true;
2061             bool paintBottomBorder = true;
2062
2063             switch (toolbar->toolBarArea){
2064             case Qt::BottomToolBarArea :
2065                 switch(toolbar->positionOfLine){
2066                 case QStyleOptionToolBar::Beginning:
2067                 case QStyleOptionToolBar::OnlyOne:
2068                     paintBottomBorder = false;
2069                 default:
2070                     break;
2071                 }
2072             case Qt::TopToolBarArea :
2073                 switch(toolbar->positionWithinLine){
2074                 case QStyleOptionToolBar::Beginning:
2075                     paintLeftBorder = false;
2076                     break;
2077                 case QStyleOptionToolBar::End:
2078                     paintRightBorder = false;
2079                     break;
2080                 case QStyleOptionToolBar::OnlyOne:
2081                     paintRightBorder = false;
2082                     paintLeftBorder = false;
2083                 default:
2084                     break;
2085                 }
2086                 if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
2087                     bool tmp = paintLeftBorder;
2088                     paintRightBorder=paintLeftBorder;
2089                     paintLeftBorder=tmp;
2090                 }
2091                 break;
2092             case Qt::RightToolBarArea :
2093                 switch (toolbar->positionOfLine){
2094                 case QStyleOptionToolBar::Beginning:
2095                 case QStyleOptionToolBar::OnlyOne:
2096                     paintRightBorder = false;
2097                     break;
2098                 default:
2099                     break;
2100                 }
2101                 break;
2102             case Qt::LeftToolBarArea :
2103                 switch (toolbar->positionOfLine){
2104                 case QStyleOptionToolBar::Beginning:
2105                 case QStyleOptionToolBar::OnlyOne:
2106                     paintLeftBorder = false;
2107                     break;
2108                 default:
2109                     break;
2110                 }
2111                 break;
2112             default:
2113                 break;
2114             }
2115
2116
2117             //draw top border
2118             p->setPen(QPen(opt->palette.light().color()));
2119             p->drawLine(rect.topLeft().x(),
2120                         rect.topLeft().y(),
2121                         rect.topRight().x(),
2122                         rect.topRight().y());
2123
2124             if (paintLeftBorder){
2125                 p->setPen(QPen(opt->palette.light().color()));
2126                 p->drawLine(rect.topLeft().x(),
2127                             rect.topLeft().y(),
2128                             rect.bottomLeft().x(),
2129                             rect.bottomLeft().y());
2130             }
2131
2132             if (paintRightBorder){
2133                 p->setPen(QPen(opt->palette.dark().color()));
2134                 p->drawLine(rect.topRight().x(),
2135                             rect.topRight().y(),
2136                             rect.bottomRight().x(),
2137                             rect.bottomRight().y());
2138             }
2139
2140             if (paintBottomBorder){
2141                 p->setPen(QPen(opt->palette.dark().color()));
2142                 p->drawLine(rect.bottomLeft().x(),
2143                             rect.bottomLeft().y(),
2144                             rect.bottomRight().x(),
2145                             rect.bottomRight().y());
2146             }
2147         }
2148         break;
2149
2150
2151 #endif // QT_NO_TOOLBAR
2152
2153     case CE_ProgressBarContents:
2154         if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
2155             QRect rect = pb->rect;
2156             if (!rect.isValid())
2157                 return;
2158
2159             bool vertical = false;
2160             bool inverted = false;
2161
2162             // Get extra style options if version 2
2163             const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
2164             if (pb2) {
2165                 vertical = (pb2->orientation == Qt::Vertical);
2166                 inverted = pb2->invertedAppearance;
2167             }
2168             QMatrix m;
2169             if (vertical) {
2170                 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height
2171                 m.rotate(90);
2172                 m.translate(0, -(rect.height() + rect.y()*2));
2173             }
2174             QPalette pal2 = pb->palette;
2175             // Correct the highlight color if it is the same as the background
2176             if (pal2.highlight() == pal2.background())
2177                 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
2178                                                                      QPalette::Highlight));
2179             bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
2180             if (inverted)
2181                 reverse = !reverse;
2182             int w = rect.width();
2183             Q_D(const QWindowsStyle);
2184             if (pb->minimum == 0 && pb->maximum == 0) {
2185                 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
2186                 QStyleOptionProgressBarV2 pbBits = *pb;
2187                 Q_ASSERT(unit_width >0);
2188
2189                 pbBits.rect = rect;
2190                 pbBits.palette = pal2;
2191
2192                 int step = 0;
2193                 int chunkCount = w / unit_width + 1;
2194                 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
2195                     step = (animation->animationStep() / 3) % chunkCount;
2196                 else
2197                     d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject));
2198                 int chunksInRow = 5;
2199                 int myY = pbBits.rect.y();
2200                 int myHeight = pbBits.rect.height();
2201                 int chunksToDraw = chunksInRow;
2202
2203                 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step);
2204                 p->save();
2205                 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
2206
2207                 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width  : rect.left() + unit_width * step;
2208                 int x = 0;
2209
2210                 for (int i = 0; i < chunksToDraw ; ++i) {
2211                     pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
2212                     pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
2213                     proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
2214                     x += reverse ? -unit_width : unit_width;
2215                 }
2216                 //Draw wrap-around chunks
2217                 if( step > chunkCount-5){
2218                     x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
2219                     x = 0;
2220                     int chunksToDraw = step - (chunkCount - chunksInRow);
2221                     for (int i = 0; i < chunksToDraw ; ++i) {
2222                         pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
2223                         pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
2224                         proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
2225                         x += reverse ? -unit_width : unit_width;
2226                     }
2227                 }
2228                 p->restore(); //restore state
2229             }
2230             else {
2231                 d->stopAnimation(opt->styleObject);
2232                 QCommonStyle::drawControl(ce, opt, p, widget);
2233             }
2234         }
2235         break;
2236
2237 #ifndef QT_NO_DOCKWIDGET
2238     case CE_DockWidgetTitle:
2239
2240         if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
2241             Q_D(const QWindowsStyle);
2242
2243             const QStyleOptionDockWidgetV2 *v2
2244                 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
2245             bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2246
2247             QRect rect = dwOpt->rect;
2248             QRect r = rect;
2249
2250             if (verticalTitleBar) {
2251                 QSize s = r.size();
2252                 s.transpose();
2253                 r.setSize(s);
2254
2255                 p->save();
2256                 p->translate(r.left(), r.top() + r.width());
2257                 p->rotate(-90);
2258                 p->translate(-r.left(), -r.top());
2259             }
2260
2261             bool floating = false;
2262             bool active = dwOpt->state & State_Active;
2263             QColor inactiveCaptionTextColor = d->inactiveCaptionText;
2264             if (dwOpt->movable) {
2265                 QColor left, right;
2266
2267                 //Titlebar gradient
2268                 if (widget && widget->isWindow()) {
2269                     floating = true;
2270                     if (active) {
2271                         left = d->activeCaptionColor;
2272                         right = d->activeGradientCaptionColor;
2273                     } else {
2274                         left = d->inactiveCaptionColor;
2275                         right = d->inactiveGradientCaptionColor;
2276                     }
2277                     QBrush fillBrush(left);
2278                     if (left != right) {
2279                         QPoint p1(r.x(), r.top() + r.height()/2);
2280                         QPoint p2(rect.right(), r.top() + r.height()/2);
2281                         QLinearGradient lg(p1, p2);
2282                         lg.setColorAt(0, left);
2283                         lg.setColorAt(1, right);
2284                         fillBrush = lg;
2285                     }
2286                     p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
2287                 }
2288             }
2289             if (!dwOpt->title.isEmpty()) {
2290                 QFont oldFont = p->font();
2291                 if (floating) {
2292                     QFont font = oldFont;
2293                     font.setBold(true);
2294                     p->setFont(font);
2295                 }
2296                 QPalette palette = dwOpt->palette;
2297                 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
2298                 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
2299                 if (verticalTitleBar) {
2300                     titleRect = QRect(r.left() + rect.bottom()
2301                                         - titleRect.bottom(),
2302                                     r.top() + titleRect.left() - rect.left(),
2303                                     titleRect.height(), titleRect.width());
2304                 }
2305                 proxy()->drawItemText(p, titleRect,
2306                             Qt::AlignLeft | Qt::AlignVCenter | Qt::TextShowMnemonic, palette,
2307                             dwOpt->state & State_Enabled, dwOpt->title,
2308                             floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
2309                 p->setFont(oldFont);
2310             }
2311             if (verticalTitleBar)
2312                 p->restore();
2313         }
2314         return;
2315 #endif // QT_NO_DOCKWIDGET
2316     default:
2317         QCommonStyle::drawControl(ce, opt, p, widget);
2318     }
2319 }
2320
2321 /*! \reimp */
2322 QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
2323 {
2324     QRect r;
2325     switch (sr) {
2326     case SE_SliderFocusRect:
2327     case SE_ToolBoxTabContents:
2328         r = visualRect(opt->direction, opt->rect, opt->rect);
2329         break;
2330     case SE_DockWidgetTitleBarText: {
2331         r = QCommonStyle::subElementRect(sr, opt, w);
2332         const QStyleOptionDockWidgetV2 *v2
2333             = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
2334         bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2335         int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
2336         if (verticalTitleBar) {
2337             r.adjust(0, 0, 0, -m);
2338         } else {
2339             if (opt->direction == Qt::LeftToRight)
2340                 r.adjust(m, 0, 0, 0);
2341             else
2342                 r.adjust(0, 0, -m, 0);
2343         }
2344         break;
2345     }
2346     case SE_ProgressBarContents:
2347         r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
2348         r.adjust(3, 3, -3, -3);
2349         break;
2350     default:
2351         r = QCommonStyle::subElementRect(sr, opt, w);
2352     }
2353     return r;
2354 }
2355
2356
2357 /*! \reimp */
2358 void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
2359                                        QPainter *p, const QWidget *widget) const
2360 {
2361     switch (cc) {
2362 #ifndef QT_NO_SLIDER
2363     case CC_Slider:
2364         if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2365             int thickness  = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
2366             int len        = proxy()->pixelMetric(PM_SliderLength, slider, widget);
2367             int ticks = slider->tickPosition;
2368             QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
2369             QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
2370
2371             if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
2372                 int mid = thickness / 2;
2373
2374                 if (ticks & QSlider::TicksAbove)
2375                     mid += len / 8;
2376                 if (ticks & QSlider::TicksBelow)
2377                     mid -= len / 8;
2378
2379                 p->setPen(slider->palette.shadow().color());
2380                 if (slider->orientation == Qt::Horizontal) {
2381                     qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
2382                                    groove.width(), 4, slider->palette, true);
2383                     p->drawLine(groove.x() + 1, groove.y() + mid - 1,
2384                                 groove.x() + groove.width() - 3, groove.y() + mid - 1);
2385                 } else {
2386                     qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
2387                                   4, groove.height(), slider->palette, true);
2388                     p->drawLine(groove.x() + mid - 1, groove.y() + 1,
2389                                 groove.x() + mid - 1, groove.y() + groove.height() - 3);
2390                 }
2391             }
2392
2393             if (slider->subControls & SC_SliderTickmarks) {
2394                 QStyleOptionSlider tmpSlider = *slider;
2395                 tmpSlider.subControls = SC_SliderTickmarks;
2396                 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
2397             }
2398
2399             if (slider->subControls & SC_SliderHandle) {
2400                 // 4444440
2401                 // 4333310
2402                 // 4322210
2403                 // 4322210
2404                 // 4322210
2405                 // 4322210
2406                 // *43210*
2407                 // **410**
2408                 // ***0***
2409                 const QColor c0 = slider->palette.shadow().color();
2410                 const QColor c1 = slider->palette.dark().color();
2411                 // const QColor c2 = g.button();
2412                 const QColor c3 = slider->palette.midlight().color();
2413                 const QColor c4 = slider->palette.light().color();
2414                 QBrush handleBrush;
2415
2416                 if (slider->state & State_Enabled) {
2417                     handleBrush = slider->palette.color(QPalette::Button);
2418                 } else {
2419                     handleBrush = QBrush(slider->palette.color(QPalette::Button),
2420                                          Qt::Dense4Pattern);
2421                 }
2422
2423
2424                 int x = handle.x(), y = handle.y(),
2425                    wi = handle.width(), he = handle.height();
2426
2427                 int x1 = x;
2428                 int x2 = x+wi-1;
2429                 int y1 = y;
2430                 int y2 = y+he-1;
2431
2432                 Qt::Orientation orient = slider->orientation;
2433                 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
2434                 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
2435
2436                 if (slider->state & State_HasFocus) {
2437                     QStyleOptionFocusRect fropt;
2438                     fropt.QStyleOption::operator=(*slider);
2439                     fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
2440                     proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
2441                 }
2442
2443                 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
2444                     Qt::BGMode oldMode = p->backgroundMode();
2445                     p->setBackgroundMode(Qt::OpaqueMode);
2446                     qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
2447                                    &handleBrush);
2448                     p->setBackgroundMode(oldMode);
2449                     return;
2450                 }
2451
2452                 QSliderDirection dir;
2453
2454                 if (orient == Qt::Horizontal)
2455                     if (tickAbove)
2456                         dir = SlUp;
2457                     else
2458                         dir = SlDown;
2459                 else
2460                     if (tickAbove)
2461                         dir = SlLeft;
2462                     else
2463                         dir = SlRight;
2464
2465                 QPolygon a;
2466
2467                 int d = 0;
2468                 switch (dir) {
2469                 case SlUp:
2470                     y1 = y1 + wi/2;
2471                     d =  (wi + 1) / 2 - 1;
2472                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
2473                     break;
2474                 case SlDown:
2475                     y2 = y2 - wi/2;
2476                     d =  (wi + 1) / 2 - 1;
2477                     a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
2478                     break;
2479                 case SlLeft:
2480                     d =  (he + 1) / 2 - 1;
2481                     x1 = x1 + he/2;
2482                     a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
2483                     break;
2484                 case SlRight:
2485                     d =  (he + 1) / 2 - 1;
2486                     x2 = x2 - he/2;
2487                     a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
2488                     break;
2489                 }
2490
2491                 QBrush oldBrush = p->brush();
2492                 bool oldQt4CompatiblePainting = p->testRenderHint(QPainter::Qt4CompatiblePainting);
2493                 p->setPen(Qt::NoPen);
2494                 p->setBrush(handleBrush);
2495                 p->setRenderHint(QPainter::Qt4CompatiblePainting);
2496                 Qt::BGMode oldMode = p->backgroundMode();
2497                 p->setBackgroundMode(Qt::OpaqueMode);
2498                 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
2499                 p->drawPolygon(a);
2500                 p->setBrush(oldBrush);
2501                 p->setBackgroundMode(oldMode);
2502
2503                 if (dir != SlUp) {
2504                     p->setPen(c4);
2505                     p->drawLine(x1, y1, x2, y1);
2506                     p->setPen(c3);
2507                     p->drawLine(x1, y1+1, x2, y1+1);
2508                 }
2509                 if (dir != SlLeft) {
2510                     p->setPen(c3);
2511                     p->drawLine(x1+1, y1+1, x1+1, y2);
2512                     p->setPen(c4);
2513                     p->drawLine(x1, y1, x1, y2);
2514                 }
2515                 if (dir != SlRight) {
2516                     p->setPen(c0);
2517                     p->drawLine(x2, y1, x2, y2);
2518                     p->setPen(c1);
2519                     p->drawLine(x2-1, y1+1, x2-1, y2-1);
2520                 }
2521                 if (dir != SlDown) {
2522                     p->setPen(c0);
2523                     p->drawLine(x1, y2, x2, y2);
2524                     p->setPen(c1);
2525                     p->drawLine(x1+1, y2-1, x2-1, y2-1);
2526                 }
2527
2528                 switch (dir) {
2529                 case SlUp:
2530                     p->setPen(c4);
2531                     p->drawLine(x1, y1, x1+d, y1-d);
2532                     p->setPen(c0);
2533                     d = wi - d - 1;
2534                     p->drawLine(x2, y1, x2-d, y1-d);
2535                     d--;
2536                     p->setPen(c3);
2537                     p->drawLine(x1+1, y1, x1+1+d, y1-d);
2538                     p->setPen(c1);
2539                     p->drawLine(x2-1, y1, x2-1-d, y1-d);
2540                     break;
2541                 case SlDown:
2542                     p->setPen(c4);
2543                     p->drawLine(x1, y2, x1+d, y2+d);
2544                     p->setPen(c0);
2545                     d = wi - d - 1;
2546                     p->drawLine(x2, y2, x2-d, y2+d);
2547                     d--;
2548                     p->setPen(c3);
2549                     p->drawLine(x1+1, y2, x1+1+d, y2+d);
2550                     p->setPen(c1);
2551                     p->drawLine(x2-1, y2, x2-1-d, y2+d);
2552                     break;
2553                 case SlLeft:
2554                     p->setPen(c4);
2555                     p->drawLine(x1, y1, x1-d, y1+d);
2556                     p->setPen(c0);
2557                     d = he - d - 1;
2558                     p->drawLine(x1, y2, x1-d, y2-d);
2559                     d--;
2560                     p->setPen(c3);
2561                     p->drawLine(x1, y1+1, x1-d, y1+1+d);
2562                     p->setPen(c1);
2563                     p->drawLine(x1, y2-1, x1-d, y2-1-d);
2564                     break;
2565                 case SlRight:
2566                     p->setPen(c4);
2567                     p->drawLine(x2, y1, x2+d, y1+d);
2568                     p->setPen(c0);
2569                     d = he - d - 1;
2570                     p->drawLine(x2, y2, x2+d, y2-d);
2571                     d--;
2572                     p->setPen(c3);
2573                     p->drawLine(x2, y1+1, x2+d, y1+1+d);
2574                     p->setPen(c1);
2575                     p->drawLine(x2, y2-1, x2+d, y2-1-d);
2576                     break;
2577                 }
2578                 p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting);
2579             }
2580         }
2581         break;
2582 #endif // QT_NO_SLIDER
2583 #ifndef QT_NO_SCROLLBAR
2584     case CC_ScrollBar:
2585         if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2586             QStyleOptionSlider newScrollbar = *scrollbar;
2587             if (scrollbar->minimum == scrollbar->maximum)
2588                 newScrollbar.state &= ~State_Enabled; //do not draw the slider.
2589             QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2590         }
2591         break;
2592 #endif // QT_NO_SCROLLBAR
2593 #ifndef QT_NO_COMBOBOX
2594     case CC_ComboBox:
2595         if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2596             QBrush editBrush = cmb->palette.brush(QPalette::Base);
2597             if ((cmb->subControls & SC_ComboBoxFrame)) {
2598                 if (cmb->frame) {
2599                     QPalette shadePal = opt->palette;
2600                     shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2601                     qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush);
2602                 }
2603                 else {
2604                     p->fillRect(opt->rect, editBrush);
2605                 }
2606             }
2607             if (cmb->subControls & SC_ComboBoxArrow) {
2608                 State flags = State_None;
2609
2610                 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2611                 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2612                                    && cmb->state & State_Sunken;
2613                 if (sunkenArrow) {
2614                     p->setPen(cmb->palette.dark().color());
2615                     p->setBrush(cmb->palette.brush(QPalette::Button));
2616                     p->drawRect(ar.adjusted(0,0,-1,-1));
2617                 } else {
2618                     // Make qDrawWinButton use the right colors for drawing the shade of the button
2619                     QPalette pal(cmb->palette);
2620                     pal.setColor(QPalette::Button, cmb->palette.light().color());
2621                     pal.setColor(QPalette::Light, cmb->palette.button().color());
2622                     qDrawWinButton(p, ar, pal, false,
2623                                    &cmb->palette.brush(QPalette::Button));
2624                 }
2625
2626                 ar.adjust(2, 2, -2, -2);
2627                 if (opt->state & State_Enabled)
2628                     flags |= State_Enabled;
2629                 if (opt->state & State_HasFocus)
2630                     flags |= State_HasFocus;
2631
2632                 if (sunkenArrow)
2633                     flags |= State_Sunken;
2634                 QStyleOption arrowOpt(0);
2635                 arrowOpt.rect = ar.adjusted(1, 1, -1, -1);
2636                 arrowOpt.palette = cmb->palette;
2637                 arrowOpt.state = flags;
2638                 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2639             }
2640
2641             if (cmb->subControls & SC_ComboBoxEditField) {
2642                 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2643                 if (cmb->state & State_HasFocus && !cmb->editable)
2644                     p->fillRect(re.x(), re.y(), re.width(), re.height(),
2645                                 cmb->palette.brush(QPalette::Highlight));
2646
2647                 if (cmb->state & State_HasFocus) {
2648                     p->setPen(cmb->palette.highlightedText().color());
2649                     p->setBackground(cmb->palette.highlight());
2650
2651                 } else {
2652                     p->setPen(cmb->palette.text().color());
2653                     p->setBackground(cmb->palette.background());
2654                 }
2655
2656                 if (cmb->state & State_HasFocus && !cmb->editable) {
2657                     QStyleOptionFocusRect focus;
2658                     focus.QStyleOption::operator=(*cmb);
2659                     focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2660                     focus.state |= State_FocusAtBorder;
2661                     focus.backgroundColor = cmb->palette.highlight().color();
2662                     proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2663                 }
2664             }
2665         }
2666         break;
2667 #endif // QT_NO_COMBOBOX
2668 #ifndef QT_NO_SPINBOX
2669     case CC_SpinBox:
2670         if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2671             QStyleOptionSpinBox copy = *sb;
2672             PrimitiveElement pe;
2673             bool enabled = opt->state & State_Enabled;
2674             if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2675                 QBrush editBrush = sb->palette.brush(QPalette::Base);
2676                 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2677                 QPalette shadePal = sb->palette;
2678                 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2679                 qDrawWinPanel(p, r, shadePal, true, &editBrush);
2680             }
2681
2682             QPalette shadePal(opt->palette);
2683             shadePal.setColor(QPalette::Button, opt->palette.light().color());
2684             shadePal.setColor(QPalette::Light, opt->palette.button().color());
2685
2686             if (sb->subControls & SC_SpinBoxUp) {
2687                 copy.subControls = SC_SpinBoxUp;
2688                 QPalette pal2 = sb->palette;
2689                 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2690                     pal2.setCurrentColorGroup(QPalette::Disabled);
2691                     copy.state &= ~State_Enabled;
2692                 }
2693
2694                 copy.palette = pal2;
2695
2696                 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2697                     copy.state |= State_On;
2698                     copy.state |= State_Sunken;
2699                 } else {
2700                     copy.state |= State_Raised;
2701                     copy.state &= ~State_Sunken;
2702                 }
2703                 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2704                                                                        : PE_IndicatorSpinUp);
2705
2706                 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2707                 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2708                                 &copy.palette.brush(QPalette::Button));
2709                 copy.rect.adjust(4, 1, -5, -1);
2710                 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2711                     && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2712                 {
2713                     QStyleOptionSpinBox lightCopy = copy;
2714                     lightCopy.rect.adjust(1, 1, 1, 1);
2715                     lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2716                     proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2717                 }
2718                 proxy()->drawPrimitive(pe, &copy, p, widget);
2719             }
2720
2721             if (sb->subControls & SC_SpinBoxDown) {
2722                 copy.subControls = SC_SpinBoxDown;
2723                 copy.state = sb->state;
2724                 QPalette pal2 = sb->palette;
2725                 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2726                     pal2.setCurrentColorGroup(QPalette::Disabled);
2727                     copy.state &= ~State_Enabled;
2728                 }
2729                 copy.palette = pal2;
2730
2731                 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2732                     copy.state |= State_On;
2733                     copy.state |= State_Sunken;
2734                 } else {
2735                     copy.state |= State_Raised;
2736                     copy.state &= ~State_Sunken;
2737                 }
2738                 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2739                                                                        : PE_IndicatorSpinDown);
2740
2741                 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2742                 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2743                                 &copy.palette.brush(QPalette::Button));
2744                 copy.rect.adjust(4, 0, -5, -1);
2745                 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2746                     && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2747                 {
2748                     QStyleOptionSpinBox lightCopy = copy;
2749                     lightCopy.rect.adjust(1, 1, 1, 1);
2750                     lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2751                     proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2752                 }
2753                 proxy()->drawPrimitive(pe, &copy, p, widget);
2754             }
2755         }
2756         break;
2757 #endif // QT_NO_SPINBOX
2758
2759     default:
2760         QCommonStyle::drawComplexControl(cc, opt, p, widget);
2761     }
2762 }
2763
2764 /*! \reimp */
2765 QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2766                                       const QSize &csz, const QWidget *widget) const
2767 {
2768     QSize sz(csz);
2769     switch (ct) {
2770     case CT_PushButton:
2771         if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2772             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2773             int w = sz.width(),
2774                 h = sz.height();
2775             int defwidth = 0;
2776             if (btn->features & QStyleOptionButton::AutoDefaultButton)
2777                 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2778             int minwidth = int(QStyleHelper::dpiScaled(75.));
2779             int minheight = int(QStyleHelper::dpiScaled(23.));
2780
2781 #ifndef QT_QWS_SMALL_PUSHBUTTON
2782             if (w < minwidth + defwidth && !btn->text.isEmpty())
2783                 w = minwidth + defwidth;
2784             if (h < minheight + defwidth)
2785                 h = minheight + defwidth;
2786 #endif
2787             sz = QSize(w, h);
2788         }
2789         break;
2790 #ifndef QT_NO_MENU
2791     case CT_MenuItem:
2792         if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2793             int w = sz.width();
2794             sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2795
2796             if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2797                 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2798             }
2799             else if (mi->icon.isNull()) {
2800                 sz.setHeight(sz.height() - 2);
2801                 w -= 6;
2802             }
2803
2804             if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2805                 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2806                 sz.setHeight(qMax(sz.height(),
2807                                   mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2808                                   + 2 * QWindowsStylePrivate::windowsItemFrame));
2809             }
2810             int maxpmw = mi->maxIconWidth;
2811             int tabSpacing = 20;
2812             if (mi->text.contains(QLatin1Char('\t')))
2813                 w += tabSpacing;
2814             else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2815                 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2816             else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2817                 // adjust the font and add the difference in size.
2818                 // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
2819                 QFontMetrics fm(mi->font);
2820                 QFont fontBold = mi->font;
2821                 fontBold.setBold(true);
2822                 QFontMetrics fmBold(fontBold);
2823                 w += fmBold.width(mi->text) - fm.width(mi->text);
2824             }
2825
2826             int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
2827             w += checkcol;
2828             w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
2829             sz.setWidth(w);
2830         }
2831         break;
2832 #endif // QT_NO_MENU
2833 #ifndef QT_NO_MENUBAR
2834     case CT_MenuBarItem:
2835         if (!sz.isEmpty())
2836             sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2837         break;
2838 #endif
2839                 // Otherwise, fall through
2840     case CT_ToolButton:
2841         if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
2842             return sz += QSize(7, 6);
2843         // Otherwise, fall through
2844
2845     default:
2846         sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2847     }
2848     return sz;
2849 }
2850
2851 /*!
2852     \reimp
2853 */
2854 QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option,
2855                                   const QWidget *widget) const
2856 {
2857     QIcon icon;
2858 #ifdef Q_OS_WIN
2859     QPixmap pixmap;
2860     switch (standardIcon) {
2861     case SP_DriveCDIcon:
2862     case SP_DriveDVDIcon:
2863     case SP_DriveNetIcon:
2864     case SP_DriveHDIcon:
2865     case SP_DriveFDIcon:
2866     case SP_FileIcon:
2867     case SP_FileLinkIcon:
2868     case SP_DesktopIcon:
2869     case SP_ComputerIcon:
2870         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2871             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2872             for (int size = 16 ; size <= 32 ; size += 16) {
2873                 pixmap = theme->standardPixmap(sp, QSizeF(size, size));
2874                 icon.addPixmap(pixmap, QIcon::Normal);
2875             }
2876         }
2877         break;
2878     case SP_DirIcon:
2879     case SP_DirLinkIcon:
2880         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2881             QPlatformTheme::StandardPixmap spOff = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2882             QPlatformTheme::StandardPixmap spOn = standardIcon == SP_DirIcon ? QPlatformTheme::DirOpenIcon :
2883                                                                                  QPlatformTheme::DirLinkOpenIcon;
2884             for (int size = 16 ; size <= 32 ; size += 16) {
2885                 QSizeF pixSize(size, size);
2886                 pixmap = theme->standardPixmap(spOff, pixSize);
2887                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::Off);
2888                 pixmap = theme->standardPixmap(spOn, pixSize);
2889                 icon.addPixmap(pixmap, QIcon::Normal, QIcon::On);
2890             }
2891         }
2892         break;
2893     case SP_VistaShield:
2894         if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
2895             QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardIcon);
2896             pixmap = theme->standardPixmap(sp, QSizeF(32, 32));
2897         }
2898         break;
2899     default:
2900         break;
2901     }
2902 #endif
2903
2904     if (icon.isNull())
2905         icon = QCommonStyle::standardIcon(standardIcon, option, widget);
2906     return icon;
2907 }
2908
2909
2910
2911 QT_END_NAMESPACE
2912
2913 #endif // QT_NO_STYLE_WINDOWS