Don't create glyphs for truncated text.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Tue, 10 Apr 2012 05:06:48 +0000 (15:06 +1000)
committerQt by Nokia <qt-info@nokia.com>
Thu, 19 Apr 2012 02:55:38 +0000 (04:55 +0200)
Instead of positioning truncated lines far out of the way where they
won't be seen, simply skip them when creating the glyph node.

Change-Id: I83bd8f76619d822fb22ec2ebd8c1e45c45b8b990
Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
src/quick/items/qquicktext.cpp
src/quick/items/qquicktextnode.cpp
src/quick/items/qquicktextnode_p.h

index f34c062..f52138c 100644 (file)
@@ -822,20 +822,16 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth, qreal *cons
                 height = preLayoutHeight;
 
                 characterCount = line.textStart() + line.textLength();
+                visibleCount -= 1;
 
-                QTextLine previousLine = layout.lineAt(visibleCount - 2);
+                QTextLine previousLine = layout.lineAt(visibleCount - 1);
                 elideText = layoutText.at(line.textStart() - 1) != QChar::LineSeparator
                         ? elidedText(lineWidth, previousLine, &line)
                         : elidedText(lineWidth, previousLine);
                 elideStart = previousLine.textStart();
                 // elideEnd isn't required for right eliding.
 
-                // The previous line is the last one visible so move the current one off somewhere
-                // out of the way and back everything up one line.
-                line.setLineWidth(0);
-                line.setPosition(QPointF(FLT_MAX, FLT_MAX));
                 line = previousLine;
-                --visibleCount;
                 height -= (lineHeightMode() == QQuickText::FixedHeight) ? lineHeight() : previousLine.height() * lineHeight();
                 break;
             }
@@ -889,8 +885,6 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth, qreal *cons
                     } else {
                         br = br.united(line.naturalTextRect());
                     }
-                    nextLine.setLineWidth(0);
-                    nextLine.setPosition(QPointF(FLT_MAX, FLT_MAX));
                     break;
                 }
             }
@@ -991,8 +985,10 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth, qreal *cons
         truncated = true;
 
     if (elide) {
-        if (!elideLayout)
+        if (!elideLayout) {
             elideLayout = new QTextLayout;
+            elideLayout->setCacheEnabled(true);
+        }
         if (styledText) {
             QList<QTextLayout::FormatRange> formats;
             switch (elideMode) {
@@ -1036,9 +1032,7 @@ QRectF QQuickTextPrivate::setupTextLayout(qreal *const naturalWidth, qreal *cons
 
         br = br.united(elidedLine.naturalTextRect());
 
-        if (visibleCount > 1)
-            line.setPosition(QPointF(FLT_MAX, FLT_MAX));
-        else
+        if (visibleCount == 1)
             layout.clearLayout();
     } else {
         delete elideLayout;
@@ -2156,7 +2150,17 @@ QSGNode *QQuickText::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *data
         d->ensureDoc();
         node->addTextDocument(bounds.topLeft(), d->extra->doc, color, d->style, styleColor, linkColor);
     } else if (d->elideMode == QQuickText::ElideNone || bounds.width() > 0.) {
-        node->addTextLayout(QPoint(0, bounds.y()), &d->layout, color, d->style, styleColor, linkColor);
+        int unelidedLineCount = d->lineCount;
+        if (d->elideLayout)
+            unelidedLineCount -= 1;
+        if (unelidedLineCount > 0) {
+            node->addTextLayout(
+                        QPoint(0, bounds.y()),
+                        &d->layout,
+                        d->color, d->style, d->styleColor, d->linkColor,
+                        QColor(), QColor(), -1, -1,
+                        0, unelidedLineCount);
+        }
         if (d->elideLayout)
             node->addTextLayout(QPoint(0, bounds.y()), d->elideLayout, color, d->style, styleColor, linkColor);
     }
index 81340d6..597ebc4 100644 (file)
@@ -1292,7 +1292,8 @@ void QQuickTextNode::addTextLayout(const QPointF &position, QTextLayout *textLay
                                 QQuickText::TextStyle style, const QColor &styleColor,
                                 const QColor &anchorColor,
                                 const QColor &selectionColor, const QColor &selectedTextColor,
-                                int selectionStart, int selectionEnd)
+                                int selectionStart, int selectionEnd,
+                                int lineStart, int lineCount)
 {
     SelectionEngine engine;
     engine.setTextColor(color);
@@ -1307,7 +1308,11 @@ void QQuickTextNode::addTextLayout(const QPointF &position, QTextLayout *textLay
     QVarLengthArray<QTextLayout::FormatRange> colorChanges;
     mergeFormats(textLayout, &colorChanges);
 
-    for (int i=0; i<textLayout->lineCount(); ++i) {
+    lineCount = lineCount >= 0
+            ? qMin(lineStart + lineCount, textLayout->lineCount())
+            : textLayout->lineCount();
+
+    for (int i=lineStart; i<lineCount; ++i) {
         QTextLine line = textLayout->lineAt(i);
 
         int start = line.textStart();
index 2ecd20d..9e75731 100644 (file)
@@ -84,7 +84,8 @@ public:
                        QQuickText::TextStyle style = QQuickText::Normal, const QColor &styleColor = QColor(),
                        const QColor &anchorColor = QColor(),
                        const QColor &selectionColor = QColor(), const QColor &selectedTextColor = QColor(),
-                       int selectionStart = -1, int selectionEnd = -1);
+                       int selectionStart = -1, int selectionEnd = -1,
+                       int lineStart = 0, int lineCount = -1);
     void addTextDocument(const QPointF &position, QTextDocument *textDocument, const QColor &color = QColor(),
                          QQuickText::TextStyle style = QQuickText::Normal, const QColor &styleColor = QColor(),
                          const QColor &anchorColor = QColor(),