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