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;
}
} else {
br = br.united(line.naturalTextRect());
}
- nextLine.setLineWidth(0);
- nextLine.setPosition(QPointF(FLT_MAX, FLT_MAX));
break;
}
}
truncated = true;
if (elide) {
- if (!elideLayout)
+ if (!elideLayout) {
elideLayout = new QTextLayout;
+ elideLayout->setCacheEnabled(true);
+ }
if (styledText) {
QList<QTextLayout::FormatRange> formats;
switch (elideMode) {
br = br.united(elidedLine.naturalTextRect());
- if (visibleCount > 1)
- line.setPosition(QPointF(FLT_MAX, FLT_MAX));
- else
+ if (visibleCount == 1)
layout.clearLayout();
} else {
delete elideLayout;
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);
}
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);
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();
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(),