diff options
-rw-r--r-- | src/quick/items/qquicktextnodeengine.cpp | 73 | ||||
-rw-r--r-- | src/quick/items/qquicktextnodeengine_p.h | 14 | ||||
-rw-r--r-- | tests/manual/scenegraph_lancelot/data/text/textinput_selected_fallback_font.qml | 17 |
3 files changed, 77 insertions, 27 deletions
diff --git a/src/quick/items/qquicktextnodeengine.cpp b/src/quick/items/qquicktextnodeengine.cpp index f746fe8b1b..67ff79d20f 100644 --- a/src/quick/items/qquicktextnodeengine.cpp +++ b/src/quick/items/qquicktextnodeengine.cpp @@ -46,12 +46,37 @@ #include <private/qtextdocumentlayout_p.h> #include <private/qtextimagehandler_p.h> #include <private/qrawfont_p.h> +#include <private/qglyphrun_p.h> QT_BEGIN_NAMESPACE +QQuickTextNodeEngine::BinaryTreeNode::BinaryTreeNode(const QGlyphRun &g, + SelectionState selState, + const QRectF &brect, + const QQuickTextNode::Decorations &decs, + const QColor &c, + const QColor &bc, + const QPointF &pos, qreal a) + : glyphRun(g) + , boundingRect(brect) + , selectionState(selState) + , clipNode(0) + , decorations(decs) + , color(c) + , backgroundColor(bc) + , position(pos) + , ascent(a) + , leftChildIndex(-1) + , rightChildIndex(-1) +{ + QGlyphRunPrivate *d = QGlyphRunPrivate::get(g); + ranges.append(qMakePair(d->textRangeStart, d->textRangeEnd)); +} + + void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState, QQuickTextNode::Decorations decorations, const QColor &textColor, - const QColor &backgroundColor, const QPointF &position, int rangeStart, int rangeEnd) + const QColor &backgroundColor, const QPointF &position) { QRectF searchRect = glyphRun.boundingRect(); searchRect.translate(position); @@ -65,8 +90,14 @@ void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode decorations |= (backgroundColor.isValid() ? QQuickTextNode::Background : QQuickTextNode::NoDecoration); qreal ascent = glyphRun.rawFont().ascent(); - insert(binaryTree, BinaryTreeNode(glyphRun, selectionState, searchRect, decorations, - textColor, backgroundColor, position, ascent, rangeStart, rangeEnd)); + insert(binaryTree, BinaryTreeNode(glyphRun, + selectionState, + searchRect, + decorations, + textColor, + backgroundColor, + position, + ascent)); } void QQuickTextNodeEngine::BinaryTreeNode::insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode) @@ -441,19 +472,27 @@ void QQuickTextNodeEngine::addTextObject(const QPointF &position, const QTextCha } } -void QQuickTextNodeEngine::addUnselectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd) +void QQuickTextNodeEngine::addUnselectedGlyphs(const QGlyphRun &glyphRun) { - BinaryTreeNode::insert(&m_currentLineTree, glyphRun, Unselected, - QQuickTextNode::NoDecoration, m_textColor, m_backgroundColor, m_position, - rangeStart, rangeEnd); + BinaryTreeNode::insert(&m_currentLineTree, + glyphRun, + Unselected, + QQuickTextNode::NoDecoration, + m_textColor, + m_backgroundColor, + m_position); } -void QQuickTextNodeEngine::addSelectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd) +void QQuickTextNodeEngine::addSelectedGlyphs(const QGlyphRun &glyphRun) { int currentSize = m_currentLineTree.size(); - BinaryTreeNode::insert(&m_currentLineTree, glyphRun, Selected, - QQuickTextNode::NoDecoration, m_textColor, m_backgroundColor, m_position, - rangeStart, rangeEnd); + BinaryTreeNode::insert(&m_currentLineTree, + glyphRun, + Selected, + QQuickTextNode::NoDecoration, + m_textColor, + m_backgroundColor, + m_position); m_hasSelection = m_hasSelection || m_currentLineTree.size() > currentSize; } @@ -526,7 +565,7 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength, QList<QGlyphRun> glyphRuns = line.glyphRuns(rangeStart, rangeLength); for (int j=0; j<glyphRuns.size(); ++j) { const QGlyphRun &glyphRun = glyphRuns.at(j); - addUnselectedGlyphs(glyphRun, rangeStart, rangeEnd - 1); + addUnselectedGlyphs(glyphRun); } } else { if (rangeStart < selectionStart) { @@ -534,7 +573,7 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength, QList<QGlyphRun> glyphRuns = line.glyphRuns(rangeStart, length); for (int j=0; j<glyphRuns.size(); ++j) { const QGlyphRun &glyphRun = glyphRuns.at(j); - addUnselectedGlyphs(glyphRun, rangeStart, rangeStart + length - 1); + addUnselectedGlyphs(glyphRun); } } @@ -545,8 +584,8 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength, for (int j=0; j<glyphRuns.size(); ++j) { const QGlyphRun &glyphRun = glyphRuns.at(j); - addSelectedGlyphs(glyphRun, start, start + length - 1); - addUnselectedGlyphs(glyphRun, start, start + length - 1); + addSelectedGlyphs(glyphRun); + addUnselectedGlyphs(glyphRun); } } @@ -556,7 +595,7 @@ void QQuickTextNodeEngine::addGlyphsInRange(int rangeStart, int rangeLength, QList<QGlyphRun> glyphRuns = line.glyphRuns(start, length); for (int j=0; j<glyphRuns.size(); ++j) { const QGlyphRun &glyphRun = glyphRuns.at(j); - addUnselectedGlyphs(glyphRun, start, start + length - 1); + addUnselectedGlyphs(glyphRun); } } } @@ -927,7 +966,7 @@ void QQuickTextNodeEngine::addTextBlock(QTextDocument *textDocument, const QText QList<QGlyphRun> glyphRuns = layout.glyphRuns(); for (int i=0; i<glyphRuns.size(); ++i) - addUnselectedGlyphs(glyphRuns.at(i), 0, layout.text().length() - 1); + addUnselectedGlyphs(glyphRuns.at(i)); } } diff --git a/src/quick/items/qquicktextnodeengine_p.h b/src/quick/items/qquicktextnodeengine_p.h index 142375b5a3..f0d52683c6 100644 --- a/src/quick/items/qquicktextnodeengine_p.h +++ b/src/quick/items/qquicktextnodeengine_p.h @@ -75,12 +75,7 @@ public: BinaryTreeNode(const QGlyphRun &g, SelectionState selState, const QRectF &brect, const QQuickTextNode::Decorations &decs, const QColor &c, const QColor &bc, - const QPointF &pos, qreal a, int rangeStart, int rangeEnd) - : glyphRun(g), boundingRect(brect), selectionState(selState), clipNode(0), decorations(decs) - , color(c), backgroundColor(bc), position(pos), ascent(a), leftChildIndex(-1), rightChildIndex(-1) - { - ranges.append(qMakePair(rangeStart, rangeEnd)); - } + const QPointF &pos, qreal a); QGlyphRun glyphRun; QRectF boundingRect; @@ -102,8 +97,7 @@ public: { insert(binaryTree, BinaryTreeNode(rect, image, selectionState, ascent)); } static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const QGlyphRun &glyphRun, SelectionState selectionState, - QQuickTextNode::Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QPointF &position, - int rangeStart, int rangeEnd); + QQuickTextNode::Decorations decorations, const QColor &textColor, const QColor &backgroundColor, const QPointF &position); static void insert(QVarLengthArray<BinaryTreeNode, 16> *binaryTree, const BinaryTreeNode &binaryTreeNode); static void inOrder(const QVarLengthArray<BinaryTreeNode, 16> &binaryTree, QVarLengthArray<int> *sortedIndexes, int currentIndex = 0); }; @@ -138,8 +132,8 @@ public: SelectionState selectionState, QTextDocument *textDocument, int pos, QTextFrameFormat::Position layoutPosition = QTextFrameFormat::InFlow); - void addSelectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd); - void addUnselectedGlyphs(const QGlyphRun &glyphRun, int rangeStart, int rangeEnd); + void addSelectedGlyphs(const QGlyphRun &glyphRun); + void addUnselectedGlyphs(const QGlyphRun &glyphRun); void addGlyphsInRange(int rangeStart, int rangeEnd, const QColor &color, const QColor &backgroundColor, int selectionStart, int selectionEnd); diff --git a/tests/manual/scenegraph_lancelot/data/text/textinput_selected_fallback_font.qml b/tests/manual/scenegraph_lancelot/data/text/textinput_selected_fallback_font.qml new file mode 100644 index 0000000000..2c5b152ea1 --- /dev/null +++ b/tests/manual/scenegraph_lancelot/data/text/textinput_selected_fallback_font.qml @@ -0,0 +1,17 @@ +import QtQuick 2.0 + +Item { + width: 320 + height: 480 + TextInput { + anchors.centerIn: parent + id: textInput + font.family: "Arial" + font.pixelSize: 14 + text: "∯AA≨" + + Component.onCompleted: { + textInput.select(2, 4) + } + } +} |