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