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