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->setBrush(p->pen().color());
768 p->drawPolygon(points.data(), static_cast<int>(points.size()));
769 }
770 if (doRestore)
771 p->restore();
772 break;
773 case PE_FrameFocusRect:
774 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(opt)) {
775 //### check for d->alt_down
776 if (!(fropt->state & State_KeyboardFocusChange) && !proxy()->styleHint(SH_UnderlineShortcut, opt, w))
777 return;
778 QRect r = opt->rect;
779 p->save();
780 p->setBackgroundMode(Qt::TransparentMode);
781 QColor bg_col = fropt->backgroundColor;
782 if (!bg_col.isValid())
783 bg_col = p->background().color();
784 // Create an "XOR" color.
785 QColor patternCol((bg_col.red() ^ 0xff) & 0xff,
786 (bg_col.green() ^ 0xff) & 0xff,
787 (bg_col.blue() ^ 0xff) & 0xff);
788 p->setBrush(QBrush(patternCol, Qt::Dense4Pattern));
789 p->setBrushOrigin(r.topLeft());
790 p->setPen(Qt::NoPen);
791 p->drawRect(r.left(), r.top(), r.width(), 1); // Top
792 p->drawRect(r.left(), r.bottom(), r.width(), 1); // Bottom
793 p->drawRect(r.left(), r.top(), 1, r.height()); // Left
794 p->drawRect(r.right(), r.top(), 1, r.height()); // Right
795 p->restore();
796 }
797 break;
798 case PE_IndicatorRadioButton:
799 {
800 QRect r = opt->rect;
801 p->save();
802 p->setRenderHint(QPainter::Antialiasing, true);
803
804 QPointF circleCenter = r.center() + QPoint(1, 1);
805 qreal radius = (r.width() + (r.width() + 1) % 2) / 2.0 - 1;
806
807 QPainterPath path1;
808 path1.addEllipse(circleCenter, radius, radius);
809 radius *= 0.85;
810 QPainterPath path2;
811 path2.addEllipse(circleCenter, radius, radius);
812 radius *= 0.85;
813 QPainterPath path3;
814 path3.addEllipse(circleCenter, radius, radius);
815 radius *= 0.5;
816 QPainterPath path4;
817 path4.addEllipse(circleCenter, radius, radius);
818
819 QPolygon topLeftPol, bottomRightPol;
820 topLeftPol.setPoints(3, r.x(), r.y(), r.x(), r.y() + r.height(), r.x() + r.width(), r.y());
821 bottomRightPol.setPoints(3, r.x(), r.y() + r.height(), r.x() + r.width(), r.y() + r.height(), r.x() + r.width(), r.y());
822
823 p->setClipRegion(QRegion(topLeftPol));
824 p->setPen(opt->palette.dark().color());
825 p->setBrush(opt->palette.dark());
826 p->drawPath(path1);
827 p->setPen(opt->palette.shadow().color());
828 p->setBrush(opt->palette.shadow());
829 p->drawPath(path2);
830
831 p->setClipRegion(QRegion(bottomRightPol));
832 p->setPen(opt->palette.light().color());
833 p->setBrush(opt->palette.light());
834 p->drawPath(path1);
835 p->setPen(opt->palette.midlight().color());
836 p->setBrush(opt->palette.midlight());
837 p->drawPath(path2);
838
839 QColor fillColor = ((opt->state & State_Sunken) || !(opt->state & State_Enabled)) ?
840 opt->palette.button().color() : opt->palette.base().color();
841
842 p->setClipping(false);
843 p->setPen(fillColor);
844 p->setBrush(fillColor);
845 p->drawPath(path3);
846
847 if (opt->state & State_On) {
848 p->setPen(opt->palette.text().color());
849 p->setBrush(opt->palette.text());
850 p->drawPath(path4);
851 }
852 p->restore();
853 break;
854 }
855#ifndef QT_NO_FRAME
856 case PE_Frame:
857 if (w && w->inherits("QComboBoxPrivateContainer")){
858 QStyleOption copy = *opt;
859 copy.state |= State_Raised;
860 proxy()->drawPrimitive(PE_PanelMenu, &copy, p, w);
861 break;
862 }
863 Q_FALLTHROUGH();
864 case PE_FrameMenu:
865 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
866 if (frame->lineWidth == 2 || pe == PE_Frame) {
867 QPalette popupPal = frame->palette;
868 if (pe == PE_FrameMenu) {
869 popupPal.setColor(QPalette::Light, frame->palette.window().color());
870 popupPal.setColor(QPalette::Midlight, frame->palette.light().color());
871 }
872 if (pe == PE_Frame && (frame->state & State_Raised))
873 qDrawWinButton(p, frame->rect, popupPal, frame->state & State_Sunken);
874 else if (pe == PE_Frame && (frame->state & State_Sunken))
875 {
876 popupPal.setColor(QPalette::Midlight, frame->palette.window().color());
877 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
878 }
879 else
880 qDrawWinPanel(p, frame->rect, popupPal, frame->state & State_Sunken);
881 } else {
882 QCommonStyle::drawPrimitive(pe, opt, p, w);
883 }
884 } else {
885 QPalette popupPal = opt->palette;
886 p->drawRect(opt->rect);
887 popupPal.setColor(QPalette::Light, opt->palette.window().color());
888 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
889 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
890 }
891 break;
892#endif // QT_NO_FRAME
893 case PE_FrameButtonBevel:
894 case PE_PanelButtonBevel: {
895 QBrush fill;
896 bool panel = pe != PE_FrameButtonBevel;
897 p->setBrushOrigin(opt->rect.topLeft());
898 if (!(opt->state & State_Sunken) && (opt->state & State_On))
899 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
900 else
901 fill = opt->palette.brush(QPalette::Button);
902
903 if (opt->state & (State_Raised | State_On | State_Sunken)) {
904 qDrawWinButton(p, opt->rect, opt->palette, opt->state & (State_Sunken | State_On),
905 panel ? &fill : nullptr);
906 } else {
907 if (panel)
908 p->fillRect(opt->rect, fill);
909 else
910 p->drawRect(opt->rect);
911 }
912 break; }
913 case PE_PanelMenu:
914 if (w && w->inherits("QComboBoxPrivateContainer")){
915 const QBrush menuBackground = opt->palette.base().color();
916 QColor borderColor = opt->palette.window().color();
917 qDrawPlainRect(p, opt->rect, borderColor, 1, &menuBackground);
918 } else {
919 QCommonStyle::drawPrimitive(pe, opt, p, w);
920 }
921 break;
922 case PE_FrameWindow: {
923 QPalette popupPal = opt->palette;
924 popupPal.setColor(QPalette::Light, opt->palette.window().color());
925 popupPal.setColor(QPalette::Midlight, opt->palette.light().color());
926 qDrawWinPanel(p, opt->rect, popupPal, opt->state & State_Sunken);
927 break; }
928#if QT_CONFIG(dockwidget)
929 case PE_IndicatorDockWidgetResizeHandle:
930 break;
931 case PE_FrameDockWidget:
932 if (qstyleoption_cast<const QStyleOptionFrame *>(opt)) {
933 proxy()->drawPrimitive(QStyle::PE_FrameWindow, opt, p, w);
934 }
935 break;
936#endif // QT_CONFIG(dockwidget)
937
938 case PE_FrameStatusBarItem:
939 qDrawShadePanel(p, opt->rect, opt->palette, true, 1, nullptr);
940 break;
941
942 case PE_IndicatorProgressChunk:
943 {
944 bool vertical = false, inverted = false;
945 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
946 vertical = !(pb->state & QStyle::State_Horizontal);
947 inverted = pb->invertedAppearance;
948 }
949
950 int space = 2;
951 int chunksize = proxy()->pixelMetric(PM_ProgressBarChunkWidth, opt, w) - space;
952 if (!vertical) {
953 if (opt->rect.width() <= chunksize)
954 space = 0;
955
956 if (inverted)
957 p->fillRect(opt->rect.x() + space, opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
958 opt->palette.brush(QPalette::Highlight));
959 else
960 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width() - space, opt->rect.height(),
961 opt->palette.brush(QPalette::Highlight));
962 } else {
963 if (opt->rect.height() <= chunksize)
964 space = 0;
965
966 if (inverted)
967 p->fillRect(opt->rect.x(), opt->rect.y(), opt->rect.width(), opt->rect.height() - space,
968 opt->palette.brush(QPalette::Highlight));
969 else
970 p->fillRect(opt->rect.x(), opt->rect.y() + space, opt->rect.width(), opt->rect.height() - space,
971 opt->palette.brush(QPalette::Highlight));
972 }
973 }
974 break;
975
976 case PE_FrameTabWidget: {
977 qDrawWinButton(p, opt->rect, opt->palette, false, nullptr);
978 break;
979 }
980 default:
981 QCommonStyle::drawPrimitive(pe, opt, p, w);
982 }
983}
984
985/*! \reimp */
986void QWindowsStyle::drawControl(ControlElement ce, const QStyleOption *opt, QPainter *p,
987 const QWidget *widget) const
988{
989 switch (ce) {
990#if QT_CONFIG(rubberband)
991 case CE_RubberBand:
992 if (qstyleoption_cast<const QStyleOptionRubberBand *>(opt)) {
993 // ### workaround for slow general painter path
994 QPixmap tiledPixmap(16, 16);
995 QPainter pixmapPainter(&tiledPixmap);
996 pixmapPainter.setPen(Qt::NoPen);
997 pixmapPainter.setBrush(Qt::Dense4Pattern);
998 pixmapPainter.setBackground(Qt::white);
999 pixmapPainter.setBackgroundMode(Qt::OpaqueMode);
1000 pixmapPainter.drawRect(0, 0, tiledPixmap.width(), tiledPixmap.height());
1001 pixmapPainter.end();
1002 tiledPixmap = QPixmap::fromImage(tiledPixmap.toImage());
1003 p->save();
1004 QRect r = opt->rect;
1005 QStyleHintReturnMask mask;
1006 if (proxy()->styleHint(QStyle::SH_RubberBand_Mask, opt, widget, &mask))
1007 p->setClipRegion(mask.region);
1008 p->drawTiledPixmap(r.x(), r.y(), r.width(), r.height(), tiledPixmap);
1009 p->restore();
1010 return;
1011 }
1012 break;
1013#endif // QT_CONFIG(rubberband)
1014
1015#if QT_CONFIG(menu) && QT_CONFIG(mainwindow)
1016 case CE_MenuBarEmptyArea:
1017 if (widget && qobject_cast<const QMainWindow *>(widget->parentWidget())) {
1018 p->fillRect(opt->rect, opt->palette.button());
1019 QPen oldPen = p->pen();
1020 p->setPen(opt->palette.dark().color());
1021 p->drawLine(opt->rect.bottomLeft(), opt->rect.bottomRight());
1022 p->setPen(oldPen);
1023 }
1024 break;
1025#endif
1026#if QT_CONFIG(menu)
1027 case CE_MenuItem:
1028 if (const QStyleOptionMenuItem *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1029 int x, y, w, h;
1030 menuitem->rect.getRect(&x, &y, &w, &h);
1031 int tab = menuitem->reservedShortcutWidth;
1032 bool dis = !(menuitem->state & State_Enabled);
1033 bool checked = menuitem->checkType != QStyleOptionMenuItem::NotCheckable
1034 ? menuitem->checked : false;
1035 bool act = menuitem->state & State_Selected;
1036
1037 // windows always has a check column, regardless whether we have an icon or not
1038 int checkcol = qMax<int>(menuitem->maxIconWidth, QWindowsStylePrivate::windowsCheckMarkWidth);
1039
1040 QBrush fill = menuitem->palette.brush(act ? QPalette::Highlight : QPalette::Button);
1041 p->fillRect(menuitem->rect.adjusted(0, 0, -1, 0), fill);
1042
1043 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator){
1044 int yoff = y-1 + h / 2;
1045 p->setPen(menuitem->palette.dark().color());
1046 p->drawLine(x + 2, yoff, x + w - 4, yoff);
1047 p->setPen(menuitem->palette.light().color());
1048 p->drawLine(x + 2, yoff + 1, x + w - 4, yoff + 1);
1049 return;
1050 }
1051
1052 QRect vCheckRect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x(), menuitem->rect.y(), checkcol, menuitem->rect.height()));
1053 if (!menuitem->icon.isNull() && checked) {
1054 if (act) {
1055 qDrawShadePanel(p, vCheckRect,
1056 menuitem->palette, true, 1,
1057 &menuitem->palette.brush(QPalette::Button));
1058 } else {
1059 QBrush fill(menuitem->palette.light().color(), Qt::Dense4Pattern);
1060 qDrawShadePanel(p, vCheckRect, menuitem->palette, true, 1, &fill);
1061 }
1062 } else if (!act) {
1063 p->fillRect(vCheckRect, menuitem->palette.brush(QPalette::Button));
1064 }
1065
1066 // On Windows Style, if we have a checkable item and an icon we
1067 // draw the icon recessed to indicate an item is checked. If we
1068 // have no icon, we draw a checkmark instead.
1069 if (!menuitem->icon.isNull()) {
1070 QIcon::Mode mode = dis ? QIcon::Disabled : QIcon::Normal;
1071 if (act && !dis)
1072 mode = QIcon::Active;
1073 const auto size = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
1074 const auto dpr = QStyleHelper::getDpr(p);
1075 const auto state = checked ? QIcon::On : QIcon::Off;
1076 const auto pixmap = menuitem->icon.pixmap(QSize(size, size), dpr, mode, state);
1077 QRect pmr(QPoint(0, 0), pixmap.deviceIndependentSize().toSize());
1078 pmr.moveCenter(vCheckRect.center());
1079 p->setPen(menuitem->palette.text().color());
1080 p->drawPixmap(pmr.topLeft(), pixmap);
1081 } else if (checked) {
1082 QStyleOptionMenuItem newMi = *menuitem;
1083 newMi.state = State_None;
1084 if (!dis)
1085 newMi.state |= State_Enabled;
1086 if (act)
1087 newMi.state |= State_On | State_Selected;
1088 newMi.rect = visualRect(opt->direction, menuitem->rect, QRect(menuitem->rect.x() + QWindowsStylePrivate::windowsItemFrame,
1089 menuitem->rect.y() + QWindowsStylePrivate::windowsItemFrame,
1090 checkcol - 2 * QWindowsStylePrivate::windowsItemFrame,
1091 menuitem->rect.height() - 2 * QWindowsStylePrivate::windowsItemFrame));
1092 proxy()->drawPrimitive(PE_IndicatorMenuCheckMark, &newMi, p, widget);
1093 }
1094 p->setPen(act ? menuitem->palette.highlightedText().color() : menuitem->palette.buttonText().color());
1095
1096 QColor discol;
1097 if (dis) {
1098 discol = menuitem->palette.text().color();
1099 p->setPen(discol);
1100 }
1101
1102 int xm = int(QWindowsStylePrivate::windowsItemFrame) + checkcol + int(QWindowsStylePrivate::windowsItemHMargin);
1103 int xpos = menuitem->rect.x() + xm;
1104 QRect textRect(xpos, y + QWindowsStylePrivate::windowsItemVMargin,
1105 w - xm - QWindowsStylePrivate::windowsRightBorder - tab + 1, h - 2 * QWindowsStylePrivate::windowsItemVMargin);
1106 QRect vTextRect = visualRect(opt->direction, menuitem->rect, textRect);
1107 QStringView s(menuitem->text);
1108 if (!s.isEmpty()) { // draw text
1109 p->save();
1110 qsizetype t = s.indexOf(u'\t');
1111 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1112 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1113 text_flags |= Qt::TextHideMnemonic;
1114 text_flags |= Qt::AlignLeft;
1115 if (t >= 0) {
1116 QRect vShortcutRect = visualRect(opt->direction, menuitem->rect,
1117 QRect(textRect.topRight(), QPoint(menuitem->rect.right(), textRect.bottom())));
1118 const QString textToDraw = s.mid(t + 1).toString();
1119 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1120 p->setPen(menuitem->palette.light().color());
1121 p->drawText(vShortcutRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1122 p->setPen(discol);
1123 }
1124 p->drawText(vShortcutRect, text_flags, textToDraw);
1125 s = s.left(t);
1126 }
1127 QFont font = menuitem->font;
1128 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1129 font.setBold(true);
1130 p->setFont(font);
1131 const QString textToDraw = s.left(t).toString();
1132 if (dis && !act && proxy()->styleHint(SH_EtchDisabledText, opt, widget)) {
1133 p->setPen(menuitem->palette.light().color());
1134 p->drawText(vTextRect.adjusted(1, 1, 1, 1), text_flags, textToDraw);
1135 p->setPen(discol);
1136 }
1137 p->drawText(vTextRect, text_flags, textToDraw);
1138 p->restore();
1139 }
1140 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1141 int dim = (h - 2 * QWindowsStylePrivate::windowsItemFrame) / 2;
1142 PrimitiveElement arrow;
1143 arrow = (opt->direction == Qt::RightToLeft) ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1144 xpos = x + w - QWindowsStylePrivate::windowsArrowHMargin - QWindowsStylePrivate::windowsItemFrame - dim;
1145 QRect vSubMenuRect = visualRect(opt->direction, menuitem->rect, QRect(xpos, y + h / 2 - dim / 2, dim, dim));
1146 QStyleOptionMenuItem newMI = *menuitem;
1147 newMI.rect = vSubMenuRect;
1148 newMI.state = dis ? State_None : State_Enabled;
1149 if (act)
1150 newMI.palette.setColor(QPalette::ButtonText,
1151 newMI.palette.highlightedText().color());
1152 proxy()->drawPrimitive(arrow, &newMI, p, widget);
1153 }
1154
1155 }
1156 break;
1157#endif // QT_CONFIG(menu)
1158#if QT_CONFIG(menubar)
1159 case CE_MenuBarItem:
1160 if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
1161 const bool active = mbi->state & State_Selected;
1162 const QBrush buttonBrush = mbi->palette.brush(QPalette::Button);
1163 QStyleOptionMenuItem newMbi = *mbi;
1164 p->fillRect(mbi->rect, buttonBrush);
1165 if (active) {
1166 const bool hasFocus = mbi->state & State_HasFocus;
1167 const bool down = mbi->state & State_Sunken;
1168 QPainterStateGuard psg(p, QPainterStateGuard::InitialState::NoSave);
1169 if (down) {
1170 psg.save();
1171 p->setBrushOrigin(p->brushOriginF() + QPointF(1, 1));
1172 }
1173 if (hasFocus)
1174 qDrawShadeRect(p, mbi->rect.x(), mbi->rect.y(), mbi->rect.width(),
1175 mbi->rect.height(), mbi->palette, active && down, 1, 0, &buttonBrush);
1176 if (down)
1177 newMbi.rect.translate(proxy()->pixelMetric(PM_ButtonShiftHorizontal, mbi, widget),
1178 proxy()->pixelMetric(PM_ButtonShiftVertical, mbi, widget));
1179 }
1180 QCommonStyle::drawControl(ce, &newMbi, p, widget);
1181 }
1182 break;
1183#endif // QT_CONFIG(menubar)
1184#if QT_CONFIG(tabbar)
1185 case CE_TabBarTabShape:
1186 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(opt)) {
1187 bool rtlHorTabs = (tab->direction == Qt::RightToLeft
1188 && (tab->shape == QTabBar::RoundedNorth
1189 || tab->shape == QTabBar::RoundedSouth));
1190 bool selected = tab->state & State_Selected;
1191 bool lastTab = ((!rtlHorTabs && tab->position == QStyleOptionTab::End)
1192 || (rtlHorTabs
1193 && tab->position == QStyleOptionTab::Beginning));
1194 bool firstTab = ((!rtlHorTabs
1195 && tab->position == QStyleOptionTab::Beginning)
1196 || (rtlHorTabs
1197 && tab->position == QStyleOptionTab::End));
1198 bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab;
1199 bool previousSelected =
1200 ((!rtlHorTabs
1201 && tab->selectedPosition == QStyleOptionTab::PreviousIsSelected)
1202 || (rtlHorTabs
1203 && tab->selectedPosition == QStyleOptionTab::NextIsSelected));
1204 bool nextSelected =
1205 ((!rtlHorTabs
1206 && tab->selectedPosition == QStyleOptionTab::NextIsSelected)
1207 || (rtlHorTabs
1208 && tab->selectedPosition
1209 == QStyleOptionTab::PreviousIsSelected));
1210 int tabBarAlignment = proxy()->styleHint(SH_TabBar_Alignment, tab, widget);
1211 bool leftAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignLeft)
1212 || (rtlHorTabs
1213 && tabBarAlignment == Qt::AlignRight);
1214
1215 bool rightAligned = (!rtlHorTabs && tabBarAlignment == Qt::AlignRight)
1216 || (rtlHorTabs
1217 && tabBarAlignment == Qt::AlignLeft);
1218
1219 QColor light = tab->palette.light().color();
1220 QColor dark = tab->palette.dark().color();
1221 QColor shadow = tab->palette.shadow().color();
1222 int borderThinkness = proxy()->pixelMetric(PM_TabBarBaseOverlap, tab, widget);
1223 if (selected)
1224 borderThinkness /= 2;
1225 QRect r2(opt->rect);
1226 int x1 = r2.left();
1227 int x2 = r2.right();
1228 int y1 = r2.top();
1229 int y2 = r2.bottom();
1230 switch (tab->shape) {
1231 default:
1232 QCommonStyle::drawControl(ce, tab, p, widget);
1233 break;
1234 case QTabBar::RoundedNorth: {
1235 if (!selected) {
1236 y1 += 2;
1237 x1 += onlyOne || firstTab ? borderThinkness : 0;
1238 x2 -= onlyOne || lastTab ? borderThinkness : 0;
1239 }
1240
1241 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 2), tab->palette.window());
1242
1243 // Delete border
1244 if (selected) {
1245 p->fillRect(QRect(x1,y2-1,x2-x1,1), tab->palette.window());
1246 p->fillRect(QRect(x1,y2,x2-x1,1), tab->palette.window());
1247 }
1248 // Left
1249 if (firstTab || selected || onlyOne || !previousSelected) {
1250 p->setPen(light);
1251 p->drawLine(x1, y1 + 2, x1, y2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1252 p->drawPoint(x1 + 1, y1 + 1);
1253 }
1254 // Top
1255 {
1256 int beg = x1 + (previousSelected ? 0 : 2);
1257 int end = x2 - (nextSelected ? 0 : 2);
1258 p->setPen(light);
1259 p->drawLine(beg, y1, end, y1);
1260 }
1261 // Right
1262 if (lastTab || selected || onlyOne || !nextSelected) {
1263 p->setPen(shadow);
1264 p->drawLine(x2, y1 + 2, x2, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1265 p->drawPoint(x2 - 1, y1 + 1);
1266 p->setPen(dark);
1267 p->drawLine(x2 - 1, y1 + 2, x2 - 1, y2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1268 }
1269 break; }
1270 case QTabBar::RoundedSouth: {
1271 if (!selected) {
1272 y2 -= 2;
1273 x1 += firstTab ? borderThinkness : 0;
1274 x2 -= lastTab ? borderThinkness : 0;
1275 }
1276
1277 p->fillRect(QRect(x1 + 1, y1 + 2, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1278
1279 // Delete border
1280 if (selected) {
1281 p->fillRect(QRect(x1, y1 + 1, (x2 - 1)-x1, 1), tab->palette.window());
1282 p->fillRect(QRect(x1, y1, (x2 - 1)-x1, 1), tab->palette.window());
1283 }
1284 // Left
1285 if (firstTab || selected || onlyOne || !previousSelected) {
1286 p->setPen(light);
1287 p->drawLine(x1, y2 - 2, x1, y1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness));
1288 p->drawPoint(x1 + 1, y2 - 1);
1289 }
1290 // Bottom
1291 {
1292 int beg = x1 + (previousSelected ? 0 : 2);
1293 int end = x2 - (nextSelected ? 0 : 2);
1294 p->setPen(shadow);
1295 p->drawLine(beg, y2, end, y2);
1296 p->setPen(dark);
1297 p->drawLine(beg, y2 - 1, end, y2 - 1);
1298 }
1299 // Right
1300 if (lastTab || selected || onlyOne || !nextSelected) {
1301 p->setPen(shadow);
1302 p->drawLine(x2, y2 - 2, x2, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1303 p->drawPoint(x2 - 1, y2 - 1);
1304 p->setPen(dark);
1305 p->drawLine(x2 - 1, y2 - 2, x2 - 1, y1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness));
1306 }
1307 break; }
1308 case QTabBar::RoundedWest: {
1309 if (!selected) {
1310 x1 += 2;
1311 y1 += firstTab ? borderThinkness : 0;
1312 y2 -= lastTab ? borderThinkness : 0;
1313 }
1314
1315 p->fillRect(QRect(x1 + 1, y1 + 1, (x2 - x1) - 2, (y2 - y1) - 1), tab->palette.window());
1316
1317 // Delete border
1318 if (selected) {
1319 p->fillRect(QRect(x2 - 1, y1, 1, y2-y1), tab->palette.window());
1320 p->fillRect(QRect(x2, y1, 1, y2-y1), tab->palette.window());
1321 }
1322 // Top
1323 if (firstTab || selected || onlyOne || !previousSelected) {
1324 p->setPen(light);
1325 p->drawLine(x1 + 2, y1, x2 - ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1326 p->drawPoint(x1 + 1, y1 + 1);
1327 }
1328 // Left
1329 {
1330 int beg = y1 + (previousSelected ? 0 : 2);
1331 int end = y2 - (nextSelected ? 0 : 2);
1332 p->setPen(light);
1333 p->drawLine(x1, beg, x1, end);
1334 }
1335 // Bottom
1336 if (lastTab || selected || onlyOne || !nextSelected) {
1337 p->setPen(shadow);
1338 p->drawLine(x1 + 3, y2, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1339 p->drawPoint(x1 + 2, y2 - 1);
1340 p->setPen(dark);
1341 p->drawLine(x1 + 3, y2 - 1, x2 - ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1342 p->drawPoint(x1 + 1, y2 - 1);
1343 p->drawPoint(x1 + 2, y2);
1344 }
1345 break; }
1346 case QTabBar::RoundedEast: {
1347 if (!selected) {
1348 x2 -= 2;
1349 y1 += firstTab ? borderThinkness : 0;
1350 y2 -= lastTab ? borderThinkness : 0;
1351 }
1352
1353 p->fillRect(QRect(x1 + 2, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1), tab->palette.window());
1354
1355 // Delete border
1356 if (selected) {
1357 p->fillRect(QRect(x1 + 1, y1, 1, (y2 - 1)-y1),tab->palette.window());
1358 p->fillRect(QRect(x1, y1, 1, (y2-1)-y1), tab->palette.window());
1359 }
1360 // Top
1361 if (firstTab || selected || onlyOne || !previousSelected) {
1362 p->setPen(light);
1363 p->drawLine(x2 - 2, y1, x1 + ((onlyOne || firstTab) && selected && leftAligned ? 0 : borderThinkness), y1);
1364 p->drawPoint(x2 - 1, y1 + 1);
1365 }
1366 // Right
1367 {
1368 int beg = y1 + (previousSelected ? 0 : 2);
1369 int end = y2 - (nextSelected ? 0 : 2);
1370 p->setPen(shadow);
1371 p->drawLine(x2, beg, x2, end);
1372 p->setPen(dark);
1373 p->drawLine(x2 - 1, beg, x2 - 1, end);
1374 }
1375 // Bottom
1376 if (lastTab || selected || onlyOne || !nextSelected) {
1377 p->setPen(shadow);
1378 p->drawLine(x2 - 2, y2, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2);
1379 p->drawPoint(x2 - 1, y2 - 1);
1380 p->setPen(dark);
1381 p->drawLine(x2 - 2, y2 - 1, x1 + ((onlyOne || lastTab) && selected && rightAligned ? 0 : borderThinkness), y2 - 1);
1382 }
1383 break; }
1384 }
1385 }
1386 break;
1387#endif // QT_CONFIG(tabbar)
1388 case CE_ToolBoxTabShape:
1389 qDrawShadePanel(p, opt->rect, opt->palette,
1390 opt->state & (State_Sunken | State_On), 1,
1391 &opt->palette.brush(QPalette::Button));
1392 break;
1393#if QT_CONFIG(splitter)
1394 case CE_Splitter:
1395 p->eraseRect(opt->rect);
1396 break;
1397#endif // QT_CONFIG(splitter)
1398#if QT_CONFIG(scrollbar)
1399 case CE_ScrollBarSubLine:
1400 case CE_ScrollBarAddLine: {
1401 if ((opt->state & State_Sunken)) {
1402 p->setPen(opt->palette.dark().color());
1403 p->setBrush(opt->palette.brush(QPalette::Button));
1404 p->drawRect(opt->rect.adjusted(0, 0, -1, -1));
1405 } else {
1406 QStyleOption buttonOpt = *opt;
1407 if (!(buttonOpt.state & State_Sunken))
1408 buttonOpt.state |= State_Raised;
1409 QPalette pal(opt->palette);
1410 pal.setColor(QPalette::Button, opt->palette.light().color());
1411 pal.setColor(QPalette::Light, opt->palette.button().color());
1412 qDrawWinButton(p, opt->rect, pal, opt->state & (State_Sunken | State_On),
1413 &opt->palette.brush(QPalette::Button));
1414 }
1415 PrimitiveElement arrow;
1416 if (opt->state & State_Horizontal) {
1417 if (ce == CE_ScrollBarAddLine)
1418 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowRight : PE_IndicatorArrowLeft;
1419 else
1420 arrow = opt->direction == Qt::LeftToRight ? PE_IndicatorArrowLeft : PE_IndicatorArrowRight;
1421 } else {
1422 if (ce == CE_ScrollBarAddLine)
1423 arrow = PE_IndicatorArrowDown;
1424 else
1425 arrow = PE_IndicatorArrowUp;
1426 }
1427 QStyleOption arrowOpt = *opt;
1428 arrowOpt.rect = opt->rect.adjusted(4, 4, -4, -4);
1429 proxy()->drawPrimitive(arrow, &arrowOpt, p, widget);
1430 break; }
1431 case CE_ScrollBarAddPage:
1432 case CE_ScrollBarSubPage: {
1433 QBrush br;
1434 QBrush bg = p->background();
1435 Qt::BGMode bg_mode = p->backgroundMode();
1436 p->setPen(Qt::NoPen);
1437 p->setBackgroundMode(Qt::OpaqueMode);
1438
1439 if (opt->state & State_Sunken) {
1440 br = QBrush(opt->palette.shadow().color(), Qt::Dense4Pattern);
1441 p->setBackground(opt->palette.dark().color());
1442 p->setBrush(br);
1443 } else {
1444 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1445 if (paletteBrush.style() == Qt::TexturePattern) {
1446 if (qHasPixmapTexture(paletteBrush))
1447 br = QBrush(paletteBrush.texture());
1448 else
1449 br = QBrush(paletteBrush.textureImage());
1450 } else
1451 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1452 p->setBackground(opt->palette.window().color());
1453 p->setBrush(br);
1454 }
1455 p->drawRect(opt->rect);
1456 p->setBackground(bg);
1457 p->setBackgroundMode(bg_mode);
1458 break; }
1459 case CE_ScrollBarSlider:
1460 if (!(opt->state & State_Enabled)) {
1461 QBrush br;
1462 const QBrush paletteBrush = opt->palette.brush(QPalette::Light);
1463 if (paletteBrush.style() == Qt::TexturePattern) {
1464 if (qHasPixmapTexture(paletteBrush))
1465 br = QBrush(paletteBrush.texture());
1466 else
1467 br = QBrush(paletteBrush.textureImage());
1468 } else
1469 br = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1470 p->setPen(Qt::NoPen);
1471 p->setBrush(br);
1472 p->setBackgroundMode(Qt::OpaqueMode);
1473 p->drawRect(opt->rect);
1474 } else {
1475 QStyleOptionButton buttonOpt;
1476 buttonOpt.QStyleOption::operator=(*opt);
1477 buttonOpt.state = State_Enabled | State_Raised;
1478
1479 QPalette pal(opt->palette);
1480 pal.setColor(QPalette::Button, opt->palette.light().color());
1481 pal.setColor(QPalette::Light, opt->palette.button().color());
1482 qDrawWinButton(p, opt->rect, pal, false, &opt->palette.brush(QPalette::Button));
1483 }
1484 break;
1485#endif // QT_CONFIG(scrollbar)
1486 case CE_HeaderSection: {
1487 QBrush fill;
1488 if (opt->state & State_On)
1489 fill = QBrush(opt->palette.light().color(), Qt::Dense4Pattern);
1490 else
1491 fill = opt->palette.brush(QPalette::Button);
1492
1493 if (opt->state & (State_Raised | State_Sunken)) {
1494 qDrawWinButton(p, opt->rect, opt->palette, opt->state & State_Sunken, &fill);
1495 } else {
1496 p->fillRect(opt->rect, fill);
1497 }
1498 break; }
1499#if QT_CONFIG(toolbar)
1500 case CE_ToolBar:
1501 if (const QStyleOptionToolBar *toolbar = qstyleoption_cast<const QStyleOptionToolBar *>(opt)) {
1502 // Reserve the beveled appearance only for mainwindow toolbars
1503 if (!(widget && qobject_cast<const QMainWindow*> (widget->parentWidget())))
1504 break;
1505
1506 QRect rect = opt->rect;
1507 bool paintLeftBorder = true;
1508 bool paintRightBorder = true;
1509 bool paintBottomBorder = true;
1510
1511 switch (toolbar->toolBarArea){
1512 case Qt::BottomToolBarArea :
1513 switch(toolbar->positionOfLine){
1514 case QStyleOptionToolBar::Beginning:
1515 case QStyleOptionToolBar::OnlyOne:
1516 paintBottomBorder = false;
1517 break;
1518 default:
1519 break;
1520 }
1521 Q_FALLTHROUGH(); // It continues in the end of the next case
1522 case Qt::TopToolBarArea :
1523 switch(toolbar->positionWithinLine){
1524 case QStyleOptionToolBar::Beginning:
1525 paintLeftBorder = false;
1526 break;
1527 case QStyleOptionToolBar::End:
1528 paintRightBorder = false;
1529 break;
1530 case QStyleOptionToolBar::OnlyOne:
1531 paintRightBorder = false;
1532 paintLeftBorder = false;
1533 break;
1534 default:
1535 break;
1536 }
1537 if (opt->direction == Qt::RightToLeft) //reverse layout changes the order of Beginning/end
1538 std::swap(paintLeftBorder, paintRightBorder);
1539 break;
1540 case Qt::RightToolBarArea :
1541 switch (toolbar->positionOfLine){
1542 case QStyleOptionToolBar::Beginning:
1543 case QStyleOptionToolBar::OnlyOne:
1544 paintRightBorder = false;
1545 break;
1546 default:
1547 break;
1548 }
1549 break;
1550 case Qt::LeftToolBarArea :
1551 switch (toolbar->positionOfLine){
1552 case QStyleOptionToolBar::Beginning:
1553 case QStyleOptionToolBar::OnlyOne:
1554 paintLeftBorder = false;
1555 break;
1556 default:
1557 break;
1558 }
1559 break;
1560 default:
1561 break;
1562 }
1563
1564
1565 //draw top border
1566 p->setPen(opt->palette.light().color());
1567 p->drawLine(rect.topLeft(), rect.topRight());
1568
1569 if (paintLeftBorder){
1570 p->setPen(opt->palette.light().color());
1571 p->drawLine(rect.topLeft(), rect.bottomLeft());
1572 }
1573
1574 if (paintRightBorder){
1575 p->setPen(opt->palette.dark().color());
1576 p->drawLine(rect.topRight(), rect.bottomRight());
1577 }
1578
1579 if (paintBottomBorder){
1580 p->setPen(opt->palette.dark().color());
1581 p->drawLine(rect.bottomLeft(), rect.bottomRight());
1582 }
1583 }
1584 break;
1585
1586
1587#endif // QT_CONFIG(toolbar)
1588
1589 case CE_ProgressBarContents:
1590 if (const QStyleOptionProgressBar *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(opt)) {
1591 QRect rect = pb->rect;
1592 if (!rect.isValid())
1593 return;
1594
1595 const bool vertical = !(pb->state & QStyle::State_Horizontal);
1596 const bool inverted = pb->invertedAppearance;
1597
1598 QTransform m;
1599 if (vertical) {
1600 rect = QRect(rect.y(), rect.x(), rect.height(), rect.width()); // flip width and height
1601 m.rotate(90);
1602 m.translate(0, -(rect.height() + rect.y()*2));
1603 }
1604 QPalette pal2 = pb->palette;
1605 // Correct the highlight color if it is the same as the background
1606 if (pal2.highlight() == pal2.window())
1607 pal2.setColor(QPalette::Highlight, pb->palette.color(QPalette::Active,
1608 QPalette::Highlight));
1609 bool reverse = ((!vertical && (pb->direction == Qt::RightToLeft)) || vertical);
1610 if (inverted)
1611 reverse = !reverse;
1612 int w = rect.width();
1613 Q_D(const QWindowsStyle);
1614 if (pb->minimum == 0 && pb->maximum == 0) {
1615 const int unit_width = proxy()->pixelMetric(PM_ProgressBarChunkWidth, pb, widget);
1616 QStyleOptionProgressBar pbBits = *pb;
1617 Q_ASSERT(unit_width >0);
1618
1619 pbBits.rect = rect;
1620 pbBits.palette = pal2;
1621
1622 int step = 0;
1623 int chunkCount = w / unit_width + 1;
1624#if QT_CONFIG(animation)
1625 if (QProgressStyleAnimation *animation = qobject_cast<QProgressStyleAnimation*>(d->animation(opt->styleObject)))
1626 step = (animation->animationStep() / 3) % chunkCount;
1627 else
1628 d->startAnimation(new QProgressStyleAnimation(d->animationFps, opt->styleObject));
1629#else
1630 Q_UNUSED(d);
1631#endif
1632 int chunksInRow = 5;
1633 int myY = pbBits.rect.y();
1634 int myHeight = pbBits.rect.height();
1635 int chunksToDraw = chunksInRow;
1636
1637 if (step > chunkCount - 5)chunksToDraw = (chunkCount - step);
1638 p->save();
1639 p->setClipRect(m.mapRect(QRectF(rect)).toRect());
1640
1641 int x0 = reverse ? rect.left() + rect.width() - unit_width*(step) - unit_width : rect.left() + unit_width * step;
1642 int x = 0;
1643
1644 for (int i = 0; i < chunksToDraw ; ++i) {
1645 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1646 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1647 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1648 x += reverse ? -unit_width : unit_width;
1649 }
1650 //Draw wrap-around chunks
1651 if ( step > chunkCount-5){
1652 x0 = reverse ? rect.left() + rect.width() - unit_width : rect.left() ;
1653 x = 0;
1654 int chunksToDraw = step - (chunkCount - chunksInRow);
1655 for (int i = 0; i < chunksToDraw ; ++i) {
1656 pbBits.rect.setRect(x0 + x, myY, unit_width, myHeight);
1657 pbBits.rect = m.mapRect(QRectF(pbBits.rect)).toRect();
1658 proxy()->drawPrimitive(PE_IndicatorProgressChunk, &pbBits, p, widget);
1659 x += reverse ? -unit_width : unit_width;
1660 }
1661 }
1662 p->restore(); //restore state
1663 }
1664 else {
1665#if QT_CONFIG(animation)
1666 d->stopAnimation(opt->styleObject);
1667#endif
1668 QCommonStyle::drawControl(ce, opt, p, widget);
1669 }
1670 }
1671 break;
1672
1673#if QT_CONFIG(dockwidget)
1674 case CE_DockWidgetTitle:
1675
1676 if (const QStyleOptionDockWidget *dwOpt = qstyleoption_cast<const QStyleOptionDockWidget *>(opt)) {
1677 Q_D(const QWindowsStyle);
1678
1679 const bool verticalTitleBar = dwOpt->verticalTitleBar;
1680
1681 QRect rect = dwOpt->rect;
1682 QRect r = rect;
1683
1684 if (verticalTitleBar) {
1685 r = r.transposed();
1686
1687 p->save();
1688 p->translate(r.left(), r.top() + r.width());
1689 p->rotate(-90);
1690 p->translate(-r.left(), -r.top());
1691 }
1692
1693 bool floating = false;
1694 bool active = dwOpt->state & State_Active;
1695 QColor inactiveCaptionTextColor = d->inactiveCaptionText;
1696 if (dwOpt->movable) {
1697 QColor left, right;
1698
1699 //Titlebar gradient
1700 if (opt->state & QStyle::State_Window) {
1701 floating = true;
1702 if (active) {
1703 left = d->activeCaptionColor;
1704 right = d->activeGradientCaptionColor;
1705 } else {
1706 left = d->inactiveCaptionColor;
1707 right = d->inactiveGradientCaptionColor;
1708 }
1709 QBrush fillBrush(left);
1710 if (left != right) {
1711 QPoint p1(r.x(), r.top() + r.height()/2);
1712 QPoint p2(rect.right(), r.top() + r.height()/2);
1713 QLinearGradient lg(p1, p2);
1714 lg.setColorAt(0, left);
1715 lg.setColorAt(1, right);
1716 fillBrush = lg;
1717 }
1718 p->fillRect(r.adjusted(0, 0, 0, -3), fillBrush);
1719 }
1720 }
1721 if (!dwOpt->title.isEmpty()) {
1722 QFont oldFont = p->font();
1723 if (floating) {
1724 QFont font = oldFont;
1725 font.setBold(true);
1726 p->setFont(font);
1727 }
1728 QPalette palette = dwOpt->palette;
1729 palette.setColor(QPalette::Window, inactiveCaptionTextColor);
1730 QRect titleRect = subElementRect(SE_DockWidgetTitleBarText, opt, widget);
1731 if (verticalTitleBar) {
1732 titleRect = QRect(r.left() + rect.bottom()
1733 - titleRect.bottom(),
1734 r.top() + titleRect.left() - rect.left(),
1735 titleRect.height(), titleRect.width());
1736 }
1737 proxy()->drawItemText(p, titleRect,
1738 Qt::AlignLeft | Qt::AlignVCenter | Qt::TextHideMnemonic, palette,
1739 dwOpt->state & State_Enabled, dwOpt->title,
1740 floating ? (active ? QPalette::BrightText : QPalette::Window) : QPalette::WindowText);
1741 p->setFont(oldFont);
1742 }
1743 if (verticalTitleBar)
1744 p->restore();
1745 }
1746 return;
1747#endif // QT_CONFIG(dockwidget)
1748#if QT_CONFIG(combobox)
1749 case CE_ComboBoxLabel:
1750 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
1751 if (cb->state & State_HasFocus) {
1752 p->setPen(cb->palette.highlightedText().color());
1753 p->setBackground(cb->palette.highlight());
1754 } else {
1755 p->setPen(cb->palette.text().color());
1756 p->setBackground(cb->palette.window());
1757 }
1758 }
1759 QCommonStyle::drawControl(ce, opt, p, widget);
1760 break;
1761#endif // QT_CONFIG(combobox)
1762 default:
1763 QCommonStyle::drawControl(ce, opt, p, widget);
1764 }
1765}
1766
1767/*! \reimp */
1768QRect QWindowsStyle::subElementRect(SubElement sr, const QStyleOption *opt, const QWidget *w) const
1769{
1770 QRect r;
1771 switch (sr) {
1772 case SE_SliderFocusRect:
1773 case SE_ToolBoxTabContents:
1774 r = visualRect(opt->direction, opt->rect, opt->rect);
1775 break;
1776 case SE_DockWidgetTitleBarText: {
1777 r = QCommonStyle::subElementRect(sr, opt, w);
1778 const QStyleOptionDockWidget *dwOpt
1779 = qstyleoption_cast<const QStyleOptionDockWidget*>(opt);
1780 const bool verticalTitleBar = dwOpt && dwOpt->verticalTitleBar;
1781 int m = proxy()->pixelMetric(PM_DockWidgetTitleMargin, opt, w);
1782 if (verticalTitleBar) {
1783 r.adjust(0, 0, 0, -m);
1784 } else {
1785 if (opt->direction == Qt::LeftToRight)
1786 r.adjust(m, 0, 0, 0);
1787 else
1788 r.adjust(0, 0, -m, 0);
1789 }
1790 break;
1791 }
1792 case SE_ProgressBarContents:
1793 r = QCommonStyle::subElementRect(SE_ProgressBarGroove, opt, w);
1794 r.adjust(3, 3, -3, -3);
1795 break;
1796 default:
1797 r = QCommonStyle::subElementRect(sr, opt, w);
1798 }
1799 return r;
1800}
1801
1802
1803/*! \reimp */
1804void QWindowsStyle::drawComplexControl(ComplexControl cc, const QStyleOptionComplex *opt,
1805 QPainter *p, const QWidget *widget) const
1806{
1807 switch (cc) {
1808#if QT_CONFIG(slider)
1809 case CC_Slider:
1810 if (const QStyleOptionSlider *slider = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
1811 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
1812 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
1813 int ticks = slider->tickPosition;
1814 QRect groove = proxy()->subControlRect(CC_Slider, slider, SC_SliderGroove, widget);
1815 QRect handle = proxy()->subControlRect(CC_Slider, slider, SC_SliderHandle, widget);
1816
1817 if ((slider->subControls & SC_SliderGroove) && groove.isValid()) {
1818 int mid = thickness / 2;
1819
1820 if (ticks & QSlider::TicksAbove)
1821 mid += len / 8;
1822 if (ticks & QSlider::TicksBelow)
1823 mid -= len / 8;
1824
1825 p->setPen(slider->palette.shadow().color());
1826 if (slider->orientation == Qt::Horizontal) {
1827 qDrawWinPanel(p, groove.x(), groove.y() + mid - 2,
1828 groove.width(), 4, slider->palette, true);
1829 p->drawLine(groove.x() + 1, groove.y() + mid - 1,
1830 groove.x() + groove.width() - 3, groove.y() + mid - 1);
1831 } else {
1832 qDrawWinPanel(p, groove.x() + mid - 2, groove.y(),
1833 4, groove.height(), slider->palette, true);
1834 p->drawLine(groove.x() + mid - 1, groove.y() + 1,
1835 groove.x() + mid - 1, groove.y() + groove.height() - 3);
1836 }
1837 }
1838
1839 if (slider->subControls & SC_SliderTickmarks) {
1840 QStyleOptionSlider tmpSlider = *slider;
1841 tmpSlider.subControls = SC_SliderTickmarks;
1842 QCommonStyle::drawComplexControl(cc, &tmpSlider, p, widget);
1843 }
1844
1845 if (slider->subControls & SC_SliderHandle) {
1846 // 4444440
1847 // 4333310
1848 // 4322210
1849 // 4322210
1850 // 4322210
1851 // 4322210
1852 // *43210*
1853 // **410**
1854 // ***0***
1855 const QColor c0 = slider->palette.shadow().color();
1856 const QColor c1 = slider->palette.dark().color();
1857 // const QColor c2 = g.button();
1858 const QColor c3 = slider->palette.midlight().color();
1859 const QColor c4 = slider->palette.light().color();
1860 QBrush handleBrush;
1861
1862 if (slider->state & State_Enabled) {
1863 handleBrush = slider->palette.color(QPalette::Button);
1864 } else {
1865 handleBrush = QBrush(slider->palette.color(QPalette::Button),
1866 Qt::Dense4Pattern);
1867 }
1868
1869
1870 int x = handle.x(), y = handle.y(),
1871 wi = handle.width(), he = handle.height();
1872
1873 int x1 = x;
1874 int x2 = x+wi-1;
1875 int y1 = y;
1876 int y2 = y+he-1;
1877
1878 Qt::Orientation orient = slider->orientation;
1879 bool tickAbove = slider->tickPosition == QSlider::TicksAbove;
1880 bool tickBelow = slider->tickPosition == QSlider::TicksBelow;
1881
1882 if (slider->state & State_HasFocus) {
1883 QStyleOptionFocusRect fropt;
1884 fropt.QStyleOption::operator=(*slider);
1885 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
1886 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, p, widget);
1887 }
1888
1889 if ((tickAbove && tickBelow) || (!tickAbove && !tickBelow)) {
1890 Qt::BGMode oldMode = p->backgroundMode();
1891 p->setBackgroundMode(Qt::OpaqueMode);
1892 qDrawWinButton(p, QRect(x, y, wi, he), slider->palette, false,
1893 &handleBrush);
1894 p->setBackgroundMode(oldMode);
1895 return;
1896 }
1897
1898 QSliderDirection dir;
1899
1900 if (orient == Qt::Horizontal)
1901 dir = tickAbove ? SlUp : SlDown;
1902 else
1903 dir = tickAbove ? SlLeft : SlRight;
1904
1905 std::array<QPoint, 5> points;
1906 int d = 0;
1907 switch (dir) {
1908 case SlUp:
1909 y1 = y1 + wi / 2;
1910 d = (wi + 1) / 2 - 1;
1911 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1912 QPoint(x2, y1), QPoint(x1 + d, y1 - d)};
1913 break;
1914 case SlDown:
1915 y2 = y2 - wi / 2;
1916 d = (wi + 1) / 2 - 1;
1917 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x1 + d, y2 + d),
1918 QPoint(x2, y2), QPoint(x2, y1)};
1919 break;
1920 case SlLeft:
1921 d = (he + 1) / 2 - 1;
1922 x1 = x1 + he / 2;
1923 points = {QPoint(x1, y1), QPoint(x1 - d, y1 + d), QPoint(x1,y2),
1924 QPoint(x2, y2), QPoint(x2, y1)};
1925 break;
1926 case SlRight:
1927 d = (he + 1) / 2 - 1;
1928 x2 = x2 - he / 2;
1929 points = {QPoint(x1, y1), QPoint(x1, y2), QPoint(x2, y2),
1930 QPoint(x2 + d, y1 + d), QPoint(x2, y1)};
1931 break;
1932 }
1933
1934 QBrush oldBrush = p->brush();
1935 p->setPen(Qt::NoPen);
1936 p->setBrush(handleBrush);
1937 Qt::BGMode oldMode = p->backgroundMode();
1938 p->setBackgroundMode(Qt::OpaqueMode);
1939 p->drawRect(x1, y1, x2-x1+1, y2-y1+1);
1940 p->drawPolygon(points.data(), static_cast<int>(points.size()));
1941 p->setBrush(oldBrush);
1942 p->setBackgroundMode(oldMode);
1943
1944 if (dir != SlUp) {
1945 p->setPen(c4);
1946 p->drawLine(x1, y1, x2, y1);
1947 p->setPen(c3);
1948 p->drawLine(x1, y1+1, x2, y1+1);
1949 }
1950 if (dir != SlLeft) {
1951 p->setPen(c3);
1952 p->drawLine(x1+1, y1+1, x1+1, y2);
1953 p->setPen(c4);
1954 p->drawLine(x1, y1, x1, y2);
1955 }
1956 if (dir != SlRight) {
1957 p->setPen(c0);
1958 p->drawLine(x2, y1, x2, y2);
1959 p->setPen(c1);
1960 p->drawLine(x2-1, y1+1, x2-1, y2-1);
1961 }
1962 if (dir != SlDown) {
1963 p->setPen(c0);
1964 p->drawLine(x1, y2, x2, y2);
1965 p->setPen(c1);
1966 p->drawLine(x1+1, y2-1, x2-1, y2-1);
1967 }
1968
1969 switch (dir) {
1970 case SlUp:
1971 p->setPen(c4);
1972 p->drawLine(x1, y1, x1+d, y1-d);
1973 p->setPen(c0);
1974 d = wi - d - 1;
1975 p->drawLine(x2, y1, x2-d, y1-d);
1976 d--;
1977 p->setPen(c3);
1978 p->drawLine(x1+1, y1, x1+1+d, y1-d);
1979 p->setPen(c1);
1980 p->drawLine(x2-1, y1, x2-1-d, y1-d);
1981 break;
1982 case SlDown:
1983 p->setPen(c4);
1984 p->drawLine(x1, y2, x1+d, y2+d);
1985 p->setPen(c0);
1986 d = wi - d - 1;
1987 p->drawLine(x2, y2, x2-d, y2+d);
1988 d--;
1989 p->setPen(c3);
1990 p->drawLine(x1+1, y2, x1+1+d, y2+d);
1991 p->setPen(c1);
1992 p->drawLine(x2-1, y2, x2-1-d, y2+d);
1993 break;
1994 case SlLeft:
1995 p->setPen(c4);
1996 p->drawLine(x1, y1, x1-d, y1+d);
1997 p->setPen(c0);
1998 d = he - d - 1;
1999 p->drawLine(x1, y2, x1-d, y2-d);
2000 d--;
2001 p->setPen(c3);
2002 p->drawLine(x1, y1+1, x1-d, y1+1+d);
2003 p->setPen(c1);
2004 p->drawLine(x1, y2-1, x1-d, y2-1-d);
2005 break;
2006 case SlRight:
2007 p->setPen(c4);
2008 p->drawLine(x2, y1, x2+d, y1+d);
2009 p->setPen(c0);
2010 d = he - d - 1;
2011 p->drawLine(x2, y2, x2+d, y2-d);
2012 d--;
2013 p->setPen(c3);
2014 p->drawLine(x2, y1+1, x2+d, y1+1+d);
2015 p->setPen(c1);
2016 p->drawLine(x2, y2-1, x2+d, y2-1-d);
2017 break;
2018 }
2019 }
2020 }
2021 break;
2022#endif // QT_CONFIG(slider)
2023#if QT_CONFIG(scrollbar)
2024 case CC_ScrollBar:
2025 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(opt)) {
2026 QStyleOptionSlider newScrollbar = *scrollbar;
2027 if (scrollbar->minimum == scrollbar->maximum)
2028 newScrollbar.state &= ~State_Enabled; //do not draw the slider.
2029 QCommonStyle::drawComplexControl(cc, &newScrollbar, p, widget);
2030 }
2031 break;
2032#endif // QT_CONFIG(scrollbar)
2033#if QT_CONFIG(combobox)
2034 case CC_ComboBox:
2035 if (const QStyleOptionComboBox *cmb = qstyleoption_cast<const QStyleOptionComboBox *>(opt)) {
2036 QBrush editBrush = cmb->palette.brush(QPalette::Button);
2037 if ((cmb->subControls & SC_ComboBoxFrame)) {
2038 if (cmb->frame) {
2039 QPalette shadePal = opt->palette;
2040 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2041 qDrawWinPanel(p, opt->rect, shadePal, true, &editBrush);
2042 }
2043 else {
2044 p->fillRect(opt->rect, editBrush);
2045 }
2046 }
2047 if (cmb->subControls & SC_ComboBoxArrow) {
2048 QRect ar = proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxArrow, widget);
2049 bool sunkenArrow = cmb->activeSubControls == SC_ComboBoxArrow
2050 && cmb->state & State_Sunken;
2051 if (sunkenArrow) {
2052 p->setPen(cmb->palette.dark().color());
2053 p->setBrush(cmb->palette.brush(QPalette::Button));
2054 p->drawRect(ar.adjusted(0,0,-1,-1));
2055 } else {
2056 // Make qDrawWinButton use the right colors for drawing the shade of the button
2057 QPalette pal(cmb->palette);
2058 pal.setColor(QPalette::Button, cmb->palette.light().color());
2059 pal.setColor(QPalette::Light, cmb->palette.button().color());
2060 qDrawWinButton(p, ar, pal, false,
2061 &cmb->palette.brush(QPalette::Button));
2062 }
2063
2064 QStyleOption arrowOpt = *cmb;
2065 arrowOpt.state = State_None;
2066 if (opt->state & State_Enabled)
2067 arrowOpt.state |= State_Enabled;
2068 if (opt->state & State_HasFocus)
2069 arrowOpt.state |= State_HasFocus;
2070 if (sunkenArrow)
2071 arrowOpt.state |= State_Sunken;
2072 arrowOpt.rect = ar.adjusted(3, 3, -3, -3);
2073 proxy()->drawPrimitive(PE_IndicatorArrowDown, &arrowOpt, p, widget);
2074 }
2075
2076 if (cmb->subControls.testFlag(SC_ComboBoxEditField) && !cmb->editable) {
2077 if (cmb->state.testFlag(State_HasFocus)) {
2078 const auto re =
2079 proxy()->subControlRect(CC_ComboBox, cmb, SC_ComboBoxEditField, widget);
2080 p->fillRect(re, cmb->palette.brush(QPalette::Highlight));
2081 }
2082
2083 if (cmb->state.testFlag(State_HasFocus)) {
2084 QStyleOptionFocusRect focus;
2085 focus.QStyleOption::operator=(*cmb);
2086 focus.rect = subElementRect(SE_ComboBoxFocusRect, cmb, widget);
2087 focus.state |= State_FocusAtBorder;
2088 focus.backgroundColor = cmb->palette.highlight().color();
2089 proxy()->drawPrimitive(PE_FrameFocusRect, &focus, p, widget);
2090 }
2091 }
2092 }
2093 break;
2094#endif // QT_CONFIG(combobox)
2095#if QT_CONFIG(spinbox)
2096 case CC_SpinBox:
2097 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
2098 QStyleOptionSpinBox copy = *sb;
2099 PrimitiveElement pe;
2100 bool enabled = opt->state & State_Enabled;
2101 if (sb->frame && (sb->subControls & SC_SpinBoxFrame)) {
2102 QBrush editBrush = sb->palette.brush(QPalette::Base);
2103 QRect r = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxFrame, widget);
2104 QPalette shadePal = sb->palette;
2105 shadePal.setColor(QPalette::Midlight, shadePal.button().color());
2106 qDrawWinPanel(p, r, shadePal, true, &editBrush);
2107 }
2108
2109 QPalette shadePal(opt->palette);
2110 shadePal.setColor(QPalette::Button, opt->palette.light().color());
2111 shadePal.setColor(QPalette::Light, opt->palette.button().color());
2112
2113 if (sb->subControls & SC_SpinBoxUp) {
2114 copy.subControls = SC_SpinBoxUp;
2115 QPalette pal2 = sb->palette;
2116 if (!(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled)) {
2117 pal2.setCurrentColorGroup(QPalette::Disabled);
2118 copy.state &= ~State_Enabled;
2119 }
2120
2121 copy.palette = pal2;
2122
2123 if (sb->activeSubControls == SC_SpinBoxUp && (sb->state & State_Sunken)) {
2124 copy.state |= State_On;
2125 copy.state |= State_Sunken;
2126 } else {
2127 copy.state |= State_Raised;
2128 copy.state &= ~State_Sunken;
2129 }
2130 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinPlus
2131 : PE_IndicatorSpinUp);
2132
2133 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxUp, widget);
2134 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2135 &copy.palette.brush(QPalette::Button));
2136 copy.rect.adjust(4, 1, -5, -1);
2137 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepUpEnabled))
2138 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2139 {
2140 QStyleOptionSpinBox lightCopy = copy;
2141 lightCopy.rect.adjust(1, 1, 1, 1);
2142 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2143 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2144 }
2145 proxy()->drawPrimitive(pe, &copy, p, widget);
2146 }
2147
2148 if (sb->subControls & SC_SpinBoxDown) {
2149 copy.subControls = SC_SpinBoxDown;
2150 copy.state = sb->state;
2151 QPalette pal2 = sb->palette;
2152 if (!(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled)) {
2153 pal2.setCurrentColorGroup(QPalette::Disabled);
2154 copy.state &= ~State_Enabled;
2155 }
2156 copy.palette = pal2;
2157
2158 if (sb->activeSubControls == SC_SpinBoxDown && (sb->state & State_Sunken)) {
2159 copy.state |= State_On;
2160 copy.state |= State_Sunken;
2161 } else {
2162 copy.state |= State_Raised;
2163 copy.state &= ~State_Sunken;
2164 }
2165 pe = (sb->buttonSymbols == QAbstractSpinBox::PlusMinus ? PE_IndicatorSpinMinus
2166 : PE_IndicatorSpinDown);
2167
2168 copy.rect = proxy()->subControlRect(CC_SpinBox, sb, SC_SpinBoxDown, widget);
2169 qDrawWinButton(p, copy.rect, shadePal, copy.state & (State_Sunken | State_On),
2170 &copy.palette.brush(QPalette::Button));
2171 copy.rect.adjust(4, 0, -5, -1);
2172 if ((!enabled || !(sb->stepEnabled & QAbstractSpinBox::StepDownEnabled))
2173 && proxy()->styleHint(SH_EtchDisabledText, opt, widget) )
2174 {
2175 QStyleOptionSpinBox lightCopy = copy;
2176 lightCopy.rect.adjust(1, 1, 1, 1);
2177 lightCopy.palette.setBrush(QPalette::ButtonText, copy.palette.light());
2178 proxy()->drawPrimitive(pe, &lightCopy, p, widget);
2179 }
2180 proxy()->drawPrimitive(pe, &copy, p, widget);
2181 }
2182 }
2183 break;
2184#endif // QT_CONFIG(spinbox)
2185
2186 default:
2187 QCommonStyle::drawComplexControl(cc, opt, p, widget);
2188 }
2189}
2190
2191/*! \reimp */
2192QSize QWindowsStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
2193 const QSize &csz, const QWidget *widget) const
2194{
2195 QSize sz(csz);
2196 switch (ct) {
2197 case CT_PushButton:
2198 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(opt)) {
2199 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2200 int w = sz.width(),
2201 h = sz.height();
2202 int defwidth = 0;
2203 if (btn->features & QStyleOptionButton::AutoDefaultButton)
2204 defwidth = 2 * proxy()->pixelMetric(PM_ButtonDefaultIndicator, btn, widget);
2205 const qreal dpi = QStyleHelper::dpi(opt);
2206 int minwidth = int(QStyleHelper::dpiScaled(75, dpi));
2207 int minheight = int(QStyleHelper::dpiScaled(23, dpi));
2208
2209 if (w < minwidth + defwidth && !btn->text.isEmpty())
2210 w = minwidth + defwidth;
2211 if (h < minheight + defwidth)
2212 h = minheight + defwidth;
2213
2214 sz = QSize(w, h);
2215 }
2216 break;
2217#if QT_CONFIG(menu)
2218 case CT_MenuItem:
2219 if (const QStyleOptionMenuItem *mi = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) {
2220 int w = sz.width();
2221 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2222
2223 if (mi->menuItemType == QStyleOptionMenuItem::Separator) {
2224 sz = QSize(10, QWindowsStylePrivate::windowsSepHeight);
2225 }
2226 else if (mi->icon.isNull()) {
2227 sz.setHeight(sz.height() - 2);
2228 w -= 6;
2229 }
2230
2231 if (mi->menuItemType != QStyleOptionMenuItem::Separator && !mi->icon.isNull()) {
2232 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, opt, widget);
2233 sz.setHeight(qMax(sz.height(),
2234 mi->icon.actualSize(QSize(iconExtent, iconExtent)).height()
2235 + 2 * QWindowsStylePrivate::windowsItemFrame));
2236 }
2237 int maxpmw = mi->maxIconWidth;
2238 int tabSpacing = 20;
2239 if (mi->text.contains(u'\t'))
2240 w += tabSpacing;
2241 else if (mi->menuItemType == QStyleOptionMenuItem::SubMenu)
2242 w += 2 * QWindowsStylePrivate::windowsArrowHMargin;
2243 else if (mi->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2244 // adjust the font and add the difference in size.
2245 // it would be better if the font could be adjusted in the initStyleOption qmenu func!!
2246 QFontMetrics fm(mi->font);
2247 QFont fontBold = mi->font;
2248 fontBold.setBold(true);
2249 QFontMetrics fmBold(fontBold);
2250 w += fmBold.horizontalAdvance(mi->text) - fm.horizontalAdvance(mi->text);
2251 }
2252
2253 int checkcol = qMax<int>(maxpmw, QWindowsStylePrivate::windowsCheckMarkWidth); // Windows always shows a check column
2254 w += checkcol;
2255 w += int(QWindowsStylePrivate::windowsRightBorder) + 10;
2256 sz.setWidth(w);
2257 }
2258 break;
2259#endif // QT_CONFIG(menu)
2260#if QT_CONFIG(menubar)
2261 case CT_MenuBarItem:
2262 if (!sz.isEmpty())
2263 sz += QSize(QWindowsStylePrivate::windowsItemHMargin * 4, QWindowsStylePrivate::windowsItemVMargin * 2);
2264 break;
2265#endif
2266 case CT_ToolButton:
2267#if QT_CONFIG(toolbutton)
2268 if (qstyleoption_cast<const QStyleOptionToolButton *>(opt))
2269 return sz += QSize(7, 6);
2270#endif // QT_CONFIG(toolbutton)
2271 Q_FALLTHROUGH();
2272
2273 default:
2274 sz = QCommonStyle::sizeFromContents(ct, opt, csz, widget);
2275 }
2276 return sz;
2277}
2278
2279/*!
2280 \reimp
2281*/
2282QIcon QWindowsStyle::standardIcon(StandardPixmap standardIcon, const QStyleOption *option,
2283 const QWidget *widget) const
2284{
2285 return QCommonStyle::standardIcon(standardIcon, option, widget);
2286}
2287
2288
2289
2290QT_END_NAMESPACE
2291
2292#include "moc_qwindowsstyle_p.cpp"
2293
2294#endif // style_windows