1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the QtGui module of the Qt Toolkit.
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.
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.
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.
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.
40 ****************************************************************************/
42 #include "qwindowsstyle.h"
43 #include "qwindowsstyle_p.h"
45 #if !defined(QT_NO_STYLE_WINDOWS) || defined(QT_PLUGIN)
47 #include <private/qsystemlibrary_p.h>
48 #include "qapplication.h"
50 #include "qdrawutil.h" // for now
54 #include <private/qmenubar_p.h>
55 #include "qpaintengine.h"
57 #include "qrubberband.h"
58 #include "qstyleoption.h"
62 #include "qmainwindow.h"
64 #include "qtextstream.h"
65 #include "qpixmapcache.h"
67 #include "qlistview.h"
68 #include <private/qmath_p.h>
70 #include <qpa/qplatformtheme.h>
71 #include <private/qguiapplication_p.h>
73 #include <private/qstylehelper_p.h>
74 #include <private/qstyleanimation_p.h>
80 QT_BEGIN_INCLUDE_NAMESPACE
81 #include "qt_windows.h"
82 QT_END_INCLUDE_NAMESPACE
83 # ifndef COLOR_GRADIENTACTIVECAPTION
84 # define COLOR_GRADIENTACTIVECAPTION 27
86 # ifndef COLOR_GRADIENTINACTIVECAPTION
87 # define COLOR_GRADIENTINACTIVECAPTION 28
97 WCHAR szPath[MAX_PATH];
100 #define _SHGFI_SMALLICON 0x000000001
101 #define _SHGFI_LARGEICON 0x000000000
102 #define _SHGFI_ICON 0x000000100
103 #define _SIID_SHIELD 77
105 typedef HRESULT (WINAPI *PtrSHGetStockIconInfo)(int siid, int uFlags, QSHSTOCKICONINFO *psii);
106 static PtrSHGetStockIconInfo pSHGetStockIconInfo = 0;
108 Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &);
109 Q_GUI_EXPORT QPixmap qt_pixmapFromWinHICON(HICON icon);
112 QT_BEGIN_INCLUDE_NAMESPACE
114 QT_END_INCLUDE_NAMESPACE
116 enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
121 QWindowsStylePrivate::QWindowsStylePrivate()
122 : alt_down(false), menuBarTimer(0)
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");
133 // Returns true if the toplevel parent of \a widget has seen the Alt-key
134 bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const
136 widget = widget->window();
137 return seenAlt.contains(widget);
143 bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
145 // Records Alt- and Focus events
146 if (!o->isWidgetType())
147 return QObject::eventFilter(o, e);
149 QWidget *widget = qobject_cast<QWidget*>(o);
152 case QEvent::KeyPress:
153 if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
154 widget = widget->window();
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))
164 // Update states before repainting
165 d->seenAlt.append(widget);
168 // Repaint all relevant widgets
169 for (int pos = 0; pos < l.size(); ++pos)
173 case QEvent::KeyRelease:
174 if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
175 widget = widget->window();
177 // Update state and repaint the menu bars.
179 #ifndef QT_NO_MENUBAR
180 QList<QMenuBar *> l = widget->findChildren<QMenuBar *>();
181 for (int i = 0; i < l.size(); ++i)
187 // Reset widget when closing
188 d->seenAlt.removeAll(widget);
189 d->seenAlt.removeAll(widget->window());
194 return QCommonStyle::eventFilter(o, e);
199 \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.
204 This style is Qt's default GUI style on Windows.
206 \image qwindowsstyle.png
207 \sa QWindowsXPStyle, QMacStyle, QPlastiqueStyle
211 Constructs a QWindowsStyle object.
213 QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate)
220 Constructs a QWindowsStyle object.
222 QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
227 /*! Destroys the QWindowsStyle object. */
228 QWindowsStyle::~QWindowsStyle()
233 static inline QRgb colorref2qrgb(COLORREF col)
235 return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
240 void QWindowsStyle::polish(QApplication *app)
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);
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();
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);
271 void QWindowsStyle::unpolish(QApplication *app)
273 QCommonStyle::unpolish(app);
274 app->removeEventFilter(this);
278 void QWindowsStyle::polish(QWidget *widget)
280 QCommonStyle::polish(widget);
284 void QWindowsStyle::unpolish(QWidget *widget)
286 QCommonStyle::unpolish(widget);
292 void QWindowsStyle::polish(QPalette &pal)
294 QCommonStyle::polish(pal);
300 int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
305 case PM_ButtonDefaultIndicator:
306 case PM_ButtonShiftHorizontal:
307 case PM_ButtonShiftVertical:
312 case PM_DockWidgetSeparatorExtent:
313 ret = int(QStyleHelper::dpiScaled(4.));
316 case PM_TabBarTabShiftHorizontal:
319 case PM_TabBarTabShiftVertical:
323 case PM_MaximumDragDistance:
324 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance);
330 case PM_SliderLength:
331 ret = int(QStyleHelper::dpiScaled(11.));
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;
342 if (ticks & QSlider::TicksAbove)
344 if (ticks & QSlider::TicksBelow)
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;
357 thick += (space * 2) / (n + 2);
363 #endif // QT_NO_SLIDER
366 case PM_MenuBarHMargin:
370 case PM_MenuBarVMargin:
374 case PM_MenuBarPanelWidth:
378 case PM_SmallIconSize:
379 ret = int(QStyleHelper::dpiScaled(16.));
382 case PM_LargeIconSize:
383 ret = int(QStyleHelper::dpiScaled(32.));
386 case PM_IconViewIconSize:
387 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
390 case PM_DockWidgetTitleMargin:
391 ret = int(QStyleHelper::dpiScaled(2.));
393 case PM_DockWidgetTitleBarButtonMargin:
394 ret = int(QStyleHelper::dpiScaled(4.));
396 #if defined(Q_WS_WIN)
397 case PM_DockWidgetFrameWidth:
398 #if defined(Q_OS_WINCE)
399 ret = GetSystemMetrics(SM_CXDLGFRAME);
401 ret = GetSystemMetrics(SM_CXFRAME);
405 case PM_DockWidgetFrameWidth:
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;
421 ret = GetSystemMetrics(SM_CYSMCAPTION) - 1;
424 ret = GetSystemMetrics(SM_CYCAPTION) - 1;
429 case PM_ScrollBarExtent:
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);
438 ret = QCommonStyle::pixelMetric(pm, opt, widget);
443 case PM_SplitterWidth:
444 ret = qMax(4, QApplication::globalStrut().width());
447 #if defined(Q_OS_WIN)
448 case PM_MdiSubWindowFrameWidth:
449 #if defined(Q_OS_WINCE)
450 ret = GetSystemMetrics(SM_CYDLGFRAME);
452 ret = GetSystemMetrics(SM_CYFRAME);
456 case PM_ToolBarItemMargin:
459 case PM_ToolBarItemSpacing:
462 case PM_ToolBarHandleExtent:
463 ret = int(QStyleHelper::dpiScaled(10.));
466 ret = QCommonStyle::pixelMetric(pm, opt, widget);
473 #ifndef QT_NO_IMAGEFORMAT_XPM
476 static const char * const qt_menu_xpm[] = {
567 static const char * const qt_close_xpm[] = {
582 static const char * const qt_maximize_xpm[]={
597 static const char * const qt_minimize_xpm[] = {
612 static const char * const qt_normalizeup_xpm[] = {
627 static const char * const qt_help_xpm[] = {
642 static const char * const qt_shade_xpm[] = {
657 static const char * const qt_unshade_xpm[] = {
672 static const char * dock_widget_close_xpm[] = {
686 static const char * const information_xpm[]={
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 "...................**..........."};
726 static const char* const warning_xpm[]={
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.."};
765 static const char* const critical_xpm[]={
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............"};
804 static const char *const question_xpm[] = {
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 "...................**..........."};
844 #endif //QT_NO_IMAGEFORMAT_XPM
849 QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
850 const QWidget *widget) const
852 #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
854 switch(standardPixmap) {
856 case SP_DriveDVDIcon:
857 case SP_DriveNetIcon:
861 case SP_FileLinkIcon:
863 case SP_DirClosedIcon:
865 case SP_ComputerIcon:
867 case SP_FileDialogNewFolder:
871 if (const QPlatformTheme *theme = QGuiApplicationPrivate::platformTheme()) {
872 QPlatformTheme::StandardPixmap sp = static_cast<QPlatformTheme::StandardPixmap>(standardPixmap);
873 desktopIcon = theme->standardPixmap(sp, QSizeF(16, 16));
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());
888 if (!desktopIcon.isNull()) {
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);
923 #endif //QT_NO_IMAGEFORMAT_XPM
924 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
928 int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
929 QStyleHintReturn *returnData) const
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:
948 case SH_ItemView_ShowDecorationSelected:
949 #ifndef QT_NO_LISTVIEW
950 if (qobject_cast<const QListView*>(widget))
954 case SH_ItemView_ChangeHighlightOnFocus:
957 case SH_ToolBox_SelectedPageTitleBold:
961 #if defined(Q_OS_WIN)
962 case SH_UnderlineShortcut:
966 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
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 *>();
978 // If we paint a menu bar draw underlines if is in the keyboardState
980 if (menuBar->d_func()->keyboardState || d->altDown())
982 // Otherwise draw underlines if the toplevel widget has seen an alt-press
984 #endif // QT_NO_MENUBAR
985 if (d->hasSeenAlt(widget)) {
992 #ifndef QT_NO_RUBBERBAND
993 case SH_RubberBand_Mask:
994 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
996 if (rbOpt->shape == QRubberBand::Rectangle) {
998 if(QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
999 mask->region = opt->rect;
1001 if (widget && widget->isWindow())
1003 mask->region -= opt->rect.adjusted(size, size, -size, -size);
1008 #endif // QT_NO_RUBBERBAND
1009 case SH_LineEdit_PasswordCharacter:
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)))
1016 else if (fm.inFont(QChar(0x2022)))
1024 #ifndef QT_NO_WIZARD
1025 case SH_WizardStyle:
1026 ret = QWizard::ModernStyle;
1029 case SH_ItemView_ArrowKeysNavigateIntoChildren:
1032 case SH_DialogButtonBox_ButtonsHaveIcons:
1036 ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
1043 void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
1044 const QWidget *w) const
1046 // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
1047 bool doRestore = false;
1050 #ifndef QT_NO_TOOLBAR
1051 case PE_IndicatorToolBarSeparator:
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);
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);
1085 case PE_IndicatorToolBarHandle:
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)
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);
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);
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());
1124 #endif // QT_NO_DOCKWIDGET
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);
1135 fill = opt->palette.brush(QPalette::Button);
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)){
1143 qDrawShadePanel(p, opt->rect, opt->palette,
1144 opt->state & (State_Sunken | State_On), 1, &fill);
1146 qDrawShadeRect(p, opt->rect, opt->palette,
1147 opt->state & (State_Sunken | State_On), 1);
1150 p->setPen(opt->palette.button().color());
1151 p->drawRect(opt->rect.adjusted(1,1,-2,-2));
1154 qDrawWinButton(p, opt->rect, opt->palette,
1155 opt->state & (State_Sunken | State_On), panel ? &fill : 0);
1158 p->fillRect(opt->rect, fill);
1162 case PE_PanelButtonCommand:
1163 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
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);
1171 fill = pal.brush(QPalette::Button);
1173 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
1174 p->setPen(pal.dark().color());
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),
1181 p->fillRect(r, fill);
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);
1194 case PE_IndicatorArrowUp:
1195 case PE_IndicatorArrowDown:
1196 case PE_IndicatorArrowRight:
1197 case PE_IndicatorArrowLeft:
1199 if (opt->rect.width() <= 1 || opt->rect.height() <= 1)
1201 QRect r = opt->rect;
1202 int size = qMin(r.height(), r.width());
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);
1212 QPainter imagePainter(&image);
1216 case PE_IndicatorArrowUp:
1217 a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize - border, sqsize/2);
1219 case PE_IndicatorArrowDown:
1220 a.setPoints(3, border, sqsize/2, sqsize/2, sqsize - border, sqsize - border, sqsize/2);
1222 case PE_IndicatorArrowRight:
1223 a.setPoints(3, sqsize - border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
1225 case PE_IndicatorArrowLeft:
1226 a.setPoints(3, border, sqsize/2, sqsize/2, border, sqsize/2, sqsize - border);
1235 if (opt->state & State_Sunken) {
1236 bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, opt, w);
1237 bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, opt, w);
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);
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());
1258 imagePainter.drawPolygon(a);
1260 pixmap = QPixmap::fromImage(image);
1261 QPixmapCache::insert(pixmapName, pixmap);
1263 int xOffset = r.x() + (r.width() - size)/2;
1264 int yOffset = r.y() + (r.height() - size)/2;
1265 p->drawPixmap(xOffset, yOffset, pixmap);
1268 case PE_IndicatorCheckBox: {
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();
1277 fill = opt->palette.background();
1280 qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
1281 if (opt->state & State_NoChange)
1282 p->setPen(opt->palette.dark().color());
1284 p->setPen(opt->palette.text().color());
1286 case PE_IndicatorViewItemCheck:
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);
1302 if (!(opt->state & State_Off)) {
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);
1313 for (i = 3; i < 7; ++i) {
1314 lines[i] = QLineF(xx, yy, xx, yy + 2);
1318 p->drawLines(lines, 7);
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))
1328 QRect r = opt->rect;
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
1348 case PE_IndicatorRadioButton:
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)
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)
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)
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)
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)
1373 // make sure the indicator is square
1374 QRect ir = opt->rect;
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());
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;
1391 //center when rect is larger than indicator size
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);
1402 p->translate(ir.x(), ir.y());
1404 p->setPen(opt->palette.dark().color());
1405 p->drawPolyline(pts1, PTSARRLEN(pts1));
1407 p->setPen(opt->palette.shadow().color());
1408 p->drawPolyline(pts2, PTSARRLEN(pts2));
1410 p->setPen(opt->palette.midlight().color());
1411 p->drawPolyline(pts3, PTSARRLEN(pts3));
1413 p->setPen(opt->palette.light().color());
1414 p->drawPolyline(pts4, PTSARRLEN(pts4));
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));
1423 p->translate(-ir.x(), -ir.y()); // restore translate
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);
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());
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))
1448 popupPal.setColor(QPalette::Midlight, frame->palette.background().color());
1449 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1452 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
1454 QCommonStyle::drawPrimitive(pe, opt, p, w);
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);
1463 #endif // QT_NO_FRAME
1464 case PE_FrameButtonBevel:
1465 case PE_PanelButtonBevel: {
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);
1472 fill = opt->palette.brush(QPalette::Button);
1474 if (opt->state & (State_Raised | State_On | State_Sunken)) {
1475 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
1479 p->fillRect(opt->rect, fill);
1481 p->drawRect(opt->rect);
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);
1490 #ifndef QT_NO_DOCKWIDGET
1491 case PE_IndicatorDockWidgetResizeHandle:
1493 case PE_FrameDockWidget:
1494 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
1495 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
1498 #endif // QT_NO_DOCKWIDGET
1500 case PE_FrameStatusBarItem:
1501 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, 0);
1504 case PE_IndicatorProgressChunk:
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;
1513 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
1515 if (opt->rect.width() <= chunksize)
1519 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1520 opt->palette.brush(QPalette::Highlight));
1522 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
1523 opt->palette.brush(QPalette::Highlight));
1525 if (opt->rect.height() <= chunksize)
1529 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
1530 opt->palette.brush(QPalette::Highlight));
1532 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
1533 opt->palette.brush(QPalette::Highlight));
1538 case PE_FrameTabWidget: {
1539 qDrawWinButton(p, opt->rect, opt->palette, false, 0);
1543 QCommonStyle::drawPrimitive(pe, opt, p, w);
1548 void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
1549 const QWidget *widget) const
1552 #ifndef QT_NO_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());
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);
1575 #endif // QT_NO_RUBBERBAND
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());
1590 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
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;
1599 // windows always has a check column, regardless whether we have an icon or not
1600 int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1602 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1603 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
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);
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) {
1617 qDrawShadePanel(p, vCheckRect,
1618 menuitem->palette, true, 1,
1619 &menuitem->palette.brush(QPalette::Button));
1621 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1622 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1625 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
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;
1634 mode = QIcon::Active;
1637 pixmap = menuitem->icon.pixmap(proxy()->pixelMetric(PM_SmallIconSize, opt, widget), mode, QIcon::On);
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;
1653 newMi.state |= State_Enabled;
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);
1662 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1666 discol = menuitem->palette.text().color();
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
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;
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));
1691 p->drawText(vShortcutRect, text_flags, s.mid(t + 1));
1694 QFont font = menuitem->font;
1695 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
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));
1703 p->drawText(vTextRect, text_flags, s.left(t));
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;
1716 newMI.palette.setColor(QPalette::ButtonText,
1717 newMI.palette.highlightedText().color());
1718 proxy()->drawPrimitive(arrow, &newMI, p, widget);
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);
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));
1745 QCommonStyle::drawControl(ce, &newMbi, p, widget);
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)
1758 && tab->position == QStyleOptionTab::Beginning));
1759 bool firstTab = ((!rtlHorTabs
1760 && tab->position == QStyleOptionTab::Beginning)
1762 && tab->position == QStyleOptionTab::End));
1763 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1764 bool previousSelected =
1766 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1768 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1771 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1773 && tab->selectedPosition
1774 == QStyleOptionTab::PreviousIsSelected));
1775 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1776 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1778 && tabBarAlignment == Qt::AlignRight);
1780 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1782 && tabBarAlignment == Qt::AlignLeft);
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);
1789 borderThinkness /= 2;
1790 QRect r2(opt->rect);
1792 int x2 = r2.right();
1794 int y2 = r2.bottom();
1795 switch (tab->shape) {
1797 QCommonStyle::drawControl(ce, tab, p, widget);
1799 case QTabBar::RoundedNorth: {
1802 x1 += onlyOne || firstTab ? borderThinkness : 0;
1803 x2 -= onlyOne || lastTab ? borderThinkness : 0;
1806 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.background());
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());
1814 if (firstTab || selected || onlyOne || !previousSelected) {
1816 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1817 p->drawPoint(x1 + 1, y1 + 1);
1821 int beg = x1 + (previousSelected ? 0 : 2);
1822 int end = x2 - (nextSelected ? 0 : 2);
1824 p->drawLine(beg, y1, end, y1);
1827 if (lastTab || selected || onlyOne || !nextSelected) {
1829 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1830 p->drawPoint(x2 - 1, y1 + 1);
1832 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1835 case QTabBar::RoundedSouth: {
1838 x1 += firstTab ? borderThinkness : 0;
1839 x2 -= lastTab ? borderThinkness : 0;
1842 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
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());
1850 if (firstTab || selected || onlyOne || !previousSelected) {
1852 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1853 p->drawPoint(x1 + 1, y2 - 1);
1857 int beg = x1 + (previousSelected ? 0 : 2);
1858 int end = x2 - (nextSelected ? 0 : 2);
1860 p->drawLine(beg, y2, end, y2);
1862 p->drawLine(beg, y2 - 1, end, y2 - 1);
1865 if (lastTab || selected || onlyOne || !nextSelected) {
1867 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1868 p->drawPoint(x2 - 1, y2 - 1);
1870 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1873 case QTabBar::RoundedWest: {
1876 y1 += firstTab ? borderThinkness : 0;
1877 y2 -= lastTab ? borderThinkness : 0;
1880 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.background());
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());
1888 if (firstTab || selected || onlyOne || !previousSelected) {
1890 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1891 p->drawPoint(x1 + 1, y1 + 1);
1895 int beg = y1 + (previousSelected ? 0 : 2);
1896 int end = y2 - (nextSelected ? 0 : 2);
1898 p->drawLine(x1, beg, x1, end);
1901 if (lastTab || selected || onlyOne || !nextSelected) {
1903 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1904 p->drawPoint(x1 + 2, y2 - 1);
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);
1911 case QTabBar::RoundedEast: {
1914 y1 += firstTab ? borderThinkness : 0;
1915 y2 -= lastTab ? borderThinkness : 0;
1918 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.background());
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());
1926 if (firstTab || selected || onlyOne || !previousSelected) {
1928 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1929 p->drawPoint(x2 - 1, y1 + 1);
1933 int beg = y1 + (previousSelected ? 0 : 2);
1934 int end = y2 - (nextSelected ? 0 : 2);
1936 p->drawLine(x2, beg, x2, end);
1938 p->drawLine(x2 - 1, beg, x2 - 1, end);
1941 if (lastTab || selected || onlyOne || !nextSelected) {
1943 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1944 p->drawPoint(x2 - 1, y2 - 1);
1946 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
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));
1958 #ifndef QT_NO_SPLITTER
1960 p->eraseRect(opt->rect);
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));
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));
1980 PrimitiveElement arrow;
1981 if (opt->state & State_Horizontal) {
1982 if (ce == CE_ScrollBarAddLine)
1983 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1985 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1987 if (ce == CE_ScrollBarAddLine)
1988 arrow = PE_IndicatorArrowDown;
1990 arrow = PE_IndicatorArrowUp;
1992 QStyleOption arrowOpt = *opt;
1993 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1994 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1996 case CE_ScrollBarAddPage:
1997 case CE_ScrollBarSubPage: {
1999 QBrush bg = p->background();
2000 Qt::BGMode bg_mode = p->backgroundMode();
2001 p->setPen(Qt::NoPen);
2002 p->setBackgroundMode(Qt::OpaqueMode);
2004 if (opt->state & State_Sunken) {
2005 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
2006 p->setBackground(opt->palette.dark().color());
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());
2014 p->drawRect(opt->rect);
2015 p->setBackground(bg);
2016 p->setBackgroundMode(bg_mode);
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);
2024 p->setBackgroundMode(Qt::OpaqueMode);
2025 p->drawRect(opt->rect);
2027 QStyleOptionButton buttonOpt;
2028 buttonOpt.QStyleOption::operator=(*opt);
2029 buttonOpt.state = State_Enabled | State_Raised;
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));
2037 #endif // QT_NO_SCROLLBAR
2038 case CE_HeaderSection: {
2040 if (opt->state & State_On)
2041 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
2043 fill = opt->palette.brush(QPalette::Button);
2045 if (opt->state & (State_Raised | State_Sunken)) {
2046 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
2048 p->fillRect(opt->rect, fill);
2051 #ifndef QT_NO_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())))
2058 QRect rect = opt->rect;
2059 bool paintLeftBorder = true;
2060 bool paintRightBorder = true;
2061 bool paintBottomBorder = true;
2063 switch (toolbar->toolBarArea){
2064 case Qt::BottomToolBarArea :
2065 switch(toolbar->positionOfLine){
2066 case QStyleOptionToolBar::Beginning:
2067 case QStyleOptionToolBar::OnlyOne:
2068 paintBottomBorder = false;
2072 case Qt::TopToolBarArea :
2073 switch(toolbar->positionWithinLine){
2074 case QStyleOptionToolBar::Beginning:
2075 paintLeftBorder = false;
2077 case QStyleOptionToolBar::End:
2078 paintRightBorder = false;
2080 case QStyleOptionToolBar::OnlyOne:
2081 paintRightBorder = false;
2082 paintLeftBorder = false;
2086 if(opt->direction == Qt::RightToLeft){ //reverse layout changes the order of Beginning/end
2087 bool tmp = paintLeftBorder;
2088 paintRightBorder=paintLeftBorder;
2089 paintLeftBorder=tmp;
2092 case Qt::RightToolBarArea :
2093 switch (toolbar->positionOfLine){
2094 case QStyleOptionToolBar::Beginning:
2095 case QStyleOptionToolBar::OnlyOne:
2096 paintRightBorder = false;
2102 case Qt::LeftToolBarArea :
2103 switch (toolbar->positionOfLine){
2104 case QStyleOptionToolBar::Beginning:
2105 case QStyleOptionToolBar::OnlyOne:
2106 paintLeftBorder = false;
2118 p->setPen(QPen(opt->palette.light().color()));
2119 p->drawLine(rect.topLeft().x(),
2121 rect.topRight().x(),
2122 rect.topRight().y());
2124 if (paintLeftBorder){
2125 p->setPen(QPen(opt->palette.light().color()));
2126 p->drawLine(rect.topLeft().x(),
2128 rect.bottomLeft().x(),
2129 rect.bottomLeft().y());
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());
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());
2151 #endif // QT_NO_TOOLBAR
2153 case CE_ProgressBarContents:
2154 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
2155 QRect rect = pb->rect;
2156 if (!rect.isValid())
2159 bool vertical = false;
2160 bool inverted = false;
2162 // Get extra style options if version 2
2163 const QStyleOptionProgressBarV2 *pb2 = qstyleoption_cast<const QStyleOptionProgressBarV2 *>(opt);
2165 vertical = (pb2->orientation == Qt::Vertical);
2166 inverted = pb2->invertedAppearance;
2170 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height
2172 m.translate(0, -(rect.height() + rect.y()*2));
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);
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);
2190 pbBits.palette = pal2;
2193 int chunkCount = w / unit_width + 1;
2194 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
2195 step = (animation->animationStep() / 3) % chunkCount;
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;
2203 if(step > chunkCount - 5)chunksToDraw = (chunkCount - step);
2205 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
2207 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
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;
2216 //Draw wrap-around chunks
2217 if( step > chunkCount-5){
2218 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
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;
2228 p->restore(); //restore state
2231 d->stopAnimation(opt->styleObject);
2232 QCommonStyle::drawControl(ce, opt, p, widget);
2237 #ifndef QT_NO_DOCKWIDGET
2238 case CE_DockWidgetTitle:
2240 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
2241 Q_D(const QWindowsStyle);
2243 const QStyleOptionDockWidgetV2 *v2
2244 = qstyleoption_cast<const QStyleOptionDockWidgetV2*>(opt);
2245 bool verticalTitleBar = v2 == 0 ? false : v2->verticalTitleBar;
2247 QRect rect = dwOpt->rect;
2250 if (verticalTitleBar) {
2256 p->translate(r.left(), r.top() + r.width());
2258 p->translate(-r.left(), -r.top());
2261 bool floating = false;
2262 bool active = dwOpt->state & State_Active;
2263 QColor inactiveCaptionTextColor = d->inactiveCaptionText;
2264 if (dwOpt->movable) {
2268 if (widget && widget->isWindow()) {
2271 left = d->activeCaptionColor;
2272 right = d->activeGradientCaptionColor;
2274 left = d->inactiveCaptionColor;
2275 right = d->inactiveGradientCaptionColor;
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);
2286 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
2289 if (!dwOpt->title.isEmpty()) {
2290 QFont oldFont = p->font();
2292 QFont font = oldFont;
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());
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);
2311 if (verticalTitleBar)
2315 #endif // QT_NO_DOCKWIDGET
2317 QCommonStyle::drawControl(ce, opt, p, widget);
2322 QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
2326 case SE_SliderFocusRect:
2327 case SE_ToolBoxTabContents:
2328 r = visualRect(opt->direction, opt->rect, opt->rect);
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);
2339 if (opt->direction == Qt::LeftToRight)
2340 r.adjust(m, 0, 0, 0);
2342 r.adjust(0, 0, -m, 0);
2346 case SE_ProgressBarContents:
2347 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
2348 r.adjust(3, 3, -3, -3);
2351 r = QCommonStyle::subElementRect(sr, opt, w);
2358 void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
2359 QPainter *p, const QWidget *widget) const
2362 #ifndef QT_NO_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);
2371 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
2372 int mid = thickness / 2;
2374 if (ticks & QSlider::TicksAbove)
2376 if (ticks & QSlider::TicksBelow)
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);
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);
2393 if (slider->subControls & SC_SliderTickmarks) {
2394 QStyleOptionSlider tmpSlider = *slider;
2395 tmpSlider.subControls = SC_SliderTickmarks;
2396 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
2399 if (slider->subControls & SC_SliderHandle) {
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();
2416 if (slider->state & State_Enabled) {
2417 handleBrush = slider->palette.color(QPalette::Button);
2419 handleBrush = QBrush(slider->palette.color(QPalette::Button),
2424 int x = handle.x(), y = handle.y(),
2425 wi = handle.width(), he = handle.height();
2432 Qt::Orientation orient = slider->orientation;
2433 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
2434 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
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);
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,
2448 p->setBackgroundMode(oldMode);
2452 QSliderDirection dir;
2454 if (orient == Qt::Horizontal)
2471 d = (wi + 1) / 2 - 1;
2472 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2,y1, x1+d,y1-d);
2476 d = (wi + 1) / 2 - 1;
2477 a.setPoints(5, x1,y1, x1,y2, x1+d,y2+d, x2,y2, x2,y1);
2480 d = (he + 1) / 2 - 1;
2482 a.setPoints(5, x1,y1, x1-d,y1+d, x1,y2, x2,y2, x2,y1);
2485 d = (he + 1) / 2 - 1;
2487 a.setPoints(5, x1,y1, x1,y2, x2,y2, x2+d,y1+d, x2,y1);
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);
2500 p->setBrush(oldBrush);
2501 p->setBackgroundMode(oldMode);
2505 p->drawLine(x1, y1, x2, y1);
2507 p->drawLine(x1, y1+1, x2, y1+1);
2509 if (dir != SlLeft) {
2511 p->drawLine(x1+1, y1+1, x1+1, y2);
2513 p->drawLine(x1, y1, x1, y2);
2515 if (dir != SlRight) {
2517 p->drawLine(x2, y1, x2, y2);
2519 p->drawLine(x2-1, y1+1, x2-1, y2-1);
2521 if (dir != SlDown) {
2523 p->drawLine(x1, y2, x2, y2);
2525 p->drawLine(x1+1, y2-1, x2-1, y2-1);
2531 p->drawLine(x1, y1, x1+d, y1-d);
2534 p->drawLine(x2, y1, x2-d, y1-d);
2537 p->drawLine(x1+1, y1, x1+1+d, y1-d);
2539 p->drawLine(x2-1, y1, x2-1-d, y1-d);
2543 p->drawLine(x1, y2, x1+d, y2+d);
2546 p->drawLine(x2, y2, x2-d, y2+d);
2549 p->drawLine(x1+1, y2, x1+1+d, y2+d);
2551 p->drawLine(x2-1, y2, x2-1-d, y2+d);
2555 p->drawLine(x1, y1, x1-d, y1+d);
2558 p->drawLine(x1, y2, x1-d, y2-d);
2561 p->drawLine(x1, y1+1, x1-d, y1+1+d);
2563 p->drawLine(x1, y2-1, x1-d, y2-1-d);
2567 p->drawLine(x2, y1, x2+d, y1+d);
2570 p->drawLine(x2, y2, x2+d, y2-d);
2573 p->drawLine(x2, y1+1, x2+d, y1+1+d);
2575 p->drawLine(x2, y2-1, x2+d, y2-1-d);
2578 p->setRenderHint(QPainter::Qt4CompatiblePainting, oldQt4CompatiblePainting);
2582 #endif // QT_NO_SLIDER
2583 #ifndef QT_NO_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);
2592 #endif // QT_NO_SCROLLBAR
2593 #ifndef QT_NO_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)) {
2599 QPalette shadePal = opt->palette;
2600 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2601 qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush);
2604 p->fillRect(opt->rect, editBrush);
2607 if (cmb->subControls & SC_ComboBoxArrow) {
2608 State flags = State_None;
2610 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2611 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2612 && cmb->state & State_Sunken;
2614 p->setPen(cmb->palette.dark().color());
2615 p->setBrush(cmb->palette.brush(QPalette::Button));
2616 p->drawRect(ar.adjusted(0,0,-1,-1));
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));
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;
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);
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));
2647 if (cmb->state & State_HasFocus) {
2648 p->setPen(cmb->palette.highlightedText().color());
2649 p->setBackground(cmb->palette.highlight());
2652 p->setPen(cmb->palette.text().color());
2653 p->setBackground(cmb->palette.background());
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);
2667 #endif // QT_NO_COMBOBOX
2668 #ifndef QT_NO_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);
2682 QPalette shadePal(opt->palette);
2683 shadePal.setColor(QPalette::Button, opt->palette.light().color());
2684 shadePal.setColor(QPalette::Light, opt->palette.button().color());
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;
2694 copy.palette = pal2;
2696 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2697 copy.state |= State_On;
2698 copy.state |= State_Sunken;
2700 copy.state |= State_Raised;
2701 copy.state &= ~State_Sunken;
2703 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2704 : PE_IndicatorSpinUp);
2706 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2707 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2708 ©.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) )
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);
2718 proxy()->drawPrimitive(pe, ©, p, widget);
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;
2729 copy.palette = pal2;
2731 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2732 copy.state |= State_On;
2733 copy.state |= State_Sunken;
2735 copy.state |= State_Raised;
2736 copy.state &= ~State_Sunken;
2738 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2739 : PE_IndicatorSpinDown);
2741 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2742 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2743 ©.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) )
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);
2753 proxy()->drawPrimitive(pe, ©, p, widget);
2757 #endif // QT_NO_SPINBOX
2760 QCommonStyle::drawComplexControl(cc, opt, p, widget);
2765 QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2766 const QSize &csz, const QWidget *widget) const
2771 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2772 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
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.));
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;
2792 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2794 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2796 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2797 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2799 else if (mi->icon.isNull()) {
2800 sz.setHeight(sz.height() - 2);
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));
2810 int maxpmw = mi->maxIconWidth;
2811 int tabSpacing = 20;
2812 if (mi->text.contains(QLatin1Char('\t')))
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);
2826 int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
2828 w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
2832 #endif // QT_NO_MENU
2833 #ifndef QT_NO_MENUBAR
2834 case CT_MenuBarItem:
2836 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2839 // Otherwise, fall through
2841 if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
2842 return sz += QSize(7, 6);
2843 // Otherwise, fall through
2846 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2854 QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option,
2855 const QWidget *widget) const
2860 switch (standardIcon) {
2861 case SP_DriveCDIcon:
2862 case SP_DriveDVDIcon:
2863 case SP_DriveNetIcon:
2864 case SP_DriveHDIcon:
2865 case SP_DriveFDIcon:
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);
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);
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));
2905 icon = QCommonStyle::standardIcon(standardIcon, option, widget);
2913 #endif // QT_NO_STYLE_WINDOWS