From a0fcb0ae6df6767a24f217b6c31b1d8265a23933 Mon Sep 17 00:00:00 2001 From: yangzhenghan Date: Fri, 10 Nov 2023 15:49:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=AA=97=E5=8F=A3=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E9=BC=A0=E6=A0=87=E6=82=AC=E6=B5=AE=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E5=89=8D=E6=99=AF=E8=89=B2=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E7=99=BD=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widgets/standardsystembutton.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/standardsystembutton.cpp b/src/widgets/standardsystembutton.cpp index 73e8205f..fd0d5fd3 100644 --- a/src/widgets/standardsystembutton.cpp +++ b/src/widgets/standardsystembutton.cpp @@ -327,6 +327,9 @@ void StandardSystemButton::paintEvent(QPaintEvent *event) if (!underMouse() && !d->active && d->inactiveForegroundColor.isValid()) { return d->inactiveForegroundColor; } + if (d->buttonType == SystemButtonType::Close && underMouse()) { + return kDefaultWhiteColor; + } if (d->activeForegroundColor.isValid()) { return d->activeForegroundColor; } From 7713230e6b5457db64fe3a671f492b5bffe2d20f Mon Sep 17 00:00:00 2001 From: yangzhenghan Date: Fri, 10 Nov 2023 15:50:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?#243=20=E4=BF=AE=E6=94=B9=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E7=9A=84=E9=BC=A0=E6=A0=87=E6=82=AC=E6=B5=AE?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E8=89=B2=E5=92=8C=E6=8C=89=E4=B8=8B=E6=97=B6?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/utils.cpp | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/core/utils.cpp b/src/core/utils.cpp index 3cf8500a..d5688e1f 100644 --- a/src/core/utils.cpp +++ b/src/core/utils.cpp @@ -25,6 +25,7 @@ #include "utils.h" #include "framelesshelpercore_global_p.h" #include "framelessmanager_p.h" +#include "framelessmanager.h" #ifdef Q_OS_WINDOWS # include "winverhelper_p.h" #endif // Q_OS_WINDOWS @@ -278,25 +279,39 @@ QColor Utils::calculateSystemButtonBackgroundColor(const SystemButtonType button if (state == ButtonState::Normal) { return kDefaultTransparentColor; } + + const bool isDark = (FramelessManager::instance()->systemTheme() == SystemTheme::Dark); const bool isClose = (button == SystemButtonType::Close); const bool isTitleColor = isTitleBarColorized(); const bool isHovered = (state == ButtonState::Hovered); - const auto result = [isClose, isTitleColor]() -> QColor { + const auto result = [isDark, isClose, isTitleColor]() -> QColor { if (isClose) { return kDefaultSystemCloseButtonBackgroundColor; } if (isTitleColor) { - return getAccentColor(); + const auto accent = getAccentColor(); + return [](const QColor &color) -> QColor { + // Calculate the most appropriate foreground color, based on the + // current background color. + const qreal grayF = ( + (qreal(0.299) * color.redF()) + + (qreal(0.587) * color.greenF()) + + (qreal(0.114) * color.blueF())); + static constexpr const auto kFlag = qreal(0.5); + if ((grayF < kFlag) || qFuzzyCompare(grayF, kFlag)) { + return kDefaultWhiteColor; + } + return kDefaultBlackColor; + }(accent); } - return kDefaultSystemButtonBackgroundColor; + return isDark ? kDefaultWhiteColor : kDefaultBlackColor; }(); if (isClose) { return (isHovered ? result.lighter(110) : result.lighter(140)); } - if (!isTitleColor) { - return (isHovered ? result.lighter(110) : result); - } - return (isHovered ? result.lighter(150) : result.lighter(120)); + + return (isHovered ? QColor(result.red(), result.green(), result.blue(), 12) : + QColor(result.red(), result.green(), result.blue(), 6)); } bool Utils::shouldAppsUseDarkMode()