From 5ad7b6b07ec7727c04abbf96faf540a5d3f0c04c Mon Sep 17 00:00:00 2001 From: mae Date: Tue, 5 May 2009 14:22:21 +0200 Subject: [PATCH] Extend change 759338df758ad16cdfd9521b270f7e379bbfa57c to cover extra selections with different foreground but no background The main concern is to avoid double painting. With anti-aliasing turned on by default, we can not draw a piece of text on top of the same piece of text without artefacts. Task-number: 252310 --- src/gui/text/qtextlayout.cpp | 39 +++++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 3222237a26..fa624ef2b6 100644 --- a/src/gui/text/qtextlayout.cpp +++ b/src/gui/text/qtextlayout.cpp @@ -1145,7 +1145,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorsave(); - p->setClipPath(region, Qt::IntersectClip); - selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush)); - // don't just clear the property, set an empty brush that overrides a potential - // background brush specified in the text - selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush()); - selection.format.clearProperty(QTextFormat::OutlinePen); + bool hasText = (selection.format.foreground().style() != Qt::NoBrush); + bool hasBackground= (selection.format.background().style() != Qt::NoBrush); + + if (hasBackground) { + selection.format.setProperty(ObjectSelectionBrush, selection.format.property(QTextFormat::BackgroundBrush)); + // don't just clear the property, set an empty brush that overrides a potential + // background brush specified in the text + selection.format.setProperty(QTextFormat::BackgroundBrush, QBrush()); + selection.format.clearProperty(QTextFormat::OutlinePen); + } - bool noText = (selection.format.foreground().style() == Qt::NoBrush); + selection.format.setProperty(SuppressText, !hasText); + + if (hasText && !hasBackground && !(textDoneRegion & region).isEmpty()) + continue; - selection.format.setProperty(SuppressText, noText); + p->save(); + p->setClipPath(region, Qt::IntersectClip); for (int line = firstLine; line < lastLine; ++line) { QTextLine l(line, d); @@ -1224,13 +1231,17 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVectorrestore(); - if (noText) - needsTextButNoBackground += region; - else - needsTextButNoBackground -= region; + if (hasText) { + textDoneRegion += region; + } else { + if (hasBackground) + textDoneRegion -= region; + } + excludedRegion += region; } + QPainterPath needsTextButNoBackground = excludedRegion - textDoneRegion; if (!needsTextButNoBackground.isEmpty()){ p->save(); p->setClipPath(needsTextButNoBackground, Qt::IntersectClip); -- 2.11.4.GIT