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