From 3dcdbe9069c452e2f0eacb925aa7412e63dc4762 Mon Sep 17 00:00:00 2001 From: hjk Date: Mon, 22 May 2023 10:32:24 +0200 Subject: [PATCH] FancyLineEdit: Mark placeholder text that doesn't pass validation ... also for place holder text. While this omission was apparently intentional, the opposite behavior was used in the Beautifier settings, arguably being a better standard as this makes clear to the user that the pre-selected placeholder value won't be ok to use. Change-Id: Iaf15b1351de929dee57329efdf18d7e831b4f8bc Reviewed-by: Reviewed-by: Eike Ziller --- src/libs/utils/fancylineedit.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp index 03e33c67b67..443845e7801 100644 --- a/src/libs/utils/fancylineedit.cpp +++ b/src/libs/utils/fancylineedit.cpp @@ -115,6 +115,7 @@ public: const QColor m_okTextColor; const QColor m_errorTextColor; + const QColor m_placeholderTextColor; QString m_errorMessage; }; @@ -123,7 +124,9 @@ FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) : m_lineEdit(parent), m_completionShortcut(completionShortcut()->key(), parent), m_okTextColor(creatorTheme()->color(Theme::TextColorNormal)), - m_errorTextColor(creatorTheme()->color(Theme::TextColorError)) + m_errorTextColor(creatorTheme()->color(Theme::TextColorError)), + m_placeholderTextColor(creatorTheme()->color(Theme::PalettePlaceholderText)) + { m_completionShortcut.setContext(Qt::WidgetShortcut); connect(completionShortcut(), &CompletionShortcut::keyChanged, @@ -485,15 +488,18 @@ void FancyLineEdit::validate() setToolTip(d->m_errorMessage); d->m_toolTipSet = true; } - // Changed..figure out if valid changed. DisplayingPlaceholderText is not valid, - // but should not show error color. Also trigger on the first change. + // Changed..figure out if valid changed. Also trigger on the first change. + // Invalid DisplayingPlaceholderText shows also error color. if (newState != d->m_state || d->m_firstChange) { const bool validHasChanged = (d->m_state == Valid) != (newState == Valid); d->m_state = newState; d->m_firstChange = false; QPalette p = palette(); - p.setColor(QPalette::Active, QPalette::Text, newState == Invalid ? d->m_errorTextColor : d->m_okTextColor); + p.setColor(QPalette::Active, QPalette::Text, + newState == Invalid ? d->m_errorTextColor : d->m_okTextColor); + p.setColor(QPalette::Active, QPalette::PlaceholderText, + validates ? d->m_placeholderTextColor : d->m_errorTextColor); setPalette(p); if (validHasChanged)