From 54f7ebf001351f8b1d9fc0ea5153b7a789d82740 Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Thu, 13 Oct 2022 13:03:01 +0200 Subject: [PATCH] Utils: Fix missing DetailsWidget outline On some systems, QPalette::Midlight can have the same color as the background color. So instead of using QPalette::Midlight on non-macOS, mix our own color with 15% text color intensity, to visually match what Qt Creator < 9.0 did. Change-Id: I40848b5e16344c07f42c20415194f893641d5f70 Reviewed-by: hjk --- src/libs/utils/detailsbutton.cpp | 16 +++++++++++----- src/libs/utils/detailsbutton.h | 1 + src/libs/utils/detailswidget.cpp | 7 ++----- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/libs/utils/detailsbutton.cpp b/src/libs/utils/detailsbutton.cpp index d5ab48238f8..32182d8ecf4 100644 --- a/src/libs/utils/detailsbutton.cpp +++ b/src/libs/utils/detailsbutton.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -81,6 +82,14 @@ QSize DetailsButton::sizeHint() const spacing + fontMetrics().height() + spacing); } +QColor DetailsButton::outlineColor() +{ + return HostOsInfo::isMacHost() + ? QGuiApplication::palette().color(QPalette::Mid) + : StyleHelper::mergedColors(creatorTheme()->color(Theme::TextColorNormal), + creatorTheme()->color(Theme::BackgroundColorNormal), 15); +} + void DetailsButton::paintEvent(QPaintEvent *e) { Q_UNUSED(e) @@ -93,11 +102,8 @@ void DetailsButton::paintEvent(QPaintEvent *e) p.restore(); } - if (!creatorTheme()->flag(Theme::FlatProjectsMode)) { - const QColor outlineColor = palette().color(HostOsInfo::isMacHost() ? QPalette::Mid - : QPalette::Midlight); - qDrawPlainRect(&p, rect(), outlineColor); - } + if (!creatorTheme()->flag(Theme::FlatProjectsMode)) + qDrawPlainRect(&p, rect(), outlineColor()); const QRect textRect(spacing + 3, 0, width(), height()); p.drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, text()); diff --git a/src/libs/utils/detailsbutton.h b/src/libs/utils/detailsbutton.h index 8895418f805..844c9e13c20 100644 --- a/src/libs/utils/detailsbutton.h +++ b/src/libs/utils/detailsbutton.h @@ -49,6 +49,7 @@ class QTCREATOR_UTILS_EXPORT DetailsButton : public ExpandButton public: DetailsButton(QWidget *parent = nullptr); QSize sizeHint() const override; + static QColor outlineColor(); private: void paintEvent(QPaintEvent *e) override; diff --git a/src/libs/utils/detailswidget.cpp b/src/libs/utils/detailswidget.cpp index e1ad8c19489..6b60bac0d87 100644 --- a/src/libs/utils/detailswidget.cpp +++ b/src/libs/utils/detailswidget.cpp @@ -227,11 +227,8 @@ void DetailsWidget::paintEvent(QPaintEvent *paintEvent) : palette().color(QPalette::Window); p.fillRect(rect(), bgColor); } - if (!creatorTheme()->flag(Theme::FlatProjectsMode)) { - const QColor outlineColor = palette().color(HostOsInfo::isMacHost() ? QPalette::Mid - : QPalette::Midlight); - qDrawPlainRect(&p, rect(), outlineColor); - } + if (!creatorTheme()->flag(Theme::FlatProjectsMode)) + qDrawPlainRect(&p, rect(), DetailsButton::outlineColor()); } void DetailsWidget::enterEvent(QEnterEvent *event)