TextEditor: skip painting overlays with invalid background

Makes it possible to turn of specific overlays by unsetting the color.
Such color resulted in a black overlay until now, which is also kind of
unexpected.

Change-Id: I90732ae496af62b573b2e3b8d8c7fe56632ca8d9
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
David Schulz
2019-01-22 14:01:30 +01:00
parent 8d9ac8d94b
commit bcda567392
2 changed files with 34 additions and 32 deletions

View File

@@ -143,6 +143,14 @@ uint qHash(const TextStyle &textStyle)
return ::qHash(quint8(textStyle));
}
static bool isOverlayCategory(TextStyle category)
{
return category == C_OCCURRENCES
|| category == C_OCCURRENCES_RENAME
|| category == C_SEARCH_RESULT
|| category == C_PARENTHESES_MISMATCH;
}
/**
* Returns the QTextCharFormat of the given format category.
*/
@@ -166,18 +174,18 @@ QTextCharFormat FontSettings::toTextCharFormat(TextStyle category) const
"Unused variable"));
}
if (f.foreground().isValid()
&& category != C_OCCURRENCES
&& category != C_OCCURRENCES_RENAME
&& category != C_SEARCH_RESULT
&& category != C_PARENTHESES_MISMATCH)
if (f.foreground().isValid() && !isOverlayCategory(category))
tf.setForeground(f.foreground());
if (f.background().isValid() && (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background()))
if (f.background().isValid()) {
if (category == C_TEXT || f.background() != m_scheme.formatFor(C_TEXT).background())
tf.setBackground(f.background());
} else if (isOverlayCategory(category)) {
// overlays without a background schouldn't get painted
tf.setBackground(QColor());
} else if (f.underlineStyle() != QTextCharFormat::NoUnderline) {
// underline does not need to fill without having background color
if (f.underlineStyle() != QTextCharFormat::NoUnderline && !f.background().isValid())
tf.setBackground(QBrush(Qt::BrushStyle::NoBrush));
tf.setBackground(Qt::BrushStyle::NoBrush);
}
tf.setFontWeight(f.bold() ? QFont::Bold : QFont::Normal);
tf.setFontItalic(f.italic());

View File

@@ -323,9 +323,7 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
const QColor &bg = selection.m_bg;
if (begin.isNull()
|| end.isNull()
|| begin.position() > end.position())
if (begin.isNull() || end.isNull() || begin.position() > end.position() || !bg.isValid())
return;
QPainterPath path = createSelectionPath(begin, end, m_editor->viewport()->rect());
@@ -339,7 +337,6 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
QRectF pathRect = path.controlPointRect();
if (bg.isValid()) {
if (!m_alpha || begin.blockNumber() != end.blockNumber()) {
// gradients are too slow for larger selections :(
QColor col = bg;
@@ -356,9 +353,6 @@ void TextEditorOverlay::paintSelection(QPainter *painter,
linearGrad.setColorAt(1, col2);
painter->setBrush(QBrush(linearGrad));
}
} else {
painter->setBrush(QBrush());
}
painter->setRenderHint(QPainter::Antialiasing);