Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwindows11style.cpp
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6#include <qstylehints.h>
7#include <private/qstyleanimation_p.h>
8#include <private/qstyle_p.h>
9#include <private/qstylehelper_p.h>
10#include <private/qapplication_p.h>
11#include <private/qcombobox_p.h>
12#include <qstyleoption.h>
13#include <qpainter.h>
14#include <qpainterstateguard.h>
15#include <QGraphicsDropShadowEffect>
16#include <QLatin1StringView>
17#include <QtCore/qoperatingsystemversion.h>
18#include <QtWidgets/qcombobox.h>
19#if QT_CONFIG(commandlinkbutton)
20#include <QtWidgets/qcommandlinkbutton.h>
21#endif
22#include <QtWidgets/qgraphicsview.h>
23#include <QtWidgets/qlistview.h>
24#include <QtWidgets/qmenu.h>
25#if QT_CONFIG(mdiarea)
26#include <QtWidgets/qmdiarea.h>
27#endif
28#include <QtWidgets/qplaintextedit.h>
29#include <QtWidgets/qtextedit.h>
30#include <QtWidgets/qtreeview.h>
31#if QT_CONFIG(datetimeedit)
32# include <QtWidgets/qdatetimeedit.h>
33#endif
34#if QT_CONFIG(tabwidget)
35# include <QtWidgets/qtabwidget.h>
36#endif
37#if QT_CONFIG(menubar)
38# include <QtWidgets/qmenubar.h>
39#endif
40#if QT_CONFIG(tooltip)
41#include "private/qtooltip_p.h"
42#endif
43#include "qdrawutil.h"
44#include <chrono>
45#include <dwmapi.h>
46
47QT_BEGIN_NAMESPACE
48
49using namespace Qt::StringLiterals;
50
51static constexpr int topLevelRoundingRadius = 8; //Radius for toplevel items like popups for round corners
52static constexpr int secondLevelRoundingRadius = 4; //Radius for second level items like hovered menu item round corners
53static constexpr int contentItemHMargin = 4; // margin between content items (e.g. text and icon)
54static constexpr int contentHMargin = 2 * 3; // margin between rounded border and content (= rounded border margin * 3)
55
56
58{
59inline bool isChecked(const QStyleOption *option)
60{
61 return option->state.testAnyFlags(QStyle::State_On | QStyle::State_NoChange);
62}
63inline bool isDisabled(const QStyleOption *option)
64{
65 return !option->state.testFlag(QStyle::State_Enabled);
66}
67inline bool isPressed(const QStyleOption *option)
68{
69 return option->state.testFlag(QStyle::State_Sunken);
70}
71inline bool isSelected(const QStyleOption *option)
72{
73 return option->state.testFlag(QStyle::State_Selected);
74}
75inline bool isHover(const QStyleOption *option)
76{
77 return option->state.testFlag(QStyle::State_MouseOver);
78}
79inline bool isAutoRaise(const QStyleOption *option)
80{
81 return option->state.testFlag(QStyle::State_AutoRaise);
82}
83inline bool hasFocus(const QStyleOption *option)
84{
85 return option->state.testFlag(QStyle::State_HasFocus);
86}
88inline ControlState calcControlState(const QStyleOption *option)
89{
90 if (isDisabled(option))
92 if (isPressed(option))
94 if (isHover(option))
97};
98
99} // namespace StyleOptionHelper
100
101template <typename R, typename P, typename B>
102static inline void drawRoundedRect(QPainter *p,
103 R &&rect,
104 P &&pen,
105 B &&brush,
106 int radius = secondLevelRoundingRadius)
107{
108 p->setPen(pen);
109 p->setBrush(brush);
110 p->drawRoundedRect(rect, radius, radius);
111}
112
113static constexpr int percentToAlpha(double percent)
114{
115 return qRound(percent * 255. / 100.);
116}
117
118static constexpr std::array<QColor, 37> WINUI3ColorsLight {
119 QColor(0x00,0x00,0x00,percentToAlpha(3.73)), // subtleHighlightColor (fillSubtleSecondary)
120 QColor(0x00,0x00,0x00,percentToAlpha(2.41)), // subtlePressedColor (fillSubtleTertiary)
121 QColor(0x00,0x00,0x00,0x0F), //frameColorLight
122 QColor(0x00,0x00,0x00,percentToAlpha(60.63)), //frameColorStrong
123 QColor(0x00,0x00,0x00,percentToAlpha(21.69)), //frameColorStrongDisabled
124 QColor(0x00,0x00,0x00,0x72), //controlStrongFill
125 QColor(0x00,0x00,0x00,0x29), //controlStrokeSecondary
126 QColor(0x00,0x00,0x00,0x14), //controlStrokePrimary
127 QColor(0xFF,0xFF,0xFF,0xFF), //menuPanelFill
128 QColor(0x00,0x00,0x00,0x66), //controlStrokeOnAccentSecondary
129 QColor(0xFF,0xFF,0xFF,0xFF), //controlFillSolid
130 QColor(0x75,0x75,0x75,0x66), //surfaceStroke
131 QColor(0xFF,0xFF,0xFF,0xFF), //focusFrameInnerStroke
132 QColor(0x00,0x00,0x00,0xFF), //focusFrameOuterStroke
133 QColor(0xFF,0xFF,0xFF,percentToAlpha(70)), // fillControlDefault
134 QColor(0xF9,0xF9,0xF9,percentToAlpha(50)), // fillControlSecondary
135 QColor(0xF9,0xF9,0xF9,percentToAlpha(30)), // fillControlTertiary
136 QColor(0xF9,0xF9,0xF9,percentToAlpha(30)), // fillControlDisabled
137 QColor(0xFF,0xFF,0xFF,percentToAlpha(100)), // fillControlInputActive
138 QColor(0x00,0x00,0x00,percentToAlpha(2.41)), // fillControlAltSecondary
139 QColor(0x00,0x00,0x00,percentToAlpha(5.78)), // fillControlAltTertiary
140 QColor(0x00,0x00,0x00,percentToAlpha(9.24)), // fillControlAltQuarternary
141 QColor(0xFF,0xFF,0xFF,percentToAlpha(0.00)), // fillControlAltDisabled
142 QColor(0x00,0x00,0x00,percentToAlpha(100)), // fillAccentDefault
143 QColor(0x00,0x00,0x00,percentToAlpha(90)), // fillAccentSecondary
144 QColor(0x00,0x00,0x00,percentToAlpha(80)), // fillAccentTertiary
145 QColor(0x00,0x00,0x00,percentToAlpha(21.69)), // fillAccentDisabled
146 QColor(0xFF,0xFF,0xFF,percentToAlpha(70)), // fillMicaAltDefault
147 QColor(0xFF,0xFF,0xFF,percentToAlpha(0)), // fillMicaAltTransparent
148 QColor(0x00,0x00,0x00,percentToAlpha(3.73)), // fillMicaAltSecondary
149 QColor(0x00,0x00,0x00,percentToAlpha(89.56)), // textPrimary
150 QColor(0x00,0x00,0x00,percentToAlpha(60.63)), // textSecondary
151 QColor(0x00,0x00,0x00,percentToAlpha(36.14)), // textDisabled
152 QColor(0xFF,0xFF,0xFF,percentToAlpha(100)), // textOnAccentPrimary
153 QColor(0xFF,0xFF,0xFF,percentToAlpha(70)), // textOnAccentSecondary
154 QColor(0xFF,0xFF,0xFF,percentToAlpha(100)), // textOnAccentDisabled
155 QColor(0x00,0x00,0x00,percentToAlpha(8.03)), // dividerStrokeDefault
156};
157
158static constexpr std::array<QColor, 37> WINUI3ColorsDark {
159 QColor(0xFF,0xFF,0xFF,percentToAlpha(6.05)), // subtleHighlightColor (fillSubtleSecondary)
160 QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // subtlePressedColor (fillSubtleTertiary)
161 QColor(0xFF,0xFF,0xFF,0x12), //frameColorLight
162 QColor(0xFF,0xFF,0xFF,percentToAlpha(60.47)), //frameColorStrong
163 QColor(0xFF,0xFF,0xFF,percentToAlpha(15.81)), //frameColorStrongDisabled
164 QColor(0xFF,0xFF,0xFF,0x8B), //controlStrongFill
165 QColor(0xFF,0xFF,0xFF,0x18), //controlStrokeSecondary
166 QColor(0xFF,0xFF,0xFF,0x12), //controlStrokePrimary
167 QColor(0x0F,0x0F,0x0F,0xFF), //menuPanelFill
168 QColor(0xFF,0xFF,0xFF,0x14), //controlStrokeOnAccentSecondary
169 QColor(0x45,0x45,0x45,0xFF), //controlFillSolid
170 QColor(0x75,0x75,0x75,0x66), //surfaceStroke
171 QColor(0x00,0x00,0x00,0xFF), //focusFrameInnerStroke
172 QColor(0xFF,0xFF,0xFF,0xFF), //focusFrameOuterStroke
173 QColor(0xFF,0xFF,0xFF,percentToAlpha(6.05)), // fillControlDefault
174 QColor(0xFF,0xFF,0xFF,percentToAlpha(8.37)), // fillControlSecondary
175 QColor(0xFF,0xFF,0xFF,percentToAlpha(3.26)), // fillControlTertiary
176 QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // fillControlDisabled
177 QColor(0x1E,0x1E,0x1E,percentToAlpha(70)), // fillControlInputActive
178 QColor(0x00,0x00,0x00,percentToAlpha(10.0)), // fillControlAltDefault
179 QColor(0xFF,0xFF,0xFF,percentToAlpha(4.19)), // fillControlAltSecondary
180 QColor(0xFF,0xFF,0xFF,percentToAlpha(6.98)), // fillControlAltTertiafillCy
181 QColor(0xFF,0xFF,0xFF,percentToAlpha(0.00)), // controlAltDisabled
182 QColor(0x00,0x00,0x00,percentToAlpha(100)), // fillAccentDefault
183 QColor(0x00,0x00,0x00,percentToAlpha(90)), // fillAccentSecondary
184 QColor(0x00,0x00,0x00,percentToAlpha(80)), // fillAccentTertiary
185 QColor(0xFF,0xFF,0xFF,percentToAlpha(15.81)), // fillAccentDisabled
186 QColor(0x3A,0x3A,0x3A,percentToAlpha(45)), // fillMicaAltDefault
187 QColor(0x00,0x00,0x00,percentToAlpha(0)), // fillMicaAltTransparent
188 QColor(0xFF,0xFF,0xFF,percentToAlpha(6.05)), // fillMicaAltSecondary
189 QColor(0xFF,0xFF,0xFF,percentToAlpha(100)), // textPrimary
190 QColor(0xFF,0xFF,0xFF,percentToAlpha(78.6)), // textSecondary
191 QColor(0xFF,0xFF,0xFF,percentToAlpha(36.28)), // textDisabled
192 QColor(0x00,0x00,0x00,percentToAlpha(100)), // textOnAccentPrimary
193 QColor(0x00,0x00,0x00,percentToAlpha(70)), // textOnAccentSecondary
194 QColor(0xFF,0xFF,0xFF,percentToAlpha(53.02)), // textOnAccentDisabled
195 QColor(0xFF,0xFF,0xFF,percentToAlpha(8.37)), // dividerStrokeDefault
196};
197
198static constexpr std::array<std::array<QColor,37>, 2> WINUI3Colors {
199 WINUI3ColorsLight,
200 WINUI3ColorsDark
201};
202
203// Color of close Button in Titlebar (default + hover)
204static constexpr QColor shellCaptionCloseFillColorPrimary(0xC4,0x2B,0x1C,0xFF);
205static constexpr QColor shellCaptionCloseTextFillColorPrimary(0xFF,0xFF,0xFF,0xFF);
206// Color of close Button in Titlebar (pressed + disabled)
207static constexpr QColor shellCaptionCloseFillColorSecondary(0xC4,0x2B,0x1C,0xE6);
208static constexpr QColor shellCaptionCloseTextFillColorSecondary(0xFF,0xFF,0xFF,0xB3);
209
210static qreal radioButtonInnerRadius(QStyle::State state)
211{
212 qreal radius = 7.0;
213 if (state & QStyle::State_Sunken)
214 radius = 4.0f;
215 else if (state & QStyle::State_MouseOver && !(state & QStyle::State_On))
216 radius = 7.0f;
217 else if (state & QStyle::State_MouseOver && (state & QStyle::State_On))
218 radius = 5.0f;
219 else if (state & QStyle::State_On)
220 radius = 4.0f;
221 return radius;
222}
223
224static qreal sliderInnerRadius(QStyle::State state, bool insideHandle)
225{
226 const bool isEnabled = state & QStyle::State_Enabled;
227 if (isEnabled) {
228 if (state & QStyle::State_Sunken)
229 return 0.29;
230 else if (insideHandle)
231 return 0.71;
232 }
233 return 0.43;
234}
235/*!
236 \class QWindows11Style
237 \brief The QWindows11Style class provides a look and feel suitable for applications on Microsoft Windows 11.
238 \since 6.6
239 \ingroup appearance
240 \inmodule QtWidgets
241 \internal
242
243 \warning This style is only available on the Windows 11 platform and above.
244
245 \sa QWindows11Style QWindowsVistaStyle, QMacStyle, QFusionStyle
246*/
247QWindows11StylePrivate::QWindows11StylePrivate()
248{
249 nativeRoundedTopLevelWindows =
250 QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11_21H2;
251}
252
253/*!
254 Constructs a QWindows11Style object.
255*/
256QWindows11Style::QWindows11Style() : QWindows11Style(*new QWindows11StylePrivate)
257{
258}
259
260/*!
261 \internal
262 Constructs a QWindows11Style object.
263*/
264QWindows11Style::QWindows11Style(QWindows11StylePrivate &dd) : QWindowsVistaStyle(dd)
265{
266 Q_D(QWindows11Style);
267 const QStringList assetFontFamilies{ "Segoe Fluent Icons"_L1, "Segoe MDL2 Assets"_L1 };
268 d->m_assetFont = QFont(assetFontFamilies);
269 d->m_assetFont.setStyleStrategy(QFont::NoFontMerging);
270 highContrastTheme = QGuiApplicationPrivate::styleHints->colorScheme() == Qt::ColorScheme::Unknown;
271 colorSchemeIndex = QGuiApplicationPrivate::styleHints->colorScheme() == Qt::ColorScheme::Light ? 0 : 1;
272}
273
274/*!
275 Destructor.
276*/
277QWindows11Style::~QWindows11Style() = default;
278
279/*!
280 \internal
281 see drawPrimitive for comments on the animation support
282
283 */
284void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOptionComplex *option,
285 QPainter *painter, const QWidget *widget) const
286{
287 QWindows11StylePrivate *d = const_cast<QWindows11StylePrivate*>(d_func());
288
289 const auto drawTitleBarButton = [&](ComplexControl control, SubControl sc, Icon ico) {
290 using namespace StyleOptionHelper;
291 const QRect buttonRect = proxy()->subControlRect(control, option, sc, widget);
292 if (buttonRect.isValid()) {
293 const bool hover = option->activeSubControls == sc && isHover(option);
294 if (hover)
295 painter->fillRect(buttonRect, winUI3Color(subtleHighlightColor));
296 painter->setPen(option->palette.color(QPalette::WindowText));
297 painter->drawText(buttonRect, Qt::AlignCenter, fluentIcon(ico));
298 }
299 };
300 const auto drawTitleBarCloseButton = [&](ComplexControl control, SubControl sc, Icon ico) {
301 using namespace StyleOptionHelper;
302 const QRect buttonRect = proxy()->subControlRect(control, option, sc, widget);
303 if (buttonRect.isValid()) {
304 const auto state = (option->activeSubControls == sc) ? calcControlState(option)
305 : ControlState::Normal;
306 QPen pen;
307 switch (state) {
309 painter->fillRect(buttonRect, shellCaptionCloseFillColorPrimary);
310 pen = shellCaptionCloseTextFillColorPrimary;
311 break;
313 painter->fillRect(buttonRect, shellCaptionCloseFillColorSecondary);
314 pen = shellCaptionCloseTextFillColorSecondary;
315 break;
318 pen = option->palette.color(QPalette::WindowText);
319 break;
320 }
321 painter->setPen(pen);
322 painter->drawText(buttonRect, Qt::AlignCenter, fluentIcon(ico));
323 }
324 };
325
326
327 State state = option->state;
328 SubControls sub = option->subControls;
329 State flags = option->state;
330 if (widget && widget->testAttribute(Qt::WA_UnderMouse) && widget->isActiveWindow())
331 flags |= State_MouseOver;
332
333 QPainterStateGuard psg(painter);
334 painter->setRenderHint(QPainter::Antialiasing);
335 if (d->transitionsEnabled() && option->styleObject) {
336 if (control == CC_Slider) {
337 if (const auto *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
338 QObject *styleObject = option->styleObject; // Can be widget or qquickitem
339
340 QRectF thumbRect = proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget);
341 const qreal outerRadius = qMin(8.0, (slider->orientation == Qt::Horizontal ? thumbRect.height() / 2.0 : thumbRect.width() / 2.0) - 1);
342 bool isInsideHandle = option->activeSubControls == SC_SliderHandle;
343
344 bool oldIsInsideHandle = styleObject->property("_q_insidehandle").toBool();
345 State oldState = State(styleObject->property("_q_stylestate").toInt());
346 SubControls oldActiveControls = SubControls(styleObject->property("_q_stylecontrols").toInt());
347
348 QRectF oldRect = styleObject->property("_q_stylerect").toRect();
349 styleObject->setProperty("_q_insidehandle", isInsideHandle);
350 styleObject->setProperty("_q_stylestate", int(state));
351 styleObject->setProperty("_q_stylecontrols", int(option->activeSubControls));
352 styleObject->setProperty("_q_stylerect", option->rect);
353 if (option->styleObject->property("_q_end_radius").isNull())
354 option->styleObject->setProperty("_q_end_radius", outerRadius * 0.43);
355
356 bool doTransition = (((state & State_Sunken) != (oldState & State_Sunken)
357 || (oldIsInsideHandle != isInsideHandle)
358 || (oldActiveControls != option->activeSubControls))
359 && state & State_Enabled);
360
361 if (oldRect != option->rect) {
362 doTransition = false;
363 d->stopAnimation(styleObject);
364 styleObject->setProperty("_q_inner_radius", outerRadius * 0.43);
365 }
366
367 if (doTransition) {
368 QNumberStyleAnimation *t = new QNumberStyleAnimation(styleObject);
369 t->setStartValue(styleObject->property("_q_inner_radius").toFloat());
370 t->setEndValue(outerRadius * sliderInnerRadius(state, isInsideHandle));
371 styleObject->setProperty("_q_end_radius", t->endValue());
372
373 t->setStartTime(d->animationTime());
374 t->setDuration(150);
375 d->startAnimation(t);
376 }
377 }
378 } else if (control == CC_ScrollBar) {
379 QObject *styleObject = option->styleObject;
380 State oldState = State(styleObject->property("_q_stylestate").toInt());
381 const bool wasMouseOver = oldState.testFlag(State_MouseOver);
382 const bool isMouseOver = state.testFlag(State_MouseOver);
383
384 if (wasMouseOver != isMouseOver) {
385 styleObject->setProperty("_q_stylestate", int(state));
386 auto anim = qobject_cast<QNumberStyleAnimation *>(d->animation(styleObject));
387 constexpr int durationMS = 100;
388 qreal startValue = isMouseOver ? 0 : 1;
389 int curDurationMS = durationMS;
390 if (anim) {
391 startValue = anim->currentValue();
392 curDurationMS = durationMS - (anim->duration() - anim->currentLoopTime());
393 d->stopAnimation(option->styleObject);
394 }
395 anim = new QNumberStyleAnimation(styleObject);
396 anim->setStartValue(startValue);
397 anim->setEndValue(isMouseOver ? 1 : 0);
398 anim->setDuration(curDurationMS);
399 d->startAnimation(anim);
400 }
401 }
402 }
403
404 switch (control) {
405#if QT_CONFIG(spinbox)
406 case CC_SpinBox:
407 if (const QStyleOptionSpinBox *sb = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
408 const auto frameRect = QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
409 drawRoundedRect(painter, frameRect, Qt::NoPen, inputFillBrush(option, widget));
410
411 if (sb->frame && (sub & SC_SpinBoxFrame))
412 drawLineEditFrame(painter, frameRect, option);
413
414 const auto drawUpDown = [&](QStyle::SubControl sc,
415 QAbstractSpinBox::StepEnabledFlag flag) {
416 const bool isEnabled =
417 state.testFlag(QStyle::State_Enabled) && sb->stepEnabled.testFlag(flag);
418 const bool isUp = sc == SC_SpinBoxUp;
419 const QRect rect = proxy()->subControlRect(CC_SpinBox, option, sc, widget);
420 if (isEnabled && sb->activeSubControls & sc)
421 drawRoundedRect(painter, rect.adjusted(1, 1, -1, -2), Qt::NoPen,
422 winUI3Color(subtleHighlightColor));
423 painter->setFont(d->m_assetFont);
424 painter->setPen(sb->palette.color(isEnabled ? QPalette::Active : QPalette::Disabled,
425 QPalette::ButtonText));
426 painter->setBrush(Qt::NoBrush);
427 painter->drawText(rect, Qt::AlignCenter, fluentIcon(isUp ? Icon::ChevronUp : Icon::ChevronDown));
428 };
429 if (sub & SC_SpinBoxUp)
430 drawUpDown(SC_SpinBoxUp, QAbstractSpinBox::StepUpEnabled);
431 if (sub & SC_SpinBoxDown)
432 drawUpDown(SC_SpinBoxDown, QAbstractSpinBox::StepDownEnabled);
433 if (state & State_KeyboardFocusChange && state & State_HasFocus) {
434 QStyleOptionFocusRect fropt;
435 fropt.QStyleOption::operator=(*option);
436 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
437 }
438 }
439 break;
440#endif // QT_CONFIG(spinbox)
441#if QT_CONFIG(slider)
442 case CC_Slider:
443 if (const auto *slider = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
444 const auto &slrect = slider->rect;
445 const bool isHorizontal = slider->orientation == Qt::Horizontal;
446 const QRectF handleRect(proxy()->subControlRect(CC_Slider, option, SC_SliderHandle, widget));
447 const QPointF handleCenter(handleRect.center());
448
449 if (sub & SC_SliderGroove) {
450 QRectF rect = proxy()->subControlRect(CC_Slider, option, SC_SliderGroove, widget);
451 QRectF leftRect;
452 QRectF rightRect;
453
454 if (isHorizontal) {
455 rect = QRectF(rect.left() + 2, rect.center().y() - 2, rect.width() - 2, 4);
456 leftRect = QRectF(rect.left(), rect.top(), handleCenter.x() - rect.left(),
457 rect.height());
458 rightRect = QRectF(handleCenter.x(), rect.top(),
459 rect.width() - handleCenter.x(),
460 rect.height());
461 } else {
462 rect = QRect(rect.center().x() - 2, rect.top() + 2, 4, rect.height() - 2);
463 leftRect = QRectF(rect.left(), rect.top(), rect.width(),
464 handleCenter.y() - rect.top());
465 rightRect = QRectF(rect.left(), handleCenter.y(), rect.width(),
466 rect.height() - handleCenter.y());
467 }
468 if (slider->upsideDown)
469 qSwap(leftRect, rightRect);
470
471 painter->setPen(Qt::NoPen);
472 painter->setBrush(calculateAccentColor(option));
473 painter->drawRoundedRect(leftRect,1,1);
474 painter->setBrush(WINUI3Colors[colorSchemeIndex][controlStrongFill]);
475 painter->drawRoundedRect(rightRect,1,1);
476 }
477 if (sub & SC_SliderTickmarks) {
478 int tickOffset = proxy()->pixelMetric(PM_SliderTickmarkOffset, slider, widget);
479 int ticks = slider->tickPosition;
480 int thickness = proxy()->pixelMetric(PM_SliderControlThickness, slider, widget);
481 int len = proxy()->pixelMetric(PM_SliderLength, slider, widget);
482 int available = proxy()->pixelMetric(PM_SliderSpaceAvailable, slider, widget);
483 int interval = slider->tickInterval;
484 if (interval <= 0) {
485 interval = slider->singleStep;
486 if (QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, interval,
487 available)
488 - QStyle::sliderPositionFromValue(slider->minimum, slider->maximum,
489 0, available) < 3)
490 interval = slider->pageStep;
491 }
492 if (!interval)
493 interval = 1;
494 int fudge = len / 2;
495 painter->setPen(slider->palette.text().color());
496 QVarLengthArray<QLineF, 32> lines;
497 int v = slider->minimum;
498 while (v <= slider->maximum + 1) {
499 if (v == slider->maximum + 1 && interval == 1)
500 break;
501 const int v_ = qMin(v, slider->maximum);
502 int tickLength = (v_ == slider->minimum || v_ >= slider->maximum) ? 4 : 3;
503 int pos = QStyle::sliderPositionFromValue(slider->minimum, slider->maximum, v_,
504 available, slider->upsideDown);
505 pos += fudge;
506 if (isHorizontal) {
507 if (ticks & QSlider::TicksAbove) {
508 lines.append(QLineF(pos, tickOffset - 0.5,
509 pos, tickOffset - tickLength - 0.5));
510 }
511
512 if (ticks & QSlider::TicksBelow) {
513 lines.append(QLineF(pos, tickOffset + thickness + 0.5,
514 pos, tickOffset + thickness + tickLength + 0.5));
515 }
516 } else {
517 if (ticks & QSlider::TicksAbove) {
518 lines.append(QLineF(tickOffset - 0.5, pos,
519 tickOffset - tickLength - 0.5, pos));
520 }
521
522 if (ticks & QSlider::TicksBelow) {
523 lines.append(QLineF(tickOffset + thickness + 0.5, pos,
524 tickOffset + thickness + tickLength + 0.5, pos));
525 }
526 }
527 // in the case where maximum is max int
528 int nextInterval = v + interval;
529 if (nextInterval < v)
530 break;
531 v = nextInterval;
532 }
533 if (!lines.isEmpty()) {
534 QPainterStateGuard psg(painter);
535 painter->translate(slrect.topLeft());
536 painter->drawLines(lines.constData(), lines.size());
537 }
538 }
539 if (sub & SC_SliderHandle) {
540 const qreal outerRadius = qMin(8.0, (isHorizontal ? handleRect.height() / 2.0 : handleRect.width() / 2.0) - 1);
541 float innerRadius = outerRadius * 0.43;
542
543 if (option->styleObject) {
544 const QNumberStyleAnimation* animation = qobject_cast<QNumberStyleAnimation *>(d->animation(option->styleObject));
545 if (animation != nullptr) {
546 innerRadius = animation->currentValue();
547 option->styleObject->setProperty("_q_inner_radius", innerRadius);
548 } else {
549 bool isInsideHandle = option->activeSubControls == SC_SliderHandle;
550 innerRadius = outerRadius * sliderInnerRadius(state, isInsideHandle);
551 }
552 }
553
554 painter->setPen(Qt::NoPen);
555 painter->setBrush(winUI3Color(controlFillSolid));
556 painter->drawEllipse(handleCenter, outerRadius, outerRadius);
557 painter->setBrush(calculateAccentColor(option));
558 painter->drawEllipse(handleCenter, innerRadius, innerRadius);
559
560 painter->setPen(winUI3Color(controlStrokeSecondary));
561 painter->setBrush(Qt::NoBrush);
562 painter->drawEllipse(handleCenter, outerRadius + 0.5, outerRadius + 0.5);
563 }
564 if (slider->state & State_HasFocus) {
565 QStyleOptionFocusRect fropt;
566 fropt.QStyleOption::operator=(*slider);
567 fropt.rect = subElementRect(SE_SliderFocusRect, slider, widget);
568 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
569 }
570 }
571 break;
572#endif
573#if QT_CONFIG(combobox)
574 case CC_ComboBox:
575 if (const QStyleOptionComboBox *combobox = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
576 const auto frameRect = QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
577 // State_On = combobox popup is open
578 const bool isPressed = option->state & QStyle::State_On;
579 QStyleOptionComboBox opt = *combobox;
580 opt.state.setFlag(QStyle::State_On, false);
581 drawRoundedRect(painter, frameRect, Qt::NoPen,
582 combobox->editable ? inputFillBrush(option, widget)
583 : controlFillBrush(&opt, ControlType::Control));
584
585 if (combobox->frame)
586 drawLineEditFrame(painter, frameRect, combobox, combobox->editable);
587
588 if (sub & SC_ComboBoxArrow) {
589 if (isPressed)
590 opt.state |= QStyle::State_Sunken;
591 QRectF rect = proxy()->subControlRect(CC_ComboBox, &opt, SC_ComboBoxArrow, widget);
592 if (isPressed) // move the arrow a little bit down
593 rect = rect.marginsRemoved(QMargins(0, 2, 0, 0));
594
595 const bool isEnabled = state.testFlag(QStyle::State_Enabled);
596 const bool isActive = combobox->activeSubControls.testFlag(SC_ComboBoxArrow);
597 if (combobox->editable && isEnabled && isActive)
598 drawRoundedRect(painter, rect.adjusted(1, 1, -1, -2), Qt::NoPen,
599 winUI3Color(subtleHighlightColor));
600
601 painter->setFont(d->m_assetFont);
602 painter->setPen(controlTextColor(&opt, true));
603 painter->drawText(rect, Qt::AlignCenter, fluentIcon(Icon::ChevronDownMed));
604 }
605 if (state & State_KeyboardFocusChange && state & State_HasFocus) {
606 QStyleOptionFocusRect fropt;
607 fropt.QStyleOption::operator=(*option);
608 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
609 }
610 }
611 break;
612#endif // QT_CONFIG(combobox)
613 case CC_ScrollBar:
614 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
615 const bool vertical = scrollbar->orientation == Qt::Vertical;
616 const bool isMouseOver = state & State_MouseOver;
617 const auto prx = proxy();
618
619 QPainterStateGuard psg(painter);
620
621 const auto anim = qobject_cast<QNumberStyleAnimation *>(d->animation(option->styleObject));
622 qreal widthFactor = isMouseOver ? 1.0 : 0.0;
623 if (anim)
624 widthFactor = anim->currentValue();
625
626 if (widthFactor > 0.6) {
627 const bool isRtl = option->direction == Qt::RightToLeft;
628
629 painter->setFont(d->assetFont(6));
630 painter->setPen(winUI3Color(controlStrongFill));
631
632 const QRectF rectAdd =
633 prx->subControlRect(CC_ScrollBar, option, SC_ScrollBarAddLine, widget);
634 const auto strAdd = vertical
635 ? Icon::CaretDownSolid8
636 : (isRtl ? Icon::CaretLeftSolid8 : Icon::CaretRightSolid8);
637 painter->drawText(rectAdd, Qt::AlignCenter, fluentIcon(strAdd));
638
639 const QRectF rectSub =
640 prx->subControlRect(CC_ScrollBar, option, SC_ScrollBarSubLine, widget);
641 const auto strSub = vertical
642 ? Icon::CaretUpSolid8
643 : (isRtl ? Icon::CaretRightSolid8 : Icon::CaretLeftSolid8);
644 painter->drawText(rectSub, Qt::AlignCenter, fluentIcon(strSub));
645 }
646 if (sub & SC_ScrollBarSlider) {
647 QRectF rect = prx->subControlRect(CC_ScrollBar, option, SC_ScrollBarSlider, widget);
648 const QPointF center = rect.center();
649 if (vertical) {
650 auto w = rect.width() / 2. * widthFactor;
651 if (w < 2)
652 w = 2;
653 const auto ofs = rect.width() / 2 - w;
654 rect.setWidth(w);
655 rect.moveCenter(QPointF(center.x() + ofs, center.y()));
656 }
657 else {
658 auto h = rect.height() / 2. * widthFactor;
659 if (h < 2)
660 h = 2;
661 const auto ofs = rect.height() / 2 - h;
662 rect.setHeight(h);
663 rect.moveCenter(QPointF(center.x(), center.y() + ofs));
664 }
665 drawRoundedRect(painter, rect, Qt::NoPen, winUI3Color(controlStrongFill), 3);
666 }
667 }
668 break;
669 case CC_MdiControls:{
670 painter->setFont(d->assetFont(8));
671 drawTitleBarCloseButton(CC_MdiControls, SC_MdiCloseButton, Icon::ChromeClose);
672 drawTitleBarButton(CC_MdiControls, SC_MdiNormalButton, Icon::ChromeRestore);
673 drawTitleBarButton(CC_MdiControls, SC_MdiMinButton, Icon::ChromeMinimize);
674 }
675 break;
676 case CC_TitleBar:
677 if (const auto* titlebar = qstyleoption_cast<const QStyleOptionTitleBar*>(option)) {
678 painter->setPen(Qt::NoPen);
679 painter->setPen(WINUI3Colors[colorSchemeIndex][surfaceStroke]);
680 painter->setBrush(titlebar->palette.button());
681 painter->drawRect(titlebar->rect);
682
683 // draw title
684 QRect textRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarLabel, widget);
685 QColor textColor = titlebar->palette.color(titlebar->titleBarState & Qt::WindowActive ? QPalette::Active : QPalette::Disabled,QPalette::WindowText);
686 painter->setPen(textColor);
687 // Note workspace also does elliding but it does not use the correct font
688 QString title = painter->fontMetrics().elidedText(titlebar->text, Qt::ElideRight, textRect.width() - 14);
689 painter->drawText(textRect.adjusted(1, 1, -1, -1), title, QTextOption(Qt::AlignHCenter | Qt::AlignVCenter));
690
691 painter->setFont(d->assetFont(8));
692 auto shouldDrawButton = [titlebar](SubControl sc, Qt::WindowType flag) {
693 return (titlebar->subControls & sc) && (titlebar->titleBarFlags & flag);
694 };
695
696 // min button
697 if (shouldDrawButton(SC_TitleBarMinButton, Qt::WindowMinimizeButtonHint) &&
698 !(titlebar->titleBarState & Qt::WindowMinimized)) {
699 drawTitleBarButton(CC_TitleBar, SC_TitleBarMinButton, Icon::ChromeMinimize);
700 }
701
702 // max button
703 if (shouldDrawButton(SC_TitleBarMaxButton, Qt::WindowMaximizeButtonHint) &&
704 !(titlebar->titleBarState & Qt::WindowMaximized)) {
705 drawTitleBarButton(CC_TitleBar, SC_TitleBarMaxButton, Icon::ChromeMaximize);
706 }
707
708 // close button
709 if (shouldDrawButton(SC_TitleBarCloseButton, Qt::WindowSystemMenuHint))
710 drawTitleBarCloseButton(CC_TitleBar, SC_TitleBarCloseButton, Icon::ChromeClose);
711
712 // normalize button
713 if ((titlebar->subControls & SC_TitleBarNormalButton) &&
714 (((titlebar->titleBarFlags & Qt::WindowMinimizeButtonHint) &&
715 (titlebar->titleBarState & Qt::WindowMinimized)) ||
716 ((titlebar->titleBarFlags & Qt::WindowMaximizeButtonHint) &&
717 (titlebar->titleBarState & Qt::WindowMaximized)))) {
718 drawTitleBarButton(CC_TitleBar, SC_TitleBarNormalButton, Icon::ChromeRestore);
719 }
720
721 // context help button
722 if (shouldDrawButton(SC_TitleBarContextHelpButton, Qt::WindowContextHelpButtonHint))
723 drawTitleBarButton(CC_TitleBar, SC_TitleBarContextHelpButton, Icon::Help);
724
725 // shade button
726 if (shouldDrawButton(SC_TitleBarShadeButton, Qt::WindowShadeButtonHint))
727 drawTitleBarButton(CC_TitleBar, SC_TitleBarShadeButton, Icon::ChevronUpSmall);
728
729 // unshade button
730 if (shouldDrawButton(SC_TitleBarUnshadeButton, Qt::WindowShadeButtonHint))
731 drawTitleBarButton(CC_TitleBar, SC_TitleBarUnshadeButton, Icon::ChevronDownSmall);
732
733 // window icon for system menu
734 if (shouldDrawButton(SC_TitleBarSysMenu, Qt::WindowSystemMenuHint)) {
735 const QRect iconRect = proxy()->subControlRect(CC_TitleBar, titlebar, SC_TitleBarSysMenu, widget);
736 if (iconRect.isValid()) {
737 if (!titlebar->icon.isNull()) {
738 titlebar->icon.paint(painter, iconRect);
739 } else {
740 QStyleOption tool = *titlebar;
741 const auto extent = proxy()->pixelMetric(PM_SmallIconSize, &tool, widget);
742 const auto dpr = QStyleHelper::getDpr(widget);
743 const auto icon = proxy()->standardIcon(SP_TitleBarMenuButton, &tool, widget);
744 const auto pm = icon.pixmap(QSize(extent, extent), dpr);
745 proxy()->drawItemPixmap(painter, iconRect, Qt::AlignCenter, pm);
746 }
747 }
748 }
749 }
750 break;
751#if QT_CONFIG(toolbutton)
752 case CC_ToolButton:
753 if (const auto toolbutton = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
754 auto prx = proxy();
755 const bool isSplitButton =
756 toolbutton->features.testFlag(QStyleOptionToolButton::MenuButtonPopup);
757 const auto fw = prx->pixelMetric(PM_DefaultFrameWidth, option, widget);
758 const auto buttonRect = prx->subControlRect(control, toolbutton, SC_ToolButton, widget);
759 const auto menuareaRect = isSplitButton
760 ? prx->subControlRect(control, toolbutton, SC_ToolButtonMenu, widget)
761 : QRect();
762
763 State bflags = toolbutton->state;
764 State mflags = toolbutton->state;
765 if (toolbutton->activeSubControls.testFlag(SC_ToolButton)) {
766 mflags &= ~(State_Sunken | State_MouseOver);
767 if (bflags.testFlag(State_Sunken))
768 mflags |= State_Raised;
769 }
770 if (toolbutton->activeSubControls.testFlag(SC_ToolButtonMenu)) {
771 bflags &= ~(State_Sunken | State_MouseOver);
772 if (mflags.testFlag(State_Sunken))
773 bflags |= State_Raised;
774 }
775
776 QStyleOption tool = *toolbutton;
777 if (toolbutton->subControls.testFlag(SC_ToolButton)) {
778 QPainterStateGuard psg(painter);
779 if (isSplitButton)
780 painter->setClipRect(buttonRect);
781 tool.state = bflags;
782 prx->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
783 if (isSplitButton) {
784 if (state.testFlag(State_Enabled)) {
785 painter->setPen(winUI3Color(controlStrokePrimary));
786 const auto top = buttonRect.topRight() + QPoint(0, fw + 1);
787 const auto btm = buttonRect.bottomRight() - QPoint(0, fw);
788 painter->drawLine(top, btm);
789 }
790 }
791 }
792
793 if (toolbutton->state.testFlag(State_HasFocus)) {
794 QStyleOptionFocusRect fr;
795 fr.QStyleOption::operator=(*toolbutton);
796 prx->drawPrimitive(PE_FrameFocusRect, &fr, painter, widget);
797 }
798 QStyleOptionToolButton label = *toolbutton;
799 label.state = bflags;
800 label.rect = buttonRect.marginsRemoved(QMargins(fw, fw, fw, fw));
801
802 if (toolbutton->subControls.testFlag(SC_ToolButtonMenu)) {
803 QPainterStateGuard psg(painter);
804 painter->setClipRect(menuareaRect);
805 tool.state = mflags;
806 prx->drawPrimitive(PE_PanelButtonTool, &tool, painter, widget);
807
808 const auto fontSize = QFontInfo(painter->font()).pointSizeF();
809 painter->setFont(d->assetFont(fontSize * 0.9f));
810 painter->setPen(controlTextColor(option));
811 const QRect textRect(menuareaRect.topLeft(), menuareaRect.size() - QSize(fw, 0));
812 painter->drawText(textRect, Qt::AlignCenter, fluentIcon(Icon::ChevronDownMed));
813
814 } else if (toolbutton->features.testFlag(QStyleOptionToolButton::HasMenu)) {
815 const int mbi = qRound(prx->pixelMetric(PM_MenuButtonIndicator, toolbutton, widget) * 0.3);
816 const QRect &ir = toolbutton->rect;
817 QRect rect(ir.right() - mbi - 2 * fw, ir.bottom() - mbi - fw, mbi,
818 mbi);
819 rect = visualRect(toolbutton->direction, buttonRect, rect);
820 const QRect lblRect = label.rect - QMargins(0, 0, rect.width(), 0);
821 label.rect = visualRect(toolbutton->direction, buttonRect, lblRect);
822 painter->setFont(d->m_assetFont);
823 painter->setPen(controlTextColor(option));
824 painter->drawText(rect, Qt::AlignCenter, fluentIcon(Icon::ChevronDownMed));
825 }
826 prx->drawControl(CE_ToolButtonLabel, &label, painter, widget);
827 }
828 break;
829#endif // QT_CONFIG(toolbutton)
830 default:
831 QWindowsVistaStyle::drawComplexControl(control, option, painter, widget);
832 }
833}
834
835void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption *option,
836 QPainter *painter,
837 const QWidget *widget) const {
838 QWindows11StylePrivate *d = const_cast<QWindows11StylePrivate*>(d_func());
839
840 const State state = option->state;
841 QPainterStateGuard psg(painter);
842 painter->setRenderHint(QPainter::Antialiasing);
843 if (d->transitionsEnabled() && option->styleObject && (element == PE_IndicatorCheckBox || element == PE_IndicatorRadioButton)) {
844 QObject *styleObject = option->styleObject; // Can be widget or qquickitem
845 int oldState = styleObject->property("_q_stylestate").toInt();
846 styleObject->setProperty("_q_stylestate", int(option->state));
847 styleObject->setProperty("_q_stylerect", option->rect);
848 bool doTransition = (((state & State_Sunken) != (oldState & State_Sunken)
849 || ((state & State_MouseOver) != (oldState & State_MouseOver))
850 || (state & State_On) != (oldState & State_On))
851 && state & State_Enabled);
852 if (doTransition) {
853 if (element == PE_IndicatorRadioButton) {
854 QNumberStyleAnimation *t = new QNumberStyleAnimation(styleObject);
855 t->setStartValue(styleObject->property("_q_inner_radius").toFloat());
856 t->setEndValue(radioButtonInnerRadius(state));
857 styleObject->setProperty("_q_end_radius", t->endValue());
858 t->setStartTime(d->animationTime());
859 t->setDuration(150);
860 d->startAnimation(t);
861 }
862 else if (element == PE_IndicatorCheckBox) {
863 if ((oldState & State_Off && state & State_On) || (oldState & State_NoChange && state & State_On)) {
864 QNumberStyleAnimation *t = new QNumberStyleAnimation(styleObject);
865 t->setStartValue(0.0f);
866 t->setEndValue(1.0f);
867 t->setStartTime(d->animationTime());
868 t->setDuration(150);
869 d->startAnimation(t);
870 }
871 }
872 }
873 }
874
875 switch (element) {
876 case PE_IndicatorArrowUp:
877 case PE_IndicatorArrowDown:
878 case PE_IndicatorArrowRight:
879 case PE_IndicatorArrowLeft: {
880 const QRect &r = option->rect;
881 if (r.width() <= 1 || r.height() <= 1)
882 break;
883 if (option->state.testFlag(State_Sunken)) {
884 const auto bsx = proxy()->pixelMetric(PM_ButtonShiftHorizontal, option, widget);
885 const auto bsy = proxy()->pixelMetric(PM_ButtonShiftVertical, option, widget);
886 if (bsx != 0 || bsy != 0)
887 painter->translate(bsx, bsy);
888 }
889 drawIndicatorArrow(painter, option->rect, element,
890 option->palette.color(QPalette::ButtonText));
891 break;
892 }
893 case PE_IndicatorTabClose: {
894 QBrush brush;
895 if (state & QStyle::State_MouseOver) {
896 QStyleOption tool = *option;
897 tool.state.setFlag(QStyle::State_AutoRaise, false);
898 brush = controlFillBrush(&tool, ControlType::ControlAlt);
899 }
900 drawRoundedRect(painter, option->rect, Qt::NoPen, brush);
901
902 const QIcon ico = proxy()->standardIcon(QStyle::SP_TabCloseButton, option, widget);
903 QIcon::Mode mode = QIcon::Disabled;
904 if (state.testFlags(State_Selected | State_Enabled))
905 mode = (state & State_Raised ? QIcon::Active : QIcon::Normal);
906 const QIcon::State iconState = state & State_Sunken ? QIcon::On : QIcon::Off;
907 ico.paint(painter, option->rect, Qt::AlignCenter, mode, iconState);
908 break;
909 }
910 case PE_FrameFocusRect: {
911 if (const QStyleOptionFocusRect *fropt = qstyleoption_cast<const QStyleOptionFocusRect *>(option)) {
912 if (!(fropt->state & State_KeyboardFocusChange))
913 break;
914 QRectF focusRect = option->rect;
915 focusRect = focusRect.marginsRemoved(QMarginsF(1.5,1.5,1.5,1.5));
916 painter->setPen(winUI3Color(focusFrameInnerStroke));
917 painter->drawRoundedRect(focusRect,4,4);
918
919 focusRect = focusRect.marginsAdded(QMarginsF(1.0,1.0,1.0,1.0));
920 painter->setPen(QPen(winUI3Color(focusFrameOuterStroke),1));
921 painter->drawRoundedRect(focusRect,4,4);
922 }
923 break;
924 }
925 case PE_PanelTipLabel: {
926 const auto rect = QRectF(option->rect).marginsRemoved(QMarginsF(0.5, 0.5, 0.5, 0.5));
927 const auto pen = highContrastTheme ? option->palette.buttonText().color()
928 : winUI3Color(frameColorLight);
929 drawRoundedRect(painter, rect, pen, option->palette.toolTipBase());
930 break;
931 }
932 case PE_FrameTabWidget:
933#if QT_CONFIG(tabwidget)
934 if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast<const QStyleOptionTabWidgetFrame *>(option)) {
935 const auto clipRegion = painter->clipRegion();
936
937 painter->setPen(highContrastTheme ? frame->palette.buttonText().color()
938 : winUI3Color(frameColorLight));
939 painter->setBrush(frame->palette.base());
940
941 const auto &rect = option->rect;
942 QRect upperRect = rect;
943 upperRect.setHeight(rect.height() / 2);
944 QRect lowerRect = rect;
945 lowerRect.setY(lowerRect.y() + rect.height() / 2);
946 painter->setClipRegion(clipRegion.isNull() ? upperRect : clipRegion & upperRect);
947 painter->drawRect(rect);
948 painter->setClipRegion(clipRegion.isNull() ? lowerRect : clipRegion & lowerRect);
949 painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
950
951 }
952#endif // QT_CONFIG(tabwidget)
953 break;
954 case PE_FrameGroupBox:
955 if (const QStyleOptionFrame *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
956 const auto pen = highContrastTheme ? frame->palette.buttonText().color()
957 : winUI3Color(frameColorStrong);
958 if (frame->features & QStyleOptionFrame::Flat) {
959 painter->setBrush(Qt::NoBrush);
960 painter->setPen(pen);
961 const QRect &fr = frame->rect;
962 QPoint p1(fr.x(), fr.y() + 1);
963 QPoint p2(fr.x() + fr.width(), p1.y());
964 painter->drawLine(p1, p2);
965 } else {
966 const auto frameRect = QRectF(frame->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
967 drawRoundedRect(painter, frameRect, pen, Qt::NoBrush);
968 }
969 }
970 break;
971 case PE_IndicatorHeaderArrow:
972 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
973 const auto indicator = header->sortIndicator;
974 if (indicator != QStyleOptionHeader::None) {
975 painter->setFont(d->assetFont(option->rect.height()));
976 painter->setPen(header->palette.text().color());
977 const auto ico = indicator == QStyleOptionHeader::SortUp ? Icon::ChevronDown
978 : Icon::ChevronUp;
979 painter->drawText(option->rect, Qt::AlignCenter, fluentIcon(ico));
980 }
981 }
982 break;
983 case PE_IndicatorCheckBox: {
984 const bool isOn = option->state & State_On;
985 const bool isPartial = option->state & State_NoChange;
986
987 const QRectF rect = option->rect;
988 const QPointF center = rect.center();
989
990 drawRoundedRect(painter, option->rect, borderPenControlAlt(option),
991 controlFillBrush(option, ControlType::ControlAlt));
992
993 if (isOn) {
994 painter->setFont(d->assetFont(8));
995 painter->setPen(controlTextColor(option));
996 const auto *animation =
997 qobject_cast<QNumberStyleAnimation *>(d->animation(option->styleObject));
998 const qreal clipWidth = animation ? animation->currentValue() : 1.0;
999 const QChar ico = fluentIcon(Icon::AcceptMedium);
1000 QFontMetrics fm(d->m_assetFont);
1001 QRectF clipRect = fm.boundingRect(ico);
1002 clipRect.moveCenter(center);
1003 clipRect.setLeft(rect.x() + (rect.width() - clipRect.width()) / 2.0 + 0.5);
1004 clipRect.setWidth(clipWidth * clipRect.width());
1005 painter->drawText(clipRect, Qt::AlignVCenter | Qt::AlignLeft, ico);
1006 } else if (isPartial) {
1007 painter->setFont(d->assetFont(6));
1008 painter->setPen(controlTextColor(option));
1009 painter->drawText(rect, Qt::AlignCenter, fluentIcon(Icon::Dash12));
1010 }
1011 }
1012 break;
1013 case PE_IndicatorBranch: {
1014 if (option->state & State_Children) {
1015 const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option);
1016 const bool isReverse = option->direction == Qt::RightToLeft;
1017 const bool isOpen = option->state & QStyle::State_Open;
1018 const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
1019 painter->setFont(d->assetFont(8));
1020 if (view && view->alternatingRowColors() && vopt && vopt->state & State_Selected)
1021 painter->setPen(winUI3Color(textOnAccentPrimary));
1022 else
1023 painter->setPen(option->palette.color(isOpen ? QPalette::Active : QPalette::Disabled,
1024 QPalette::WindowText));
1025 const auto ico = isOpen ? Icon::ChevronDownMed
1026 : (isReverse ? Icon::ChevronLeftMed
1027 : Icon::ChevronRightMed);
1028 painter->drawText(option->rect, Qt::AlignCenter, fluentIcon(ico));
1029 }
1030 }
1031 break;
1032 case PE_IndicatorRadioButton: {
1033 const auto *animation =
1034 qobject_cast<QNumberStyleAnimation *>(d->animation(option->styleObject));
1035 const qreal innerRadius =
1036 animation ? animation->currentValue() : radioButtonInnerRadius(state);
1037 const QRectF rect = option->rect;
1038 const QPointF center = rect.center();
1039
1040 if (option->styleObject)
1041 option->styleObject->setProperty("_q_inner_radius", innerRadius);
1042 painter->setPen(borderPenControlAlt(option));
1043 painter->setBrush(controlFillBrush(option, ControlType::ControlAlt));
1044 if (option->state.testFlag(State_On)) {
1045 QPainterPath path;
1046 path.addEllipse(center, 7.5, 7.5);
1047 path.addEllipse(center, innerRadius, innerRadius);
1048 painter->drawPath(path);
1049 // Text On Accent/Primary
1050 painter->setBrush(option->palette.window().color());
1051 painter->drawEllipse(center, innerRadius, innerRadius);
1052 } else {
1053 painter->drawEllipse(center, 7.5, 7.5);
1054 }
1055 }
1056 break;
1057 case PE_PanelButtonTool:
1058 case PE_PanelButtonBevel:{
1059 const bool isEnabled = state & QStyle::State_Enabled;
1060 const bool isMouseOver = state & QStyle::State_MouseOver;
1061 const bool isAutoRaise = state & QStyle::State_AutoRaise;
1062 const int fw = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
1063 const QRectF rect = option->rect.marginsRemoved(QMargins(fw, fw, fw, fw));
1064 if (element == PE_PanelButtonTool && ((!isMouseOver && isAutoRaise) || !isEnabled))
1065 painter->setPen(Qt::NoPen);
1066 else
1067 painter->setPen(winUI3Color(controlStrokePrimary));
1068 painter->setBrush(controlFillBrush(option, ControlType::Control));
1069 if (element == PE_PanelButtonTool && widget) {
1070 const auto name = widget->objectName();
1071 if (name == "ScrollLeftButton"_L1 || name == "ScrollRightButton"_L1) {
1072 painter->setPen(Qt::NoPen);
1073 if (isMouseOver)
1074 painter->setBrush(controlFillBrush(option, ControlType::ControlAlt));
1075 else
1076 painter->setBrush(Qt::NoBrush);
1077 }
1078 }
1079 painter->drawRoundedRect(rect,
1080 secondLevelRoundingRadius, secondLevelRoundingRadius);
1081 }
1082 break;
1083 case PE_FrameDefaultButton:
1084 painter->setPen(option->palette.accent().color());
1085 painter->setBrush(Qt::NoBrush);
1086 painter->drawRoundedRect(option->rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
1087 break;
1088 case PE_FrameMenu:
1089 break;
1090 case PE_PanelMenu: {
1091 if (!d->nativeRoundedTopLevelWindows) {
1092 const QRect rect = option->rect.marginsRemoved(QMargins(2, 2, 2, 2));
1093 painter->setPen(highContrastTheme ? QPen(option->palette.windowText().color(), 2)
1094 : winUI3Color(frameColorLight));
1095 painter->setBrush(winUI3Color(menuPanelFill));
1096 painter->drawRoundedRect(rect, topLevelRoundingRadius, topLevelRoundingRadius);
1097 }
1098 break;
1099 }
1100 case PE_PanelLineEdit:
1101 if (const auto *panel = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1102 const bool isInSpinBox =
1103 widget && qobject_cast<const QAbstractSpinBox *>(widget->parent()) != nullptr;
1104 const bool isInComboBox =
1105 widget && qobject_cast<const QComboBox *>(widget->parent()) != nullptr;
1106 if (!isInSpinBox && !isInComboBox) {
1107 const auto frameRect =
1108 QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
1109 drawRoundedRect(painter, frameRect, Qt::NoPen, inputFillBrush(option, widget));
1110 if (panel->lineWidth > 0)
1111 proxy()->drawPrimitive(PE_FrameLineEdit, panel, painter, widget);
1112 }
1113 }
1114 break;
1115 case PE_FrameLineEdit: {
1116 const auto frameRect = QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
1117 drawLineEditFrame(painter, frameRect, option);
1118 if (state & State_KeyboardFocusChange && state & State_HasFocus) {
1119 QStyleOptionFocusRect fropt;
1120 fropt.QStyleOption::operator=(*option);
1121 proxy()->drawPrimitive(PE_FrameFocusRect, &fropt, painter, widget);
1122 }
1123 break;
1124 }
1125 case PE_Frame: {
1126 if (const auto *frame = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1127 const auto rect = QRectF(option->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
1128 if (qobject_cast<const QComboBoxPrivateContainer *>(widget)) {
1129 if (d->nativeRoundedTopLevelWindows)
1130 break;
1131 QPen pen;
1132 if (highContrastTheme)
1133 pen = QPen(option->palette.windowText().color(), 2);
1134 else
1135 pen = Qt::NoPen;
1136 drawRoundedRect(painter, rect, pen, winUI3Color(menuPanelFill));
1137 } else if (qobject_cast<const QTextEdit *>(widget)
1138 || qobject_cast<const QPlainTextEdit *>(widget)) {
1139 drawRoundedRect(painter, rect, Qt::NoPen, inputFillBrush(option, widget));
1140 }
1141
1142 if (frame->frameShape == QFrame::NoFrame)
1143 break;
1144
1145 const bool isEditable = qobject_cast<const QTextEdit *>(widget) != nullptr
1146 || qobject_cast<const QPlainTextEdit *>(widget) != nullptr;
1147 drawLineEditFrame(painter, rect, option, isEditable);
1148 }
1149 break;
1150 }
1151 case PE_PanelItemViewItem:
1152 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
1153 if (vopt->backgroundBrush.style() != Qt::NoBrush) {
1154 painter->setBrushOrigin(vopt->rect.topLeft());
1155 painter->fillRect(vopt->rect, vopt->backgroundBrush);
1156 }
1157 }
1158 break;
1159 case PE_PanelItemViewRow:
1160 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
1161 const QRect &rect = vopt->rect;
1162 const bool isRtl = option->direction == Qt::RightToLeft;
1163 if (rect.width() <= 0)
1164 break;
1165
1166 if (vopt->features & QStyleOptionViewItem::Alternate) {
1167 QPalette::ColorGroup cg =
1168 (widget ? widget->isEnabled() : (vopt->state & QStyle::State_Enabled))
1169 ? QPalette::Normal
1170 : QPalette::Disabled;
1171 if (cg == QPalette::Normal && !(vopt->state & QStyle::State_Active))
1172 cg = QPalette::Inactive;
1173 painter->fillRect(rect, option->palette.brush(cg, QPalette::AlternateBase));
1174 }
1175
1176 if (option->state & State_Selected && !highContrastTheme) {
1177 // keep in sync with CE_ItemViewItem QListView indicator painting
1178 const auto col = option->palette.accent().color();
1179 painter->setBrush(col);
1180 painter->setPen(col);
1181 const auto xPos = isRtl ? rect.right() - 4.5f : rect.left() + 3.5f;
1182 const auto yOfs = rect.height() / 4.;
1183 QRectF r(QPointF(xPos, rect.y() + yOfs),
1184 QPointF(xPos + 1, rect.y() + rect.height() - yOfs));
1185 painter->drawRoundedRect(r, 1, 1);
1186 }
1187
1188 const bool isTreeDecoration = vopt->features.testFlag(
1189 QStyleOptionViewItem::IsDecorationForRootColumn);
1190 if (isTreeDecoration && vopt->state.testAnyFlags(State_Selected | State_MouseOver) &&
1191 vopt->showDecorationSelected) {
1192 const bool onlyOne = vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne ||
1193 vopt->viewItemPosition == QStyleOptionViewItem::Invalid;
1194 bool isFirst = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
1195 bool isLast = vopt->viewItemPosition == QStyleOptionViewItem::End;
1196
1197 if (onlyOne)
1198 isFirst = true;
1199
1200 if (isRtl) {
1201 isFirst = !isFirst;
1202 isLast = !isLast;
1203 }
1204
1205 const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
1206 painter->setBrush(view->alternatingRowColors() && state & State_Selected ? calculateAccentColor(option) : WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
1207 painter->setPen(Qt::NoPen);
1208 if (isFirst) {
1209 painter->setClipRect(rect);
1210 painter->drawRoundedRect(rect.marginsRemoved(QMargins(2, 2, -secondLevelRoundingRadius, 2)),
1211 secondLevelRoundingRadius, secondLevelRoundingRadius);
1212 } else if (isLast) {
1213 painter->setClipRect(rect);
1214 painter->drawRoundedRect(rect.marginsRemoved(QMargins(-secondLevelRoundingRadius, 2, 2, 2)),
1215 secondLevelRoundingRadius, secondLevelRoundingRadius);
1216 } else {
1217 painter->drawRect(vopt->rect.marginsRemoved(QMargins(0, 2, 0, 2)));
1218 }
1219 }
1220 }
1221 break;
1222 case PE_Widget:
1223 break;
1224 case QStyle::PE_FrameWindow:
1225 if (const auto *frm = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1226
1227 QRectF rect= option->rect;
1228 int fwidth = int((frm->lineWidth + frm->midLineWidth) / QWindowsStylePrivate::nativeMetricScaleFactor(widget));
1229
1230 QRectF bottomLeftCorner = QRectF(rect.left() + 1.0,
1231 rect.bottom() - 1.0 - secondLevelRoundingRadius,
1232 secondLevelRoundingRadius,
1233 secondLevelRoundingRadius);
1234 QRectF bottomRightCorner = QRectF(rect.right() - 1.0 - secondLevelRoundingRadius,
1235 rect.bottom() - 1.0 - secondLevelRoundingRadius,
1236 secondLevelRoundingRadius,
1237 secondLevelRoundingRadius);
1238
1239 //Draw Mask
1240 if (widget != nullptr) {
1241 QBitmap mask(widget->width(), widget->height());
1242 mask.clear();
1243
1244 QPainter maskPainter(&mask);
1245 maskPainter.setRenderHint(QPainter::Antialiasing);
1246 maskPainter.setBrush(Qt::color1);
1247 maskPainter.setPen(Qt::NoPen);
1248 maskPainter.drawRoundedRect(option->rect,secondLevelRoundingRadius,secondLevelRoundingRadius);
1249 const_cast<QWidget*>(widget)->setMask(mask);
1250 }
1251
1252 //Draw Window
1253 painter->setPen(QPen(frm->palette.base(), fwidth));
1254 painter->drawLine(QPointF(rect.left(), rect.top()),
1255 QPointF(rect.left(), rect.bottom() - fwidth));
1256 painter->drawLine(QPointF(rect.left() + fwidth, rect.bottom()),
1257 QPointF(rect.right() - fwidth, rect.bottom()));
1258 painter->drawLine(QPointF(rect.right(), rect.top()),
1259 QPointF(rect.right(), rect.bottom() - fwidth));
1260
1261 painter->setPen(WINUI3Colors[colorSchemeIndex][surfaceStroke]);
1262 painter->drawLine(QPointF(rect.left() + 0.5, rect.top() + 0.5),
1263 QPointF(rect.left() + 0.5, rect.bottom() - 0.5 - secondLevelRoundingRadius));
1264 painter->drawLine(QPointF(rect.left() + 0.5 + secondLevelRoundingRadius, rect.bottom() - 0.5),
1265 QPointF(rect.right() - 0.5 - secondLevelRoundingRadius, rect.bottom() - 0.5));
1266 painter->drawLine(QPointF(rect.right() - 0.5, rect.top() + 1.5),
1267 QPointF(rect.right() - 0.5, rect.bottom() - 0.5 - secondLevelRoundingRadius));
1268
1269 painter->setPen(Qt::NoPen);
1270 painter->setBrush(frm->palette.base());
1271 painter->drawPie(bottomRightCorner.marginsAdded(QMarginsF(2.5,2.5,0.0,0.0)),
1272 270 * 16,90 * 16);
1273 painter->drawPie(bottomLeftCorner.marginsAdded(QMarginsF(0.0,2.5,2.5,0.0)),
1274 -90 * 16,-90 * 16);
1275
1276 painter->setPen(WINUI3Colors[colorSchemeIndex][surfaceStroke]);
1277 painter->setBrush(Qt::NoBrush);
1278 painter->drawArc(bottomRightCorner,
1279 0 * 16,-90 * 16);
1280 painter->drawArc(bottomLeftCorner,
1281 -90 * 16,-90 * 16);
1282 }
1283 break;
1284#if QT_CONFIG(tabbar)
1285 case PE_FrameTabBarBase:
1286 if (const auto *tab = qstyleoption_cast<const QStyleOptionTabBarBase *>(option)) {
1287 const auto clipRegion = painter->clipRegion();
1288
1289 painter->setPen(highContrastTheme ? tab->palette.buttonText().color()
1290 : winUI3Color(frameColorLight));
1291 painter->setBrush(tab->palette.base());
1292 QRect upperRect = tab->rect;
1293 upperRect.setHeight(tab->rect.height() / 2);
1294 QRect lowerRect = tab->rect;
1295 lowerRect.setY(lowerRect.y() + tab->rect.height() / 2);
1296 painter->setClipRegion(clipRegion.isNull() ? upperRect : clipRegion & upperRect);
1297 painter->drawRoundedRect(tab->rect, secondLevelRoundingRadius,
1298 secondLevelRoundingRadius);
1299 painter->setClipRegion(clipRegion.isNull() ? lowerRect : clipRegion & lowerRect);
1300 painter->drawRect(tab->rect);
1301 }
1302 break;
1303#endif // QT_CONFIG(tabbar)
1304 case PE_IndicatorTabTearLeft:
1305 case PE_IndicatorTabTearRight:
1306 break;
1307 default:
1308 QWindowsVistaStyle::drawPrimitive(element, option, painter, widget);
1309 }
1310}
1311
1312/*!
1313 \internal
1314*/
1315void QWindows11Style::drawControl(ControlElement element, const QStyleOption *option,
1316 QPainter *painter, const QWidget *widget) const
1317{
1318 Q_D(const QWindows11Style);
1319
1320 QPainterStateGuard psg(painter);
1321 painter->setRenderHint(QPainter::Antialiasing);
1322 switch (element) {
1323 case QStyle::CE_ComboBoxLabel:
1324#if QT_CONFIG(combobox)
1325 if (const QStyleOptionComboBox *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
1326 QStyleOptionComboBox newOption = *cb;
1327 // State_On = combobox popup is open
1328 if (option->state & QStyle::State_On)
1329 newOption.state |= QStyle::State_Sunken;
1330 painter->setPen(controlTextColor(&newOption, true));
1331 newOption.rect.adjust(4,0,-4,0);
1332 QCommonStyle::drawControl(element, &newOption, painter, widget);
1333 }
1334#endif // QT_CONFIG(combobox)
1335 break;
1336#if QT_CONFIG(tabbar)
1337 case CE_TabBarTabShape:
1338 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
1339 const bool isSelected = tab->state.testFlag(State_Selected);
1340 const auto clipRegion = painter->clipRegion();
1341 const bool onlyOne = tab->position == QStyleOptionTab::OnlyOneTab
1342 || tab->position == QStyleOptionTab::Moving;
1343 auto leftMargin = (tab->position == QStyleOptionTab::Beginning || onlyOne) ? 1 : 0;
1344 auto rightMargin = (tab->position == QStyleOptionTab::End || onlyOne) ? 1 : 0;
1345 if (QCommonStylePrivate::rtl(option))
1346 std::swap(leftMargin, rightMargin);
1347
1348 QRectF tabRect = tab->rect.marginsRemoved(QMargins(leftMargin, 0, rightMargin, -3));
1349 painter->setPen(highContrastTheme ? tab->palette.buttonText().color() : winUI3Color(frameColorLight));
1350 painter->setBrush(tab->palette.base());
1351 if (isSelected) {
1352 painter->setBrush(winUI3Color(fillMicaAltDefault));
1353 } else {
1354 if (tab->state.testFlag(State_Sunken))
1355 painter->setBrush(winUI3Color(fillMicaAltDefault));
1356 else if (tab->state.testFlag(State_MouseOver))
1357 painter->setBrush(winUI3Color(fillMicaAltSecondary));
1358 else
1359 painter->setBrush(winUI3Color(fillMicaAltTransparent));
1360 }
1361 QRect upperRect = tab->rect;
1362 upperRect.setHeight(tab->rect.height() / 2.);
1363 QRect lowerRect = tab->rect;
1364 lowerRect.setY(lowerRect.y() + tab->rect.height() / 2.);
1365 painter->setClipRegion(clipRegion.isNull() ? upperRect : clipRegion & upperRect);
1366 painter->drawRoundedRect(tabRect, secondLevelRoundingRadius, secondLevelRoundingRadius);
1367 painter->setClipRegion(clipRegion.isNull() ? lowerRect : clipRegion & lowerRect);
1368 painter->drawRect(tabRect);
1369 }
1370 break;
1371 case CE_TabBarTabLabel:
1372 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
1373 const bool isEnabled = tab->state.testFlags(State_Enabled);
1374 const bool isSelected = tab->state.testFlags(State_Selected);
1375
1376 QRect tr = tab->rect;
1377 bool verticalTabs = tab->shape == QTabBar::RoundedEast
1378 || tab->shape == QTabBar::RoundedWest || tab->shape == QTabBar::TriangularEast
1379 || tab->shape == QTabBar::TriangularWest;
1380
1381 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1382 if (!proxy()->styleHint(SH_UnderlineShortcut, option, widget))
1383 alignment |= Qt::TextHideMnemonic;
1384
1385 if (verticalTabs) {
1386 int newX, newY, newRot;
1387 if (tab->shape == QTabBar::RoundedEast || tab->shape == QTabBar::TriangularEast) {
1388 newX = tr.width() + tr.x();
1389 newY = tr.y();
1390 newRot = 90;
1391 } else {
1392 newX = tr.x();
1393 newY = tr.y() + tr.height();
1394 newRot = -90;
1395 }
1396 QTransform m = QTransform::fromTranslate(newX, newY);
1397 m.rotate(newRot);
1398 painter->setTransform(m, true);
1399 }
1400 QRect iconRect;
1401 d->tabLayout(tab, widget, &tr, &iconRect);
1402
1403 // compute tr again, unless tab is moving, because the style may override subElementRect
1404 if (tab->position != QStyleOptionTab::TabPosition::Moving)
1405 tr = proxy()->subElementRect(SE_TabBarTabText, option, widget);
1406
1407 if (!tab->icon.isNull()) {
1408 const auto mode = isEnabled ? QIcon::Normal : QIcon::Disabled;
1409 const auto state = isSelected ? QIcon::On : QIcon::Off;
1410 tab->icon.paint(painter, iconRect, Qt::AlignCenter, mode, state);
1411 }
1412
1413 const auto textRole = widget ? widget->foregroundRole() : QPalette::WindowText;
1414
1415 if (tab->palette.isBrushSet(QPalette::Current, textRole)) {
1416 painter->setPen(tab->palette.color(QPalette::Current, textRole));
1417 } else {
1418 painter->setPen(winUI3Color(isEnabled ? (isSelected ? textPrimary : textSecondary)
1419 : textDisabled));
1420 }
1421 proxy()->drawItemText(painter, tr, alignment, tab->palette, isEnabled, tab->text);
1422 }
1423 break;
1424#endif // QT_CONFIG(tabbar)
1425 case CE_ToolButtonLabel:
1426#if QT_CONFIG(toolbutton)
1427 if (const QStyleOptionToolButton *toolbutton
1428 = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
1429 QRect rect = toolbutton->rect;
1430 int shiftX = 0;
1431 int shiftY = 0;
1432 if (toolbutton->state & (State_Sunken | State_On)) {
1433 shiftX = proxy()->pixelMetric(PM_ButtonShiftHorizontal, toolbutton, widget);
1434 shiftY = proxy()->pixelMetric(PM_ButtonShiftVertical, toolbutton, widget);
1435 }
1436 // Arrow type always overrules and is always shown
1437 bool hasArrow = toolbutton->features & QStyleOptionToolButton::Arrow;
1438 if (((!hasArrow && toolbutton->icon.isNull()) && !toolbutton->text.isEmpty())
1439 || toolbutton->toolButtonStyle == Qt::ToolButtonTextOnly) {
1440 int alignment = Qt::AlignCenter | Qt::TextShowMnemonic;
1441 if (!proxy()->styleHint(SH_UnderlineShortcut, toolbutton, widget))
1442 alignment |= Qt::TextHideMnemonic;
1443 rect.translate(shiftX, shiftY);
1444 painter->setFont(toolbutton->font);
1445 const QString text = d->toolButtonElideText(toolbutton, rect, alignment);
1446 painter->setPen(controlTextColor(option));
1447 proxy()->drawItemText(painter, rect, alignment, toolbutton->palette,
1448 toolbutton->state & State_Enabled, text);
1449 } else {
1450 QPixmap pm;
1451 QSize pmSize = toolbutton->iconSize;
1452 if (!toolbutton->icon.isNull()) {
1453 QIcon::State state = toolbutton->state & State_On ? QIcon::On : QIcon::Off;
1454 QIcon::Mode mode;
1455 if (!(toolbutton->state & State_Enabled))
1456 mode = QIcon::Disabled;
1457 else if ((toolbutton->state & State_MouseOver) && (toolbutton->state & State_AutoRaise))
1458 mode = QIcon::Active;
1459 else
1460 mode = QIcon::Normal;
1461 pm = toolbutton->icon.pixmap(toolbutton->rect.size().boundedTo(toolbutton->iconSize), painter->device()->devicePixelRatio(),
1462 mode, state);
1463 pmSize = pm.size() / pm.devicePixelRatio();
1464 }
1465
1466 if (toolbutton->toolButtonStyle != Qt::ToolButtonIconOnly) {
1467 painter->setFont(toolbutton->font);
1468 QRect pr = rect,
1469 tr = rect;
1470 int alignment = Qt::TextShowMnemonic | Qt::AlignCenter;
1471 if (!proxy()->styleHint(SH_UnderlineShortcut, toolbutton, widget))
1472 alignment |= Qt::TextHideMnemonic;
1473
1474 if (toolbutton->toolButtonStyle == Qt::ToolButtonTextUnderIcon) {
1475 pr.setHeight(pmSize.height() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
1476 tr.adjust(0, pr.height() - 1, 0, -1);
1477 } else {
1478 pr.setWidth(pmSize.width() + 4); //### 4 is currently hardcoded in QToolButton::sizeHint()
1479 tr.adjust(pr.width(), 0, 0, 0);
1480 }
1481 pr.translate(shiftX, shiftY);
1482 if (hasArrow) {
1483 drawIndicatorArrow(painter, pr, toolbutton, widget);
1484 } else {
1485 const auto vr = QStyle::visualRect(toolbutton->direction, rect, pr);
1486 proxy()->drawItemPixmap(painter, vr, Qt::AlignCenter, pm);
1487 }
1488 tr.translate(shiftX, shiftY);
1489 painter->setPen(controlTextColor(option));
1490 const QString text = d->toolButtonElideText(toolbutton, tr, alignment);
1491 const auto vr = QStyle::visualRect(toolbutton->direction, rect, tr);
1492 proxy()->drawItemText(painter, vr, alignment, toolbutton->palette,
1493 toolbutton->state & State_Enabled, text);
1494 } else {
1495 rect.translate(shiftX, shiftY);
1496 if (hasArrow)
1497 drawIndicatorArrow(painter, rect, toolbutton, widget);
1498 else
1499 proxy()->drawItemPixmap(painter, rect, Qt::AlignCenter, pm);
1500 }
1501 }
1502 }
1503#endif // QT_CONFIG(toolbutton)
1504 break;
1505 case QStyle::CE_ShapedFrame:
1506 if (const QStyleOptionFrame *f = qstyleoption_cast<const QStyleOptionFrame *>(option)) {
1507 int frameShape = f->frameShape;
1508 int frameShadow = QFrame::Plain;
1509 if (f->state & QStyle::State_Sunken)
1510 frameShadow = QFrame::Sunken;
1511 else if (f->state & QStyle::State_Raised)
1512 frameShadow = QFrame::Raised;
1513
1514 int lw = f->lineWidth;
1515 int mlw = f->midLineWidth;
1516
1517 switch (frameShape) {
1518 case QFrame::Box:
1519 if (frameShadow == QFrame::Plain)
1520 qDrawPlainRoundedRect(painter, f->rect, secondLevelRoundingRadius, secondLevelRoundingRadius, highContrastTheme == true ? f->palette.buttonText().color() : WINUI3Colors[colorSchemeIndex][frameColorStrong], lw);
1521 else
1522 qDrawShadeRect(painter, f->rect, f->palette, frameShadow == QFrame::Sunken, lw, mlw);
1523 break;
1524 case QFrame::Panel:
1525 if (frameShadow == QFrame::Plain)
1526 qDrawPlainRoundedRect(painter, f->rect, secondLevelRoundingRadius, secondLevelRoundingRadius, highContrastTheme == true ? f->palette.buttonText().color() : WINUI3Colors[colorSchemeIndex][frameColorStrong], lw);
1527 else
1528 qDrawShadePanel(painter, f->rect, f->palette, frameShadow == QFrame::Sunken, lw);
1529 break;
1530 default:
1531 QWindowsVistaStyle::drawControl(element, option, painter, widget);
1532 }
1533 }
1534 break;
1535#if QT_CONFIG(progressbar)
1536 case CE_ProgressBarGroove:
1537 if (const auto baropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
1538 QRect rect = option->rect;
1539 QPointF center = rect.center();
1540 if (baropt->state & QStyle::State_Horizontal) {
1541 rect.setHeight(1);
1542 rect.moveTop(center.y());
1543 } else {
1544 rect.setWidth(1);
1545 rect.moveLeft(center.x());
1546 }
1547 painter->setPen(Qt::NoPen);
1548 painter->setBrush(Qt::gray);
1549 painter->drawRect(rect);
1550 }
1551 break;
1552 case CE_ProgressBarContents:
1553 if (const auto baropt = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
1554 QRectF rect = option->rect;
1555 painter->translate(rect.topLeft());
1556 rect.translate(-rect.topLeft());
1557
1558 constexpr qreal progressBarThickness = 3;
1559 constexpr qreal progressBarHalfThickness = progressBarThickness / 2.0;
1560
1561 const auto isIndeterminate = baropt->maximum == 0 && baropt->minimum == 0;
1562 const auto orientation =
1563 (baropt->state & QStyle::State_Horizontal) ? Qt::Horizontal : Qt::Vertical;
1564 const auto inverted = baropt->invertedAppearance;
1565 const auto reverse = (baropt->direction == Qt::RightToLeft) ^ inverted;
1566 // If the orientation is vertical, we use a transform to rotate
1567 // the progress bar 90 degrees (counter)clockwise. This way we can use the
1568 // same rendering code for both orientations.
1569 if (orientation == Qt::Vertical) {
1570 rect = QRectF(rect.left(), rect.top(), rect.height(),
1571 rect.width()); // flip width and height
1572 QTransform m;
1573 if (inverted) {
1574 m.rotate(90);
1575 m.translate(0, -rect.height() + 1);
1576 } else {
1577 m.rotate(-90);
1578 m.translate(-rect.width(), 0);
1579 }
1580 painter->setTransform(m, true);
1581 } else if (reverse) {
1582 QTransform m = QTransform::fromScale(-1, 1);
1583 m.translate(-rect.width(), 0);
1584 painter->setTransform(m, true);
1585 }
1586 const qreal offset = (int(rect.height()) % 2 == 0) ? 0.5f : 0.0f;
1587
1588 if (isIndeterminate) {
1589#if QT_CONFIG(animation)
1590 auto anim = d->animation(option->styleObject);
1591 if (!anim) {
1592 auto anim = new QStyleAnimation(option->styleObject);
1593 anim->setFrameRate(QStyleAnimation::SixtyFps);
1594 d->startAnimation(anim);
1595 }
1596 constexpr auto loopDurationMSec = 4000;
1597 const auto elapsedTime = std::chrono::time_point_cast<std::chrono::milliseconds>(
1598 std::chrono::system_clock::now());
1599 const auto elapsed = elapsedTime.time_since_epoch().count();
1600 const auto handleCenter = (elapsed % loopDurationMSec) / float(loopDurationMSec);
1601 const auto isLongHandle = (elapsed / loopDurationMSec) % 2 == 0;
1602 const auto lengthFactor = (isLongHandle ? 33.0f : 25.0f) / 100.0f;
1603#else
1604 constexpr auto handleCenter = 0.5f;
1605 constexpr auto lengthFactor = 1;
1606#endif
1607 const auto begin = qMax(handleCenter * (1 + lengthFactor) - lengthFactor, 0.0f);
1608 const auto end = qMin(handleCenter * (1 + lengthFactor), 1.0f);
1609 const auto barBegin = begin * rect.width();
1610 const auto barEnd = end * rect.width();
1611 rect = QRectF(QPointF(rect.left() + barBegin, rect.top()),
1612 QPointF(rect.left() + barEnd, rect.bottom()));
1613 } else {
1614#if QT_CONFIG(animation)
1615 d->stopAnimation(option->styleObject);
1616#endif
1617 const auto fillPercentage = (float(baropt->progress - baropt->minimum))
1618 / (float(baropt->maximum - baropt->minimum));
1619 rect.setWidth(rect.width() * fillPercentage);
1620 }
1621 const QPointF center = rect.center();
1622 rect.setHeight(progressBarThickness);
1623 rect.moveTop(center.y() - progressBarHalfThickness - offset);
1624 drawRoundedRect(painter, rect, Qt::NoPen, baropt->palette.accent());
1625 }
1626 break;
1627 case CE_ProgressBarLabel:
1628 if (const auto baropt = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
1629 const bool vertical = !(baropt->state & QStyle::State_Horizontal);
1630 if (!vertical) {
1631 proxy()->drawItemText(painter, baropt->rect, Qt::AlignCenter | Qt::TextSingleLine,
1632 baropt->palette, baropt->state & State_Enabled, baropt->text,
1633 QPalette::Text);
1634 }
1635 }
1636 break;
1637#endif // QT_CONFIG(progressbar)
1638 case CE_PushButtonLabel:
1639 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1640 QStyleOptionButton btnCopy(*btn);
1641 btnCopy.rect = btn->rect.marginsRemoved(QMargins(contentHMargin, 0, contentHMargin, 0));
1642 btnCopy.palette.setBrush(QPalette::ButtonText, controlTextColor(option));
1643 QCommonStyle::drawControl(element, &btnCopy, painter, widget);
1644 }
1645 break;
1646 case CE_PushButtonBevel:
1647 if (const QStyleOptionButton *btn = qstyleoption_cast<const QStyleOptionButton *>(option)) {
1648 using namespace StyleOptionHelper;
1649
1650 const auto rect = QRectF(btn->rect).marginsRemoved(QMarginsF(1.5, 1.5, 1.5, 1.5));
1651 if (btn->features.testFlag(QStyleOptionButton::Flat)) {
1652 const QBrush brush = isPressed(option)
1653 ? winUI3Color(subtlePressedColor)
1654 : (isHover(option) ? winUI3Color(subtleHighlightColor) : Qt::transparent);
1655 drawRoundedRect(painter, rect, Qt::NoPen, brush);
1656 } else {
1657 const bool defaultButton = btn->features.testFlag(QStyleOptionButton::DefaultButton);
1658 const QPen pen = defaultButton ? option->palette.color(QPalette::Accent)
1659 : winUI3Color(controlStrokePrimary);
1660 drawRoundedRect(painter, rect, pen, controlFillBrush(option, ControlType::Control));
1661 }
1662 if (btn->features.testFlag(QStyleOptionButton::HasMenu)) {
1663 QRect textRect = btn->rect.marginsRemoved(QMargins(contentHMargin, 0, contentHMargin, 0));
1664 const auto indSize = proxy()->pixelMetric(PM_MenuButtonIndicator, btn, widget);
1665 const auto indRect =
1666 QRect(btn->rect.right() - indSize - contentItemHMargin, textRect.top(),
1667 indSize + contentItemHMargin, btn->rect.height());
1668 const auto vindRect = visualRect(btn->direction, btn->rect, indRect);
1669 textRect.setWidth(textRect.width() - indSize);
1670
1671 const auto fontSize = QFontInfo(painter->font()).pointSizeF();
1672 painter->setFont(d->assetFont(fontSize * 0.9f));
1673 painter->setPen(controlTextColor(option));
1674 painter->drawText(vindRect, Qt::AlignCenter, fluentIcon(Icon::ChevronDownMed));
1675 }
1676 }
1677 break;
1678 case CE_MenuBarItem:
1679 if (const auto *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
1680 using namespace StyleOptionHelper;
1681
1682 constexpr int hPadding = 11;
1683 constexpr int topPadding = 4;
1684 constexpr int bottomPadding = 6;
1685 QStyleOptionMenuItem newMbi = *mbi;
1686
1687 if (auto mbiV2 = qstyleoption_cast<const QStyleOptionMenuItemV2 *>(option))
1688 newMbi.state.setFlag(State_Sunken, mbiV2->mouseDown);
1689
1690 newMbi.font.setPointSize(10);
1691 newMbi.palette.setColor(QPalette::ButtonText, controlTextColor(&newMbi));
1692 if (!isDisabled(&newMbi)) {
1693 QPen pen(Qt::NoPen);
1694 QBrush brush(Qt::NoBrush);
1695 if (highContrastTheme) {
1696 pen = QPen(newMbi.palette.highlight().color(), 2);
1697 brush = newMbi.palette.window();
1698 } else if (isPressed(&newMbi)) {
1699 brush = winUI3Color(subtlePressedColor);
1700 } else if (isHover(&newMbi)) {
1701 brush = winUI3Color(subtleHighlightColor);
1702 }
1703 if (pen != Qt::NoPen || brush != Qt::NoBrush) {
1704 const QRect rect = mbi->rect.marginsRemoved(QMargins(5, 0, 5, 0));
1705 drawRoundedRect(painter, rect, pen, brush);
1706 }
1707 }
1708 newMbi.rect.adjust(hPadding,topPadding,-hPadding,-bottomPadding);
1709 painter->setFont(newMbi.font);
1710 QCommonStyle::drawControl(element, &newMbi, painter, widget);
1711 }
1712 break;
1713
1714#if QT_CONFIG(menu)
1715 case CE_MenuEmptyArea:
1716 break;
1717
1718 case CE_MenuItem:
1719 if (const auto *menuitem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
1720 using namespace StyleOptionHelper;
1721
1722 const auto visualMenuRect = [&](const QRect &rect) {
1723 return visualRect(option->direction, menuitem->rect, rect);
1724 };
1725
1726 const bool checked =
1727 menuitem->checkType != QStyleOptionMenuItem::NotCheckable && menuitem->checked;
1728
1729 const QRect rect = menuitem->rect.marginsRemoved(QMargins(2,2,2,2));
1730 if (!isDisabled(menuitem)) {
1731 QPen pen(Qt::NoPen);
1732 QBrush brush(Qt::NoBrush);
1733 if (highContrastTheme) {
1734 pen = QPen(menuitem->palette.highlight().color(), 2);
1735 brush = menuitem->palette.window();
1736 } else if (isPressed(menuitem)) {
1737 brush = winUI3Color(subtlePressedColor);
1738 } else if (isSelected(menuitem)) { // == hover
1739 brush = winUI3Color(subtleHighlightColor);
1740 }
1741 if (pen != Qt::NoPen || brush != Qt::NoBrush)
1742 drawRoundedRect(painter, rect, pen, brush);
1743 }
1744 if (menuitem->menuItemType == QStyleOptionMenuItem::Separator) {
1745 constexpr int yoff = 1;
1746 painter->setPen(highContrastTheme ? menuitem->palette.buttonText().color() : winUI3Color(dividerStrokeDefault));
1747 painter->drawLine(menuitem->rect.topLeft() + QPoint(0, yoff),
1748 menuitem->rect.topRight() + QPoint(0, yoff));
1749 break;
1750 }
1751
1752 int xOffset = contentHMargin;
1753 // WinUI3 draws, in contrast to former windows styles, the checkmark and icon separately
1754 const auto checkMarkWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
1755 if (checked) {
1756 QRect vRect(visualMenuRect(QRect(rect.x() + xOffset, rect.y(),
1757 checkMarkWidth, rect.height())));
1758 QPainterStateGuard psg(painter);
1759 painter->setFont(d->m_assetFont);
1760 painter->setPen(option->palette.text().color());
1761 painter->drawText(vRect, Qt::AlignCenter, fluentIcon(Icon::CheckMark));
1762 }
1763 if (menuitem->menuHasCheckableItems)
1764 xOffset += checkMarkWidth + contentItemHMargin;
1765 if (!menuitem->icon.isNull()) {
1766 // 4 is added to maxIconWidth in qmenu.cpp to PM_SmallIconSize
1767 QRect vRect(visualMenuRect(QRect(rect.x() + xOffset,
1768 rect.y(),
1769 menuitem->maxIconWidth - 4,
1770 rect.height())));
1771 const auto mode = isDisabled(menuitem)
1772 ? QIcon::Disabled
1773 : (isSelected(menuitem) ? QIcon::Active : QIcon::Normal);
1774 const auto size = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
1775 QRect pmr(QPoint(0, 0), QSize(size, size));
1776 pmr.moveCenter(vRect.center());
1777 menuitem->icon.paint(painter, pmr, Qt::AlignCenter, mode,
1778 checked ? QIcon::On : QIcon::Off);
1779 }
1780 if (menuitem->maxIconWidth > 0)
1781 xOffset += menuitem->maxIconWidth - 4 + contentItemHMargin;
1782
1783 QStringView s(menuitem->text);
1784 if (!s.isEmpty()) { // draw text
1785 QPoint tl(rect.left() + xOffset, rect.top());
1786 QPoint br(rect.right() - menuitem->reservedShortcutWidth - contentHMargin,
1787 rect.bottom());
1788 QRect textRect(tl, br);
1789 QRect vRect(visualMenuRect(textRect));
1790
1791 QColor penColor;
1792 if (highContrastTheme) {
1793 penColor = menuitem->palette.color(
1794 isSelected(menuitem) ? QPalette::HighlightedText : QPalette::Text);
1795 } else {
1796 QStyleOption tmpOpt(*option);
1797 tmpOpt.state.setFlag(State_Sunken, false);
1798 penColor = controlTextColor(&tmpOpt);
1799 }
1800 painter->setPen(penColor);
1801
1802 qsizetype t = s.indexOf(u'\t');
1803 int text_flags = Qt::AlignVCenter | Qt::TextShowMnemonic | Qt::TextDontClip | Qt::TextSingleLine;
1804 if (!proxy()->styleHint(SH_UnderlineShortcut, menuitem, widget))
1805 text_flags |= Qt::TextHideMnemonic;
1806 text_flags |= Qt::AlignLeft;
1807 // a submenu doesn't paint a possible shortcut in WinUI3
1808 if (t >= 0 && menuitem->menuItemType != QStyleOptionMenuItem::SubMenu) {
1809 QRect shortcutRect(QPoint(textRect.right(), textRect.top()),
1810 QPoint(rect.right(), textRect.bottom()));
1811 QRect vShortcutRect(visualMenuRect(shortcutRect));
1812 const QString textToDraw = s.mid(t + 1).toString();
1813 painter->drawText(vShortcutRect, text_flags, textToDraw);
1814 s = s.left(t);
1815 }
1816 QFont font = menuitem->font;
1817 if (menuitem->menuItemType == QStyleOptionMenuItem::DefaultItem)
1818 font.setBold(true);
1819 painter->setFont(font);
1820 const QString textToDraw = s.left(t).toString();
1821 painter->drawText(vRect, text_flags, textToDraw);
1822 }
1823 if (menuitem->menuItemType == QStyleOptionMenuItem::SubMenu) {// draw sub menu arrow
1824 const auto fontSize = QFontInfo(painter->font()).pointSizeF();
1825 painter->setFont(d->assetFont(fontSize * 0.9f));
1826 int yOfs = qRound(fontSize / 3.0f); // an offset to align the '>' with the baseline of the text
1827 QPoint tl(rect.right() - 2 * QWindowsStylePrivate::windowsArrowHMargin - contentItemHMargin,
1828 rect.top() + yOfs);
1829 QRect submenuRect(tl, rect.bottomRight());
1830 QRect vSubMenuRect = visualMenuRect(submenuRect);
1831 painter->setPen(option->palette.text().color());
1832 const bool isReverse = option->direction == Qt::RightToLeft;
1833 const auto ico = isReverse ? Icon::ChevronLeftMed : Icon::ChevronRightMed;
1834 painter->drawText(vSubMenuRect, Qt::AlignCenter, fluentIcon(ico));
1835 }
1836 }
1837 break;
1838#endif // QT_CONFIG(menu)
1839 case CE_MenuBarEmptyArea: {
1840 break;
1841 }
1842 case CE_HeaderEmptyArea:
1843 break;
1844 case CE_HeaderSection: {
1845 if (const QStyleOptionHeader *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
1846 painter->setPen(Qt::NoPen);
1847 painter->setBrush(header->palette.button());
1848 painter->drawRect(header->rect);
1849 const bool isRtl = option->direction == Qt::RightToLeft;
1850 const QPointF tr = isRtl ? option->rect.topLeft() : option->rect.topRight();
1851 const QPointF br = isRtl ? option->rect.bottomLeft() : option->rect.bottomRight();
1852 const QPointF bl = isRtl ? option->rect.bottomRight() : option->rect.bottomLeft();
1853 constexpr QPointF trOfs = QPointF(0.5, 0.0);
1854 constexpr QPointF brOfs = QPointF(0.5, 0.5);
1855 constexpr QPointF blOfs = QPointF(0.0, 0.5);
1856 const std::array<QPointF, 3> points = { tr + trOfs, br + brOfs, bl + blOfs };
1857 QPen pen(highContrastTheme ? header->palette.buttonText().color()
1858 : winUI3Color(frameColorLight));
1859 pen.setJoinStyle(Qt::MiterJoin);
1860 painter->setPen(pen);
1861 painter->drawPolyline(points.data(), int(points.size()));
1862 }
1863 break;
1864 }
1865 case CE_ItemViewItem: {
1866 if (const QStyleOptionViewItem *vopt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
1867 const auto p = proxy();
1868 QRect checkRect = p->subElementRect(SE_ItemViewItemCheckIndicator, vopt, widget);
1869 QRect iconRect = p->subElementRect(SE_ItemViewItemDecoration, vopt, widget);
1870 QRect textRect = p->subElementRect(SE_ItemViewItemText, vopt, widget);
1871
1872 // draw the background
1873 proxy()->drawPrimitive(PE_PanelItemViewItem, option, painter, widget);
1874
1875 const QRect &rect = vopt->rect;
1876 const bool isRtl = option->direction == Qt::RightToLeft;
1877 bool onlyOne = vopt->viewItemPosition == QStyleOptionViewItem::OnlyOne ||
1878 vopt->viewItemPosition == QStyleOptionViewItem::Invalid;
1879 bool isFirst = vopt->viewItemPosition == QStyleOptionViewItem::Beginning;
1880 bool isLast = vopt->viewItemPosition == QStyleOptionViewItem::End;
1881
1882 const QAbstractItemView *view = qobject_cast<const QAbstractItemView *>(widget);
1883 if (qobject_cast<const QTableView *>(view)) {
1884 onlyOne = true;
1885 } else {
1886 // the tree decoration already painted the left side of the rounded rect
1887 if (vopt->features.testFlag(QStyleOptionViewItem::IsDecoratedRootColumn) &&
1888 vopt->showDecorationSelected) {
1889 isFirst = false;
1890 if (onlyOne) {
1891 onlyOne = false;
1892 isLast = true;
1893 }
1894 }
1895
1896 if (isRtl) {
1897 if (isFirst) {
1898 isFirst = false;
1899 isLast = true;
1900 } else if (isLast) {
1901 isFirst = true;
1902 isLast = false;
1903 }
1904 }
1905 }
1906
1907 const bool highlightCurrent = vopt->state.testAnyFlags(State_Selected | State_MouseOver);
1908 if (highlightCurrent) {
1909 if (highContrastTheme) {
1910 painter->setBrush(vopt->palette.highlight());
1911 } else {
1912 painter->setBrush(view && view->alternatingRowColors() && vopt->state & State_Selected
1913 ? calculateAccentColor(option)
1914 : winUI3Color(subtleHighlightColor));
1915 }
1916 } else {
1917 painter->setBrush(vopt->backgroundBrush);
1918 }
1919 painter->setPen(Qt::NoPen);
1920
1921 if (onlyOne) {
1922 painter->drawRoundedRect(rect.marginsRemoved(QMargins(2, 2, 2, 2)),
1923 secondLevelRoundingRadius, secondLevelRoundingRadius);
1924 } else if (isFirst) {
1925 QPainterStateGuard psg(painter);
1926 painter->setClipRect(rect);
1927 painter->drawRoundedRect(rect.marginsRemoved(QMargins(2, 2, -secondLevelRoundingRadius, 2)),
1928 secondLevelRoundingRadius, secondLevelRoundingRadius);
1929 } else if (isLast) {
1930 QPainterStateGuard psg(painter);
1931 painter->setClipRect(rect);
1932 painter->drawRoundedRect(rect.marginsRemoved(QMargins(-secondLevelRoundingRadius, 2, 2, 2)),
1933 secondLevelRoundingRadius, secondLevelRoundingRadius);
1934 } else {
1935 painter->drawRect(rect.marginsRemoved(QMargins(0, 2, 0, 2)));
1936 }
1937
1938 // draw the check mark
1939 if (vopt->features & QStyleOptionViewItem::HasCheckIndicator) {
1940 QStyleOptionViewItem option(*vopt);
1941 option.rect = checkRect;
1942 option.state = option.state & ~QStyle::State_HasFocus;
1943
1944 switch (vopt->checkState) {
1945 case Qt::Unchecked:
1946 option.state |= QStyle::State_Off;
1947 break;
1948 case Qt::PartiallyChecked:
1949 option.state |= QStyle::State_NoChange;
1950 break;
1951 case Qt::Checked:
1952 option.state |= QStyle::State_On;
1953 break;
1954 }
1955 proxy()->drawPrimitive(QStyle::PE_IndicatorItemViewItemCheck, &option, painter, widget);
1956 }
1957
1958 // draw the icon
1959 if (iconRect.isValid()) {
1960 QIcon::Mode mode = QIcon::Normal;
1961 if (!(vopt->state & QStyle::State_Enabled))
1962 mode = QIcon::Disabled;
1963 else if (vopt->state & QStyle::State_Selected)
1964 mode = QIcon::Selected;
1965 QIcon::State state = vopt->state & QStyle::State_Open ? QIcon::On : QIcon::Off;
1966 vopt->icon.paint(painter, iconRect, vopt->decorationAlignment, mode, state);
1967 }
1968
1969 if (highlightCurrent && highContrastTheme) {
1970 painter->setPen(vopt->palette.base().color());
1971 } else if ((view && view->alternatingRowColors() && highlightCurrent && vopt->state & State_Selected)) {
1972 painter->setPen(winUI3Color(textOnAccentPrimary));
1973 } else {
1974 painter->setPen(vopt->palette.text().color());
1975 }
1976 d->viewItemDrawText(painter, vopt, textRect);
1977
1978 // paint a vertical marker for QListView
1979 if (vopt->state & State_Selected && !highContrastTheme) {
1980 if (const QListView *lv = qobject_cast<const QListView *>(widget);
1981 lv && lv->viewMode() != QListView::IconMode) {
1982 const auto col = vopt->palette.accent().color();
1983 painter->setBrush(col);
1984 painter->setPen(col);
1985 const auto xPos = isRtl ? rect.right() - 4.5f : rect.left() + 3.5f;
1986 const auto yOfs = rect.height() / 4.;
1987 QRectF r(QPointF(xPos, rect.y() + yOfs),
1988 QPointF(xPos + 1, rect.y() + rect.height() - yOfs));
1989 painter->drawRoundedRect(r, 1, 1);
1990 }
1991 }
1992 }
1993 break;
1994 }
1995 default:
1996 QWindowsVistaStyle::drawControl(element, option, painter, widget);
1997 }
1998}
1999
2000int QWindows11Style::styleHint(StyleHint hint, const QStyleOption *opt,
2001 const QWidget *widget, QStyleHintReturn *returnData) const {
2002 switch (hint) {
2003 case QStyle::SH_Menu_AllowActiveAndDisabled:
2004 return 0;
2005 case SH_GroupBox_TextLabelColor:
2006 if (opt!=nullptr && widget!=nullptr)
2007 return opt->palette.text().color().rgba();
2008 return 0;
2009 case QStyle::SH_ItemView_ShowDecorationSelected:
2010 return 1;
2011 case QStyle::SH_Slider_AbsoluteSetButtons:
2012 return Qt::LeftButton;
2013 case QStyle::SH_Slider_PageSetButtons:
2014 return 0;
2015 case SH_SpinControls_DisableOnBounds:
2016 return 1;
2017 default:
2018 return QWindowsVistaStyle::styleHint(hint, opt, widget, returnData);
2019 }
2020}
2021
2022QRect QWindows11Style::subElementRect(QStyle::SubElement element, const QStyleOption *option,
2023 const QWidget *widget) const
2024{
2025 QRect ret;
2026 switch (element) {
2027 case QStyle::SE_RadioButtonIndicator:
2028 case QStyle::SE_CheckBoxIndicator: {
2029 ret = QWindowsVistaStyle::subElementRect(element, option, widget);
2030 const auto ofs =
2031 QCommonStylePrivate::rtl(option) ? -contentItemHMargin : +contentItemHMargin;
2032 ret.moveLeft(ret.left() + ofs);
2033 break;
2034 }
2035 case QStyle::SE_ComboBoxFocusRect:
2036 case QStyle::SE_CheckBoxFocusRect:
2037 case QStyle::SE_RadioButtonFocusRect:
2038 case QStyle::SE_PushButtonFocusRect:
2039 ret = option->rect;
2040 break;
2041 case QStyle::SE_LineEditContents:
2042 ret = option->rect.adjusted(4,0,-4,0);
2043 break;
2044 case SE_ItemViewItemCheckIndicator:
2045 case SE_ItemViewItemDecoration:
2046 case SE_ItemViewItemText: {
2047 ret = QWindowsVistaStyle::subElementRect(element, option, widget);
2048 if (!ret.isValid() || highContrastTheme)
2049 return ret;
2050
2051 const auto needPlaceForSelectionMarker = [](const QWidget *w) {
2052 if (qobject_cast<const QTableView *>(w))
2053 return true;
2054 if (const QListView *lv = qobject_cast<const QListView *>(w);
2055 lv && lv->viewMode() != QListView::IconMode)
2056 return true;
2057 return false;
2058 };
2059 if (needPlaceForSelectionMarker(widget)) {
2060 const int xOfs = contentHMargin;
2061 const bool isRtl = option->direction == Qt::RightToLeft;
2062 if (isRtl) {
2063 ret.moveRight(ret.right() - xOfs);
2064 if (ret.left() < option->rect.left())
2065 ret.setLeft(option->rect.left());
2066 } else {
2067 ret.moveLeft(ret.left() + xOfs);
2068 if (ret.right() > option->rect.right())
2069 ret.setRight(option->rect.right());
2070 }
2071 }
2072 break;
2073 }
2074#if QT_CONFIG(progressbar)
2075 case SE_ProgressBarGroove:
2076 case SE_ProgressBarContents:
2077 case SE_ProgressBarLabel:
2078 if (const auto *pb = qstyleoption_cast<const QStyleOptionProgressBar *>(option)) {
2079 QStyleOptionProgressBar optCopy(*pb);
2080 // we only support label right from content
2081 optCopy.textAlignment = Qt::AlignRight;
2082 return QWindowsVistaStyle::subElementRect(element, &optCopy, widget);
2083 }
2084 break;
2085#endif // QT_CONFIG(progressbar)
2086#if QT_CONFIG(toolbar)
2087 case SE_TabBarScrollLeftButton:
2088 case SE_TabBarScrollRightButton: {
2089 const bool isRightButton = element == SE_TabBarScrollRightButton;
2090 const bool vertical = option->rect.width() < option->rect.height();
2091 const int buttonWidth = proxy()->pixelMetric(PM_TabBarScrollButtonWidth, option, widget);
2092
2093 if (vertical) {
2094 const int yOfs =
2095 isRightButton ? option->rect.height() - buttonWidth : 0;
2096 const QSize sz(option->rect.width(), buttonWidth);
2097 const QPoint tl(option->rect.topLeft() + QPoint(0, yOfs));
2098 ret = QRect(tl, sz);
2099 } else {
2100 const int xOfs =
2101 isRightButton ? option->rect.width() - buttonWidth : 0;
2102 const QSize sz(buttonWidth, option->rect.height());
2103 const QPoint tl(option->rect.topLeft() + QPoint(xOfs, 0));
2104 ret = QRect(tl, sz);
2105 ret = visualRect(widget->layoutDirection(), option->rect, ret);
2106 }
2107 break;
2108 }
2109 case SE_TabBarTearIndicatorLeft:
2110 case SE_TabBarTearIndicatorRight:
2111 if (const QStyleOptionTab *tab = qstyleoption_cast<const QStyleOptionTab *>(option)) {
2112 const bool isRightButton = element == SE_TabBarTearIndicatorRight;
2113 const int buttonWidth =
2114 proxy()->pixelMetric(PM_TabBarScrollButtonWidth, nullptr, widget);
2115 switch (tab->shape) {
2116 case QTabBar::RoundedNorth:
2117 case QTabBar::TriangularNorth:
2118 case QTabBar::RoundedSouth:
2119 case QTabBar::TriangularSouth: {
2120 const auto ofs = isRightButton
2121 ? option->rect.width() - 2 - buttonWidth - contentItemHMargin
2122 : 2 + buttonWidth + contentItemHMargin;
2123 const QPoint tl(tab->rect.topLeft() + QPoint(ofs, 0));
2124 ret = QRect(tl, QSize(1, option->rect.height()));
2125 break;
2126 }
2127 case QTabBar::RoundedWest:
2128 case QTabBar::TriangularWest:
2129 case QTabBar::RoundedEast:
2130 case QTabBar::TriangularEast: {
2131 const auto ofs = isRightButton
2132 ? option->rect.height() - 2 - buttonWidth - contentItemHMargin
2133 : 2 + buttonWidth + contentItemHMargin;
2134 const QPoint tl(tab->rect.topLeft() + QPoint(0, ofs));
2135 ret = QRect(tl, QSize(option->rect.width(), 1));
2136 break;
2137 }
2138 default:
2139 break;
2140 }
2141 ret = visualRect(option->direction, option->rect, ret);
2142 }
2143 break;
2144#endif // QT_CONFIG(toolbar)
2145 case SE_HeaderLabel: {
2146 const int margin = proxy()->pixelMetric(PM_HeaderMargin, option, widget);
2147 ret = option->rect.marginsRemoved({ margin, margin, margin, margin });
2148 break;
2149 }
2150 case SE_HeaderArrow: {
2151 ret = option->rect;
2152 if (const auto *header = qstyleoption_cast<const QStyleOptionHeader *>(option)) {
2153 // the sort indicator is always show above in the win11 style
2154 if (header->sortIndicator != QStyleOptionHeader::None) {
2155 const int arrowSize = proxy()->pixelMetric(PM_HeaderMarkSize, option, widget);
2156 const int xCenter = ret.center().x();
2157 ret = QRect(xCenter - arrowSize / 2, ret.top(), arrowSize, arrowSize);
2158 }
2159 }
2160 break;
2161 }
2162 case SE_PushButtonContents: {
2163 int border = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2164 ret = option->rect.marginsRemoved(QMargins(border, border, border, border));
2165 break;
2166 }
2167 default:
2168 ret = QWindowsVistaStyle::subElementRect(element, option, widget);
2169 }
2170 return ret;
2171}
2172
2173/*!
2174 \internal
2175 */
2176QRect QWindows11Style::subControlRect(ComplexControl control, const QStyleOptionComplex *option,
2177 SubControl subControl, const QWidget *widget) const
2178{
2179 QRect ret;
2180
2181 switch (control) {
2182#if QT_CONFIG(spinbox)
2183 case CC_SpinBox:
2184 if (const QStyleOptionSpinBox *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2185 const bool hasButtons = spinbox->buttonSymbols != QAbstractSpinBox::NoButtons;
2186 const int fw = spinbox->frame
2187 ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget)
2188 : 0;
2189 int textFieldLength = spinbox->rect.width() - 2 * fw;
2190 int buttonHeight = 0;
2191 int buttonWidth = 0;
2192 if (hasButtons) {
2193 const QWidget *w = qobject_cast<QWidget *>(spinbox->styleObject);
2194 buttonWidth = w
2195 ? widthFromChar(w->font(), Icon::ChevronUp, m_fontPoint2ChevronUpWidth)
2196 : spinbox->fontMetrics.horizontalAdvance(fluentIcon(Icon::ChevronUp));
2197 buttonHeight = spinbox->rect.height() - 4 * fw; // 4 * fw - some more space around the buttons
2198 textFieldLength -= 2 * (buttonWidth + fw) + 2 * fw;
2199 }
2200 const QPoint topLeft(spinbox->rect.topLeft() + QPoint(fw, fw));
2201 switch (subControl) {
2202 case SC_SpinBoxUp:
2203 case SC_SpinBoxDown: {
2204 if (!hasButtons)
2205 return QRect();
2206 const int yOfs = ((spinbox->rect.height() - 2 * fw) - buttonHeight) / 2;
2207 ret = QRect(topLeft.x() + textFieldLength + fw, topLeft.y() + yOfs, buttonWidth,
2208 buttonHeight);
2209 if (subControl == SC_SpinBoxDown)
2210 ret.moveRight(ret.right() + buttonWidth + fw);
2211 break;
2212 }
2213 case SC_SpinBoxEditField:
2214 ret = QRect(topLeft,
2215 QPoint(topLeft.x() + textFieldLength, spinbox->rect.bottom() - fw));
2216 break;
2217 case SC_SpinBoxFrame:
2218 ret = spinbox->rect;
2219 default:
2220 break;
2221 }
2222 ret = visualRect(spinbox->direction, spinbox->rect, ret);
2223 }
2224 break;
2225 case CC_TitleBar:
2226 if (const QStyleOptionTitleBar *titlebar = qstyleoption_cast<const QStyleOptionTitleBar *>(option)) {
2227 SubControl sc = subControl;
2228 ret = QCommonStyle::subControlRect(control, option, subControl, widget);
2229 static constexpr int indent = 3;
2230 static constexpr int controlWidthMargin = 2;
2231 const int controlHeight = titlebar->rect.height();
2232 const int controlWidth = 46;
2233 const int iconSize = proxy()->pixelMetric(QStyle::PM_TitleBarButtonIconSize, option, widget);
2234 int offset = -(controlWidthMargin + indent);
2235
2236 bool isMinimized = titlebar->titleBarState & Qt::WindowMinimized;
2237 bool isMaximized = titlebar->titleBarState & Qt::WindowMaximized;
2238
2239 switch (sc) {
2240 case SC_TitleBarLabel:
2241 if (titlebar->titleBarFlags & (Qt::WindowTitleHint | Qt::WindowSystemMenuHint)) {
2242 ret = titlebar->rect;
2243 if (titlebar->titleBarFlags & Qt::WindowSystemMenuHint)
2244 ret.adjust(iconSize + controlWidthMargin + indent, 0, -controlWidth, 0);
2245 if (titlebar->titleBarFlags & Qt::WindowMinimizeButtonHint)
2246 ret.adjust(0, 0, -controlWidth, 0);
2247 if (titlebar->titleBarFlags & Qt::WindowMaximizeButtonHint)
2248 ret.adjust(0, 0, -controlWidth, 0);
2249 if (titlebar->titleBarFlags & Qt::WindowShadeButtonHint)
2250 ret.adjust(0, 0, -controlWidth, 0);
2251 if (titlebar->titleBarFlags & Qt::WindowContextHelpButtonHint)
2252 ret.adjust(0, 0, -controlWidth, 0);
2253 }
2254 break;
2255 case SC_TitleBarContextHelpButton:
2256 if (titlebar->titleBarFlags & Qt::WindowContextHelpButtonHint)
2257 offset += controlWidth;
2258 Q_FALLTHROUGH();
2259 case SC_TitleBarMinButton:
2260 if (!isMinimized && (titlebar->titleBarFlags & Qt::WindowMinimizeButtonHint))
2261 offset += controlWidth;
2262 else if (sc == SC_TitleBarMinButton)
2263 break;
2264 Q_FALLTHROUGH();
2265 case SC_TitleBarNormalButton:
2266 if (isMinimized && (titlebar->titleBarFlags & Qt::WindowMinimizeButtonHint))
2267 offset += controlWidth;
2268 else if (isMaximized && (titlebar->titleBarFlags & Qt::WindowMaximizeButtonHint))
2269 offset += controlWidth;
2270 else if (sc == SC_TitleBarNormalButton)
2271 break;
2272 Q_FALLTHROUGH();
2273 case SC_TitleBarMaxButton:
2274 if (!isMaximized && (titlebar->titleBarFlags & Qt::WindowMaximizeButtonHint))
2275 offset += controlWidth;
2276 else if (sc == SC_TitleBarMaxButton)
2277 break;
2278 Q_FALLTHROUGH();
2279 case SC_TitleBarShadeButton:
2280 if (!isMinimized && (titlebar->titleBarFlags & Qt::WindowShadeButtonHint))
2281 offset += controlWidth;
2282 else if (sc == SC_TitleBarShadeButton)
2283 break;
2284 Q_FALLTHROUGH();
2285 case SC_TitleBarUnshadeButton:
2286 if (isMinimized && (titlebar->titleBarFlags & Qt::WindowShadeButtonHint))
2287 offset += controlWidth;
2288 else if (sc == SC_TitleBarUnshadeButton)
2289 break;
2290 Q_FALLTHROUGH();
2291 case SC_TitleBarCloseButton:
2292 if (titlebar->titleBarFlags & Qt::WindowSystemMenuHint)
2293 offset += controlWidth;
2294 else if (sc == SC_TitleBarCloseButton)
2295 break;
2296 ret.setRect(titlebar->rect.right() - offset, titlebar->rect.top(),
2297 controlWidth, controlHeight);
2298 break;
2299 case SC_TitleBarSysMenu:
2300 if (titlebar->titleBarFlags & Qt::WindowSystemMenuHint) {
2301 const auto yOfs = titlebar->rect.top() + (titlebar->rect.height() - iconSize) / 2;
2302 ret.setRect(titlebar->rect.left() + controlWidthMargin + indent, yOfs, iconSize,
2303 iconSize);
2304 }
2305 break;
2306 default:
2307 break;
2308 }
2309 if (widget && isMinimized && titlebar->rect.width() < offset)
2310 const_cast<QWidget*>(widget)->resize(controlWidthMargin + indent + offset + iconSize + controlWidthMargin, controlWidth);
2311 ret = visualRect(titlebar->direction, titlebar->rect, ret);
2312 }
2313 break;
2314#endif // Qt_NO_SPINBOX
2315 case CC_ScrollBar:
2316 {
2317 ret = QCommonStyle::subControlRect(control, option, subControl, widget);
2318
2319 if (subControl == SC_ScrollBarAddLine || subControl == SC_ScrollBarSubLine) {
2320 if (const QStyleOptionSlider *scrollbar = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2321 if (scrollbar->orientation == Qt::Vertical)
2322 ret = ret.adjusted(2,2,-2,-3);
2323 else
2324 ret = ret.adjusted(3,2,-2,-2);
2325 }
2326 }
2327 break;
2328 }
2329 case CC_ComboBox: {
2330 if (const auto *cb = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
2331 switch (subControl) {
2332 case SC_ComboBoxArrow: {
2333 const int fw =
2334 cb->frame ? proxy()->pixelMetric(PM_ComboBoxFrameWidth, cb, widget) : 0;
2335 const int buttonHeight =
2336 qMin(cb->rect.height() - 3 * fw, cb->fontMetrics.height() * 5 / 4);
2337 const QSize buttonSize(buttonHeight * 6 / 5, buttonHeight);
2338 const int textFieldLength = cb->rect.width() - 2 * fw - buttonSize.width();
2339 const QPoint topLeft(cb->rect.topLeft() + QPoint(fw, fw));
2340 const int yOfs = ((cb->rect.height() - 2 * fw) - buttonSize.height()) / 2;
2341 ret = QRect(topLeft.x() + textFieldLength, topLeft.y() + yOfs, buttonSize.width(),
2342 buttonSize.height());
2343 ret = visualRect(option->direction, option->rect, ret);
2344 break;
2345 }
2346 case SC_ComboBoxEditField: {
2347 const auto indicatorWidth =
2348 proxy()->pixelMetric(PM_MenuButtonIndicator, option, widget);
2349 ret = option->rect;
2350 if (cb->frame) {
2351 const int fw = proxy()->pixelMetric(PM_ComboBoxFrameWidth, cb, widget);
2352 ret = ret.marginsRemoved(QMargins(fw, fw, fw, fw));
2353 }
2354 ret.setWidth(ret.width() - indicatorWidth - contentHMargin * 2);
2355 ret = visualRect(option->direction, option->rect, ret);
2356 break;
2357 }
2358 default:
2359 ret = QWindowsVistaStyle::subControlRect(control, option, subControl, widget);
2360 break;
2361 }
2362 }
2363 break;
2364 }
2365#if QT_CONFIG(groupbox)
2366 case CC_GroupBox: {
2367 ret = QWindowsVistaStyle::subControlRect(control, option, subControl, widget);
2368 switch (subControl) {
2369 case SC_GroupBoxCheckBox:
2370 ret.moveTop(1);
2371 break;
2372 default:
2373 break;
2374 }
2375 break;
2376 }
2377#endif // QT_CONFIG(groupbox)
2378 default:
2379 ret = QWindowsVistaStyle::subControlRect(control, option, subControl, widget);
2380 }
2381 return ret;
2382}
2383
2384/*!
2385 \internal
2386 */
2387QSize QWindows11Style::sizeFromContents(ContentsType type, const QStyleOption *option,
2388 const QSize &size, const QWidget *widget) const
2389{
2390 QSize contentSize(size);
2391
2392 switch (type) {
2393
2394#if QT_CONFIG(menubar)
2395 case CT_MenuBarItem:
2396 if (!contentSize.isEmpty()) {
2397 constexpr int hMargin = 2 * 6;
2398 constexpr int hPadding = 2 * 11;
2399 constexpr int itemHeight = 32;
2400 contentSize.setWidth(contentSize.width() + hMargin + hPadding);
2401#if QT_CONFIG(tabwidget)
2402 if (widget->parent() && !qobject_cast<const QTabWidget *>(widget->parent()))
2403#endif
2404 contentSize.setHeight(itemHeight);
2405 }
2406 break;
2407#endif
2408#if QT_CONFIG(menu)
2409 case CT_MenuItem:
2410 if (const auto *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(option)) {
2411 int width = size.width();
2412 int height;
2413 if (menuItem->menuItemType == QStyleOptionMenuItem::Separator) {
2414 width = 10;
2415 height = 3;
2416 } else {
2417 height = menuItem->fontMetrics.height() + 8;
2418 if (!menuItem->icon.isNull()) {
2419 int iconExtent = proxy()->pixelMetric(PM_SmallIconSize, option, widget);
2420 height = qMax(height,
2421 menuItem->icon.actualSize(QSize(iconExtent, iconExtent)).height() + 4);
2422 }
2423 }
2424 if (menuItem->text.contains(u'\t'))
2425 width += contentItemHMargin; // the text width is already in
2426 if (menuItem->menuItemType == QStyleOptionMenuItem::SubMenu)
2427 width += 2 * QWindowsStylePrivate::windowsArrowHMargin + contentItemHMargin;
2428 if (menuItem->menuItemType == QStyleOptionMenuItem::DefaultItem) {
2429 const QFontMetrics fm(menuItem->font);
2430 QFont fontBold = menuItem->font;
2431 fontBold.setBold(true);
2432 const QFontMetrics fmBold(fontBold);
2433 width += fmBold.horizontalAdvance(menuItem->text) - fm.horizontalAdvance(menuItem->text);
2434 }
2435 // in contrast to windowsvista, the checkmark and icon are drawn separately
2436 if (menuItem->menuHasCheckableItems) {
2437 const auto checkMarkWidth = proxy()->pixelMetric(PM_IndicatorWidth, option, widget);
2438 width += checkMarkWidth + contentItemHMargin * 2;
2439 }
2440 // we have an icon and it's already in the given size, only add margins
2441 // 4 is added in qmenu.cpp to PM_SmallIconSize
2442 if (menuItem->maxIconWidth > 0)
2443 width += contentItemHMargin * 2 + menuItem->maxIconWidth - 4;
2444 width += 2 * 2; // margins for rounded border
2445 width += 2 * contentHMargin;
2446 if (width < 100) // minimum size
2447 width = 100;
2448 contentSize = QSize(width, height);
2449 }
2450 break;
2451#endif // QT_CONFIG(menu)
2452#if QT_CONFIG(spinbox)
2453 case CT_SpinBox: {
2454 if (const auto *spinbox = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
2455 // Add button + frame widths
2456 const bool hasButtons = (spinbox->buttonSymbols != QAbstractSpinBox::NoButtons);
2457 const int margins = 0;
2458 int buttonWidth = 0;
2459 if (hasButtons) {
2460 buttonWidth = widget
2461 ? widthFromChar(widget->font(), Icon::ChevronUp, m_fontPoint2ChevronUpWidth)
2462 : spinbox->fontMetrics.horizontalAdvance(fluentIcon(Icon::ChevronUp));
2463 buttonWidth += 3; // margins, see subControlRect/SC_SpinBoxUp/Down
2464 }
2465 const int frameWidth = spinbox->frame
2466 ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, option, widget)
2467 : 0;
2468 // 4 -> SE_LineEditContents removes 4px left and right
2469 contentSize += QSize(2 * (buttonWidth + frameWidth + margins + 4), 2 * frameWidth);
2470 }
2471 break;
2472 }
2473#endif
2474#if QT_CONFIG(combobox)
2475 case CT_ComboBox:
2476 if (const auto *comboBoxOpt = qstyleoption_cast<const QStyleOptionComboBox *>(option)) {
2477 contentSize = QWindowsStyle::sizeFromContents(type, option, size, widget); // don't rely on QWindowsThemeData
2478 contentSize += QSize(0, 4); // for the lineedit frame
2479 if (comboBoxOpt->subControls & SC_ComboBoxArrow) {
2480 const auto w = proxy()->pixelMetric(PM_MenuButtonIndicator, option, widget);
2481 contentSize.rwidth() += w + contentItemHMargin;
2482 }
2483 }
2484 break;
2485#endif
2486 case CT_LineEdit: {
2487 if (qstyleoption_cast<const QStyleOptionFrame *>(option)) {
2488 contentSize = QWindowsStyle::sizeFromContents(type, option, size, widget); // don't rely on QWindowsThemeData
2489 contentSize += QSize(0, 4); // for the lineedit frame
2490 }
2491 contentSize += QSize(2 * 4, 0); // SE_LineEditContents removes 4px left and right
2492 break;
2493 }
2494 case CT_HeaderSection:
2495 // windows vista does not honor the indicator (as it was drawn above the text, not on the
2496 // side) so call QWindowsStyle::styleHint directly to get the correct size hint
2497 contentSize = QWindowsStyle::sizeFromContents(type, option, size, widget);
2498 break;
2499 case CT_RadioButton:
2500 case CT_CheckBox:
2501 if (const auto *buttonOpt = qstyleoption_cast<const QStyleOptionButton *>(option)) {
2502 const auto p = proxy();
2503 const bool isRadio = (type == CT_RadioButton);
2504
2505 const int width = p->pixelMetric(
2506 isRadio ? PM_ExclusiveIndicatorWidth : PM_IndicatorWidth, option, widget);
2507 const int height = p->pixelMetric(
2508 isRadio ? PM_ExclusiveIndicatorHeight : PM_IndicatorHeight, option, widget);
2509
2510 int margins = 2 * contentItemHMargin;
2511 if (!buttonOpt->icon.isNull() || !buttonOpt->text.isEmpty()) {
2512 margins += p->pixelMetric(isRadio ? PM_RadioButtonLabelSpacing
2513 : PM_CheckBoxLabelSpacing,
2514 option, widget);
2515 }
2516
2517 contentSize += QSize(width + margins, 4);
2518 contentSize.setHeight(qMax(size.height(), height + 2 * contentItemHMargin));
2519 }
2520 break;
2521
2522 // the indicator needs 2px more in width when there is no text, not needed when
2523 // the style draws the text
2524 contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
2525 if (size.width() == 0)
2526 contentSize.rwidth() += 2;
2527 break;
2528 case CT_PushButton: {
2529 contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
2530 // we want our own horizontal spacing
2531 const int oldMargin = proxy()->pixelMetric(PM_ButtonMargin, option, widget);
2532 contentSize.rwidth() += 2 * contentHMargin - oldMargin;
2533 break;
2534 }
2535 case CT_ToolButton: {
2536 contentSize = size;
2537 if (const auto tb = qstyleoption_cast<const QStyleOptionToolButton *>(option)) {
2538 // no separate menu, only dropdown icon
2539 if (!tb->subControls.testFlag(SC_ToolButtonMenu)) {
2540 if (tb->features.testFlag(QStyleOptionToolButton::HasMenu))
2541 contentSize.rwidth() += 2;
2542 }
2543 if (tb->toolButtonStyle == Qt::ToolButtonTextBesideIcon
2544 || tb->toolButtonStyle == Qt::ToolButtonIconOnly) {
2545 contentSize.rheight() = qMax(contentSize.height(), tb->iconSize.height() + 4);
2546 }
2547 }
2548 const auto fw = proxy()->pixelMetric(PM_DefaultFrameWidth, option, widget);
2549 contentSize += QSize(contentHMargin + 2 * fw, 2 * fw);
2550 break;
2551 }
2552 case CT_ItemViewItem: {
2553 if (const auto *viewItemOpt = qstyleoption_cast<const QStyleOptionViewItem *>(option)) {
2554 if (const QListView *lv = qobject_cast<const QListView *>(widget);
2555 lv && lv->viewMode() != QListView::IconMode) {
2556 QStyleOptionViewItem vOpt(*viewItemOpt);
2557 // viewItemSize only takes PM_FocusFrameHMargin into account but no additional
2558 // margin, therefore adjust it here for a correct width during layouting when
2559 // WrapText is enabled
2560 vOpt.rect.setRight(vOpt.rect.right() - contentHMargin);
2561 contentSize = QWindowsVistaStyle::sizeFromContents(type, &vOpt, size, widget);
2562 contentSize.rwidth() += contentHMargin;
2563 contentSize.rheight() += 2 * contentHMargin;
2564
2565 } else {
2566 contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
2567 }
2568 }
2569 break;
2570 }
2571 default:
2572 contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
2573 break;
2574 }
2575
2576 return contentSize;
2577}
2578
2579
2580/*!
2581 \internal
2582 */
2583int QWindows11Style::pixelMetric(PixelMetric metric, const QStyleOption *option, const QWidget *widget) const
2584{
2585 int res = 0;
2586
2587 switch (metric) {
2588 case QStyle::PM_IndicatorWidth:
2589 case QStyle::PM_IndicatorHeight:
2590 case QStyle::PM_ExclusiveIndicatorWidth:
2591 case QStyle::PM_ExclusiveIndicatorHeight:
2592 res = 16;
2593 break;
2594 case PM_SliderThickness: // full height of a slider
2595 if (auto opt = qstyleoption_cast<const QStyleOptionSlider *>(option)) {
2596 // hard-coded in qslider.cpp, but we need a little bit more
2597 constexpr auto TickSpace = 5;
2598 if (opt->tickPosition & QSlider::TicksAbove)
2599 res += 6 - TickSpace;
2600 if (opt->tickPosition & QSlider::TicksBelow)
2601 res += 6 - TickSpace;
2602 }
2603 Q_FALLTHROUGH();
2604 case PM_SliderControlThickness: // size of the control handle
2605 case PM_SliderLength: // same because handle is a circle with r=8
2606 res += 2 * 8;
2607 break;
2608 case PM_RadioButtonLabelSpacing:
2609 case PM_CheckBoxLabelSpacing:
2610 res = 2 * contentItemHMargin;
2611 break;
2612 case QStyle::PM_TitleBarButtonIconSize:
2613 res = 16;
2614 break;
2615 case QStyle::PM_TitleBarButtonSize:
2616 res = 32;
2617 break;
2618#if QT_CONFIG(toolbar)
2619 case PM_TabBarScrollButtonWidth:
2620 res = 16 + contentItemHMargin;
2621 break;
2622 case PM_ToolBarExtensionExtent:
2623 res = int(QStyleHelper::dpiScaled(32., option));
2624 break;
2625 case PM_ToolBarHandleExtent:
2626 res = int(QStyleHelper::dpiScaled(8., option));
2627 break;
2628#endif // QT_CONFIG(toolbar)
2629 case QStyle::PM_ScrollBarExtent:
2630 res = 12;
2631 break;
2632 case QStyle::PM_SubMenuOverlap:
2633 res = -1;
2634 break;
2635 case PM_MenuButtonIndicator: {
2636 res = contentItemHMargin;
2637 if (widget) {
2638 res += qRound(widthFromChar(widget->font(), Icon::ChevronDownMed,
2639 m_fontPoint2ChevronDownMedWidth) * 0.9);
2640 } else {
2641 res += 12;
2642 }
2643 break;
2644 }
2645 case PM_ComboBoxFrameWidth:
2646 case PM_SpinBoxFrameWidth:
2647 case PM_DefaultFrameWidth:
2648 res = 2;
2649 break;
2650 case PM_ButtonShiftHorizontal:
2651 case PM_ButtonShiftVertical:
2652 case PM_TabBarTabShiftHorizontal:
2653 case PM_TabBarTabShiftVertical:
2654 case PM_TabBarBaseOverlap:
2655 case PM_TabBarBaseHeight:
2656 res = 0;
2657 break;
2658 case PM_TreeViewIndentation:
2659 res = 30;
2660 break;
2661 case PM_ProgressBarChunkWidth:
2662 res = 0; // no chunks on windows11
2663 break;
2664 case PM_HeaderMarkSize:
2665 res = 6;
2666 break;
2667 default:
2668 res = QWindowsVistaStyle::pixelMetric(metric, option, widget);
2669 }
2670
2671 return res;
2672}
2673
2674void QWindows11Style::polish(QWidget* widget)
2675{
2676 Q_D(QWindows11Style);
2677
2678#if QT_CONFIG(commandlinkbutton)
2679 if (!qobject_cast<QCommandLinkButton *>(widget))
2680#endif // QT_CONFIG(commandlinkbutton)
2681 QWindowsVistaStyle::polish(widget);
2682
2683 const bool isScrollBar = qobject_cast<QScrollBar *>(widget);
2684 const auto comboBoxContainer = qobject_cast<const QComboBoxPrivateContainer *>(widget);
2685 const auto isComboBoxContainer = !d->nativeRoundedTopLevelWindows && comboBoxContainer != nullptr;
2686 const auto isMenu = !d->nativeRoundedTopLevelWindows && qobject_cast<QMenu *>(widget) != nullptr;
2687
2688#if QT_CONFIG(menubar)
2689 if (qobject_cast<QMenuBar *>(widget)) {
2690 constexpr int itemHeight = 32;
2691 if (widget->maximumHeight() < itemHeight) {
2692 widget->setProperty("_q_original_menubar_maxheight", widget->maximumHeight());
2693 widget->setMaximumHeight(itemHeight);
2694 }
2695 }
2696#endif
2697 if (comboBoxContainer && d->nativeRoundedTopLevelWindows) {
2698 auto view = comboBoxContainer->itemView();
2699 if (view && view->viewport())
2700 view->viewport()->setAutoFillBackground(false);
2701 }
2702 if (isScrollBar || isMenu || isComboBoxContainer) {
2703 bool wasCreated = widget->testAttribute(Qt::WA_WState_Created);
2704 bool layoutDirection = widget->testAttribute(Qt::WA_RightToLeft);
2705 widget->setAttribute(Qt::WA_OpaquePaintEvent,false);
2706 widget->setAttribute(Qt::WA_TranslucentBackground);
2707 if (!isScrollBar)
2708 widget->setWindowFlag(Qt::FramelessWindowHint);
2709 widget->setWindowFlag(Qt::NoDropShadowWindowHint);
2710 widget->setAttribute(Qt::WA_RightToLeft, layoutDirection);
2711 widget->setAttribute(Qt::WA_WState_Created, wasCreated);
2712 if (!isScrollBar) {
2713 bool inGraphicsView = widget->graphicsProxyWidget() != nullptr;
2714 if (!inGraphicsView && comboBoxContainer && comboBoxContainer->parentWidget())
2715 inGraphicsView = comboBoxContainer->parentWidget()->graphicsProxyWidget() != nullptr;
2716 if (!inGraphicsView) { // for menus and combobox containers...
2717 QGraphicsDropShadowEffect *dropshadow = new QGraphicsDropShadowEffect(widget);
2718 dropshadow->setBlurRadius(3);
2719 dropshadow->setXOffset(3);
2720 dropshadow->setYOffset(3);
2721 widget->setGraphicsEffect(dropshadow);
2722 }
2723 }
2724 } else if (QComboBox* cb = qobject_cast<QComboBox*>(widget)) {
2725 if (cb->isEditable()) {
2726 QLineEdit *le = cb->lineEdit();
2727 le->setFrame(false);
2728 }
2729 } else if (qobject_cast<QTextEdit *>(widget)
2730 || qobject_cast<QPlainTextEdit *>(widget)) {
2731 const auto *scrollarea = static_cast<QAbstractScrollArea *>(widget);
2732 // These two widgets have rounded inner borders
2733 if (scrollarea->frameShape() == QFrame::StyledPanel) {
2734 const auto vp = scrollarea->viewport();
2735 const bool isAutoFillBackground = vp->autoFillBackground();
2736 if (isAutoFillBackground) {
2737 vp->setProperty("_q_original_autofill_background", isAutoFillBackground);
2738 vp->setAutoFillBackground(false);
2739 }
2740 widget->setAttribute(Qt::WA_Hover, true);
2741 }
2742 } else if (auto table = qobject_cast<QTableView *>(widget)) {
2743 // QTreeView & QListView are already set in the base windowsvista style
2744 table->viewport()->setAttribute(Qt::WA_Hover, true);
2745 } else if (qobject_cast<QComboBox *>(widget)) {
2746 widget->setAttribute(Qt::WA_Hover, true);
2747 }
2748}
2749
2750void QWindows11Style::unpolish(QWidget *widget)
2751{
2752 Q_D(QWindows11Style);
2753#if QT_CONFIG(commandlinkbutton)
2754 if (!qobject_cast<QCommandLinkButton *>(widget))
2755#endif // QT_CONFIG(commandlinkbutton)
2756 QWindowsVistaStyle::unpolish(widget);
2757
2758#if QT_CONFIG(menubar)
2759 if (qobject_cast<QMenuBar *>(widget) && !widget->property("_q_original_menubar_maxheight").isNull()) {
2760 widget->setMaximumHeight(widget->property("_q_original_menubar_maxheight").toInt());
2761 widget->setProperty("_q_original_menubar_maxheight", QVariant());
2762 }
2763#endif
2764 const bool isScrollBar = qobject_cast<QScrollBar *>(widget);
2765 const auto comboBoxContainer = qobject_cast<const QComboBoxPrivateContainer *>(widget);
2766 const auto isComboBoxContainer = !d->nativeRoundedTopLevelWindows && comboBoxContainer != nullptr;
2767 const auto isMenu = !d->nativeRoundedTopLevelWindows && qobject_cast<QMenu *>(widget) != nullptr;
2768
2769 if (comboBoxContainer && d->nativeRoundedTopLevelWindows) {
2770 auto view = comboBoxContainer->itemView();
2771 // see QAbstractScrollAreaPrivate::init()
2772 if (view && view->viewport())
2773 view->viewport()->setAutoFillBackground(true);
2774 }
2775 if (isScrollBar || isMenu || isComboBoxContainer) {
2776 widget->setAttribute(Qt::WA_OpaquePaintEvent, true);
2777 widget->setAttribute(Qt::WA_TranslucentBackground, false);
2778 widget->setWindowFlag(Qt::FramelessWindowHint, false);
2779 widget->setWindowFlag(Qt::NoDropShadowWindowHint, false);
2780 }
2781
2782 if (const auto *scrollarea = qobject_cast<QAbstractScrollArea *>(widget);
2783 scrollarea
2784#if QT_CONFIG(mdiarea)
2785 && !qobject_cast<QMdiArea *>(widget)
2786#endif
2787 ) {
2788 const auto vp = scrollarea->viewport();
2789 const auto propertyVal = vp->property("_q_original_autofill_background");
2790 if (!propertyVal.isNull()) {
2791 const auto wasAutoFillBackground = propertyVal.toBool();
2792 vp->setAutoFillBackground(wasAutoFillBackground);
2793 vp->setProperty("_q_original_autofill_background", QVariant());
2794 }
2795 }
2796 dwmSetWindowCornerPreference(widget, false);
2797}
2798
2799void QWindows11Style::polish(QApplication *app)
2800{
2801 Q_D(const QWindows11Style);
2802 if (d->nativeRoundedTopLevelWindows)
2803 app->installEventFilter(this);
2804 QWindowsVistaStyle::polish(app);
2805}
2806
2807void QWindows11Style::unpolish(QApplication *app)
2808{
2809 Q_D(const QWindows11Style);
2810 if (d->nativeRoundedTopLevelWindows)
2811 app->removeEventFilter(this);
2812 QWindowsVistaStyle::unpolish(app);
2813}
2814
2815bool QWindows11Style::eventFilter(QObject *obj, QEvent *event)
2816{
2817 // QEvent::WinIdChange is too early so we have to wait for QEvent::Show
2818 // QEvent::WindowStateChange is needed to update the corners when the
2819 // window enters or leaves fullscreen
2820 if (event->type() == QEvent::Show || event->type() == QEvent::WindowStateChange)
2821 dwmSetWindowCornerPreference(qobject_cast<QWidget *>(obj), true);
2822 return QWindowsVistaStyle::eventFilter(obj, event);
2823}
2824
2825void QWindows11Style::dwmSetWindowCornerPreference(const QWidget *widget, bool bSet) const
2826{
2827 Q_D(const QWindows11Style);
2828 if (!d->nativeRoundedTopLevelWindows)
2829 return;
2830#ifdef Q_CC_MSVC
2831 static constexpr auto dmwmaWindowCornerPreference = DWMWA_WINDOW_CORNER_PREFERENCE;
2832 static constexpr auto dwmcpRound = DWMWCP_ROUND;
2833 static constexpr auto dwmcpRoundSmall = DWMWCP_ROUNDSMALL;
2834 static constexpr auto dwmcpDefault = DWMWCP_DEFAULT;
2835#else
2836 // MinGW 13.1.0 does not provide this
2837 static constexpr auto dmwmaWindowCornerPreference = 33;
2838 static constexpr auto dwmcpRound = 2;
2839 static constexpr auto dwmcpRoundSmall = 3;
2840 static constexpr auto dwmcpDefault = 0;
2841#endif
2842 if (widget && widget->isWindow() && widget->testAttribute(Qt::WA_WState_Created)
2843 && !widget->windowFlags().testFlag(Qt::FramelessWindowHint)) {
2844 const auto window = widget->windowHandle();
2845 if (window && window->handle()) {
2846 const auto wId = reinterpret_cast<HWND>(widget->winId());
2847 if (wId != 0) {
2848 const bool isToolTip =
2849#if QT_CONFIG(tooltip)
2850 qobject_cast<const QTipLabel *>(widget) != nullptr;
2851#else
2852 false;
2853#endif
2854 // A fullscreen window must not have rounded corners because
2855 // then it would not cover the whole screen (QTBUG-147453)
2856 const bool round = bSet && !widget->isFullScreen();
2857 uint32_t pref = round ? (isToolTip ? dwmcpRoundSmall : dwmcpRound) : dwmcpDefault;
2858 DwmSetWindowAttribute(wId, dmwmaWindowCornerPreference, &pref, sizeof(pref));
2859 }
2860 }
2861 }
2862}
2863
2864/*
2865The colors for Windows 11 are taken from the official WinUI3 Figma style at
2866https://www.figma.com/community/file/1159947337437047524
2867*/
2868#define SET_IF_UNRESOLVED(GROUP, ROLE, VALUE)
2869 if (!result.isBrushSet(QPalette::Inactive, ROLE) || styleSheetChanged)
2870 result.setColor(GROUP, ROLE, VALUE)
2871
2872static void populateLightSystemBasePalette(QPalette &result)
2873{
2874 static QString oldStyleSheet;
2875 const bool styleSheetChanged = oldStyleSheet != qApp->styleSheet();
2876
2877 constexpr QColor textColor = QColor(0x00,0x00,0x00,0xE4);
2878 constexpr QColor textDisabled = QColor(0x00, 0x00, 0x00, 0x5C);
2879 constexpr QColor btnFace = QColor(0xFF, 0xFF, 0xFF, 0xB3);
2880 constexpr QColor base = QColor(0xFF, 0xFF, 0xFF, 0xFF);
2881 constexpr QColor alternateBase = QColor(0x00, 0x00, 0x00, 0x09);
2882 const QColor btnHighlight = result.accent().color();
2883 const QColor btnColor = result.button().color();
2884
2885 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Highlight, btnHighlight);
2886 SET_IF_UNRESOLVED(QPalette::Active, QPalette::WindowText, textColor);
2887 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Button, btnFace);
2888 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Light, btnColor.lighter(150));
2889 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Dark, btnColor.darker(200));
2890 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Mid, btnColor.darker(150));
2891 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Text, textColor);
2892 SET_IF_UNRESOLVED(QPalette::Active, QPalette::BrightText, btnHighlight);
2893 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Base, base);
2894 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF));
2895 SET_IF_UNRESOLVED(QPalette::Active, QPalette::ButtonText, textColor);
2896 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Midlight, btnColor.lighter(125));
2897 SET_IF_UNRESOLVED(QPalette::Active, QPalette::Shadow, Qt::black);
2898 SET_IF_UNRESOLVED(QPalette::Active, QPalette::ToolTipBase, result.window().color());
2899 SET_IF_UNRESOLVED(QPalette::Active, QPalette::ToolTipText, result.windowText().color());
2900 SET_IF_UNRESOLVED(QPalette::Active, QPalette::AlternateBase, alternateBase);
2901
2902 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Highlight, btnHighlight);
2903 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::WindowText, textColor);
2904 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Button, btnFace);
2905 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Light, btnColor.lighter(150));
2906 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Dark, btnColor.darker(200));
2907 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Mid, btnColor.darker(150));
2908 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Text, textColor);
2909 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::BrightText, btnHighlight);
2910 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Base, base);
2911 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Window, QColor(0xF3,0xF3,0xF3,0xFF));
2912 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::ButtonText, textColor);
2913 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Midlight, btnColor.lighter(125));
2914 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Shadow, Qt::black);
2915 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::ToolTipBase, result.window().color());
2916 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::ToolTipText, result.windowText().color());
2917 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::AlternateBase, alternateBase);
2918
2919 result.setColor(QPalette::Disabled, QPalette::WindowText, textDisabled);
2920
2921 if (result.midlight() == result.button())
2922 result.setColor(QPalette::Midlight, btnColor.lighter(110));
2923 oldStyleSheet = qApp->styleSheet();
2924}
2925
2926static void populateDarkSystemBasePalette(QPalette &result)
2927{
2928 static QString oldStyleSheet;
2929 const bool styleSheetChanged = oldStyleSheet != qApp->styleSheet();
2930
2931 constexpr QColor alternateBase = QColor(0xFF, 0xFF, 0xFF, 0x0F);
2932
2933 SET_IF_UNRESOLVED(QPalette::Active, QPalette::AlternateBase, alternateBase);
2934
2935 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::AlternateBase, alternateBase);
2936
2937 oldStyleSheet = qApp->styleSheet();
2938}
2939
2940/*!
2941 \internal
2942 */
2943void QWindows11Style::polish(QPalette& result)
2944{
2945 highContrastTheme = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Unknown;
2946 colorSchemeIndex = QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Light ? 0 : 1;
2947
2948 if (!highContrastTheme && colorSchemeIndex == 0)
2949 populateLightSystemBasePalette(result);
2950 else if (!highContrastTheme && colorSchemeIndex == 1)
2951 populateDarkSystemBasePalette(result);
2952
2953 const bool styleSheetChanged = false; // so the macro works
2954
2955 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Button, result.button().color());
2956 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Window, result.window().color());
2957 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Light, result.light().color());
2958 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Dark, result.dark().color());
2959 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Accent, result.accent().color());
2960 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Highlight, result.highlight().color());
2961 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::HighlightedText, result.highlightedText().color());
2962 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::Text, result.text().color());
2963 SET_IF_UNRESOLVED(QPalette::Inactive, QPalette::WindowText, result.windowText().color());
2964
2965 auto *d = const_cast<QWindows11StylePrivate *>(d_func());
2966 d->m_standardIcons.clear();
2967}
2968
2969QPixmap QWindows11Style::standardPixmap(StandardPixmap standardPixmap,
2970 const QStyleOption *option,
2971 const QWidget *widget) const
2972{
2973 switch (standardPixmap) {
2974 case SP_TabScrollLeftButton:
2975 case SP_TabScrollRightButton:
2976 case SP_TabScrollUpButton:
2977 case SP_TabScrollDownButton:
2978 case SP_ToolBarHorizontalExtensionButton:
2979 case SP_ToolBarVerticalExtensionButton: {
2980 const int size = proxy()->pixelMetric(PM_ToolBarExtensionExtent, option, widget);
2981 return standardIcon(standardPixmap, option, widget).pixmap(size);
2982 }
2983 case SP_TitleBarMenuButton:
2984 case SP_TitleBarMinButton:
2985 case SP_TitleBarMaxButton:
2986 case SP_TitleBarCloseButton:
2987 case SP_TitleBarNormalButton:
2988 case SP_TitleBarShadeButton:
2989 case SP_TitleBarUnshadeButton:
2990 case SP_TitleBarContextHelpButton:
2991 case SP_DockWidgetCloseButton:
2992 case SP_MessageBoxInformation:
2993 case SP_MessageBoxWarning:
2994 case SP_MessageBoxCritical:
2995 case SP_MessageBoxQuestion:
2996 case SP_TrashIcon:
2997 case SP_ComputerIcon:
2998 case SP_DriveFDIcon:
2999 case SP_DriveHDIcon:
3000 case SP_DriveCDIcon:
3001 case SP_DriveDVDIcon:
3002 case SP_DriveNetIcon:
3003 case SP_DirOpenIcon:
3004 case SP_DirClosedIcon:
3005 case SP_FileIcon:
3006 case SP_FileDialogToParent:
3007 case SP_FileDialogNewFolder:
3008 case SP_FileDialogDetailedView:
3009 case SP_FileDialogInfoView:
3010 case SP_FileDialogContentsView:
3011 case SP_FileDialogListView:
3012 case SP_FileDialogBack:
3013 case SP_DirIcon:
3014 case SP_DialogOkButton:
3015 case SP_DialogCancelButton:
3016 case SP_DialogHelpButton:
3017 case SP_DialogOpenButton:
3018 case SP_DialogSaveButton:
3019 case SP_DialogCloseButton:
3020 case SP_DialogApplyButton:
3021 case SP_DialogResetButton:
3022 case SP_ArrowUp:
3023 case SP_ArrowDown:
3024 case SP_ArrowLeft:
3025 case SP_ArrowRight:
3026 case SP_ArrowBack:
3027 case SP_ArrowForward:
3028 case SP_DirHomeIcon:
3029 case SP_VistaShield:
3030 case SP_BrowserReload:
3031 case SP_BrowserStop:
3032 case SP_MediaPlay:
3033 case SP_MediaStop:
3034 case SP_MediaPause:
3035 case SP_MediaSkipForward:
3036 case SP_MediaSkipBackward:
3037 case SP_MediaSeekForward:
3038 case SP_MediaSeekBackward:
3039 case SP_MediaVolume:
3040 case SP_MediaVolumeMuted:
3041 case SP_LineEditClearButton:
3042 case SP_TabCloseButton:
3043 return standardIcon(standardPixmap, option, widget).pixmap(16, 16);
3044 // not (yet) implemented
3045 case SP_DesktopIcon:
3046 case SP_DirLinkIcon:
3047 case SP_DirLinkOpenIcon:
3048 case SP_FileLinkIcon:
3049 case SP_FileDialogStart:
3050 case SP_FileDialogEnd:
3051 case SP_DialogDiscardButton:
3052 case SP_DialogYesButton:
3053 case SP_DialogNoButton:
3054 case SP_CommandLink:
3055 case SP_DialogYesToAllButton:
3056 case SP_DialogNoToAllButton:
3057 case SP_DialogSaveAllButton:
3058 case SP_DialogAbortButton:
3059 case SP_DialogRetryButton:
3060 case SP_DialogIgnoreButton:
3061 case SP_RestoreDefaultsButton:
3062 case NStandardPixmap:
3063 case SP_CustomBase:
3064 break;
3065 }
3066 return QWindowsVistaStyle::standardPixmap(standardPixmap, option, widget);
3067}
3068
3069QIcon QWindows11Style::standardIcon(StandardPixmap standardIcon,
3070 const QStyleOption *option,
3071 const QWidget *widget) const
3072{
3073 Q_D(const QWindows11Style);
3074
3075 const auto getIcon = [&](Icon ico, double scale) {
3076 auto *d = const_cast<QWindows11StylePrivate *>(d_func());
3077 QIcon &icon = d->m_standardIcons[ico];
3078 if (icon.isNull()) {
3079 auto engine = new WinFontIconEngine(fluentIcon(ico), d->m_assetFont);
3080 engine->setScale(scale);
3081 icon = QIcon(engine);
3082 }
3083 return icon;
3084 };
3085
3086 switch (standardIcon) {
3087 case SP_TitleBarMenuButton:
3088 return getIcon(Icon::ButtonMenu, 1.0);
3089 case SP_TitleBarMinButton:
3090 return getIcon(Icon::ChromeMinimize, 0.7);
3091 case SP_TitleBarMaxButton:
3092 return getIcon(Icon::ChromeMaximize, 0.7);
3093 case SP_TitleBarCloseButton:
3094 return getIcon(Icon::ChromeClose, 0.7);
3095 case SP_TitleBarNormalButton:
3096 return getIcon(Icon::ChromeRestore, 0.7);
3097 case SP_TitleBarShadeButton:
3098 return getIcon(Icon::CaretSolidUp, 1.0);
3099 case SP_TitleBarUnshadeButton:
3100 return getIcon(Icon::CaretSolidDown, 1.0);
3101 case SP_TitleBarContextHelpButton:
3102 return getIcon(Icon::Help, 1.0);
3103 case SP_DockWidgetCloseButton:
3104 return getIcon(Icon::ChromeClose, 1.0);
3105 case SP_MessageBoxInformation:
3106 return getIcon(Icon::Info, 1.0);
3107 case SP_MessageBoxWarning:
3108 return getIcon(Icon::Warning, 1.0);
3109 case SP_MessageBoxCritical:
3110 return getIcon(Icon::ErrorBadge, 1.0);
3111 case SP_MessageBoxQuestion:
3112 return getIcon(Icon::Help, 1.0);
3113 case SP_DesktopIcon:
3114 break;
3115 case SP_TrashIcon:
3116 return getIcon(Icon::Delete, 1.0);
3117 case SP_ComputerIcon:
3118 return getIcon(Icon::DeviceLaptopNoPic, 1.0);
3119 case SP_DriveFDIcon:
3120 return getIcon(Icon::Save, 1.0);
3121 case SP_DriveHDIcon:
3122 return getIcon(Icon::HardDrive, 1.0);
3123 case SP_DriveCDIcon:
3124 case SP_DriveDVDIcon:
3125 return getIcon(Icon::StorageOptical, 1.0);
3126 case SP_DriveNetIcon:
3127 return getIcon(Icon::Network, 1.0);
3128 case SP_DirOpenIcon:
3129 return getIcon(Icon::OpenFolderHorizontal, 1.0);
3130 case SP_DirClosedIcon:
3131 return getIcon(Icon::FolderHorizontal, 1.0);
3132 case SP_DirLinkIcon:
3133 case SP_DirLinkOpenIcon:
3134 break;
3135 case SP_FileIcon:
3136 return getIcon(Icon::Document, 1.0);
3137 case SP_FileLinkIcon:
3138 break;
3139 case SP_ToolBarHorizontalExtensionButton:
3140 case SP_ToolBarVerticalExtensionButton:
3141 return getIcon(Icon::More, 1.0);
3142 case SP_FileDialogStart:
3143 case SP_FileDialogEnd:
3144 break;
3145 case SP_FileDialogToParent:
3146 break;
3147 return getIcon(Icon::ChevronUpMed, 1.0);
3148 case SP_FileDialogNewFolder:
3149 return getIcon(Icon::NewFolder, 1.0);
3150 case SP_FileDialogDetailedView:
3151 return getIcon(Icon::BulletedList, 1.0);
3152 case SP_FileDialogInfoView:
3153 return getIcon(Icon::Info, 1.0);
3154 case SP_FileDialogContentsView:
3155 return getIcon(Icon::BulletedList2, 1.0);
3156 case SP_FileDialogListView:
3157 return getIcon(Icon::FolderList, 1.0);
3158 case SP_FileDialogBack:
3159 return getIcon(d->rtl(option) ? Icon::ChevronRightMed : Icon::ChevronLeftMed, 1.0);
3160 case SP_DirIcon:
3161 return getIcon(Icon::FolderHorizontal, 1.0);
3162 case SP_DialogOkButton:
3163 return getIcon(Icon::ReturnKey, 1.0);
3164 case SP_DialogCancelButton:
3165 return getIcon(Icon::ChromeClose, 1.0);
3166 case SP_DialogHelpButton:
3167 return getIcon(Icon::GetHelpApp, 1.0);
3168 case SP_DialogOpenButton:
3169 return getIcon(Icon::OpenFile, 1.0);
3170 case SP_DialogSaveButton:
3171 return getIcon(Icon::Save, 1.0);
3172 case SP_DialogCloseButton:
3173 return getIcon(Icon::ChromeClose, 1.0);
3174 case SP_DialogApplyButton:
3175 return getIcon(Icon::CheckMark, 1.0);
3176 case SP_DialogResetButton:
3177 return getIcon(Icon::UpdateRestore, 1.0);
3178 case SP_DialogDiscardButton:
3179 case SP_DialogYesButton:
3180 case SP_DialogNoButton:
3181 break;
3182 case SP_ArrowUp:
3183 return getIcon(Icon::ChevronUpMed, 1.0);
3184 case SP_ArrowDown:
3185 return getIcon(Icon::ChevronDownMed, 1.0);
3186 case SP_ArrowLeft:
3187 return getIcon(Icon::ChevronLeftMed, 1.0);
3188 case SP_ArrowRight:
3189 return getIcon(Icon::ChevronRightMed, 1.0);
3190 case SP_ArrowBack:
3191 return getIcon(d->rtl(option) ? Icon::ChevronRightMed : Icon::ChevronLeftMed, 1.0);
3192 case SP_ArrowForward:
3193 return getIcon(d->rtl(option) ? Icon::ChevronLeftMed : Icon::ChevronRightMed, 1.0);
3194 case SP_DirHomeIcon:
3195 return getIcon(Icon::Home, 1.0);
3196 case SP_CommandLink:
3197 break;
3198 case SP_VistaShield:
3199 return getIcon(Icon::Shield, 1.0);
3200 case SP_BrowserReload:
3201 return getIcon(Icon::Refresh, 1.0);
3202 case SP_BrowserStop:
3203 return getIcon(Icon::ErrorBadge, 1.0);
3204 case SP_MediaPlay:
3205 return getIcon(Icon::Play, 1.0);
3206 case SP_MediaStop:
3207 return getIcon(Icon::Stop, 1.0);
3208 case SP_MediaPause:
3209 return getIcon(Icon::Pause, 1.0);
3210 case SP_MediaSkipForward:
3211 return getIcon(d->rtl(option) ? Icon::Previous : Icon::Next, 1.0);
3212 case SP_MediaSkipBackward:
3213 return getIcon(d->rtl(option) ? Icon::Next : Icon::Previous, 1.0);
3214 case SP_MediaSeekForward:
3215 return getIcon(d->rtl(option) ? Icon::Rewind : Icon::FastForward, 1.0);
3216 case SP_MediaSeekBackward:
3217 return getIcon(d->rtl(option) ? Icon::FastForward : Icon::Rewind, 1.0);
3218 case SP_MediaVolume:
3219 return getIcon(Icon::Volume, 1.0);
3220 case SP_MediaVolumeMuted:
3221 return getIcon(Icon::Mute, 1.0);
3222 case SP_LineEditClearButton:
3223 return getIcon(Icon::Clear, 0.7);
3224 case SP_DialogYesToAllButton:
3225 case SP_DialogNoToAllButton:
3226 case SP_DialogSaveAllButton:
3227 case SP_DialogAbortButton:
3228 case SP_DialogRetryButton:
3229 case SP_DialogIgnoreButton:
3230 case SP_RestoreDefaultsButton:
3231 break;
3232 case SP_TabCloseButton:
3233 return getIcon(Icon::ChromeClose, 0.6);
3234 case SP_TabScrollLeftButton:
3235 return getIcon(Icon::CaretLeftSolid8, 0.5);
3236 case SP_TabScrollRightButton:
3237 return getIcon(Icon::CaretRightSolid8, 0.5);
3238 case SP_TabScrollUpButton:
3239 return getIcon(Icon::CaretUpSolid8, 0.5);
3240 case SP_TabScrollDownButton:
3241 return getIcon(Icon::CaretDownSolid8, 0.5);
3242 case NStandardPixmap:
3243 case SP_CustomBase:
3244 break;
3245 }
3246 return QWindowsVistaStyle::standardIcon(standardIcon, option, widget);
3247}
3248
3249QPixmap QWindows11Style::generatedIconPixmap(QIcon::Mode iconMode, const QPixmap &pixmap,
3250 const QStyleOption *option) const
3251{
3252 if (iconMode == QIcon::Disabled)
3253 return QWindowsVistaStyle::generatedIconPixmap(iconMode, pixmap, option);
3254 return pixmap;
3255}
3256
3257
3258QColor QWindows11Style::calculateAccentColor(const QStyleOption *option) const
3259{
3260 using namespace StyleOptionHelper;
3261 if (isDisabled(option))
3262 return winUI3Color(fillAccentDisabled);
3263 const auto alphaColor = isPressed(option) ? fillAccentTertiary
3264 : isHover(option) ? fillAccentSecondary
3265 : fillAccentDefault;
3266 const auto alpha = winUI3Color(alphaColor);
3267 QColor col = option->palette.accent().color();
3268 col.setAlpha(alpha.alpha());
3269 return col;
3270}
3271
3272QPen QWindows11Style::borderPenControlAlt(const QStyleOption *option) const
3273{
3274 using namespace StyleOptionHelper;
3275 if (isChecked(option))
3276 return Qt::NoPen; // same color as fill color, so no pen needed
3277 if (highContrastTheme)
3278 return option->palette.buttonText().color();
3279 if (isDisabled(option) || isPressed(option))
3280 return winUI3Color(frameColorStrongDisabled);
3281 return winUI3Color(frameColorStrong);
3282}
3283
3284QBrush QWindows11Style::controlFillBrush(const QStyleOption *option, ControlType controlType) const
3285{
3286 using namespace StyleOptionHelper;
3287 static constexpr WINUI3Color colorEnums[2][4] = {
3288 // Light & Dark Control
3291 // Light & Dark Control Alt
3294 };
3295
3296 if (option->palette.isBrushSet(QPalette::Current, QPalette::Button))
3297 return option->palette.brush(QPalette::Current, QPalette::Button);
3298
3299 if (!isChecked(option) && isAutoRaise(option))
3300 return Qt::NoBrush;
3301
3302 // checked is the same for Control (Buttons) and Control Alt (Radiobuttons/Checkboxes)
3303 if (isChecked(option))
3304 return calculateAccentColor(option);
3305
3306 const auto state = calcControlState(option);
3307 return winUI3Color(colorEnums[int(controlType)][int(state)]);
3308}
3309
3310QBrush QWindows11Style::inputFillBrush(const QStyleOption *option, const QWidget *widget) const
3311{
3312 // slightly different states than in controlFillBrush
3313 using namespace StyleOptionHelper;
3314 const auto role = widget ? widget->backgroundRole() : QPalette::Window;
3315 if (option->palette.isBrushSet(QPalette::Current, role))
3316 return option->palette.brush(QPalette::Current, role);
3317
3318 if (isDisabled(option))
3319 return winUI3Color(fillControlDisabled);
3320 if (hasFocus(option))
3321 return winUI3Color(fillControlInputActive);
3322 if (isHover(option))
3323 return winUI3Color(fillControlSecondary);
3324 return winUI3Color(fillControlDefault);
3325}
3326
3327QColor QWindows11Style::controlTextColor(const QStyleOption *option, bool ignoreIsChecked) const
3328{
3329 using namespace StyleOptionHelper;
3330 static constexpr WINUI3Color colorEnums[2][4] = {
3331 // Control, unchecked
3333 // Control, checked
3335 };
3336
3337 if (option->palette.isBrushSet(QPalette::Current, QPalette::ButtonText))
3338 return option->palette.color(QPalette::Current, QPalette::ButtonText);
3339
3340 const int colorIndex = !ignoreIsChecked && isChecked(option) ? 1 : 0;
3341 const auto state = calcControlState(option);
3342 return winUI3Color(colorEnums[colorIndex][int(state)]);
3343}
3344
3345void QWindows11Style::drawLineEditFrame(QPainter *p, const QRectF &rect, const QStyleOption *o, bool isEditable) const
3346{
3347 const bool isHovered = o->state & State_MouseOver;
3348 const auto frameCol = highContrastTheme
3349 ? o->palette.color(isHovered ? QPalette::Accent
3350 : QPalette::ButtonText)
3351 : winUI3Color(frameColorLight);
3352 drawRoundedRect(p, rect, frameCol, Qt::NoBrush);
3353
3354 if (!isEditable || StyleOptionHelper::isDisabled(o))
3355 return;
3356
3357 const bool hasFocus = o->state & State_HasFocus;
3358 const auto underlineCol = hasFocus
3359 ? o->palette.color(QPalette::Accent)
3360 : colorSchemeIndex == 0 ? QColor(0x80, 0x80, 0x80)
3361 : QColor(0xa0, 0xa0, 0xa0);
3362 QPainterStateGuard psg(p);
3363 if (hasFocus) {
3364 p->setClipRect(rect.marginsRemoved(QMarginsF(0, rect.height() - 1.5, 0, -1)));
3365 const QRectF r(rect.top(), rect.left(), rect.width(), rect.height() - 1);
3366 drawRoundedRect(p, r, QPen(underlineCol, 2), Qt::NoBrush);
3367 } else {
3368 p->setClipRect(rect.marginsRemoved(QMarginsF(0, rect.height() - 0.5, 0, -1)));
3369 drawRoundedRect(p, rect, underlineCol, Qt::NoBrush);
3370 }
3371}
3372
3373void QWindows11Style::drawIndicatorArrow(QPainter *painter, const QRect &rect,
3374 PrimitiveElement arrowType, QPen pen) const
3375{
3376 Q_D(const QWindows11Style);
3377
3378 if (rect.width() <= 1 || rect.height() <= 1)
3379 return;
3380 Icon ico = Icon::Help;
3381 switch (arrowType) {
3382 case PE_IndicatorArrowUp:
3383 ico = Icon::ChevronUpMed;
3384 break;
3385 case PE_IndicatorArrowDown:
3386 ico = Icon::ChevronDownMed;
3387 break;
3388 case PE_IndicatorArrowLeft:
3389 ico = Icon::ChevronLeftMed;
3390 break;
3391 case PE_IndicatorArrowRight:
3392 ico = Icon::ChevronRightMed;
3393 break;
3394 default:
3395 return;
3396 }
3397 QPainterStateGuard psg(painter);
3398 painter->setFont(d->m_assetFont);
3399 painter->setPen(pen);
3400 painter->drawText(rect, Qt::AlignCenter, fluentIcon(ico));
3401}
3402
3403#if QT_CONFIG(toolbutton)
3404void QWindows11Style::drawIndicatorArrow(QPainter *painter, const QRect &rect,
3405 const QStyleOptionToolButton *option,
3406 const QWidget *widget) const
3407{
3408 const auto arrowType = QCommonStylePrivate::arrowToPrimitiveElement(option->arrowType);
3409 QStyleOption arrowOpt = *option;
3410 arrowOpt.rect = rect;
3411 arrowOpt.palette.setColor(QPalette::ButtonText, controlTextColor(option));
3412 proxy()->drawPrimitive(arrowType, &arrowOpt, painter, widget);
3413}
3414#endif
3415
3416
3417QColor QWindows11Style::winUI3Color(enum WINUI3Color col) const
3418{
3419 return WINUI3Colors[colorSchemeIndex][col];
3420}
3421
3422template <typename C>
3423int QWindows11Style::widthFromChar(const QFont &widgetFont, Icon icon, C &cacheContainer) const
3424{
3425 Q_D(const QWindows11Style);
3426 int fontSize = QFontInfo(widgetFont).pointSize();
3427 if (fontSize <= 0)
3428 fontSize = widgetFont.pixelSize() * -1;
3429 auto it = cacheContainer.find(fontSize);
3430 if (it == cacheContainer.end()) {
3431 QFont f(d->m_assetFont);
3432 QFontMetrics fm(f.resolve(widgetFont));
3433 const auto width = fm.horizontalAdvance(fluentIcon(icon));
3434 cacheContainer.insert(fontSize, width);
3435 return width;
3436 }
3437 return it.value();
3438}
3439
3440#undef SET_IF_UNRESOLVED
3441
3442QT_END_NAMESPACE
friend class QPainter
QPainter * painter() const
Returns the paint engine's painter.
friend class QWidget
Definition qpainter.h:432
\inmodule QtCore\reentrant
Definition qpoint.h:232
\inmodule QtCore\reentrant
Definition qpoint.h:30
bool isDisabled(const QStyleOption *option)
ControlState calcControlState(const QStyleOption *option)
bool hasFocus(const QStyleOption *option)
bool isChecked(const QStyleOption *option)
bool isSelected(const QStyleOption *option)
bool isPressed(const QStyleOption *option)
bool isHover(const QStyleOption *option)
bool isAutoRaise(const QStyleOption *option)
#define qApp
static constexpr std::array< std::array< QColor, 37 >, 2 > WINUI3Colors
#define SET_IF_UNRESOLVED(GROUP, ROLE, VALUE)
static constexpr std::array< QColor, 37 > WINUI3ColorsDark
static constexpr QColor shellCaptionCloseFillColorSecondary(0xC4, 0x2B, 0x1C, 0xE6)
static qreal sliderInnerRadius(QStyle::State state, bool insideHandle)
static qreal radioButtonInnerRadius(QStyle::State state)
static constexpr QColor shellCaptionCloseFillColorPrimary(0xC4, 0x2B, 0x1C, 0xFF)
static constexpr int contentHMargin
static void populateLightSystemBasePalette(QPalette &result)
static constexpr std::array< QColor, 37 > WINUI3ColorsLight
static constexpr int percentToAlpha(double percent)
static void populateDarkSystemBasePalette(QPalette &result)
static constexpr int contentItemHMargin
static constexpr QColor shellCaptionCloseTextFillColorPrimary(0xFF, 0xFF, 0xFF, 0xFF)
static void drawRoundedRect(QPainter *p, R &&rect, P &&pen, B &&brush, int radius=secondLevelRoundingRadius)
static constexpr int topLevelRoundingRadius
static constexpr QColor shellCaptionCloseTextFillColorSecondary(0xFF, 0xFF, 0xFF, 0xB3)
static constexpr int secondLevelRoundingRadius
WINUI3Color
@ fillControlAltSecondary
@ fillControlTertiary
@ textOnAccentPrimary
@ fillControlDefault
@ fillControlDisabled
@ subtleHighlightColor
@ textPrimary
@ textDisabled
@ fillControlSecondary
@ textSecondary
@ textOnAccentSecondary
@ textOnAccentDisabled
@ fillControlAltQuarternary
@ fillControlAltTertiary
@ fillControlAltDisabled