summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorJiang Jiang <jiang.jiang@nokia.com>2011-05-25 08:55:52 (GMT)
committerJiang Jiang <jiang.jiang@nokia.com>2011-05-25 09:21:10 (GMT)
commit2552c99cfeaaba44db77467bf50176173ff14457 (patch)
tree77fe7562e4a17e6dfb3f66b91139fd2b7b8a2841 /src/gui
parent727f5e50447bf47040746a7a37d488204b279171 (diff)
downloadQt-2552c99cfeaaba44db77467bf50176173ff14457.zip
Qt-2552c99cfeaaba44db77467bf50176173ff14457.tar.gz
Qt-2552c99cfeaaba44db77467bf50176173ff14457.tar.bz2
Fix cursor position test on CursorOnCharacter case
Reviewed-by: TrustMe
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/text/qtextengine.cpp5
-rw-r--r--src/gui/text/qtextengine_p.h2
-rw-r--r--src/gui/text/qtextlayout.cpp6
3 files changed, 9 insertions, 4 deletions
diff --git a/src/gui/text/qtextengine.cpp b/src/gui/text/qtextengine.cpp
index 0df543b..9bbc4a4 100644
--- a/src/gui/text/qtextengine.cpp
+++ b/src/gui/text/qtextengine.cpp
@@ -2844,7 +2844,8 @@ int QTextEngine::getClusterLength(unsigned short *logClusters,
}
int QTextEngine::positionInLigature(const QScriptItem *si, int end,
- QFixed x, QFixed edge, int glyph_pos)
+ QFixed x, QFixed edge, int glyph_pos,
+ bool cursorOnCharacter)
{
unsigned short *logClusters = this->logClusters(si);
int clusterStart = -1;
@@ -2882,6 +2883,8 @@ int QTextEngine::positionInLigature(const QScriptItem *si, int end,
int n = ((x - left) / perItemWidth).floor().toInt();
QFixed dist = x - left - n * perItemWidth;
int closestItem = dist > (perItemWidth / 2) ? n + 1 : n;
+ if (cursorOnCharacter && closestItem > 0)
+ closestItem--;
int pos = si->position + clusterStart + closestItem;
// Jump to the next charStop
while (!attrs[pos].charStop && pos < end)
diff --git a/src/gui/text/qtextengine_p.h b/src/gui/text/qtextengine_p.h
index 8e1d796..90e931c 100644
--- a/src/gui/text/qtextengine_p.h
+++ b/src/gui/text/qtextengine_p.h
@@ -620,7 +620,7 @@ public:
QFixed leadingSpaceWidth(const QScriptLine &line);
QFixed offsetInLigature(const QScriptItem *si, int pos, int max, int glyph_pos);
- int positionInLigature(const QScriptItem *si, int end, QFixed x, QFixed edge, int glyph_pos);
+ int positionInLigature(const QScriptItem *si, int end, QFixed x, QFixed edge, int glyph_pos, bool cursorOnCharacter);
int previousLogicalPosition(int oldPos) const;
int nextLogicalPosition(int oldPos) const;
int lineNumberForTextPosition(int pos);
diff --git a/src/gui/text/qtextlayout.cpp b/src/gui/text/qtextlayout.cpp
index 20edb87..8ec3edf 100644
--- a/src/gui/text/qtextlayout.cpp
+++ b/src/gui/text/qtextlayout.cpp
@@ -2780,11 +2780,13 @@ int QTextLine::xToCursor(qreal _x, CursorPosition cpos) const
if (rtl && nchars > 0)
return insertionPoints[lastLine ? nchars : nchars - 1];
}
- return eng->positionInLigature(&si, end, x, pos, -1);
+ return eng->positionInLigature(&si, end, x, pos, -1,
+ cpos == QTextLine::CursorOnCharacter);
}
}
Q_ASSERT(glyph_pos != -1);
- return eng->positionInLigature(&si, end, x, edge, glyph_pos);
+ return eng->positionInLigature(&si, end, x, edge, glyph_pos,
+ cpos == QTextLine::CursorOnCharacter);
}
}
// right of last item