From 11473410c2de8188131c0d87827ab575cbe67387 Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Mon, 19 Aug 2024 12:17:51 +0200 Subject: [PATCH] QWindows11Style: Make MdiControls darkmode aware Pick-to: 6.7 Change-Id: I525602c9757a8fed3d5ab6d64fe856adaa75b83d Reviewed-by: Oliver Wolff (cherry picked from commit 982314aace15109857784b0b6c3b49cc6e13b9b7) Reviewed-by: Qt Cherry-pick Bot --- .../styles/modernwindows/qwindows11style.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index ce28f4e40fd..0da7f4d836b 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -551,6 +551,48 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt } } break; + case CC_MdiControls:{ + QFont buttonFont = QFont(assetFont); + buttonFont.setPointSize(8); + QPoint mousePos = widget->mapFromGlobal(QCursor::pos()); + if (option->subControls.testFlag(SC_MdiCloseButton)) { + const QRect closeButtonRect = proxy()->subControlRect(QStyle::CC_MdiControls, option, SC_MdiCloseButton, widget);; + if (closeButtonRect.isValid()) { + bool hover = closeButtonRect.contains(mousePos); + if (hover) + painter->fillRect(closeButtonRect,shellCloseButtonColor); + const QString textToDraw("\uE8BB"); + painter->setPen(QPen(hover ? option->palette.highlightedText().color() : option->palette.text().color())); + painter->setFont(buttonFont); + painter->drawText(closeButtonRect, Qt::AlignVCenter | Qt::AlignHCenter, textToDraw); + } + } + if (option->subControls.testFlag(SC_MdiNormalButton)) { + const QRect normalButtonRect = proxy()->subControlRect(QStyle::CC_MdiControls, option, SC_MdiNormalButton, widget);; + if (normalButtonRect.isValid()) { + bool hover = normalButtonRect.contains(mousePos); + if (hover) + painter->fillRect(normalButtonRect,WINUI3Colors[colorSchemeIndex][subtleHighlightColor]); + const QString textToDraw("\uE923"); + painter->setPen(QPen(option->palette.text().color())); + painter->setFont(buttonFont); + painter->drawText(normalButtonRect, Qt::AlignVCenter | Qt::AlignHCenter, textToDraw); + } + } + if (option->subControls.testFlag(QStyle::SC_MdiMinButton)) { + const QRect minButtonRect = proxy()->subControlRect(QStyle::CC_MdiControls, option, SC_MdiMinButton, widget); + if (minButtonRect.isValid()) { + bool hover = minButtonRect.contains(mousePos); + if (hover) + painter->fillRect(minButtonRect,WINUI3Colors[colorSchemeIndex][subtleHighlightColor]); + const QString textToDraw("\uE921"); + painter->setPen(QPen(option->palette.text().color())); + painter->setFont(buttonFont); + painter->drawText(minButtonRect, Qt::AlignVCenter | Qt::AlignHCenter, textToDraw); + } + } + } + break; case CC_TitleBar: if (const auto* titlebar = qstyleoption_cast(option)) { painter->setPen(Qt::NoPen);