Issues: Fix ugly error text when item is selected

Trying to make red text work on a various possibility of selection
colors is futile. Just use the normal "blended" text color, like for
file names that are found, for the selected item. Use the theme defined
error color for items that are not selected.

Fixes: QTCREATORBUG-27525
Change-Id: I423487fbf8b5333993774ccebcb488ffb156dc0e
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Eike Ziller
2023-01-18 15:23:21 +01:00
parent a20c4c4490
commit 7e9e103c53

View File

@@ -25,6 +25,8 @@
#include <utils/itemviews.h> #include <utils/itemviews.h>
#include <utils/outputformatter.h> #include <utils/outputformatter.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <utils/stylehelper.h>
#include <utils/theme/theme.h>
#include <utils/utilsicons.h> #include <utils/utilsicons.h>
#include <QDir> #include <QDir>
@@ -940,20 +942,16 @@ void TaskDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
} }
} }
QColor mix; const QColor mix = StyleHelper::mergedColors(textColor, backgroundColor, 70);
mix.setRgb( static_cast<int>(0.7 * textColor.red() + 0.3 * backgroundColor.red()),
static_cast<int>(0.7 * textColor.green() + 0.3 * backgroundColor.green()),
static_cast<int>(0.7 * textColor.blue() + 0.3 * backgroundColor.blue()));
painter->setPen(mix);
const QString directory = QDir::toNativeSeparators(index.data(TaskModel::File).toString()); const QString directory = QDir::toNativeSeparators(index.data(TaskModel::File).toString());
int secondBaseLine = positions.top() + fm.ascent() + height + leading; int secondBaseLine = positions.top() + fm.ascent() + height + leading;
if (index.data(TaskModel::FileNotFound).toBool() if (index.data(TaskModel::FileNotFound).toBool() && !directory.isEmpty()) {
&& !directory.isEmpty()) { const QString fileNotFound = Tr::tr("File not found: %1").arg(directory);
QString fileNotFound = Tr::tr("File not found: %1").arg(directory); const QColor errorColor = selected ? mix : creatorTheme()->color(Theme::TextColorError);
painter->setPen(Qt::red); painter->setPen(errorColor);
painter->drawText(positions.textAreaLeft(), secondBaseLine, fileNotFound); painter->drawText(positions.textAreaLeft(), secondBaseLine, fileNotFound);
} else { } else {
painter->setPen(mix);
painter->drawText(positions.textAreaLeft(), secondBaseLine, directory); painter->drawText(positions.textAreaLeft(), secondBaseLine, directory);
} }
} }