Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindowsstyle.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7
8#if QT_CONFIG(style_windows) || defined(QT_PLUGIN)
9
10#include "qapplication.h"
11#include "qbitmap.h"
12#include "qdrawutil.h" // for now
13#include "qevent.h"
14#if QT_CONFIG(menu)
15#include "qmenu.h"
16#endif
17#if QT_CONFIG(menubar)
18#include "qmenubar.h"
19#include <private/qmenubar_p.h>
20#endif
21#include "qpaintengine.h"
22#include "qpainter.h"
23#include "qpainterstateguard.h"
24#if QT_CONFIG(rubberband)
25#include "qrubberband.h"
26#endif
27#include "qstyleoption.h"
28#if QT_CONFIG(tabbar)
29#include "qtabbar.h"
30#endif
31#include "qwidget.h"
32#include "qdebug.h"
33#if QT_CONFIG(mainwindow)
34#include "qmainwindow.h"
35#endif
36#include "qfile.h"
37#include "qtextstream.h"
38#include "qpixmapcache.h"
39#if QT_CONFIG(wizard)
40#include "qwizard.h"
41#endif
42#if QT_CONFIG(listview)
43#include "qlistview.h"
44#endif
45#include <private/qmath_p.h>
46#include <qmath.h>
47#include <QtGui/qpainterpath.h>
48#include <QtGui/qscreen.h>
49#include <QtGui/qstylehints.h>
50#include <QtGui/qwindow.h>
51#include <qpa/qplatformtheme.h>
52#include <qpa/qplatformscreen.h>
53#include <private/qguiapplication_p.h>
54#include <private/qhighdpiscaling_p.h>
55#include <qpa/qplatformintegration.h>
56#include <private/qwidget_p.h>
57
58#include <private/qstylehelper_p.h>
59#if QT_CONFIG(animation)
60#include <private/qstyleanimation_p.h>
61#endif
62
63#include <QtCore/qoperatingsystemversion.h>
64
65#include <algorithm>
66
67QT_BEGIN_NAMESPACE
68
69#if defined(Q_OS_WIN)
70
71QT_BEGIN_INCLUDE_NAMESPACE
72#include "qt_windows.h"
73QT_END_INCLUDE_NAMESPACE
74# ifndef COLOR_GRADIENTACTIVECAPTION
75# define COLOR_GRADIENTACTIVECAPTION 27
76# endif
77# ifndef COLOR_GRADIENTINACTIVECAPTION
78# define COLOR_GRADIENTINACTIVECAPTION 28
79# endif
80
81Q_GUI_EXPORT HICON qt_pixmapToWinHICON(const QPixmap &);
82#endif //Q_OS_WIN
83
84QT_BEGIN_INCLUDE_NAMESPACE
85#include <limits.h>
86QT_END_INCLUDE_NAMESPACE
87
88enum QSliderDirection { SlUp, SlDown, SlLeft, SlRight };
89
90/*
91 \internal
92*/
93
94QWindowsStylePrivate::QWindowsStylePrivate() = default;
95
96// Returns \c true if the toplevel parent of \a widget has seen the Alt-key
97bool QWindowsStylePrivate::hasSeenAlt(const QWidget *widget) const
98{
99 widget = widget->window();
100 return seenAlt.contains(widget);
101}
102
103/*!
104 \reimp
105*/
106bool QWindowsStyle::eventFilter(QObject *o, QEvent *e)
107{
108 // Records Alt- and Focus events
109 if (!o->isWidgetType())
110 return QObject::eventFilter(o, e);
111
112 QWidget *widget = qobject_cast<QWidget*>(o);
113 Q_D(QWindowsStyle);
114 switch(e->type()) {
115 case QEvent::KeyPress:
116 if (static_cast<QKeyEvent *>(e)->key() == Qt::Key_Alt) {
117 widget = widget->window();
118
119 // Alt has been pressed - find all widgets that care
120 const QList<QWidget *> children = widget->findChildren<QWidget *>();
121 auto ignorable = [](QWidget *w) {
122 return w->isWindow() || !w->isVisible();
123 };
124 // Update states before repainting
125 d->seenAlt.append(widget);
126 d->alt_down = true;
127
128 // Repaint all relevant widgets
129 for (QWidget *w : children) {
130 if (!ignorable(w))
131 w->update();
132 }
133 }
134 break;
135 case QEvent::KeyRelease:
136 if (static_cast<QKeyEvent*>(e)->key() == Qt::Key_Alt) {
137 widget = widget->window();
138
139 // Update state and repaint the menu bars.
140 d->alt_down = false;
141#if QT_CONFIG(menubar)
142 const QList<QMenuBar *> menuBars = widget->findChildren<QMenuBar *>();
143 for (QWidget *w : menuBars)
144 w->update();
145#endif
146 }
147 break;
148 case QEvent::Close:
149 // Reset widget when closing
150 d->seenAlt.removeAll(widget);
151 d->seenAlt.removeAll(widget->window());
152 break;
153 default:
154 break;
155 }
156 return QCommonStyle::eventFilter(o, e);
157}
158
159/*!
160 \class QWindowsStyle
161 \brief The QWindowsStyle class provides a Microsoft Windows-like look and feel.
162
163 \ingroup appearance
164 \inmodule QtWidgets
165 \internal
166
167 This style is Qt's default GUI style on Windows.
168
169 \image qwindowsstyle.png {Gallery of widgets using the default GUI style}
170 \sa QWindowsVistaStyle, QMacStyle, QFusionStyle
171*/
172
173/*!
174 Constructs a QWindowsStyle object.
175*/
176QWindowsStyle::QWindowsStyle() : QCommonStyle(*new QWindowsStylePrivate)
177{
178}
179
180/*!
181 \internal
182
183 Constructs a QWindowsStyle object.
184*/
185QWindowsStyle::QWindowsStyle(QWindowsStylePrivate &dd) : QCommonStyle(dd)
186{
187}
188
189
190/*! Destroys the QWindowsStyle object. */
191QWindowsStyle::~QWindowsStyle()
192{
193}
194
195#ifdef Q_OS_WIN
196static inline QRgb colorref2qrgb(COLORREF col)
197{
198 return qRgb(GetRValue(col), GetGValue(col), GetBValue(col));
199}
200#endif
201
202/*! \reimp */
203void QWindowsStyle::polish(QApplication *app)
204{
205 QCommonStyle::polish(app);
206 QWindowsStylePrivate *d = const_cast<QWindowsStylePrivate*>(d_func());
207 // We only need the overhead when shortcuts are sometimes hidden
208 if (!proxy()->styleHint(SH_UnderlineShortcut, nullptr) && app)
209 app->installEventFilter(this);
210
211 const auto &palette = QGuiApplication::palette();
212 d->activeGradientCaptionColor = palette.highlight().color();
213 d->activeCaptionColor = d->activeGradientCaptionColor;
214 d->inactiveGradientCaptionColor = palette.dark().color();
215 d->inactiveCaptionColor = d->inactiveGradientCaptionColor;
216 d->inactiveCaptionText = palette.window().color();
217
218#if defined(Q_OS_WIN) //fetch native title bar colors
219 if (app->desktopSettingsAware()){
220 DWORD activeCaption = GetSysColor(COLOR_ACTIVECAPTION);
221 DWORD gradientActiveCaption = GetSysColor(COLOR_GRADIENTACTIVECAPTION);
222 DWORD inactiveCaption = GetSysColor(COLOR_INACTIVECAPTION);
223 DWORD gradientInactiveCaption = GetSysColor(COLOR_GRADIENTINACTIVECAPTION);
224 DWORD inactiveCaptionText = GetSysColor(COLOR_INACTIVECAPTIONTEXT);
225 d->activeCaptionColor = colorref2qrgb(activeCaption);
226 d->activeGradientCaptionColor = colorref2qrgb(gradientActiveCaption);
227 d->inactiveCaptionColor = colorref2qrgb(inactiveCaption);
228 d->inactiveGradientCaptionColor = colorref2qrgb(gradientInactiveCaption);
229 d->inactiveCaptionText = colorref2qrgb(inactiveCaptionText);
230 }
231#endif
232}
233
234/*! \reimp */
235void QWindowsStyle::unpolish(QApplication *app)
236{
237 QCommonStyle::unpolish(app);
238 app->removeEventFilter(this);
239}
240
241/*! \reimp */
242void QWindowsStyle::polish(QWidget *widget)
243{
244 QCommonStyle::polish(widget);
245}
246
247/*! \reimp */
248void QWindowsStyle::unpolish(QWidget *widget)
249{
250 QCommonStyle::unpolish(widget);
251}
252
253/*!
254 \reimp
255*/
256void QWindowsStyle::polish(QPalette &pal)
257{
258 QCommonStyle::polish(pal);
259}
260
261int QWindowsStylePrivate::pixelMetricFromSystemDp(QStyle::PixelMetric pm, const QStyleOption *, const QWidget *widget)
262{
263#if defined(Q_OS_WIN)
264 // The pixel metrics are in device indepentent pixels;
265 // hardcode DPI to 1x 96 DPI.
266 const int dpi = 96;
267
268 switch (pm) {
269 case QStyle::PM_DockWidgetFrameWidth:
270 return GetSystemMetricsForDpi(SM_CXFRAME, dpi);
271
272 case QStyle::PM_TitleBarHeight: {
273 const int resizeBorderThickness =
274 GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi) + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
275 if (widget && (widget->windowType() == Qt::Tool))
276 return GetSystemMetricsForDpi(SM_CYSMCAPTION, dpi) + resizeBorderThickness;
277 return GetSystemMetricsForDpi(SM_CYCAPTION, dpi) + resizeBorderThickness;
278 }
279
280 case QStyle::PM_ScrollBarExtent:
281 {
282 NONCLIENTMETRICS ncm;
283 ncm.cbSize = sizeof(NONCLIENTMETRICS);
284 if (SystemParametersInfoForDpi(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0, dpi))
285 return qMax(ncm.iScrollHeight, ncm.iScrollWidth);
286 }
287 break;
288
289 case QStyle::PM_MdiSubWindowFrameWidth:
290 return GetSystemMetricsForDpi(SM_CYFRAME, dpi);
291
292 default:
293 break;
294 }
295#else // Q_OS_WIN
296 Q_UNUSED(pm);
297 Q_UNUSED(widget);
298#endif
299 return QWindowsStylePrivate::InvalidMetric;
300}
301
302int QWindowsStylePrivate::fixedPixelMetric(QStyle::PixelMetric pm)
303{
304 switch (pm) {
305 case QStyle::PM_ToolBarItemSpacing:
306 return 0;
307 case QStyle::PM_ButtonDefaultIndicator:
308 case QStyle::PM_ButtonShiftHorizontal:
309 case QStyle::PM_ButtonShiftVertical:
310 case QStyle::PM_MenuHMargin:
311 case QStyle::PM_MenuVMargin:
312 case QStyle::PM_ToolBarItemMargin:
313 return 1;
314 case QStyle::PM_DockWidgetSeparatorExtent:
315 return 4;
316#if QT_CONFIG(tabbar)
317 case QStyle::PM_TabBarTabShiftHorizontal:
318 return 0;
319 case QStyle::PM_TabBarTabShiftVertical:
320 return 2;
321#endif
322
323#if QT_CONFIG(slider)
324 case QStyle::PM_SliderLength:
325 return 11;
326#endif // QT_CONFIG(slider)
327
328#if QT_CONFIG(menu)
329 case QStyle::PM_MenuBarHMargin:
330 case QStyle::PM_MenuBarVMargin:
331 case QStyle::PM_MenuBarPanelWidth:
332 return 0;
333 case QStyle::PM_SmallIconSize:
334 return 16;
335 case QStyle::PM_LargeIconSize:
336 return 32;
337 case QStyle::PM_DockWidgetTitleMargin:
338 return 2;
339 case QStyle::PM_DockWidgetTitleBarButtonMargin:
340 case QStyle::PM_DockWidgetFrameWidth:
341 return 4;
342
343#endif // QT_CONFIG(menu)
344 case QStyle::PM_ToolBarHandleExtent:
345 return 10;
346 default:
347 break;
348 }
349 return QWindowsStylePrivate::InvalidMetric;
350}
351
352static QScreen *screenOf(const QWidget *w)
353{
354 if (w) {
355 if (auto screen = qt_widget_private(const_cast<QWidget *>(w))->associatedScreen())
356 return screen;
357 }
358 return QGuiApplication::primaryScreen();
359}
360
361// Calculate the overall scale factor to obtain Qt Device Independent
362// Pixels from a native Windows size.
363qreal QWindowsStylePrivate::nativeMetricScaleFactor(const QWidget *widget)
364{
365 return qreal(1) / QHighDpiScaling::factor(screenOf(widget));
366}
367
368/*!
369 \reimp
370*/
371int QWindowsStyle::pixelMetric(PixelMetric pm, const QStyleOption *opt, const QWidget *widget) const
372{
373 int ret = QWindowsStylePrivate::pixelMetricFromSystemDp(pm, opt, widget);
374 if (ret != QWindowsStylePrivate::InvalidMetric)
375 return ret;
376
377 ret = QWindowsStylePrivate::fixedPixelMetric(pm);
378 if (ret != QWindowsStylePrivate::InvalidMetric)
379 return int(QStyleHelper::dpiScaled(ret, opt));
380
381 ret = 0;
382
383 switch (pm) {
384 case PM_MaximumDragDistance:
385 ret = QCommonStyle::pixelMetric(PM_MaximumDragDistance, opt, widget);
386 if (ret == -1)
387 ret = 60;
388 break;
389
390#if QT_CONFIG(slider)
391 // Returns the number of pixels to use for the business part of the
392 // slider (i.e., the non-tickmark portion). The remaining space is shared
393 // equally between the tickmark regions.
394 case PM_SliderControlThickness:
395 if (const QStyleOptionSlider *sl = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
396 int space = (sl->orientation == Qt::Horizontal) ? sl->rect.height() : sl->rect.width();
397 int ticks = sl->tickPosition;
398 int n = 0;
399 if (ticks & QSlider::TicksAbove)
400 ++n;
401 if (ticks & QSlider::TicksBelow)
402 ++n;
403 if (!n) {
404 ret = space;
405 break;
406 }
407
408 int thick = 6; // Magic constant to get 5 + 16 + 5
409 if (ticks != QSlider::TicksBothSides && ticks != QSlider::NoTicks)
410 thick += proxy()->pixelMetric(PM_SliderLength, sl, widget) / 4;
411
412 space -= thick;
413 if (space > 0)
414 thick += (space * 2) / (n + 2);
415 ret = thick;
416 }
417 break;
418#endif // QT_CONFIG(slider)
419
420 case PM_IconViewIconSize:
421 ret = proxy()->pixelMetric(PM_LargeIconSize, opt, widget);
422 break;
423
424 case PM_SplitterWidth:
425 ret = QStyleHelper::dpiScaled(4, opt);
426 break;
427
428 default:
429 ret = QCommonStyle::pixelMetric(pm, opt, widget);
430 break;
431 }
432
433 return ret;
434}
435
436/*!
437 \reimp
438 */
439QPixmap QWindowsStyle::standardPixmap(StandardPixmap standardPixmap, const QStyleOption *opt,
440 const QWidget *widget) const
441{
442 return QCommonStyle::standardPixmap(standardPixmap, opt, widget);
443}
444
445/*! \reimp */
446int QWindowsStyle::styleHint(StyleHint hint, const QStyleOption *opt, const QWidget *widget,
447 QStyleHintReturn *returnData) const
448{
449 int ret = 0;
450
451 switch (hint) {
452 case SH_EtchDisabledText: {
453 const QPalette pal = opt ? opt->palette
454 : widget ? widget->palette()
455 : QPalette();
456 ret = pal.window().color().lightness() > pal.text().color().lightness()
457 ? 1 : 0;
458 break;
459 }
460 case SH_Slider_SnapToValue:
461 case SH_PrintDialog_RightAlignButtons:
462 case SH_FontDialog_SelectAssociatedText:
463 case SH_Menu_AllowActiveAndDisabled:
464 case SH_MenuBar_AltKeyNavigation:
465 case SH_MenuBar_MouseTracking:
466 case SH_Menu_MouseTracking:
467 case SH_ComboBox_ListMouseTracking_Current:
468 case SH_Slider_StopMouseOverSlider:
469 case SH_MainWindow_SpaceBelowMenuBar:
470 ret = 1;
471
472 break;
473 case SH_ItemView_ShowDecorationSelected:
474#if QT_CONFIG(listview)
475 if (qobject_cast<const QListView*>(widget))
476 ret = 1;
477#endif
478 break;
479 case SH_ItemView_ChangeHighlightOnFocus:
480 ret = 1;
481 break;
482 case SH_ToolBox_SelectedPageTitleBold:
483 ret = 0;
484 break;
485
486#if defined(Q_OS_WIN)
487 case SH_UnderlineShortcut:
488 {
489 ret = 1;
490 BOOL cues = false;
491 SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &cues, 0);
492 ret = int(cues);
493 // Do nothing if we always paint underlines
494 Q_D(const QWindowsStyle);
495 if (!ret && widget && d) {
496#if QT_CONFIG(menubar)
497 const QMenuBar *menuBar = qobject_cast<const QMenuBar *>(widget);
498 if (!menuBar && qobject_cast<const QMenu *>(widget)) {
499 QWidget *w = QApplication::activeWindow();
500 if (w && w != widget)
501 menuBar = w->findChild<QMenuBar *>();
502 }
503 // If we paint a menu bar draw underlines if is in the keyboardState
504 if (menuBar) {
505 if (menuBar->d_func()->keyboardState || d->altDown())
506 ret = 1;
507 // Otherwise draw underlines if the toplevel widget has seen an alt-press
508 } else
509#endif // QT_CONFIG(menubar)
510 if (d->hasSeenAlt(widget)) {
511 ret = 1;
512 }
513 }
514#if QT_CONFIG(accessibility)
515 if (!ret && opt && opt->type == QStyleOption::SO_MenuItem
516 && QStyleHelper::isInstanceOf(opt->styleObject, QAccessible::MenuItem)
517 && opt->styleObject->property("_q_showUnderlined").toBool())
518 ret = 1;
519#endif // QT_CONFIG(accessibility)
520 break;
521 }
522#endif // Q_OS_WIN
523 case SH_Menu_SubMenuSloppyCloseTimeout:
524 case SH_Menu_SubMenuPopupDelay: {
525#if defined(Q_OS_WIN)
526 DWORD delay;
527 if (SystemParametersInfo(SPI_GETMENUSHOWDELAY, 0, &delay, 0))
528 ret = delay;
529 else
530#endif // Q_OS_WIN
531 ret = 400;
532 break;
533 }
534#if QT_CONFIG(rubberband)
535 case SH_RubberBand_Mask:
536 if (const QStyleOptionRubberBand *rbOpt = qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
537 ret = 0;
538 if (rbOpt->shape == QRubberBand::Rectangle) {
539 ret = true;
540 if (QStyleHintReturnMask *mask = qstyleoption_cast<QStyleHintReturnMask*>(returnData)) {
541 mask->region = opt->rect;
542 int size = 1;
543 if (widget && widget->isWindow())
544 size = 4;
545 mask->region -= opt->rect.adjusted(size, size, -size, -size);
546 }
547 }
548 }
549 break;
550#endif // QT_CONFIG(rubberband)
551#if QT_CONFIG(wizard)
552 case SH_WizardStyle:
553 ret = QOperatingSystemVersion::currentType() == QOperatingSystemVersion::Windows
554 && QGuiApplication::styleHints()->colorScheme() != Qt::ColorScheme::Dark
555 ? QWizard::AeroStyle : QWizard::ModernStyle;
556 break;
557#endif
558 case SH_ItemView_ArrowKeysNavigateIntoChildren:
559 ret = true;
560 break;
561 case SH_DialogButtonBox_ButtonsHaveIcons:
562 ret = 0;
563 break;
564 default:
565 ret = QCommonStyle::styleHint(hint, opt, widget, returnData);
566 break;
567 }
568 return ret;
569}
570
571/*! \reimp */
572void QWindowsStyle::drawPrimitive(PrimitiveElement pe, const QStyleOption *opt, QPainter *p,
573 const QWidget *w) const
574{
575 // Used to restore across fallthrough cases. Currently only used in PE_IndicatorCheckBox
576 bool doRestore = false;
577
578 switch (pe) {
579#if QT_CONFIG(toolbar)
580 case PE_IndicatorToolBarSeparator: {
581 QPainterStateGuard psg(p);
582 const QRect &rect = opt->rect;
583 constexpr int margin = 2;
584 if (opt->state & State_Horizontal){
585 const int offset = rect.width() / 2;
586 const auto &tl = rect.topLeft();
587 const auto &bl = rect.bottomLeft();
588 p->setPen(opt->palette.dark().color());
589 p->drawLine(QLine(bl.x() + offset, bl.y() - margin,
590 tl.x() + offset, tl.y() + margin));
591 p->setPen(opt->palette.light().color());
592 p->drawLine(QLine(bl.x() + offset + 1, bl.y() - margin,
593 tl.x() + offset + 1, tl.y() + margin));
594 }
595 else{ //Draw vertical separator
596 const int offset = rect.height() / 2;
597 const auto &tl = rect.topLeft();
598 const auto &tr = rect.topRight();
599 p->setPen(opt->palette.dark().color());
600 p->drawLine(QLine(tl.x() + margin, tl.y() + offset,
601 tr.x() - margin, tr.y() + offset));
602 p->setPen(opt->palette.light().color());
603 p->drawLine(QLine(tl.x() + margin, tl.y() + offset + 1,
604 tr.x() - margin, tr.y() + offset + 1));
605 }
606 break;
607 }
608 case PE_IndicatorToolBarHandle: {
609 QPainterStateGuard psg(p);
610 p->translate(opt->rect.x(), opt->rect.y());
611 if (opt->state & State_Horizontal) {
612 if (opt->rect.height() > 4) {
613 int x = opt->rect.width() / 2 - 4;
614 if (opt->direction == Qt::RightToLeft)
615 x -= 2;
616 qDrawShadePanel(p, x, 2, 3, opt->rect.height() - 4,
617 opt->palette, false, 1, nullptr);
618 qDrawShadePanel(p, x + 3, 2, 3, opt->rect.height() - 4,
619 opt->palette, false, 1, nullptr);
620 }
621 } else {
622 if (opt->rect.width() > 4) {
623 int y = opt->rect.height() / 2 - 4;
624 qDrawShadePanel(p, 2, y, opt->rect.width() - 4, 3,
625 opt->palette, false, 1, nullptr);
626 qDrawShadePanel(p, 2, y + 3, opt->rect.width() - 4, 3,
627 opt->palette, false, 1, nullptr);
628 }
629 }
630 break;
631 }
632#endif // QT_CONFIG(toolbar)
633 case PE_FrameButtonTool:
634 case PE_PanelButtonTool: {
635 QPen oldPen = p->pen();
636#if QT_CONFIG(dockwidget)
637 if (w && w->inherits("QDockWidgetTitleButton")) {
638 if (const QWidget *dw = w->parentWidget())
639 if (dw->isWindow()){
640 qDrawWinButton(p, opt->rect.adjusted(1, 1, 0, 0), opt->palette, opt->state & (State_Sunken | State_On),
641 &opt->palette.button());
642
643 return;
644 }
645 }
646#endif // QT_CONFIG(dockwidget)
647 QBrush fill;
648 bool stippled;
649 bool panel = (pe == PE_PanelButtonTool);
650 if ((!(opt->state & State_Sunken ))
651 && (!(opt->state & State_Enabled)
652 || !(opt->state & State_MouseOver && opt->state & State_AutoRaise))
653 && (opt->state & State_On)) {
654 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
655 stippled = true;
656 } else {
657 fill = opt->palette.brush(QPalette::Button);
658 stippled = false;
659 }
660
661 if (opt->state & (State_Raised | State_Sunken | State_On)) {
662 if (opt->state & State_AutoRaise) {
663 if (opt->state & (State_Enabled | State_Sunken | State_On)){
664 if (panel)
665 qDrawShadePanel(p, opt->rect, opt->palette,
666 opt->state & (State_Sunken | State_On), 1, &fill);
667 else
668 qDrawShadeRect(p, opt->rect, opt->palette,
669 opt->state & (State_Sunken | State_On), 1);
670 }
671 if (stippled) {
672 p->setPen(opt->palette.button().color());
673 p->drawRect(opt->rect.adjusted(1,1,-2,-2));
674 }
675 } else {
676 qDrawWinButton(p, opt->rect, opt->palette,
677 opt->state & (State_Sunken | State_On), panel ? &fill : nullptr);
678 }
679 } else {
680 p->fillRect(opt->rect, fill);
681 }
682 p->setPen(oldPen);
683 break; }
684 case PE_PanelButtonCommand:
685 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
686 QBrush fill;
687 State flags = opt->state;
688 QPalette pal = opt->palette;
689 QRect r = opt->rect;
690 if (! (flags & State_Sunken) && (flags & State_On))
691 fill = QBrush(pal.light().color(), Qt::Dense4Pattern);
692 else
693 fill = pal.brush(QPalette::Button);
694
695 if (btn->features & QStyleOptionButton::DefaultButton && flags & State_Sunken) {
696 p->setPen(pal.dark().color());
697 p->setBrush(fill);
698 p->drawRect(r.adjusted(0, 0, -1, -1));
699 } else if (flags & (State_Raised | State_On | State_Sunken)) {
700 qDrawWinButton(p, r, pal, flags & (State_Sunken | State_On),
701 &fill);
702 } else {
703 p->fillRect(r, fill);
704 }
705 }
706 break;
707 case PE_FrameDefaultButton: {
708 QPen oldPen = p->pen();
709 p->setPen(QPen(opt->palette.shadow().color(), 0));
710 QRectF rect = opt->rect;
711 const qreal dpi = QStyleHelper::dpi(opt);
712 const qreal topLevelAdjustment = QStyleHelper::dpiScaled(0.5, dpi);
713 const qreal bottomRightAdjustment = QStyleHelper::dpiScaled(-1.5, dpi);
714 rect.adjust(topLevelAdjustment, topLevelAdjustment,
715 bottomRightAdjustment, bottomRightAdjustment);
716 p->drawRect(rect);
717 p->setPen(oldPen);
718 break;
719 }
720 case PE_IndicatorCheckBox: {
721 QBrush fill;
722 if (opt->state & State_NoChange)
723 fill = QBrush(opt->palette.base().color(), Qt::Dense4Pattern);
724 else if (opt->state & State_Sunken)
725 fill = opt->palette.button();
726 else if (opt->state & State_Enabled)
727 fill = opt->palette.base();
728 else
729 fill = opt->palette.window();
730 p->save();
731 doRestore = true;
732 qDrawWinPanel(p, opt->rect, opt->palette, true, &fill);
733 if (opt->state & State_NoChange)
734 p->setPen(opt->palette.dark().color());
735 else
736 p->setPen(opt->palette.text().color());
737 }
738 Q_FALLTHROUGH();
739 case PE_IndicatorItemViewItemCheck:
740 if (!doRestore) {
741 p->save();
742 doRestore = true;
743 }
744#if QT_CONFIG(itemviews)
745 if (pe == PE_IndicatorItemViewItemCheck) {
746 const QStyleOptionViewItem *itemViewOpt = qstyleoption_cast<const QStyleOptionViewItem *>(opt);
747 p->setPen(itemViewOpt
748 && itemViewOpt->showDecorationSelected
749 && opt->state & State_Selected
750 ? opt->palette.highlightedText().color()
751 : opt->palette.text().color());
752 if (opt->state & State_NoChange)
753 p->setBrush(opt->palette.brush(QPalette::Button));
754 p->drawRect(opt->rect.x() + 1, opt->rect.y() + 1, opt->rect.width() - 2, opt->rect.height() - 2);
755 }
756#endif // QT_CONFIG(itemviews)
757 if (!(opt->state & State_Off)) {
758 std::array<QPointF, 6> points;
759 qreal scaleh = opt->rect.width() / 12.0;
760 qreal scalev = opt->rect.height() / 12.0;
761 points[0] = { opt->rect.x() + qreal(3.5) * scaleh, opt->rect.y() + qreal(5.5) * scalev };
762 points[1] = { points[0].x(), points[0].y() + 2 * scalev };
763 points[2] = { points[1].x() + 2 * scaleh, points[1].y() + 2 * scalev };
764 points[3] = { points[2].x() + 4 * scaleh, points[2].y() - 4 * scalev };
765 points[4] = { points[3].x(), points[3].y() - 2 * scalev };
766 points[5] = { points[4].x() - 4 * scaleh, points[4].y() + 4 * scalev };
767 p->setPen(QPen(opt->palette.text().color(), 0));
768 p->setBrush(opt->palette.text());
769 p->drawPolygon(points.data(), static_cast<int>(points.size()));
770 }
771 if (doRestore)
772 p->restore();
773 break;
774 case PE_FrameFocusRect:
775 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
776 //### check for d->alt_down
777 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt, w))
778 return;
779 QRect r = opt->rect;
780 p->save();
781 p->setBackgroundMode(Qt::TransparentMode);
782 QColor bg_col = fropt->backgroundColor;
783 if (!bg_col.isValid())
784 bg_col = p->background().color();
785 // Create an "XOR" color.
786 QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
787 (bg_col.green() ^ 0xff) & 0xff,
788 (bg_col.blue() ^ 0xff) & 0xff);
789 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
790 p->setBrushOrigin(r.topLeft());
791 p->setPen(Qt::NoPen);
792 p->drawRect(r.left(), r.top(), r.width(), 1); // Top
793 p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
794 p->drawRect(r.left(), r.top(), 1, r.height()); // Left
795 p->drawRect(r.right(), r.top(), 1, r.height()); // Right
796 p->restore();
797 }
798 break;
799 case PE_IndicatorRadioButton:
800 {
801 QRect r = opt->rect;
802 p->save();
803 p->setRenderHint(QPainter::Antialiasing, true);
804
805 QPointF circleCenter = r.center() + QPoint(1, 1);
806 qreal radius = (r.width() + (r.width() + 1) % 2) / 2.0 - 1;
807
808 QPainterPath path1;
809 path1.addEllipse(circleCenter, radius, radius);
810 radius *= 0.85;
811 QPainterPath path2;
812 path2.addEllipse(circleCenter, radius, radius);
813 radius *= 0.85;
814 QPainterPath path3;
815 path3.addEllipse(circleCenter, radius, radius);
816 radius *= 0.5;
817 QPainterPath path4;
818 path4.addEllipse(circleCenter, radius, radius);
819
820 QPolygon topLeftPol, bottomRightPol;
821 topLeftPol.setPoints(3, r.x(), r.y(), r.x(), r.y() + r.height(), r.x() + r.width(), r.y());
822 bottomRightPol.setPoints(3, r.x(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y());
823
824 p->setClipRegion(QRegion(topLeftPol));
825 p->setPen(opt->palette.dark().color());
826 p->setBrush(opt->palette.dark());
827 p->drawPath(path1);
828 p->setPen(opt->palette.shadow().color());
829 p->setBrush(opt->palette.shadow());
830 p->drawPath(path2);
831
832 p->setClipRegion(QRegion(bottomRightPol));
833 p->setPen(opt->palette.light().color());
834 p->setBrush(opt->palette.light());
835 p->drawPath(path1);
836 p->setPen(opt->palette.midlight().color());
837 p->setBrush(opt->palette.midlight());
838 p->drawPath(path2);
839
840 QColor fillColor = ((opt->state & State_Sunken) || !(opt->state & State_Enabled)) ?
841 opt->palette.button().color() : opt->palette.base().color();
842
843 p->setClipping(false);
844 p->setPen(fillColor);
845 p->setBrush(fillColor);
846 p->drawPath(path3);
847
848 if (opt->state & State_On) {
849 p->setPen(opt->palette.text().color());
850 p->setBrush(opt->palette.text());
851 p->drawPath(path4);
852 }
853 p->restore();
854 break;
855 }
856#ifndef QT_NO_FRAME
857 case PE_Frame:
858 if (w && w->inherits("QComboBoxPrivateContainer")){
859 QStyleOption copy = *opt;
860 copy.state |= State_Raised;
861 proxy()->drawPrimitive(PE_PanelMenu, &copy, p, w);
862 break;
863 }
864 Q_FALLTHROUGH();
865 case PE_FrameMenu:
866 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
867 if (frame->lineWidth == 2 || pe == PE_Frame) {
868 QPalette popupPal = frame->palette;
869 if (pe == PE_FrameMenu) {
870 popupPal.setColor(QPalette::Light, frame->palette.window().color());
871 popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
872 }
873 if (pe == PE_Frame && (frame->state & State_Raised))
874 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
875 else if (pe == PE_Frame && (frame->state & State_Sunken))
876 {
877 popupPal.setColor(QPalette::Midlight, frame->palette.window().color());
878 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
879 }
880 else
881 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
882 } else {
883 QCommonStyle::drawPrimitive(pe, opt, p, w);
884 }
885 } else {
886 QPalette popupPal = opt->palette;
887 p->drawRect(opt->rect);
888 popupPal.setColor(QPalette::Light, opt->palette.window().color());
889 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
890 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
891 }
892 break;
893#endif // QT_NO_FRAME
894 case PE_FrameButtonBevel:
895 case PE_PanelButtonBevel: {
896 QBrush fill;
897 bool panel = pe != PE_FrameButtonBevel;
898 p->setBrushOrigin(opt->rect.topLeft());
899 if (!(opt->state & State_Sunken) && (opt->state & State_On))
900 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
901 else
902 fill = opt->palette.brush(QPalette::Button);
903
904 if (opt->state & (State_Raised | State_On | State_Sunken)) {
905 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
906 panel ? &fill : nullptr);
907 } else {
908 if (panel)
909 p->fillRect(opt->rect, fill);
910 else
911 p->drawRect(opt->rect);
912 }
913 break; }
914 case PE_PanelMenu:
915 if (w && w->inherits("QComboBoxPrivateContainer")){
916 const QBrush menuBackground = opt->palette.base().color();
917 QColor borderColor = opt->palette.window().color();
918 qDrawPlainRect(p, opt->rect, borderColor, 1, &menuBackground);
919 } else {
920 QCommonStyle::drawPrimitive(pe, opt, p, w);
921 }
922 break;
923 case PE_FrameWindow: {
924 QPalette popupPal = opt->palette;
925 popupPal.setColor(QPalette::Light, opt->palette.window().color());
926 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
927 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
928 break; }
929#if QT_CONFIG(dockwidget)
930 case PE_IndicatorDockWidgetResizeHandle:
931 break;
932 case PE_FrameDockWidget:
933 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
934 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
935 }
936 break;
937#endif // QT_CONFIG(dockwidget)
938
939 case PE_FrameStatusBarItem:
940 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, nullptr);
941 break;
942
943 case PE_IndicatorProgressChunk:
944 {
945 bool vertical = false, inverted = false;
946 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
947 vertical = !(pb->state & QStyle::State_Horizontal);
948 inverted = pb->invertedAppearance;
949 }
950
951 int space = 2;
952 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
953 if (!vertical) {
954 if (opt->rect.width() <= chunksize)
955 space = 0;
956
957 if (inverted)
958 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
959 opt->palette.brush(QPalette::Highlight));
960 else
961 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
962 opt->palette.brush(QPalette::Highlight));
963 } else {
964 if (opt->rect.height() <= chunksize)
965 space = 0;
966
967 if (inverted)
968 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
969 opt->palette.brush(QPalette::Highlight));
970 else
971 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
972 opt->palette.brush(QPalette::Highlight));
973 }
974 }
975 break;
976
977 case PE_FrameTabWidget: {
978 qDrawWinButton(p, opt->rect, opt->palette, false, nullptr);
979 break;
980 }
981 default:
982 QCommonStyle::drawPrimitive(pe, opt, p, w);
983 }
984}
985
986/*! \reimp */
987void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
988 const QWidget *widget) const
989{
990 switch (ce) {
991#if QT_CONFIG(rubberband)
992 case CE_RubberBand:
993 if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
994 // ### workaround for slow general painter path
995 QPixmap tiledPixmap(16, 16);
996 QPainter pixmapPainter(&tiledPixmap);
997 pixmapPainter.setPen(Qt::NoPen);
998 pixmapPainter.setBrush(Qt::Dense4Pattern);
999 pixmapPainter.setBackground(Qt::white);
1000 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1001 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1002 pixmapPainter.end();
1003 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1004 p->save();
1005 QRect r = opt->rect;
1006 QStyleHintReturnMask mask;
1007 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1008 p->setClipRegion(mask.region);
1009 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1010 p->restore();
1011 return;
1012 }
1013 break;
1014#endif // QT_CONFIG(rubberband)
1015
1016#if QT_CONFIG(menu) && QT_CONFIG(mainwindow)
1017 case CE_MenuBarEmptyArea:
1018 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
1019 p->fillRect(opt->rect, opt->palette.button());
1020 QPen oldPen = p->pen();
1021 p->setPen(opt->palette.dark().color());
1022 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1023 p->setPen(oldPen);
1024 }
1025 break;
1026#endif
1027#if QT_CONFIG(menu)
1028 case CE_MenuItem:
1029 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1030 int x, y, w, h;
1031 menuitem->rect.getRect(&x, &y, &w, &h);
1032 int tab = menuitem->reservedShortcutWidth;
1033 bool dis = !(menuitem->state & State_Enabled);
1034 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1035 ? menuitem->checked : false;
1036 bool act = menuitem->state & State_Selected;
1037
1038 // windows always has a check column, regardless whether we have an icon or not
1039 int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1040
1041 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1042 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1043
1044 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1045 int yoff = y-1 + h / 2;
1046 p->setPen(menuitem->palette.dark().color());
1047 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1048 p->setPen(menuitem->palette.light().color());
1049 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1050 return;
1051 }
1052
1053 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1054 if (!menuitem->icon.isNull() && checked) {
1055 if (act) {
1056 qDrawShadePanel(p, vCheckRect,
1057 menuitem->palette, true, 1,
1058 &menuitem->palette.brush(QPalette::Button));
1059 } else {
1060 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1061 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1062 }
1063 } else if (!act) {
1064 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1065 }
1066
1067 // On Windows Style, if we have a checkable item and an icon we
1068 // draw the icon recessed to indicate an item is checked. If we
1069 // have no icon, we draw a checkmark instead.
1070 if (!menuitem->icon.isNull()) {
1071 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1072 if (act && !dis)
1073 mode = QIcon::Active;
1074 const auto size = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1075 const auto dpr = QStyleHelper::getDpr(p);
1076 const auto state = checked ? QIcon::On : QIcon::Off;
1077 const auto pixmap = menuitem->icon.pixmap(QSize(size, size), dpr, mode, state);
1078 QRect pmr(QPoint(0, 0), pixmap.deviceIndependentSize().toSize());
1079 pmr.moveCenter(vCheckRect.center());
1080 p->setPen(menuitem->palette.text().color());
1081 p->drawPixmap(pmr.topLeft(), pixmap);
1082 } else if (checked) {
1083 QStyleOptionMenuItem newMi = *menuitem;
1084 newMi.state = State_None;
1085 if (!dis)
1086 newMi.state |= State_Enabled;
1087 if (act)
1088 newMi.state |= State_On | State_Selected;
1089 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1090 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1091 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1092 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1093 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1094 }
1095 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1096
1097 QColor discol;
1098 if (dis) {
1099 discol = menuitem->palette.text().color();
1100 p->setPen(discol);
1101 }
1102
1103 int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin);
1104 int xpos = menuitem->rect.x() + xm;
1105 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1106 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1107 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1108 QStringView s(menuitem->text);
1109 if (!s.isEmpty()) { // draw text
1110 p->save();
1111 qsizetype t = s.indexOf(u'\t');
1112 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1113 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1114 text_flags |= Qt::TextHideMnemonic;
1115 text_flags |= Qt::AlignLeft;
1116 if (t >= 0) {
1117 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1118 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1119 const QString textToDraw = s.mid(t + 1).toString();
1120 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1121 p->setPen(menuitem->palette.light().color());
1122 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1123 p->setPen(discol);
1124 }
1125 p->drawText(vShortcutRect, text_flags, textToDraw);
1126 s = s.left(t);
1127 }
1128 QFont font = menuitem->font;
1129 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1130 font.setBold(true);
1131 p->setFont(font);
1132 const QString textToDraw = s.left(t).toString();
1133 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1134 p->setPen(menuitem->palette.light().color());
1135 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1136 p->setPen(discol);
1137 }
1138 p->drawText(vTextRect, text_flags, textToDraw);
1139 p->restore();
1140 }
1141 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1142 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1143 PrimitiveElement arrow;
1144 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1145 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1146 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1147 QStyleOptionMenuItem newMI = *menuitem;
1148 newMI.rect = vSubMenuRect;
1149 newMI.state = dis ? State_None : State_Enabled;
1150 if (act)
1151 newMI.palette.setColor(QPalette::ButtonText,
1152 newMI.palette.highlightedText().color());
1153 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1154 }
1155
1156 }
1157 break;
1158#endif // QT_CONFIG(menu)
1159#if QT_CONFIG(menubar)
1160 case CE_MenuBarItem:
1161 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1162 const bool active = mbi->state & State_Selected;
1163 const QBrush buttonBrush = mbi->palette.brush(QPalette::Button);
1164 QStyleOptionMenuItem newMbi = *mbi;
1165 p->fillRect(mbi->rect, buttonBrush);
1166 if (active) {
1167 const bool hasFocus = mbi->state & State_HasFocus;
1168 const bool down = mbi->state & State_Sunken;
1169 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1170 if (down) {
1171 psg.save();
1172 p->setBrushOrigin(p->brushOriginF() + QPointF(1, 1));
1173 }
1174 if (hasFocus)
1175 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1176 mbi->rect.height(), mbi->palette, active && down, 1, 0, &buttonBrush);
1177 if (down)
1178 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1179 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1180 }
1181 QCommonStyle::drawControl(ce, &newMbi, p, widget);
1182 }
1183 break;
1184#endif // QT_CONFIG(menubar)
1185#if QT_CONFIG(tabbar)
1186 case CE_TabBarTabShape:
1187 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1188 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1189 && (tab->shape == QTabBar::RoundedNorth
1190 || tab->shape == QTabBar::RoundedSouth));
1191 bool selected = tab->state & State_Selected;
1192 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1193 || (rtlHorTabs
1194 && tab->position == QStyleOptionTab::Beginning));
1195 bool firstTab = ((!rtlHorTabs
1196 && tab->position == QStyleOptionTab::Beginning)
1197 || (rtlHorTabs
1198 && tab->position == QStyleOptionTab::End));
1199 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1200 bool previousSelected =
1201 ((!rtlHorTabs
1202 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1203 || (rtlHorTabs
1204 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1205 bool nextSelected =
1206 ((!rtlHorTabs
1207 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1208 || (rtlHorTabs
1209 && tab->selectedPosition
1210 == QStyleOptionTab::PreviousIsSelected));
1211 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1212 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1213 || (rtlHorTabs
1214 && tabBarAlignment == Qt::AlignRight);
1215
1216 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1217 || (rtlHorTabs
1218 && tabBarAlignment == Qt::AlignLeft);
1219
1220 QColor light = tab->palette.light().color();
1221 QColor dark = tab->palette.dark().color();
1222 QColor shadow = tab->palette.shadow().color();
1223 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1224 if (selected)
1225 borderThinkness /= 2;
1226 QRect r2(opt->rect);
1227 int x1 = r2.left();
1228 int x2 = r2.right();
1229 int y1 = r2.top();
1230 int y2 = r2.bottom();
1231 switch (tab->shape) {
1232 default:
1233 QCommonStyle::drawControl(ce, tab, p, widget);
1234 break;
1235 case QTabBar::RoundedNorth: {
1236 if (!selected) {
1237 y1 += 2;
1238 x1 += onlyOne || firstTab ? borderThinkness : 0;
1239 x2 -= onlyOne || lastTab ? borderThinkness : 0;
1240 }
1241
1242 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window());
1243
1244 // Delete border
1245 if (selected) {
1246 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window());
1247 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window());
1248 }
1249 // Left
1250 if (firstTab || selected || onlyOne || !previousSelected) {
1251 p->setPen(light);
1252 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1253 p->drawPoint(x1 + 1, y1 + 1);
1254 }
1255 // Top
1256 {
1257 int beg = x1 + (previousSelected ? 0 : 2);
1258 int end = x2 - (nextSelected ? 0 : 2);
1259 p->setPen(light);
1260 p->drawLine(beg, y1, end, y1);
1261 }
1262 // Right
1263 if (lastTab || selected || onlyOne || !nextSelected) {
1264 p->setPen(shadow);
1265 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1266 p->drawPoint(x2 - 1, y1 + 1);
1267 p->setPen(dark);
1268 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1269 }
1270 break; }
1271 case QTabBar::RoundedSouth: {
1272 if (!selected) {
1273 y2 -= 2;
1274 x1 += firstTab ? borderThinkness : 0;
1275 x2 -= lastTab ? borderThinkness : 0;
1276 }
1277
1278 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1279
1280 // Delete border
1281 if (selected) {
1282 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window());
1283 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window());
1284 }
1285 // Left
1286 if (firstTab || selected || onlyOne || !previousSelected) {
1287 p->setPen(light);
1288 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1289 p->drawPoint(x1 + 1, y2 - 1);
1290 }
1291 // Bottom
1292 {
1293 int beg = x1 + (previousSelected ? 0 : 2);
1294 int end = x2 - (nextSelected ? 0 : 2);
1295 p->setPen(shadow);
1296 p->drawLine(beg, y2, end, y2);
1297 p->setPen(dark);
1298 p->drawLine(beg, y2 - 1, end, y2 - 1);
1299 }
1300 // Right
1301 if (lastTab || selected || onlyOne || !nextSelected) {
1302 p->setPen(shadow);
1303 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1304 p->drawPoint(x2 - 1, y2 - 1);
1305 p->setPen(dark);
1306 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1307 }
1308 break; }
1309 case QTabBar::RoundedWest: {
1310 if (!selected) {
1311 x1 += 2;
1312 y1 += firstTab ? borderThinkness : 0;
1313 y2 -= lastTab ? borderThinkness : 0;
1314 }
1315
1316 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window());
1317
1318 // Delete border
1319 if (selected) {
1320 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window());
1321 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window());
1322 }
1323 // Top
1324 if (firstTab || selected || onlyOne || !previousSelected) {
1325 p->setPen(light);
1326 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1327 p->drawPoint(x1 + 1, y1 + 1);
1328 }
1329 // Left
1330 {
1331 int beg = y1 + (previousSelected ? 0 : 2);
1332 int end = y2 - (nextSelected ? 0 : 2);
1333 p->setPen(light);
1334 p->drawLine(x1, beg, x1, end);
1335 }
1336 // Bottom
1337 if (lastTab || selected || onlyOne || !nextSelected) {
1338 p->setPen(shadow);
1339 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1340 p->drawPoint(x1 + 2, y2 - 1);
1341 p->setPen(dark);
1342 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1343 p->drawPoint(x1 + 1, y2 - 1);
1344 p->drawPoint(x1 + 2, y2);
1345 }
1346 break; }
1347 case QTabBar::RoundedEast: {
1348 if (!selected) {
1349 x2 -= 2;
1350 y1 += firstTab ? borderThinkness : 0;
1351 y2 -= lastTab ? borderThinkness : 0;
1352 }
1353
1354 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1355
1356 // Delete border
1357 if (selected) {
1358 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window());
1359 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window());
1360 }
1361 // Top
1362 if (firstTab || selected || onlyOne || !previousSelected) {
1363 p->setPen(light);
1364 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1365 p->drawPoint(x2 - 1, y1 + 1);
1366 }
1367 // Right
1368 {
1369 int beg = y1 + (previousSelected ? 0 : 2);
1370 int end = y2 - (nextSelected ? 0 : 2);
1371 p->setPen(shadow);
1372 p->drawLine(x2, beg, x2, end);
1373 p->setPen(dark);
1374 p->drawLine(x2 - 1, beg, x2 - 1, end);
1375 }
1376 // Bottom
1377 if (lastTab || selected || onlyOne || !nextSelected) {
1378 p->setPen(shadow);
1379 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1380 p->drawPoint(x2 - 1, y2 - 1);
1381 p->setPen(dark);
1382 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1383 }
1384 break; }
1385 }
1386 }
1387 break;
1388#endif // QT_CONFIG(tabbar)
1389 case CE_ToolBoxTabShape:
1390 qDrawShadePanel(p, opt->rect, opt->palette,
1391 opt->state & (State_Sunken | State_On), 1,
1392 &opt->palette.brush(QPalette::Button));
1393 break;
1394#if QT_CONFIG(splitter)
1395 case CE_Splitter:
1396 p->eraseRect(opt->rect);
1397 break;
1398#endif // QT_CONFIG(splitter)
1399#if QT_CONFIG(scrollbar)
1400 case CE_ScrollBarSubLine:
1401 case CE_ScrollBarAddLine: {
1402 if ((opt->state & State_Sunken)) {
1403 p->setPen(opt->palette.dark().color());
1404 p->setBrush(opt->palette.brush(QPalette::Button));
1405 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1406 } else {
1407 QStyleOption buttonOpt = *opt;
1408 if (!(buttonOpt.state & State_Sunken))
1409 buttonOpt.state |= State_Raised;
1410 QPalette pal(opt->palette);
1411 pal.setColor(QPalette::Button, opt->palette.light().color());
1412 pal.setColor(QPalette::Light, opt->palette.button().color());
1413 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1414 &opt->palette.brush(QPalette::Button));
1415 }
1416 PrimitiveElement arrow;
1417 if (opt->state & State_Horizontal) {
1418 if (ce == CE_ScrollBarAddLine)
1419 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1420 else
1421 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1422 } else {
1423 if (ce == CE_ScrollBarAddLine)
1424 arrow = PE_IndicatorArrowDown;
1425 else
1426 arrow = PE_IndicatorArrowUp;
1427 }
1428 QStyleOption arrowOpt = *opt;
1429 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1430 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1431 break; }
1432 case CE_ScrollBarAddPage:
1433 case CE_ScrollBarSubPage: {
1434 QBrush br;
1435 QBrush bg = p->background();
1436 Qt::BGMode bg_mode = p->backgroundMode();
1437 p->setPen(Qt::NoPen);
1438 p->setBackgroundMode(Qt::OpaqueMode);
1439
1440 if (opt->state & State_Sunken) {
1441 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
1442 p->setBackground(opt->palette.dark().color());
1443 p->setBrush(br);
1444 } else {
1445 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1446 if (paletteBrush.style() == Qt::TexturePattern) {
1447 if (qHasPixmapTexture(paletteBrush))
1448 br = QBrush(paletteBrush.texture());
1449 else
1450 br = QBrush(paletteBrush.textureImage());
1451 } else
1452 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1453 p->setBackground(opt->palette.window().color());
1454 p->setBrush(br);
1455 }
1456 p->drawRect(opt->rect);
1457 p->setBackground(bg);
1458 p->setBackgroundMode(bg_mode);
1459 break; }
1460 case CE_ScrollBarSlider:
1461 if (!(opt->state & State_Enabled)) {
1462 QBrush br;
1463 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1464 if (paletteBrush.style() == Qt::TexturePattern) {
1465 if (qHasPixmapTexture(paletteBrush))
1466 br = QBrush(paletteBrush.texture());
1467 else
1468 br = QBrush(paletteBrush.textureImage());
1469 } else
1470 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1471 p->setPen(Qt::NoPen);
1472 p->setBrush(br);
1473 p->setBackgroundMode(Qt::OpaqueMode);
1474 p->drawRect(opt->rect);
1475 } else {
1476 QStyleOptionButton buttonOpt;
1477 buttonOpt.QStyleOption::operator=(*opt);
1478 buttonOpt.state = State_Enabled | State_Raised;
1479
1480 QPalette pal(opt->palette);
1481 pal.setColor(QPalette::Button, opt->palette.light().color());
1482 pal.setColor(QPalette::Light, opt->palette.button().color());
1483 qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button));
1484 }
1485 break;
1486#endif // QT_CONFIG(scrollbar)
1487 case CE_HeaderSection: {
1488 QBrush fill;
1489 if (opt->state & State_On)
1490 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1491 else
1492 fill = opt->palette.brush(QPalette::Button);
1493
1494 if (opt->state & (State_Raised | State_Sunken)) {
1495 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
1496 } else {
1497 p->fillRect(opt->rect, fill);
1498 }
1499 break; }
1500#if QT_CONFIG(toolbar)
1501 case CE_ToolBar:
1502 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
1503 // Reserve the beveled appearance only for mainwindow toolbars
1504 if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
1505 break;
1506
1507 QRect rect = opt->rect;
1508 bool paintLeftBorder = true;
1509 bool paintRightBorder = true;
1510 bool paintBottomBorder = true;
1511
1512 switch (toolbar->toolBarArea){
1513 case Qt::BottomToolBarArea :
1514 switch(toolbar->positionOfLine){
1515 case QStyleOptionToolBar::Beginning:
1516 case QStyleOptionToolBar::OnlyOne:
1517 paintBottomBorder = false;
1518 break;
1519 default:
1520 break;
1521 }
1522 Q_FALLTHROUGH(); // It continues in the end of the next case
1523 case Qt::TopToolBarArea :
1524 switch(toolbar->positionWithinLine){
1525 case QStyleOptionToolBar::Beginning:
1526 paintLeftBorder = false;
1527 break;
1528 case QStyleOptionToolBar::End:
1529 paintRightBorder = false;
1530 break;
1531 case QStyleOptionToolBar::OnlyOne:
1532 paintRightBorder = false;
1533 paintLeftBorder = false;
1534 break;
1535 default:
1536 break;
1537 }
1538 if (opt->direction == Qt::RightToLeft) //reverse layout changes the order of Beginning/end
1539 std::swap(paintLeftBorder, paintRightBorder);
1540 break;
1541 case Qt::RightToolBarArea :
1542 switch (toolbar->positionOfLine){
1543 case QStyleOptionToolBar::Beginning:
1544 case QStyleOptionToolBar::OnlyOne:
1545 paintRightBorder = false;
1546 break;
1547 default:
1548 break;
1549 }
1550 break;
1551 case Qt::LeftToolBarArea :
1552 switch (toolbar->positionOfLine){
1553 case QStyleOptionToolBar::Beginning:
1554 case QStyleOptionToolBar::OnlyOne:
1555 paintLeftBorder = false;
1556 break;
1557 default:
1558 break;
1559 }
1560 break;
1561 default:
1562 break;
1563 }
1564
1565
1566 //draw top border
1567 p->setPen(opt->palette.light().color());
1568 p->drawLine(rect.topLeft(), rect.topRight());
1569
1570 if (paintLeftBorder){
1571 p->setPen(opt->palette.light().color());
1572 p->drawLine(rect.topLeft(), rect.bottomLeft());
1573 }
1574
1575 if (paintRightBorder){
1576 p->setPen(opt->palette.dark().color());
1577 p->drawLine(rect.topRight(), rect.bottomRight());
1578 }
1579
1580 if (paintBottomBorder){
1581 p->setPen(opt->palette.dark().color());
1582 p->drawLine(rect.bottomLeft(), rect.bottomRight());
1583 }
1584 }
1585 break;
1586
1587
1588#endif // QT_CONFIG(toolbar)
1589
1590 case CE_ProgressBarContents:
1591 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1592 QRect rect = pb->rect;
1593 if (!rect.isValid())
1594 return;
1595
1596 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1597 const bool inverted = pb->invertedAppearance;
1598
1599 QTransform m;
1600 if (vertical) {
1601 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height
1602 m.rotate(90);
1603 m.translate(0, -(rect.height() + rect.y()*2));
1604 }
1605 QPalette pal2 = pb->palette;
1606 // Correct the highlight color if it is the same as the background
1607 if (pal2.highlight() == pal2.window())
1608 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1609 QPalette::Highlight));
1610 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1611 if (inverted)
1612 reverse = !reverse;
1613 int w = rect.width();
1614 Q_D(const QWindowsStyle);
1615 if (pb->minimum == 0 && pb->maximum == 0) {
1616 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1617 QStyleOptionProgressBar pbBits = *pb;
1618 Q_ASSERT(unit_width >0);
1619
1620 pbBits.rect = rect;
1621 pbBits.palette = pal2;
1622
1623 int step = 0;
1624 int chunkCount = w / unit_width + 1;
1625#if QT_CONFIG(animation)
1626 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
1627 step = (animation->animationStep() / 3) % chunkCount;
1628 else
1629 d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject));
1630#else
1631 Q_UNUSED(d);
1632#endif
1633 int chunksInRow = 5;
1634 int myY = pbBits.rect.y();
1635 int myHeight = pbBits.rect.height();
1636 int chunksToDraw = chunksInRow;
1637
1638 if (step > chunkCount - 5)chunksToDraw = (chunkCount - step);
1639 p->save();
1640 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
1641
1642 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
1643 int x = 0;
1644
1645 for (int i = 0; i < chunksToDraw ; ++i) {
1646 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1647 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1648 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1649 x += reverse ? -unit_width : unit_width;
1650 }
1651 //Draw wrap-around chunks
1652 if ( step > chunkCount-5){
1653 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
1654 x = 0;
1655 int chunksToDraw = step - (chunkCount - chunksInRow);
1656 for (int i = 0; i < chunksToDraw ; ++i) {
1657 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1658 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1659 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1660 x += reverse ? -unit_width : unit_width;
1661 }
1662 }
1663 p->restore(); //restore state
1664 }
1665 else {
1666#if QT_CONFIG(animation)
1667 d->stopAnimation(opt->styleObject);
1668#endif
1669 QCommonStyle::drawControl(ce, opt, p, widget);
1670 }
1671 }
1672 break;
1673
1674#if QT_CONFIG(dockwidget)
1675 case CE_DockWidgetTitle:
1676
1677 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
1678 Q_D(const QWindowsStyle);
1679
1680 const bool verticalTitleBar = dwOpt->verticalTitleBar;
1681
1682 QRect rect = dwOpt->rect;
1683 QRect r = rect;
1684
1685 if (verticalTitleBar) {
1686 r = r.transposed();
1687
1688 p->save();
1689 p->translate(r.left(), r.top() + r.width());
1690 p->rotate(-90);
1691 p->translate(-r.left(), -r.top());
1692 }
1693
1694 bool floating = false;
1695 bool active = dwOpt->state & State_Active;
1696 QColor inactiveCaptionTextColor = d->inactiveCaptionText;
1697 if (dwOpt->movable) {
1698 QColor left, right;
1699
1700 //Titlebar gradient
1701 if (opt->state & QStyle::State_Window) {
1702 floating = true;
1703 if (active) {
1704 left = d->activeCaptionColor;
1705 right = d->activeGradientCaptionColor;
1706 } else {
1707 left = d->inactiveCaptionColor;
1708 right = d->inactiveGradientCaptionColor;
1709 }
1710 QBrush fillBrush(left);
1711 if (left != right) {
1712 QPoint p1(r.x(), r.top() + r.height()/2);
1713 QPoint p2(rect.right(), r.top() + r.height()/2);
1714 QLinearGradient lg(p1, p2);
1715 lg.setColorAt(0, left);
1716 lg.setColorAt(1, right);
1717 fillBrush = lg;
1718 }
1719 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
1720 }
1721 }
1722 if (!dwOpt->title.isEmpty()) {
1723 QFont oldFont = p->font();
1724 if (floating) {
1725 QFont font = oldFont;
1726 font.setBold(true);
1727 p->setFont(font);
1728 }
1729 QPalette palette = dwOpt->palette;
1730 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
1731 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
1732 if (verticalTitleBar) {
1733 titleRect = QRect(r.left() + rect.bottom()
1734 - titleRect.bottom(),
1735 r.top() + titleRect.left() - rect.left(),
1736 titleRect.height(), titleRect.width());
1737 }
1738 proxy()->drawItemText(p, titleRect,
1739 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, palette,
1740 dwOpt->state & State_Enabled, dwOpt->title,
1741 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
1742 p->setFont(oldFont);
1743 }
1744 if (verticalTitleBar)
1745 p->restore();
1746 }
1747 return;
1748#endif // QT_CONFIG(dockwidget)
1749#if QT_CONFIG(combobox)
1750 case CE_ComboBoxLabel:
1751 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1752 if (cb->state & State_HasFocus) {
1753 p->setPen(cb->palette.highlightedText().color());
1754 p->setBackground(cb->palette.highlight());
1755 } else {
1756 p->setPen(cb->palette.text().color());
1757 p->setBackground(cb->palette.window());
1758 }
1759 }
1760 QCommonStyle::drawControl(ce, opt, p, widget);
1761 break;
1762#endif // QT_CONFIG(combobox)
1763 default:
1764 QCommonStyle::drawControl(ce, opt, p, widget);
1765 }
1766}
1767
1768/*! \reimp */
1769QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
1770{
1771 QRect r;
1772 switch (sr) {
1773 case SE_SliderFocusRect:
1774 case SE_ToolBoxTabContents:
1775 r = visualRect(opt->direction, opt->rect, opt->rect);
1776 break;
1777 case SE_DockWidgetTitleBarText: {
1778 r = QCommonStyle::subElementRect(sr, opt, w);
1779 const QStyleOptionDockWidget *dwOpt
1780 = qstyleoption_cast<const QStyleOptionDockWidget*>(opt);
1781 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
1782 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
1783 if (verticalTitleBar) {
1784 r.adjust(0, 0, 0, -m);
1785 } else {
1786 if (opt->direction == Qt::LeftToRight)
1787 r.adjust(m, 0, 0, 0);
1788 else
1789 r.adjust(0, 0, -m, 0);
1790 }
1791 break;
1792 }
1793 case SE_ProgressBarContents:
1794 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
1795 r.adjust(3, 3, -3, -3);
1796 break;
1797 default:
1798 r = QCommonStyle::subElementRect(sr, opt, w);
1799 }
1800 return r;
1801}
1802
1803
1804/*! \reimp */
1805void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
1806 QPainter *p, const QWidget *widget) const
1807{
1808 switch (cc) {
1809#if QT_CONFIG(slider)
1810 case CC_Slider:
1811 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1812 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
1813 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
1814 int ticks = slider->tickPosition;
1815 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1816 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1817
1818 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1819 int mid = thickness / 2;
1820
1821 if (ticks & QSlider::TicksAbove)
1822 mid += len / 8;
1823 if (ticks & QSlider::TicksBelow)
1824 mid -= len / 8;
1825
1826 p->setPen(slider->palette.shadow().color());
1827 if (slider->orientation == Qt::Horizontal) {
1828 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
1829 groove.width(), 4, slider->palette, true);
1830 p->drawLine(groove.x() + 1, groove.y() + mid - 1,
1831 groove.x() + groove.width() - 3, groove.y() + mid - 1);
1832 } else {
1833 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
1834 4, groove.height(), slider->palette, true);
1835 p->drawLine(groove.x() + mid - 1, groove.y() + 1,
1836 groove.x() + mid - 1, groove.y() + groove.height() - 3);
1837 }
1838 }
1839
1840 if (slider->subControls & SC_SliderTickmarks) {
1841 QStyleOptionSlider tmpSlider = *slider;
1842 tmpSlider.subControls = SC_SliderTickmarks;
1843 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
1844 }
1845
1846 if (slider->subControls & SC_SliderHandle) {
1847 // 4444440
1848 // 4333310
1849 // 4322210
1850 // 4322210
1851 // 4322210
1852 // 4322210
1853 // *43210*
1854 // **410**
1855 // ***0***
1856 const QColor c0 = slider->palette.shadow().color();
1857 const QColor c1 = slider->palette.dark().color();
1858 // const QColor c2 = g.button();
1859 const QColor c3 = slider->palette.midlight().color();
1860 const QColor c4 = slider->palette.light().color();
1861 QBrush handleBrush;
1862
1863 if (slider->state & State_Enabled) {
1864 handleBrush = slider->palette.color(QPalette::Button);
1865 } else {
1866 handleBrush = QBrush(slider->palette.color(QPalette::Button),
1867 Qt::Dense4Pattern);
1868 }
1869
1870
1871 int x = handle.x(), y = handle.y(),
1872 wi = handle.width(), he = handle.height();
1873
1874 int x1 = x;
1875 int x2 = x+wi-1;
1876 int y1 = y;
1877 int y2 = y+he-1;
1878
1879 Qt::Orientation orient = slider->orientation;
1880 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1881 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1882
1883 if (slider->state & State_HasFocus) {
1884 QStyleOptionFocusRect fropt;
1885 fropt.QStyleOption::operator=(*slider);
1886 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1887 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1888 }
1889
1890 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1891 Qt::BGMode oldMode = p->backgroundMode();
1892 p->setBackgroundMode(Qt::OpaqueMode);
1893 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
1894 &handleBrush);
1895 p->setBackgroundMode(oldMode);
1896 return;
1897 }
1898
1899 QSliderDirection dir;
1900
1901 if (orient == Qt::Horizontal)
1902 dir = tickAbove ? SlUp : SlDown;
1903 else
1904 dir = tickAbove ? SlLeft : SlRight;
1905
1906 std::array<QPoint, 5> points;
1907 int d = 0;
1908 switch (dir) {
1909 case SlUp:
1910 y1 = y1 + wi / 2;
1911 d = (wi + 1) / 2 - 1;
1912 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1913 QPoint(x2, y1), QPoint(x1 + d, y1 - d)};
1914 break;
1915 case SlDown:
1916 y2 = y2 - wi / 2;
1917 d = (wi + 1) / 2 - 1;
1918 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d),
1919 QPoint(x2, y2), QPoint(x2, y1)};
1920 break;
1921 case SlLeft:
1922 d = (he + 1) / 2 - 1;
1923 x1 = x1 + he / 2;
1924 points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2),
1925 QPoint(x2, y2), QPoint(x2, y1)};
1926 break;
1927 case SlRight:
1928 d = (he + 1) / 2 - 1;
1929 x2 = x2 - he / 2;
1930 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1931 QPoint(x2 + d, y1 + d), QPoint(x2, y1)};
1932 break;
1933 }
1934
1935 QBrush oldBrush = p->brush();
1936 p->setPen(Qt::NoPen);
1937 p->setBrush(handleBrush);
1938 Qt::BGMode oldMode = p->backgroundMode();
1939 p->setBackgroundMode(Qt::OpaqueMode);
1940 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
1941 p->drawPolygon(points.data(), static_cast<int>(points.size()));
1942 p->setBrush(oldBrush);
1943 p->setBackgroundMode(oldMode);
1944
1945 if (dir != SlUp) {
1946 p->setPen(c4);
1947 p->drawLine(x1, y1, x2, y1);
1948 p->setPen(c3);
1949 p->drawLine(x1, y1+1, x2, y1+1);
1950 }
1951 if (dir != SlLeft) {
1952 p->setPen(c3);
1953 p->drawLine(x1+1, y1+1, x1+1, y2);
1954 p->setPen(c4);
1955 p->drawLine(x1, y1, x1, y2);
1956 }
1957 if (dir != SlRight) {
1958 p->setPen(c0);
1959 p->drawLine(x2, y1, x2, y2);
1960 p->setPen(c1);
1961 p->drawLine(x2-1, y1+1, x2-1, y2-1);
1962 }
1963 if (dir != SlDown) {
1964 p->setPen(c0);
1965 p->drawLine(x1, y2, x2, y2);
1966 p->setPen(c1);
1967 p->drawLine(x1+1, y2-1, x2-1, y2-1);
1968 }
1969
1970 switch (dir) {
1971 case SlUp:
1972 p->setPen(c4);
1973 p->drawLine(x1, y1, x1+d, y1-d);
1974 p->setPen(c0);
1975 d = wi - d - 1;
1976 p->drawLine(x2, y1, x2-d, y1-d);
1977 d--;
1978 p->setPen(c3);
1979 p->drawLine(x1+1, y1, x1+1+d, y1-d);
1980 p->setPen(c1);
1981 p->drawLine(x2-1, y1, x2-1-d, y1-d);
1982 break;
1983 case SlDown:
1984 p->setPen(c4);
1985 p->drawLine(x1, y2, x1+d, y2+d);
1986 p->setPen(c0);
1987 d = wi - d - 1;
1988 p->drawLine(x2, y2, x2-d, y2+d);
1989 d--;
1990 p->setPen(c3);
1991 p->drawLine(x1+1, y2, x1+1+d, y2+d);
1992 p->setPen(c1);
1993 p->drawLine(x2-1, y2, x2-1-d, y2+d);
1994 break;
1995 case SlLeft:
1996 p->setPen(c4);
1997 p->drawLine(x1, y1, x1-d, y1+d);
1998 p->setPen(c0);
1999 d = he - d - 1;
2000 p->drawLine(x1, y2, x1-d, y2-d);
2001 d--;
2002 p->setPen(c3);
2003 p->drawLine(x1, y1+1, x1-d, y1+1+d);
2004 p->setPen(c1);
2005 p->drawLine(x1, y2-1, x1-d, y2-1-d);
2006 break;
2007 case SlRight:
2008 p->setPen(c4);
2009 p->drawLine(x2, y1, x2+d, y1+d);
2010 p->setPen(c0);
2011 d = he - d - 1;
2012 p->drawLine(x2, y2, x2+d, y2-d);
2013 d--;
2014 p->setPen(c3);
2015 p->drawLine(x2, y1+1, x2+d, y1+1+d);
2016 p->setPen(c1);
2017 p->drawLine(x2, y2-1, x2+d, y2-1-d);
2018 break;
2019 }
2020 }
2021 }
2022 break;
2023#endif // QT_CONFIG(slider)
2024#if QT_CONFIG(scrollbar)
2025 case CC_ScrollBar:
2026 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2027 QStyleOptionSlider newScrollbar = *scrollbar;
2028 if (scrollbar->minimum == scrollbar->maximum)
2029 newScrollbar.state &= ~State_Enabled; //do not draw the slider.
2030 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2031 }
2032 break;
2033#endif // QT_CONFIG(scrollbar)
2034#if QT_CONFIG(combobox)
2035 case CC_ComboBox:
2036 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2037 QBrush editBrush = cmb->palette.brush(QPalette::Button);
2038 if ((cmb->subControls & SC_ComboBoxFrame)) {
2039 if (cmb->frame) {
2040 QPalette shadePal = opt->palette;
2041 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2042 qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush);
2043 }
2044 else {
2045 p->fillRect(opt->rect, editBrush);
2046 }
2047 }
2048 if (cmb->subControls & SC_ComboBoxArrow) {
2049 State flags = State_None;
2050
2051 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2052 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2053 && cmb->state & State_Sunken;
2054 if (sunkenArrow) {
2055 p->setPen(cmb->palette.dark().color());
2056 p->setBrush(cmb->palette.brush(QPalette::Button));
2057 p->drawRect(ar.adjusted(0,0,-1,-1));
2058 } else {
2059 // Make qDrawWinButton use the right colors for drawing the shade of the button
2060 QPalette pal(cmb->palette);
2061 pal.setColor(QPalette::Button, cmb->palette.light().color());
2062 pal.setColor(QPalette::Light, cmb->palette.button().color());
2063 qDrawWinButton(p, ar, pal, false,
2064 &cmb->palette.brush(QPalette::Button));
2065 }
2066
2067 ar.adjust(2, 2, -2, -2);
2068 if (opt->state & State_Enabled)
2069 flags |= State_Enabled;
2070 if (opt->state & State_HasFocus)
2071 flags |= State_HasFocus;
2072
2073 if (sunkenArrow)
2074 flags |= State_Sunken;
2075 QStyleOption arrowOpt = *cmb;
2076 arrowOpt.rect = ar.adjusted(1, 1, -1, -1);
2077 arrowOpt.state = flags;
2078 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2079 }
2080
2081 if (cmb->subControls & SC_ComboBoxEditField) {
2082 QRect re = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2083 if (cmb->state & State_HasFocus && !cmb->editable)
2084 p->fillRect(re.x(), re.y(), re.width(), re.height(),
2085 cmb->palette.brush(QPalette::Highlight));
2086
2087 if (cmb->state & State_HasFocus) {
2088 p->setPen(cmb->palette.highlightedText().color());
2089 p->setBackground(cmb->palette.highlight());
2090
2091 } else {
2092 p->setPen(cmb->palette.text().color());
2093 p->setBackground(cmb->palette.window());
2094 }
2095
2096 if (cmb->state & State_HasFocus && !cmb->editable) {
2097 QStyleOptionFocusRect focus;
2098 focus.QStyleOption::operator=(*cmb);
2099 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2100 focus.state |= State_FocusAtBorder;
2101 focus.backgroundColor = cmb->palette.highlight().color();
2102 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2103 }
2104 }
2105 }
2106 break;
2107#endif // QT_CONFIG(combobox)
2108#if QT_CONFIG(spinbox)
2109 case CC_SpinBox:
2110 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2111 QStyleOptionSpinBox copy = *sb;
2112 PrimitiveElement pe;
2113 bool enabled = opt->state & State_Enabled;
2114 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2115 QBrush editBrush = sb->palette.brush(QPalette::Base);
2116 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2117 QPalette shadePal = sb->palette;
2118 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2119 qDrawWinPanel(p, r, shadePal, true, &editBrush);
2120 }
2121
2122 QPalette shadePal(opt->palette);
2123 shadePal.setColor(QPalette::Button, opt->palette.light().color());
2124 shadePal.setColor(QPalette::Light, opt->palette.button().color());
2125
2126 if (sb->subControls & SC_SpinBoxUp) {
2127 copy.subControls = SC_SpinBoxUp;
2128 QPalette pal2 = sb->palette;
2129 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2130 pal2.setCurrentColorGroup(QPalette::Disabled);
2131 copy.state &= ~State_Enabled;
2132 }
2133
2134 copy.palette = pal2;
2135
2136 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2137 copy.state |= State_On;
2138 copy.state |= State_Sunken;
2139 } else {
2140 copy.state |= State_Raised;
2141 copy.state &= ~State_Sunken;
2142 }
2143 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2144 : PE_IndicatorSpinUp);
2145
2146 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2147 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2148 &copy.palette.brush(QPalette::Button));
2149 copy.rect.adjust(4, 1, -5, -1);
2150 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2151 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2152 {
2153 QStyleOptionSpinBox lightCopy = copy;
2154 lightCopy.rect.adjust(1, 1, 1, 1);
2155 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2156 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2157 }
2158 proxy()->drawPrimitive(pe, &copy, p, widget);
2159 }
2160
2161 if (sb->subControls & SC_SpinBoxDown) {
2162 copy.subControls = SC_SpinBoxDown;
2163 copy.state = sb->state;
2164 QPalette pal2 = sb->palette;
2165 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2166 pal2.setCurrentColorGroup(QPalette::Disabled);
2167 copy.state &= ~State_Enabled;
2168 }
2169 copy.palette = pal2;
2170
2171 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2172 copy.state |= State_On;
2173 copy.state |= State_Sunken;
2174 } else {
2175 copy.state |= State_Raised;
2176 copy.state &= ~State_Sunken;
2177 }
2178 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2179 : PE_IndicatorSpinDown);
2180
2181 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2182 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2183 &copy.palette.brush(QPalette::Button));
2184 copy.rect.adjust(4, 0, -5, -1);
2185 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2186 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2187 {
2188 QStyleOptionSpinBox lightCopy = copy;
2189 lightCopy.rect.adjust(1, 1, 1, 1);
2190 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2191 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2192 }
2193 proxy()->drawPrimitive(pe, &copy, p, widget);
2194 }
2195 }
2196 break;
2197#endif // QT_CONFIG(spinbox)
2198
2199 default:
2200 QCommonStyle::drawComplexControl(cc, opt, p, widget);
2201 }
2202}
2203
2204/*! \reimp */
2205QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2206 const QSize &csz, const QWidget *widget) const
2207{
2208 QSize sz(csz);
2209 switch (ct) {
2210 case CT_PushButton:
2211 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2212 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2213 int w = sz.width(),
2214 h = sz.height();
2215 int defwidth = 0;
2216 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2217 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2218 const qreal dpi = QStyleHelper::dpi(opt);
2219 int minwidth = int(QStyleHelper::dpiScaled(75, dpi));
2220 int minheight = int(QStyleHelper::dpiScaled(23, dpi));
2221
2222 if (w < minwidth + defwidth && !btn->text.isEmpty())
2223 w = minwidth + defwidth;
2224 if (h < minheight + defwidth)
2225 h = minheight + defwidth;
2226
2227 sz = QSize(w, h);
2228 }
2229 break;
2230#if QT_CONFIG(menu)
2231 case CT_MenuItem:
2232 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2233 int w = sz.width();
2234 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2235
2236 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2237 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2238 }
2239 else if (mi->icon.isNull()) {
2240 sz.setHeight(sz.height() - 2);
2241 w -= 6;
2242 }
2243
2244 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2245 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2246 sz.setHeight(qMax(sz.height(),
2247 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2248 + 2 * QWindowsStylePrivate::windowsItemFrame));
2249 }
2250 int maxpmw = mi->maxIconWidth;
2251 int tabSpacing = 20;
2252 if (mi->text.contains(u'\t'))
2253 w += tabSpacing;
2254 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2255 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2256 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2257 // adjust the font and add the difference in size.
2258 // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
2259 QFontMetrics fm(mi->font);
2260 QFont fontBold = mi->font;
2261 fontBold.setBold(true);
2262 QFontMetrics fmBold(fontBold);
2263 w += fmBold.horizontalAdvance(mi->text) - fm.horizontalAdvance(mi->text);
2264 }
2265
2266 int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
2267 w += checkcol;
2268 w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
2269 sz.setWidth(w);
2270 }
2271 break;
2272#endif // QT_CONFIG(menu)
2273#if QT_CONFIG(menubar)
2274 case CT_MenuBarItem:
2275 if (!sz.isEmpty())
2276 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2277 break;
2278#endif
2279 case CT_ToolButton:
2280#if QT_CONFIG(toolbutton)
2281 if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
2282 return sz += QSize(7, 6);
2283#endif // QT_CONFIG(toolbutton)
2284 Q_FALLTHROUGH();
2285
2286 default:
2287 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2288 }
2289 return sz;
2290}
2291
2292/*!
2293 \reimp
2294*/
2295QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option,
2296 const QWidget *widget) const
2297{
2298 return QCommonStyle::standardIcon(standardIcon, option, widget);
2299}
2300
2301
2302
2303QT_END_NAMESPACE
2304
2305#include "moc_qwindowsstyle_p.cpp"
2306
2307#endif // style_windows