24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 #include <QTimer> |
25 #include <QTimer> |
26 #include <hbinputmethod.h> |
26 #include <hbinputmethod.h> |
27 #include <hbinputkeymapfactory.h> |
27 #include <hbinputkeymapfactory.h> |
28 #include <hbinputpredictionengine.h> |
28 #include <hbinputpredictionengine.h> |
|
29 #include <hbinputbutton.h> |
29 |
30 |
30 #include "hbinputpredictionqwertyhandler.h" |
31 #include "hbinputpredictionqwertyhandler.h" |
31 #include "hbinputpredictionhandler_p.h" |
32 #include "hbinputpredictionhandler_p.h" |
32 #include "hbinputabstractbase.h" |
33 #include "hbinputabstractbase.h" |
33 |
34 |
41 |
42 |
42 public: |
43 public: |
43 bool buttonPressed(const QKeyEvent *event); |
44 bool buttonPressed(const QKeyEvent *event); |
44 bool buttonReleased(const QKeyEvent *event); |
45 bool buttonReleased(const QKeyEvent *event); |
45 void init(); |
46 void init(); |
46 void _q_timeout(); |
|
47 |
47 |
48 public: |
48 public: |
49 int mButton; |
49 int mButton; |
50 HbFnState mFnState; |
50 HbFnState mFnState; |
51 bool mExactPopupLaunched; |
51 bool mExactPopupLaunched; |
52 bool mPreviewAvailable; |
52 bool mLongPressHappened; |
53 }; |
53 }; |
54 |
54 |
55 HbInputPredictionQwertyHandlerPrivate::HbInputPredictionQwertyHandlerPrivate() |
55 HbInputPredictionQwertyHandlerPrivate::HbInputPredictionQwertyHandlerPrivate() |
56 :mButton(0), |
56 :mButton(0), |
57 mFnState(HbFnOff), |
57 mFnState(HbFnOff), |
58 mExactPopupLaunched(false), |
58 mExactPopupLaunched(false), |
59 mPreviewAvailable(false) |
59 mLongPressHappened(false) |
60 { |
60 { |
61 } |
61 } |
62 |
62 |
63 HbInputPredictionQwertyHandlerPrivate::~HbInputPredictionQwertyHandlerPrivate() |
63 HbInputPredictionQwertyHandlerPrivate::~HbInputPredictionQwertyHandlerPrivate() |
64 { |
64 { |
65 } |
65 } |
66 |
66 |
67 void HbInputPredictionQwertyHandlerPrivate::init() |
67 void HbInputPredictionQwertyHandlerPrivate::init() |
68 { |
68 { |
69 } |
69 } |
70 |
|
71 void HbInputPredictionQwertyHandlerPrivate::_q_timeout() |
|
72 { |
|
73 qDebug("HbInputPredictionQwertyHandler::timeout called"); |
|
74 mTimer->stop(); |
|
75 QStringList spellList; |
|
76 |
|
77 //If long key press of shift key is received, just return |
|
78 if (mButton == Qt::Key_Shift) { |
|
79 return; |
|
80 } |
|
81 else if (mButton == Qt::Key_Control) { |
|
82 mInputMethod->selectSpecialCharacterTableMode(); |
|
83 } |
|
84 |
|
85 //If long key press of shift key, space key and enter key is received, don't |
|
86 if (mButton) { |
|
87 mInputMethod->launchCharacterPreviewPane(mButton); |
|
88 } |
|
89 } |
|
90 |
|
91 |
70 |
92 bool HbInputPredictionQwertyHandlerPrivate::buttonReleased(const QKeyEvent *event) |
71 bool HbInputPredictionQwertyHandlerPrivate::buttonReleased(const QKeyEvent *event) |
93 { |
72 { |
94 Q_Q(HbInputPredictionQwertyHandler); |
73 Q_Q(HbInputPredictionQwertyHandler); |
95 HbInputFocusObject *focusObject = 0; |
74 HbInputFocusObject *focusObject = 0; |
97 if (!focusObject) { |
76 if (!focusObject) { |
98 qDebug("HbVirtualQwerty::virtualButtonClicked : no focused editor widget!"); |
77 qDebug("HbVirtualQwerty::virtualButtonClicked : no focused editor widget!"); |
99 return false; |
78 return false; |
100 } |
79 } |
101 |
80 |
|
81 if (mLongPressHappened) { |
|
82 mLongPressHappened = false; |
|
83 return false; |
|
84 } |
|
85 |
102 int key = event->key(); |
86 int key = event->key(); |
103 |
87 |
104 // If the timer is not active and it is alpha mode, it is a long press |
|
105 // and handled in another function. So just return. |
|
106 if (mTimer->isActive()) { |
|
107 mTimer->stop(); |
|
108 } else if (key == Qt::Key_Control) { |
|
109 return true; |
|
110 } else if (!(key & 0xffff0000) && mPreviewAvailable) { |
|
111 return false; |
|
112 } |
|
113 |
|
114 bool ret = true; |
88 bool ret = true; |
115 switch(key) { |
89 switch(key) { |
116 case Qt::Key_Alt: //Fn |
90 case Qt::Key_Alt: //Fn |
117 if (mFnState == HbFnOff) { |
91 if (mFnState == HbFnOff) { |
118 mFnState = HbFnNext; |
92 mFnState = HbFnNext; |
120 mFnState = HbFnOn; |
94 mFnState = HbFnOn; |
121 } else { |
95 } else { |
122 mFnState = HbFnOff; |
96 mFnState = HbFnOff; |
123 } |
97 } |
124 break; |
98 break; |
125 case Qt::Key_Shift: { |
99 case HbInputButton::ButtonKeyCodeShift: { |
126 HbTextCase currentTextCase = (HbTextCase)focusObject->editorInterface().textCase(); |
100 HbTextCase currentTextCase = (HbTextCase)focusObject->editorInterface().textCase(); |
127 HbInputLanguage language = mInputMethod->inputState().language(); |
101 HbInputLanguage language = mInputMethod->inputState().language(); |
128 |
102 |
129 // Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well |
103 // Update the Case Information in HbInputState, it internally updates in HbEditorInterface as well |
130 switch(currentTextCase) { |
104 switch(currentTextCase) { |
149 HbInputState state = mInputMethod->inputState(); |
123 HbInputState state = mInputMethod->inputState(); |
150 state.setTextCase(currentTextCase); |
124 state.setTextCase(currentTextCase); |
151 mInputMethod->activateState(state); |
125 mInputMethod->activateState(state); |
152 } |
126 } |
153 break; |
127 break; |
154 case Qt::Key_Control: { // Ctrl/Chr |
128 case HbInputButton::ButtonKeyCodeSymbol: { // Ctrl/Chr |
|
129 case HbInputButton::ButtonKeyCodeAlphabet: |
155 mInputMethod->switchSpecialCharacterTable(); |
130 mInputMethod->switchSpecialCharacterTable(); |
156 } |
131 } |
157 break; |
132 break; |
158 default: { |
133 default: { |
159 HbTextCase currentTextCase = focusObject->editorInterface().textCase(); |
134 HbTextCase currentTextCase = focusObject->editorInterface().textCase(); |
167 // If shift is pressed, the shifted characters have to be input. |
142 // If shift is pressed, the shifted characters have to be input. |
168 if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) { |
143 if ( HbTextCaseUpper == currentTextCase || HbTextCaseAutomatic == currentTextCase ) { |
169 modifiers |= Qt::ShiftModifier; |
144 modifiers |= Qt::ShiftModifier; |
170 } |
145 } |
171 |
146 |
|
147 if (key != HbInputButton::ButtonKeyCodeDelete && |
|
148 key != HbInputButton::ButtonKeyCodeEnter && |
|
149 mInputMethod->currentKeyboardType() == HbKeyboardSctLandscape) { |
|
150 q->sctCharacterSelected(QChar(key)); |
|
151 return true; |
|
152 } |
|
153 |
172 // let's pass it to the base class. |
154 // let's pass it to the base class. |
173 ret = q->HbInputPredictionHandler::filterEvent(event); |
155 ret = q->HbInputPredictionHandler::filterEvent(event); |
174 |
156 |
175 mInputMethod->updateState(); |
157 mInputMethod->updateState(); |
176 } |
158 } |
179 return ret; |
161 return ret; |
180 } |
162 } |
181 |
163 |
182 bool HbInputPredictionQwertyHandlerPrivate::buttonPressed(const QKeyEvent *event) |
164 bool HbInputPredictionQwertyHandlerPrivate::buttonPressed(const QKeyEvent *event) |
183 { |
165 { |
|
166 if (event->isAutoRepeat() && mButton == event->key()) { |
|
167 if (mButton == HbInputButton::ButtonKeyCodeSymbol) { |
|
168 mInputMethod->selectSpecialCharacterTableMode(); |
|
169 mLongPressHappened = true; |
|
170 } |
|
171 if (mLongPressHappened) { |
|
172 mButton = 0; |
|
173 return true; |
|
174 } |
|
175 } |
|
176 |
184 mButton = event->key(); |
177 mButton = event->key(); |
185 mTimer->start(HbLongPressTimerTimeout); |
|
186 mPreviewAvailable = false; |
|
187 return false; |
178 return false; |
188 } |
179 } |
189 |
180 |
190 |
181 |
191 HbInputPredictionQwertyHandler::HbInputPredictionQwertyHandler(HbInputAbstractMethod *inputMethod) |
182 HbInputPredictionQwertyHandler::HbInputPredictionQwertyHandler(HbInputAbstractMethod *inputMethod) |
208 Q_D(HbInputPredictionQwertyHandler); |
199 Q_D(HbInputPredictionQwertyHandler); |
209 bool ret = true; |
200 bool ret = true; |
210 switch (action) { |
201 switch (action) { |
211 case HbInputModeActionCancelButtonPress: |
202 case HbInputModeActionCancelButtonPress: |
212 case HbInputModeActionReset: |
203 case HbInputModeActionReset: |
213 if (d->mTimer->isActive()) { |
|
214 d->mTimer->stop(); |
|
215 } |
|
216 break; |
204 break; |
217 case HbInputModeActionFocusRecieved: |
205 case HbInputModeActionFocusRecieved: |
218 HbInputPredictionHandler::actionHandler(HbInputModeActionSetCandidateList); |
206 HbInputPredictionHandler::actionHandler(HbInputModeActionSetCandidateList); |
219 HbInputPredictionHandler::actionHandler(HbInputModeActionSetKeypad); |
207 HbInputPredictionHandler::actionHandler(HbInputModeActionSetKeypad); |
220 d->mTimer->stop(); |
|
221 break; |
208 break; |
222 case HbInputModeActionFocusLost: |
209 case HbInputModeActionFocusLost: |
223 HbInputPredictionHandler::actionHandler(HbInputModeActionFocusLost); |
210 HbInputPredictionHandler::actionHandler(HbInputModeActionFocusLost); |
224 |
211 |
225 //TODO |
212 //TODO |
275 Q_D(HbInputPredictionHandler); |
262 Q_D(HbInputPredictionHandler); |
276 d->deleteOneCharacter(); |
263 d->deleteOneCharacter(); |
277 } |
264 } |
278 |
265 |
279 /*! |
266 /*! |
280 this SLOT is called when a character on character previe pane is selected. |
|
281 */ |
|
282 void HbInputPredictionQwertyHandler::charFromPreviewSelected(QString character) |
|
283 { |
|
284 Q_D(HbInputPredictionQwertyHandler); |
|
285 if(character.size() > 0) { |
|
286 appendUnicodeCharacter(character[0]); |
|
287 d->mInputMethod->updateState(); |
|
288 } |
|
289 } |
|
290 |
|
291 /*! |
|
292 this function is called by HbPredictionHandler when HbPredictionHandler encounters a exact word. |
267 this function is called by HbPredictionHandler when HbPredictionHandler encounters a exact word. |
293 */ |
268 */ |
294 void HbInputPredictionQwertyHandler::processExactWord(QString exactWord) |
269 void HbInputPredictionQwertyHandler::processExactWord(QString exactWord) |
295 { |
270 { |
296 Q_D(HbInputPredictionQwertyHandler); |
271 Q_D(HbInputPredictionQwertyHandler); |
317 } |
292 } |
318 |
293 |
319 void HbInputPredictionQwertyHandler::smileySelected(QString smiley) |
294 void HbInputPredictionQwertyHandler::smileySelected(QString smiley) |
320 { |
295 { |
321 HbInputPredictionHandler::smileySelected(smiley); |
296 HbInputPredictionHandler::smileySelected(smiley); |
322 } |
|
323 void HbInputPredictionQwertyHandler::characterPreviewAvailable(bool available) |
|
324 { |
|
325 Q_D(HbInputPredictionQwertyHandler); |
|
326 d->mPreviewAvailable = available; |
|
327 } |
297 } |
328 |
298 |
329 /*! |
299 /*! |
330 Returns true if preidciton engine is available and initialized. |
300 Returns true if preidciton engine is available and initialized. |
331 */ |
301 */ |