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