diff options
author | mae <qt-info@nokia.com> | 2009-05-05 12:22:21 (GMT) |
---|---|---|
committer | mae <qt-info@nokia.com> | 2009-05-05 15:39:19 (GMT) |
commit | 5ad7b6b07ec7727c04abbf96faf540a5d3f0c04c (patch) | |
tree | 856c842c8366047fb0a1d4536944bd337e37e39f /src | |
parent | fcb702ca8641026fc6af85171061de49248adc17 (diff) | |
download | Qt-5ad7b6b07ec7727c04abbf96faf540a5d3f0c04c.zip Qt-5ad7b6b07ec7727c04abbf96faf540a5d3f0c04c.tar.gz Qt-5ad7b6b07ec7727c04abbf96faf540a5d3f0c04c.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextlayout.cpp | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp index 3222237..fa624ef 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 QVector<FormatRang } QPainterPath excludedRegion; - QPainterPath needsTextButNoBackground; + QPainterPath textDoneRegion; for (int i = 0; i < selections.size(); ++i) { FormatRange selection = selections.at(i); const QBrush bg = selection.format.background(); @@ -1205,18 +1205,25 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang } - p->save(); - 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 QVector<FormatRang } p->restore(); - 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); |