aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJarkko Koivikko <jarkko.koivikko@code-q.fi>2017-08-30 22:20:36 +0300
committerJarkko Koivikko <jarkko.koivikko@code-q.fi>2017-09-08 17:11:31 +0000
commitc8de16ef278a6ce5515b377893d731ad366c9013 (patch)
tree3db3d040fd8a934a5cfb3fe19ebed9b27f26b59a /src
parentf430cffbe94f0bf906b241bbca3fd3f91b3dba86 (diff)
3rdparty/t9write: Show gestures for secondary word candidates
Previously the suggested gestures were only applied to primary candidate. In this case the primary candidate was committed and followed by the gesture. This change adds support for displaying and applying gesture for secondary candidate. It currently supports space and new line gestures. [ChangeLog] Added support for displaying gestures in word suggestions in T9 Write handwriting input mode. Change-Id: I644823fd0d25dc4b6f9f38e04c32262df948ad7f Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/virtualkeyboard/t9writeinputmethod.cpp85
1 files changed, 70 insertions, 15 deletions
diff --git a/src/virtualkeyboard/t9writeinputmethod.cpp b/src/virtualkeyboard/t9writeinputmethod.cpp
index 47b5966e..1a834318 100644
--- a/src/virtualkeyboard/t9writeinputmethod.cpp
+++ b/src/virtualkeyboard/t9writeinputmethod.cpp
@@ -1268,7 +1268,11 @@ public:
#endif
finishRecognition();
+ QChar gesture = T9WriteInputMethodPrivate::mapSymbolToGesture(finalWord.right(1).at(0));
+ if (!gesture.isNull())
+ finalWord.chop(1);
q->inputContext()->commit(finalWord);
+ applyGesture(gesture);
} else if (sessionSettings.recognitionMode == scrMode) {
QString finalWord = scrResult;
finishRecognition();
@@ -1344,6 +1348,31 @@ public:
symbolStrokes = result["symbolStrokes"].toList();
if (sessionSettings.recognitionMode == scrMode)
break;
+ } else {
+ // Add a gesture symbol to the secondary candidate
+ if (sessionSettings.recognitionMode != scrMode && result.contains("gesture")) {
+ QString gesture2 = result["gesture"].toString();
+ if (gesture2.length() == 1) {
+ QChar symbol = T9WriteInputMethodPrivate::mapGestureToSymbol(gesture2.at(0).unicode());
+ if (!symbol.isNull()) {
+ // Check for duplicates
+ bool duplicateFound = false;
+ for (const QString &wordCandidate : newWordCandidates) {
+ duplicateFound = wordCandidate.size() == 1 && wordCandidate.at(0) == symbol;
+ if (duplicateFound)
+ break;
+ }
+ if (!duplicateFound) {
+ if (!resultChars.isEmpty()) {
+ newWordCandidates.last().append(symbol);
+ } else {
+ newWordCandidates.append(symbol);
+ newWordCandidatesHwrResultIndex.append(i);
+ }
+ }
+ }
+ }
+ }
}
}
@@ -1374,23 +1403,9 @@ public:
if (!gesture.isEmpty()) {
DECUMA_UNICODE gestureSymbol = gesture.at(0).unicode();
- switch (gestureSymbol) {
- case '\b':
- ic->inputEngine()->virtualKeyClick(Qt::Key_Backspace, QString(), Qt::NoModifier);
- break;
-
- case '\r':
- ic->inputEngine()->virtualKeyClick(Qt::Key_Return, QLatin1String("\n"), Qt::NoModifier);
- break;
-
- case ' ':
- ic->inputEngine()->virtualKeyClick(Qt::Key_Space, QLatin1String(" "), Qt::NoModifier);
- break;
-
- default:
+ if (!applyGesture(gestureSymbol)) {
ic->commit(ic->preeditText());
finishRecognition();
- break;
}
return;
@@ -1416,6 +1431,46 @@ public:
}
}
+ static QChar mapGestureToSymbol(const QChar &gesture)
+ {
+ switch (gesture.unicode()) {
+ case '\r':
+ return QChar(0x23CE);
+ case ' ':
+ return QChar(0x2423);
+ default:
+ return QChar();
+ }
+ }
+
+ static QChar mapSymbolToGesture(const QChar &symbol)
+ {
+ switch (symbol.unicode()) {
+ case 0x23CE:
+ return QChar('\r');
+ case 0x2423:
+ return QChar(' ');
+ default:
+ return QChar();
+ }
+ }
+
+ bool applyGesture(const QChar &gesture)
+ {
+ Q_Q(T9WriteInputMethod);
+ InputContext *ic = q->inputContext();
+ switch (gesture.unicode()) {
+ case '\b':
+ return ic->inputEngine()->virtualKeyClick(Qt::Key_Backspace, QString(), Qt::NoModifier);
+ case '\r':
+ return ic->inputEngine()->virtualKeyClick(Qt::Key_Return, QLatin1String("\n"), Qt::NoModifier);
+ case ' ':
+ return ic->inputEngine()->virtualKeyClick(Qt::Key_Space, QLatin1String(" "), Qt::NoModifier);
+ default:
+ return false;
+ }
+ }
+
bool handleGesture()
{
if (countActiveTraces() > 0)