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