summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorGeir Vattekar <geir.vattekar@trolltech.com>2009-05-06 09:26:04 (GMT)
committerGeir Vattekar <geir.vattekar@trolltech.com>2009-05-06 09:26:04 (GMT)
commit3cb649475bc8ab50bc7341d47dc8b02e8b6075ea (patch)
tree931e3d285f6a0f4c9575d176229424a48729bb03 /src/gui/text
parenta78dba4353318efdf7b11116518650fd539a9fd9 (diff)
parent6ba793ea76e72332786ee90022ee169fca311446 (diff)
downloadQt-3cb649475bc8ab50bc7341d47dc8b02e8b6075ea.zip
Qt-3cb649475bc8ab50bc7341d47dc8b02e8b6075ea.tar.gz
Qt-3cb649475bc8ab50bc7341d47dc8b02e8b6075ea.tar.bz2
Merge branch '4.5' of git@scm.dev.nokia.troll.no:qt/qt into 4.5
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextformat.h6
-rw-r--r--src/gui/text/qtextlayout.cpp62
2 files changed, 56 insertions, 12 deletions
diff --git a/src/gui/text/qtextformat.h b/src/gui/text/qtextformat.h
index 0571d75..8eaeeb1 100644
--- a/src/gui/text/qtextformat.h
+++ b/src/gui/text/qtextformat.h
@@ -232,6 +232,12 @@ public:
ImageWidth = 0x5010,
ImageHeight = 0x5011,
+ // internal
+ /*
+ SuppressText = 0x5012,
+ SuppressBackground = 0x513
+ */
+
// selection properties
FullWidthSelection = 0x06000,
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 434d1ca..fa624ef 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -61,6 +61,8 @@
QT_BEGIN_NAMESPACE
#define ObjectSelectionBrush (QTextFormat::ForegroundBrush + 1)
+#define SuppressText 0x5012
+#define SuppressBackground 0x513
static inline QFixed leadingSpaceWidth(QTextEngine *eng, const QScriptLine &line)
{
@@ -1143,6 +1145,7 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
}
QPainterPath excludedRegion;
+ QPainterPath textDoneRegion;
for (int i = 0; i < selections.size(); ++i) {
FormatRange selection = selections.at(i);
const QBrush bg = selection.format.background();
@@ -1202,23 +1205,55 @@ void QTextLayout::draw(QPainter *p, const QPointF &pos, const QVector<FormatRang
}
+
+ 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);
+ }
+
+ selection.format.setProperty(SuppressText, !hasText);
+
+ if (hasText && !hasBackground && !(textDoneRegion & region).isEmpty())
+ continue;
+
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);
-
for (int line = firstLine; line < lastLine; ++line) {
QTextLine l(line, d);
l.draw(p, position, &selection);
}
p->restore();
- if (selection.format.foreground().style() != Qt::NoBrush) // i.e. we have drawn text
- excludedRegion += 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);
+ FormatRange selection;
+ selection.start = 0;
+ selection.length = INT_MAX;
+ selection.format.setProperty(SuppressBackground, true);
+ for (int line = firstLine; line < lastLine; ++line) {
+ QTextLine l(line, d);
+ l.draw(p, position, &selection);
+ }
+ p->restore();
}
if (!excludedRegion.isEmpty()) {
@@ -1912,14 +1947,17 @@ static void drawMenuText(QPainter *p, QFixed x, QFixed y, const QScriptItem &si,
static void setPenAndDrawBackground(QPainter *p, const QPen &defaultPen, const QTextCharFormat &chf, const QRectF &r)
{
QBrush c = chf.foreground();
- if (c.style() == Qt::NoBrush)
+ if (c.style() == Qt::NoBrush) {
p->setPen(defaultPen);
+ }
QBrush bg = chf.background();
- if (bg.style() != Qt::NoBrush)
+ if (bg.style() != Qt::NoBrush && !chf.property(SuppressBackground).toBool())
p->fillRect(r, bg);
- if (c.style() != Qt::NoBrush)
+ if (c.style() != Qt::NoBrush) {
p->setPen(QPen(c, 0));
+ }
+
}
/*!
@@ -1933,7 +1971,7 @@ void QTextLine::draw(QPainter *p, const QPointF &pos, const QTextLayout::FormatR
const QScriptLine &line = eng->lines[i];
QPen pen = p->pen();
- bool noText = (selection && selection->format.foreground().style() == Qt::NoBrush);
+ bool noText = (selection && selection->format.property(SuppressText).toBool());
if (!line.length) {
if (selection