QtSupport: Fix output formatter test on dark systems

Change-Id: If511632de2be26899d2bea824b1a5de6ce1c4947
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2025-02-06 13:06:08 +01:00
parent 6e5f649d96
commit b5c22ff232

View File

@@ -425,17 +425,21 @@ static QTextCharFormat blueFormat()
return result;
}
static QTextCharFormat tweakedBlueFormat()
static QTextCharFormat tweakedFormat(QTextCharFormat format)
{
// foreground gets tweaked when passing doAppendMessage()
QTextCharFormat tweakedBlue = blueFormat();
QColor foreground = tweakedBlue.foreground().color();
const QColor background = tweakedBlue.hasProperty(QTextCharFormat::BackgroundBrush)
? tweakedBlue.background().color()
QColor foreground = format.foreground().color();
const QColor background = format.hasProperty(QTextCharFormat::BackgroundBrush)
? format.background().color()
: Utils::creatorColor(Theme::BackgroundColorNormal);
foreground = StyleHelper::ensureReadableOn(background, foreground);
tweakedBlue.setForeground(foreground);
return tweakedBlue;
format.setForeground(foreground);
return format;
}
static QTextCharFormat tweakedBlueFormat()
{
return tweakedFormat(blueFormat());
}
static QTextCharFormat greenFormat()
@@ -445,6 +449,11 @@ static QTextCharFormat greenFormat()
return result;
}
static QTextCharFormat tweakedGreenFormat()
{
return tweakedFormat(greenFormat());
}
void QtOutputFormatterTest::testQtOutputFormatter_appendMessage_data()
{
QTest::addColumn<QString>("inputText");
@@ -518,7 +527,7 @@ void QtOutputFormatterTest::testQtOutputFormatter_appendMixedAssertAndAnsi()
QCOMPARE(edit.toPlainText(), outputText);
edit.moveCursor(QTextCursor::Start);
QCOMPARE(edit.currentCharFormat(), greenFormat());
QCOMPARE(edit.currentCharFormat(), tweakedGreenFormat());
edit.moveCursor(QTextCursor::WordRight);
edit.moveCursor(QTextCursor::Right);