Diffstat (limited to 'inputmethods/handwriting/qimpenmatch.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | inputmethods/handwriting/qimpenmatch.cpp | 35 |
1 files changed, 18 insertions, 17 deletions
diff --git a/inputmethods/handwriting/qimpenmatch.cpp b/inputmethods/handwriting/qimpenmatch.cpp index 0d3e25a..a0448b6 100644 --- a/inputmethods/handwriting/qimpenmatch.cpp +++ b/inputmethods/handwriting/qimpenmatch.cpp | |||
@@ -22,12 +22,13 @@ | |||
22 | 22 | ||
23 | #include <qpe/qdawg.h> | 23 | #include <qpe/qdawg.h> |
24 | #include <qpe/global.h> | 24 | #include <qpe/global.h> |
25 | 25 | ||
26 | #include <qapplication.h> | 26 | #include <qapplication.h> |
27 | #include <qtimer.h> | 27 | #include <qtimer.h> |
28 | #include <opie2/odebug.h> | ||
28 | 29 | ||
29 | #include <limits.h> | 30 | #include <limits.h> |
30 | 31 | ||
31 | #define ERROR_THRESHOLD 200000 | 32 | #define ERROR_THRESHOLD 200000 |
32 | #define LOOKAHEAD_ERROR 2500 | 33 | #define LOOKAHEAD_ERROR 2500 |
33 | //#define DEBUG_QIMPEN | 34 | //#define DEBUG_QIMPEN |
@@ -65,65 +66,65 @@ void QIMPenMatch::beginStroke() | |||
65 | multiTimer->stop(); | 66 | multiTimer->stop(); |
66 | } | 67 | } |
67 | 68 | ||
68 | void QIMPenMatch::strokeEntered( QIMPenStroke *st ) | 69 | void QIMPenMatch::strokeEntered( QIMPenStroke *st ) |
69 | { | 70 | { |
70 | #ifdef DEBUG_QIMPEN | 71 | #ifdef DEBUG_QIMPEN |
71 | qDebug( "---------- new stroke -------------" ); | 72 | odebug << "---------- new stroke -------------" << oendl; |
72 | #endif | 73 | #endif |
73 | strokes.append( new QIMPenStroke( *st ) ); | 74 | strokes.append( new QIMPenStroke( *st ) ); |
74 | 75 | ||
75 | QIMPenChar testChar; | 76 | QIMPenChar testChar; |
76 | QIMPenStrokeIterator it(strokes); | 77 | QIMPenStrokeIterator it(strokes); |
77 | for ( ; it.current(); ++it ) { | 78 | for ( ; it.current(); ++it ) { |
78 | testChar.addStroke( it.current() ); | 79 | testChar.addStroke( it.current() ); |
79 | } | 80 | } |
80 | 81 | ||
81 | QIMPenCharMatchList ml; | 82 | QIMPenCharMatchList ml; |
82 | if ( strokes.count() > 1 && multiCharSet ) { | 83 | if ( strokes.count() > 1 && multiCharSet ) { |
83 | #ifdef DEBUG_QIMPEN | 84 | #ifdef DEBUG_QIMPEN |
84 | qDebug( "Matching against multi set" ); | 85 | odebug << "Matching against multi set" << oendl; |
85 | #endif | 86 | #endif |
86 | ml = multiCharSet->match( &testChar ); | 87 | ml = multiCharSet->match( &testChar ); |
87 | } else { | 88 | } else { |
88 | #ifdef DEBUG_QIMPEN | 89 | #ifdef DEBUG_QIMPEN |
89 | qDebug( "Matching against single set" ); | 90 | odebug << "Matching against single set" << oendl; |
90 | #endif | 91 | #endif |
91 | ml = charSet->match( &testChar ); | 92 | ml = charSet->match( &testChar ); |
92 | } | 93 | } |
93 | 94 | ||
94 | processMatches( ml ); | 95 | processMatches( ml ); |
95 | } | 96 | } |
96 | 97 | ||
97 | void QIMPenMatch::processMatches( QIMPenCharMatchList &ml ) | 98 | void QIMPenMatch::processMatches( QIMPenCharMatchList &ml ) |
98 | { | 99 | { |
99 | #ifdef DEBUG_QIMPEN | 100 | #ifdef DEBUG_QIMPEN |
100 | qDebug( "Entering strokes.count() = %d", strokes.count() ); | 101 | odebug << "Entering strokes.count() = " << strokes.count() << oendl; |
101 | #endif | 102 | #endif |
102 | QIMPenCharMatch candidate1 = { INT_MAX, 0 }; | 103 | QIMPenCharMatch candidate1 = { INT_MAX, 0 }; |
103 | QIMPenCharMatch candidate2 = { INT_MAX, 0 }; | 104 | QIMPenCharMatch candidate2 = { INT_MAX, 0 }; |
104 | QIMPenCharMatchList ml2; | 105 | QIMPenCharMatchList ml2; |
105 | 106 | ||
106 | if ( ml.count() ) {//&& | 107 | if ( ml.count() ) {//&& |
107 | // ml.first().penChar->penStrokes().count() == strokes.count() ) { | 108 | // ml.first().penChar->penStrokes().count() == strokes.count() ) { |
108 | candidate1 = ml.first(); | 109 | candidate1 = ml.first(); |
109 | #ifdef DEBUG_QIMPEN | 110 | #ifdef DEBUG_QIMPEN |
110 | qDebug( QString("Candidate1 = %1").arg(QChar(candidate1.penChar->character())) ); | 111 | odebug << "Candidate1 = " << candidate1.penChar->character() << oendl; |
111 | #endif | 112 | #endif |
112 | } | 113 | } |
113 | 114 | ||
114 | if ( strokes.count() > 1 ) { | 115 | if ( strokes.count() > 1 ) { |
115 | // See if the last stroke can match a new character | 116 | // See if the last stroke can match a new character |
116 | QIMPenChar testChar; | 117 | QIMPenChar testChar; |
117 | QIMPenStroke *st = strokes.at(strokes.count()-1); | 118 | QIMPenStroke *st = strokes.at(strokes.count()-1); |
118 | testChar.addStroke( st ); | 119 | testChar.addStroke( st ); |
119 | ml2 = charSet->match( &testChar ); | 120 | ml2 = charSet->match( &testChar ); |
120 | if ( ml2.count() ) { | 121 | if ( ml2.count() ) { |
121 | candidate2 = ml2.first(); | 122 | candidate2 = ml2.first(); |
122 | #ifdef DEBUG_QIMPEN | 123 | #ifdef DEBUG_QIMPEN |
123 | qDebug( QString("Candidate2 = %1").arg(QChar(candidate2.penChar->character())) ); | 124 | odebug << "Candidate2 = " << candidate2.penChar->character() << oendl; |
124 | #endif | 125 | #endif |
125 | } | 126 | } |
126 | } | 127 | } |
127 | 128 | ||
128 | bool eraseLast = FALSE; | 129 | bool eraseLast = FALSE; |
129 | bool output = TRUE; | 130 | bool output = TRUE; |
@@ -139,68 +140,68 @@ void QIMPenMatch::processMatches( QIMPenCharMatchList &ml ) | |||
139 | } | 140 | } |
140 | prevMatchChar = candidate2.penChar; | 141 | prevMatchChar = candidate2.penChar; |
141 | prevMatchError = candidate2.error; | 142 | prevMatchError = candidate2.error; |
142 | multiCharSet = charSet; | 143 | multiCharSet = charSet; |
143 | ml = ml2; | 144 | ml = ml2; |
144 | #ifdef DEBUG_QIMPEN | 145 | #ifdef DEBUG_QIMPEN |
145 | qDebug( "** Using Candidate2" ); | 146 | odebug << "** Using Candidate2" << oendl; |
146 | #endif | 147 | #endif |
147 | } else { | 148 | } else { |
148 | if ( (prevMatchChar->character() >> 16) != Qt::Key_Backspace && | 149 | if ( (prevMatchChar->character() >> 16) != Qt::Key_Backspace && |
149 | (prevMatchChar->character() >> 16) < QIMPenChar::ModeBase ) | 150 | (prevMatchChar->character() >> 16) < QIMPenChar::ModeBase ) |
150 | eraseLast = TRUE; | 151 | eraseLast = TRUE; |
151 | prevMatchChar = candidate1.penChar; | 152 | prevMatchChar = candidate1.penChar; |
152 | prevMatchError = candidate1.error; | 153 | prevMatchError = candidate1.error; |
153 | #ifdef DEBUG_QIMPEN | 154 | #ifdef DEBUG_QIMPEN |
154 | qDebug( "** Using Candidate1, with erase" ); | 155 | odebug << "** Using Candidate1, with erase" << oendl; |
155 | #endif | 156 | #endif |
156 | } | 157 | } |
157 | } else if ( candidate1.penChar ) { | 158 | } else if ( candidate1.penChar ) { |
158 | if ( strokes.count() != 1 ) | 159 | if ( strokes.count() != 1 ) |
159 | eraseLast = TRUE; | 160 | eraseLast = TRUE; |
160 | else | 161 | else |
161 | multiCharSet = charSet; | 162 | multiCharSet = charSet; |
162 | prevMatchChar = candidate1.penChar; | 163 | prevMatchChar = candidate1.penChar; |
163 | prevMatchError = candidate1.error; | 164 | prevMatchError = candidate1.error; |
164 | #ifdef DEBUG_QIMPEN | 165 | #ifdef DEBUG_QIMPEN |
165 | qDebug( "** Using Candidate1" ); | 166 | odebug << "** Using Candidate1" << oendl; |
166 | #endif | 167 | #endif |
167 | } else if ( candidate2.penChar ) { | 168 | } else if ( candidate2.penChar ) { |
168 | int i = strokes.count()-1; | 169 | int i = strokes.count()-1; |
169 | while ( i-- ) { | 170 | while ( i-- ) { |
170 | strokes.removeFirst(); | 171 | strokes.removeFirst(); |
171 | emit removeStroke(); | 172 | emit removeStroke(); |
172 | } | 173 | } |
173 | prevMatchChar = candidate2.penChar; | 174 | prevMatchChar = candidate2.penChar; |
174 | prevMatchError = candidate2.error; | 175 | prevMatchError = candidate2.error; |
175 | multiCharSet = charSet; | 176 | multiCharSet = charSet; |
176 | ml = ml2; | 177 | ml = ml2; |
177 | #ifdef DEBUG_QIMPEN | 178 | #ifdef DEBUG_QIMPEN |
178 | qDebug( "** Using Candidate2" ); | 179 | odebug << "** Using Candidate2" << oendl; |
179 | #endif | 180 | #endif |
180 | } else { | 181 | } else { |
181 | if ( !ml.count() ) { | 182 | if ( !ml.count() ) { |
182 | #ifdef DEBUG_QIMPEN | 183 | #ifdef DEBUG_QIMPEN |
183 | qDebug( "** Failed" ); | 184 | odebug << "** Failed" << oendl; |
184 | #endif | 185 | #endif |
185 | canErase = FALSE; | 186 | canErase = FALSE; |
186 | } else { | 187 | } else { |
187 | #ifdef DEBUG_QIMPEN | 188 | #ifdef DEBUG_QIMPEN |
188 | qDebug( "Need more strokes" ); | 189 | odebug << "Need more strokes" << oendl; |
189 | #endif | 190 | #endif |
190 | if ( strokes.count() == 1 ) | 191 | if ( strokes.count() == 1 ) |
191 | canErase = FALSE; | 192 | canErase = FALSE; |
192 | multiCharSet = charSet; | 193 | multiCharSet = charSet; |
193 | } | 194 | } |
194 | output = FALSE; | 195 | output = FALSE; |
195 | emit noMatch(); | 196 | emit noMatch(); |
196 | } | 197 | } |
197 | 198 | ||
198 | if ( eraseLast && canErase ) { | 199 | if ( eraseLast && canErase ) { |
199 | #ifdef DEBUG_QIMPEN | 200 | #ifdef DEBUG_QIMPEN |
200 | qDebug( "deleting last" ); | 201 | odebug << "deleting last" << oendl; |
201 | #endif | 202 | #endif |
202 | emit erase(); | 203 | emit erase(); |
203 | wordChars.removeLast(); | 204 | wordChars.removeLast(); |
204 | wordEntered.truncate( wordEntered.length() - 1 ); | 205 | wordEntered.truncate( wordEntered.length() - 1 ); |
205 | } | 206 | } |
206 | 207 | ||
@@ -225,18 +226,18 @@ void QIMPenMatch::updateWordMatch( QIMPenCharMatchList &ml ) | |||
225 | int ch = ml.first().penChar->character(); | 226 | int ch = ml.first().penChar->character(); |
226 | QChar qch( ch ); | 227 | QChar qch( ch ); |
227 | int code = ch >> 16; | 228 | int code = ch >> 16; |
228 | if ( qch.isPunct() || qch.isSpace() || | 229 | if ( qch.isPunct() || qch.isSpace() || |
229 | code == Qt::Key_Enter || code == Qt::Key_Return || | 230 | code == Qt::Key_Enter || code == Qt::Key_Return || |
230 | code == Qt::Key_Tab || code == Qt::Key_Escape ) { | 231 | code == Qt::Key_Tab || code == Qt::Key_Escape ) { |
231 | //qDebug( "Word Matching: Clearing word" ); | 232 | //odebug << "Word Matching: Clearing word" << oendl; |
232 | wordChars.clear(); | 233 | wordChars.clear(); |
233 | wordMatches.clear(); | 234 | wordMatches.clear(); |
234 | wordEntered = QString(); | 235 | wordEntered = QString(); |
235 | } else if ( code == Qt::Key_Backspace ) { | 236 | } else if ( code == Qt::Key_Backspace ) { |
236 | //qDebug( "Word Matching: Handle backspace" ); | 237 | //odebug << "Word Matching: Handle backspace" << oendl; |
237 | wordChars.removeLast(); | 238 | wordChars.removeLast(); |
238 | wordEntered.truncate( wordEntered.length() - 1 ); | 239 | wordEntered.truncate( wordEntered.length() - 1 ); |
239 | matchWords(); | 240 | matchWords(); |
240 | } else { | 241 | } else { |
241 | QIMPenChar *matchCh; | 242 | QIMPenChar *matchCh; |
242 | 243 | ||
@@ -278,17 +279,17 @@ void QIMPenMatch::matchWords() | |||
278 | maxGuess = 3; | 279 | maxGuess = 3; |
279 | QString str; | 280 | QString str; |
280 | scanDict( Global::fixedDawg().root(), 0, str, 0 ); | 281 | scanDict( Global::fixedDawg().root(), 0, str, 0 ); |
281 | /* | 282 | /* |
282 | QListIterator<MatchWord> it( wordMatches); | 283 | QListIterator<MatchWord> it( wordMatches); |
283 | for ( ; it.current(); ++it ) { | 284 | for ( ; it.current(); ++it ) { |
284 | qDebug( QString("Match word: %1").arg(it.current()->word) ); | 285 | odebug << "Match word: " << it.current()->word << oendl; |
285 | } | 286 | } |
286 | */ | 287 | */ |
287 | } | 288 | } |
288 | //qDebug( "Possibles: Good %d, total %d", goodMatches, wordMatches.count() ); | 289 | //odebug << "Possibles: Good " << goodMatches << ", total " << wordMatches.count() << oendl; |
289 | wordMatches.sort(); | 290 | wordMatches.sort(); |
290 | } | 291 | } |
291 | 292 | ||
292 | void QIMPenMatch::scanDict( const QDawg::Node* n, int ipos, const QString& str, int error ) | 293 | void QIMPenMatch::scanDict( const QDawg::Node* n, int ipos, const QString& str, int error ) |
293 | { | 294 | { |
294 | if ( !n ) | 295 | if ( !n ) |