42 #include "hbinputprediction12keyhandler.h" |
42 #include "hbinputprediction12keyhandler.h" |
43 #include "hbinputpredictionhandler_p.h" |
43 #include "hbinputpredictionhandler_p.h" |
44 #include "hbinputabstractbase.h" |
44 #include "hbinputabstractbase.h" |
45 #include "hbinputprediction12keyhandler_p.h" |
45 #include "hbinputprediction12keyhandler_p.h" |
46 |
46 |
47 static const qreal HbDeltaHeight = 3.0; |
|
48 static const qint16 MAXUDBWORDSIZE = 64; |
|
49 |
|
50 HbInputPrediction12KeyHandlerPrivate::HbInputPrediction12KeyHandlerPrivate() |
47 HbInputPrediction12KeyHandlerPrivate::HbInputPrediction12KeyHandlerPrivate() |
51 :mLastKey(0), |
48 :mLastKey(0), |
52 mButtonDown(false), |
49 mButtonDown(false), |
53 mCurrentChar(0), |
50 mCurrentChar(0), |
54 mLongPressHappened(false), |
51 mLongPressHappened(false), |
63 void HbInputPrediction12KeyHandlerPrivate::chopQMarkAndUpdateEditor() |
60 void HbInputPrediction12KeyHandlerPrivate::chopQMarkAndUpdateEditor() |
64 { |
61 { |
65 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
62 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
66 (*mCandidates)[mBestGuessLocation].chop(1); |
63 (*mCandidates)[mBestGuessLocation].chop(1); |
67 updateEditor(); |
64 updateEditor(); |
|
65 if (!mCanContinuePrediction) { |
|
66 mShowTail = false; |
68 mCanContinuePrediction = true; |
67 mCanContinuePrediction = true; |
|
68 } |
69 } |
69 } |
70 } |
70 } |
71 |
71 |
72 bool HbInputPrediction12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) |
72 bool HbInputPrediction12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) |
73 { |
73 { |
81 |
81 |
82 int buttonId = keyEvent->key(); |
82 int buttonId = keyEvent->key(); |
83 |
83 |
84 if (keyEvent->isAutoRepeat() && mLastKey == buttonId) { |
84 if (keyEvent->isAutoRepeat() && mLastKey == buttonId) { |
85 // mode switch should happen only when Qt::Key_Asterisk key is pressed in non-SCT |
85 // mode switch should happen only when Qt::Key_Asterisk key is pressed in non-SCT |
86 // keypad. |
86 // keypad. |
87 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
87 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
88 !mInputMethod->isSctModeActive()) { |
88 !mInputMethod->isSctModeActive()) { |
89 //Remove the "?" mark if present |
89 //Remove the "?" mark if present |
90 if (!mCanContinuePrediction) { |
90 if (!mCanContinuePrediction) { |
91 chopQMarkAndUpdateEditor(); |
91 chopQMarkAndUpdateEditor(); |
92 } |
92 } |
93 mInputMethod->switchMode(buttonId); |
93 mInputMethod->switchMode(buttonId); |
94 mLongPressHappened = true; |
94 mLongPressHappened = true; |
95 } else if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
95 } else if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
96 mInputMethod->switchMode(HbInputButton::ButtonKeyCodeShift); |
96 mInputMethod->switchMode(HbInputButton::ButtonKeyCodeShift); |
97 mLongPressHappened = true; |
97 mLongPressHappened = true; |
110 if (!mCanContinuePrediction) { |
110 if (!mCanContinuePrediction) { |
111 deleteOneCharacter(); |
111 deleteOneCharacter(); |
112 mLongPressHappened = true; |
112 mLongPressHappened = true; |
113 } |
113 } |
114 // commit the first mapped number character when long key press |
114 // commit the first mapped number character when long key press |
115 // of character key received in alphanumeric mode |
115 // of character key received in alphanumeric mode |
116 if (buttonId != HbInputButton::ButtonKeyCodeDelete && |
116 if (buttonId != HbInputButton::ButtonKeyCodeDelete && |
117 !mInputMethod->isSctModeActive()) { |
117 !mInputMethod->isSctModeActive()) { |
118 q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType()); |
118 q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType()); |
119 mLongPressHappened = true; |
119 mLongPressHappened = true; |
120 } |
120 } |
154 |
154 |
155 // since button is released we can set buttonDown back to false. |
155 // since button is released we can set buttonDown back to false. |
156 mButtonDown = false; |
156 mButtonDown = false; |
157 int buttonId = keyEvent->key(); |
157 int buttonId = keyEvent->key(); |
158 |
158 |
159 // short key press of character keys should not be handled when "?" is displayed |
159 // short key press of character keys should not be handled when "?" is displayed |
160 if (!mCanContinuePrediction && !mLongPressHappened && |
160 if (!mCanContinuePrediction && !mLongPressHappened && |
161 buttonId >= Qt::Key_1 && buttonId <= Qt::Key_9) { |
161 buttonId >= Qt::Key_1 && buttonId <= Qt::Key_9) { |
162 return false; |
162 return false; |
163 } |
163 } |
164 // Sym key is handled in this class it self, so not passing it to |
164 // Sym key is handled in this class it self, so not passing it to |
165 // the base mode handlers. |
165 // the base mode handlers. |
166 if (buttonId == HbInputButton::ButtonKeyCodeSymbol || |
166 if (buttonId == HbInputButton::ButtonKeyCodeSymbol || |
167 buttonId == HbInputButton::ButtonKeyCodeAlphabet) { |
167 buttonId == HbInputButton::ButtonKeyCodeAlphabet) { |
168 //Remove the "?" mark if present |
168 //Remove the "?" mark if present |
169 chopQMarkAndUpdateEditor(); |
169 chopQMarkAndUpdateEditor(); |
170 mInputMethod->switchMode(buttonId); |
170 mInputMethod->switchMode(buttonId); |
174 - Should launch Candidate List if we can continue with prediction i.e. "?" is not displayed |
174 - Should launch Candidate List if we can continue with prediction i.e. "?" is not displayed |
175 - Should launch Spell Query Dialog if we cannot continue with prediction |
175 - Should launch Spell Query Dialog if we cannot continue with prediction |
176 - Behavior of Short Press of Asterisk Key when not in inline editing state |
176 - Behavior of Short Press of Asterisk Key when not in inline editing state |
177 - Should launch SCT |
177 - Should launch SCT |
178 - Behaviour of Short Press of Asterisk Key in SCT keypad |
178 - Behaviour of Short Press of Asterisk Key in SCT keypad |
179 - Should input the * character and should not change the keypad mode |
179 - Should input the * character and should not change the keypad mode |
180 */ |
180 */ |
181 else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
181 else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
182 !mInputMethod->isSctModeActive()) { |
182 !mInputMethod->isSctModeActive()) { |
183 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
183 if(!mCanContinuePrediction && (*mCandidates)[mBestGuessLocation].endsWith('?')) { |
184 //Remove the "?" mark |
184 //Remove the "?" mark |
185 (*mCandidates)[mBestGuessLocation].chop(1); |
185 (*mCandidates)[mBestGuessLocation].chop(1); |
186 updateEditor(); |
186 updateEditor(); |
187 q->launchSpellQueryDialog(); |
187 q->launchSpellQueryDialog(); |
188 } else { |
188 } else { |
189 mInputMethod->starKeySelected(); |
189 mInputMethod->starKeySelected(); |
190 } |
190 } |
191 return true; |
191 return true; |
192 } |
192 } |
193 else if (buttonId == HbInputButton::ButtonKeyCodeEnter) { |
193 |
194 mInputMethod->closeKeypad(); |
|
195 return true; |
|
196 } |
|
197 if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
194 if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
198 // single tap of shift key toggles prediction status in case insensitive languages |
195 // single tap of shift key toggles prediction status in case insensitive languages |
199 if (!HbInputSettingProxy::instance()->globalInputLanguage().isCaseSensitiveLanguage()) { |
196 if (!mInputMethod->inputState().language().isCaseSensitiveLanguage()) { |
200 HbInputSettingProxy::instance()->togglePrediction(); |
197 HbInputSettingProxy::instance()->togglePrediction(); |
201 } else { |
198 } else { |
202 if (mShiftKeyDoubleTap) { |
199 if (mShiftKeyDoubleTap) { |
203 mTimer->stop(); |
200 mTimer->stop(); |
204 mShiftKeyDoubleTap = false; |
201 mShiftKeyDoubleTap = false; |
205 //mShowTail = false; |
202 //mShowTail = false; |
206 if (HbInputSettingProxy::instance()->globalInputLanguage()== mInputMethod->inputState().language()) { |
203 if (HbInputSettingProxy::instance()->globalInputLanguage()== mInputMethod->inputState().language()) { |
207 // in latin variants , double tap of shift key toggles the prediction status |
204 // in latin variants , double tap of shift key toggles the prediction status |
208 // revert back to the old case as this is a double tap |
205 // revert back to the old case as this is a double tap |
209 // (the case was changed on the single tap) |
206 // (the case was changed on the single tap) |
210 updateTextCase(); |
207 updateTextCase(); |
211 q->togglePrediction(); |
208 q->togglePrediction(); |
212 } else { |
209 } else { |
225 } |
222 } |
226 } |
223 } |
227 } |
224 } |
228 return true; |
225 return true; |
229 } |
226 } |
230 // ButtonKeyCodeSettings should not be propagated to the engine |
227 // ButtonKeyCodeSettings should not be propagated to the engine |
231 if(buttonId == HbInputButton::ButtonKeyCodeSettings) { |
228 if(buttonId == HbInputButton::ButtonKeyCodeSettings) { |
232 return true; |
229 return true; |
233 } |
230 } |
234 if (buttonId != HbInputButton::ButtonKeyCodeDelete && |
231 if (buttonId != HbInputButton::ButtonKeyCodeDelete && |
|
232 buttonId != HbInputButton::ButtonKeyCodeEnter && |
235 mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) { |
233 mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) { |
236 q->sctCharacterSelected(QChar(buttonId)); |
234 q->sctCharacterSelected(QChar(buttonId)); |
237 return true; |
235 return true; |
238 } |
236 } |
239 |
237 |
240 // text input happens on button release |
238 // text input happens on button release |
241 if (q->HbInputPredictionHandler::filterEvent(keyEvent)) { |
239 if (q->HbInputPredictionHandler::filterEvent(keyEvent)) { |
242 return true; |
240 return true; |
243 } |
241 } |
244 return false; |
242 return false; |
245 } |
243 } |
246 |
244 |
247 |
245 |
248 void HbInputPrediction12KeyHandlerPrivate::cancelButtonPress() |
246 void HbInputPrediction12KeyHandlerPrivate::cancelButtonPress() |
285 //any meaningful word for the input sequence. |
283 //any meaningful word for the input sequence. |
286 if(!d->mCanContinuePrediction) { |
284 if(!d->mCanContinuePrediction) { |
287 int eventKey = event->key(); |
285 int eventKey = event->key(); |
288 switch(eventKey) { |
286 switch(eventKey) { |
289 case Qt::Key_0: |
287 case Qt::Key_0: |
|
288 case HbInputButton::ButtonKeyCodeSettings: |
290 case HbInputButton::ButtonKeyCodeSpace: { |
289 case HbInputButton::ButtonKeyCodeSpace: { |
291 if(d->mCandidates->size() && focusObject) { |
290 if(d->mCandidates->size() && focusObject) { |
292 //Remove the "?" mark |
291 //Remove the "?" mark |
293 (*d->mCandidates)[d->mBestGuessLocation].chop(1); |
292 (*d->mCandidates)[d->mBestGuessLocation].chop(1); |
294 d->updateEditor(); |
293 d->updateEditor(); |