39 |
39 |
40 public: |
40 public: |
41 HbInputNumeric12KeyHandlerPrivate(); |
41 HbInputNumeric12KeyHandlerPrivate(); |
42 ~HbInputNumeric12KeyHandlerPrivate(); |
42 ~HbInputNumeric12KeyHandlerPrivate(); |
43 |
43 |
44 void handleMultitapStarKey(); |
44 void handleMultitapStarKey(); |
45 bool handleAlphaEvent(int buttonId, HbKeyboardType type); |
45 bool handleAlphaEvent(int buttonId, HbKeyboardType type); |
46 bool buttonPressed(const QKeyEvent *keyEvent); |
46 bool buttonPressed(const QKeyEvent *keyEvent); |
47 bool buttonReleased(const QKeyEvent *keyEvent); |
47 bool buttonReleased(const QKeyEvent *keyEvent); |
48 void _q_timeout(); |
48 void _q_timeout(); |
49 public: |
49 public: |
50 int mLastKey; |
50 int mLastKey; |
51 bool mLongPressHappened; |
51 bool mLongPressHappened; |
52 int mButtonDown; |
52 int mButtonDown; |
53 int mMultiTapNum; |
53 int mMultiTapNum; |
54 QChar mCurrentMultitapChar; |
54 QChar mCurrentMultitapChar; |
55 }; |
55 }; |
56 |
56 |
57 HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate(): |
57 HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate(): |
58 mLastKey(0), mLongPressHappened(false), |
58 mLastKey(0), mLongPressHappened(false), |
59 mButtonDown(false), |
59 mButtonDown(false), |
60 mMultiTapNum(0), |
60 mMultiTapNum(0), |
61 mCurrentMultitapChar(0) |
61 mCurrentMultitapChar(0) |
62 { |
62 { |
63 } |
63 } |
64 |
64 |
65 HbInputNumeric12KeyHandlerPrivate::~HbInputNumeric12KeyHandlerPrivate() |
65 HbInputNumeric12KeyHandlerPrivate::~HbInputNumeric12KeyHandlerPrivate() |
66 { |
66 { |
67 } |
67 } |
68 |
68 |
69 void HbInputNumeric12KeyHandlerPrivate::handleMultitapStarKey() |
69 void HbInputNumeric12KeyHandlerPrivate::handleMultitapStarKey() |
70 { |
70 { |
71 HbInputFocusObject *focusObject = mInputMethod->focusObject(); |
71 HbInputFocusObject *focusObject = mInputMethod->focusObject(); |
72 if (!focusObject) { |
72 if (!focusObject) { |
73 return; |
73 return; |
74 } |
74 } |
75 QChar MultitapStarKeyArray[] = {'*','+','p','w','\0'}; |
75 QChar MultitapStarKeyArray[] = {'*','+','p','w','\0'}; |
76 |
76 |
77 int index = mMultiTapNum; |
77 int index = mMultiTapNum; |
78 do { |
78 do { |
79 mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum]; |
79 mCurrentMultitapChar = MultitapStarKeyArray[mMultiTapNum]; |
80 mMultiTapNum = (++mMultiTapNum)%4; |
80 mMultiTapNum = (++mMultiTapNum)%4; |
81 if (mCurrentMultitapChar != 0) { |
81 if (mCurrentMultitapChar != 0) { |
82 if (focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { |
82 if (focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { |
83 QString str; |
83 QString str; |
84 str += mCurrentMultitapChar; |
84 str += mCurrentMultitapChar; |
85 |
85 |
86 QList<QInputMethodEvent::Attribute> list; |
86 QList<QInputMethodEvent::Attribute> list; |
87 QInputMethodEvent event(str,list); |
87 QInputMethodEvent event(str,list); |
88 focusObject->sendEvent(event); |
88 focusObject->sendEvent(event); |
89 return; |
89 return; |
90 } |
90 } |
91 } |
91 } |
92 } while (index != mMultiTapNum); |
92 } while (index != mMultiTapNum); |
93 } |
93 } |
94 |
94 |
95 bool HbInputNumeric12KeyHandlerPrivate::handleAlphaEvent(int buttonId, HbKeyboardType type) |
95 bool HbInputNumeric12KeyHandlerPrivate::handleAlphaEvent(int buttonId, HbKeyboardType type) |
96 { |
96 { |
101 if (!focusObject) { |
101 if (!focusObject) { |
102 return false; |
102 return false; |
103 } |
103 } |
104 |
104 |
105 QChar character = 0; |
105 QChar character = 0; |
106 //This condition is to avoid get the characters mapped to Asterisk |
106 //This condition is to avoid get the characters mapped to Asterisk |
107 //Especially for Thai language we have mapped character to Asterisk |
107 //Especially for Thai language we have mapped character to Asterisk |
108 if (buttonId != HbInputButton::ButtonKeyCodeAsterisk || |
108 if (buttonId != HbInputButton::ButtonKeyCodeAsterisk || |
109 mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) { |
109 mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait) { |
110 int index = 0; |
110 int index = 0; |
111 character = q->getNthCharacterInKey(index, buttonId, type); |
111 character = q->getNthCharacterInKey(index, buttonId, type); |
112 } |
112 } |
113 |
113 |
114 if (character != 0) { |
114 if (character != 0) { |
115 q->commitAndUpdate(character); |
115 q->commitAndUpdate(character); |
116 return true; |
116 return true; |
117 } |
117 } |
119 } |
119 } |
120 |
120 |
121 bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) |
121 bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) |
122 { |
122 { |
123 Q_Q(HbInputNumeric12KeyHandler); |
123 Q_Q(HbInputNumeric12KeyHandler); |
124 HbInputFocusObject *focusObject = 0; |
124 mLongPressHappened = false; |
|
125 HbInputFocusObject *focusObject = 0; |
125 focusObject = mInputMethod->focusObject(); |
126 focusObject = mInputMethod->focusObject(); |
126 if (!focusObject) { |
127 if (!focusObject) { |
127 return false; |
128 return false; |
128 } |
129 } |
129 int buttonId = keyEvent->key(); |
130 int buttonId = keyEvent->key(); |
130 mButtonDown = buttonId; |
131 mButtonDown = buttonId; |
131 if (keyEvent->isAutoRepeat() && mLastKey == buttonId) { |
132 if (keyEvent->isAutoRepeat() && mLastKey == buttonId) { |
132 if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
133 if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
133 // If the editor is not a number only editor, then activate the alphanumeric keypad |
134 // If the editor is not a number only editor, then activate the alphanumeric keypad |
134 if (!focusObject->editorInterface().isNumericEditor()) { |
135 if (!focusObject->editorInterface().isNumericEditor()) { |
135 mInputMethod->switchMode(buttonId); |
136 mInputMethod->switchMode(buttonId); |
137 } |
138 } |
138 } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { |
139 } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { |
139 mInputMethod->selectSpecialCharacterTableMode(); |
140 mInputMethod->selectSpecialCharacterTableMode(); |
140 mLongPressHappened = true; |
141 mLongPressHappened = true; |
141 } else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
142 } else if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
142 mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) { |
143 mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait && |
|
144 mInputMethod->currentKeyboardType() != HbKeyboardSctEmail && |
|
145 mInputMethod->currentKeyboardType() != HbKeyboardSctUrl) { |
143 mLongPressHappened = true; |
146 mLongPressHappened = true; |
144 mCurrentMultitapChar = QChar(HbInputButton::ButtonKeyCodeAsterisk); |
147 mCurrentMultitapChar = QChar(HbInputButton::ButtonKeyCodeAsterisk); |
145 HbInputFocusObject *focusedObject = mInputMethod->focusObject(); |
148 HbInputFocusObject *focusedObject = mInputMethod->focusObject(); |
146 if (focusedObject) { |
149 if (focusedObject) { |
147 focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); |
150 focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); |
148 } |
151 } |
149 mCurrentMultitapChar = 0; |
152 mCurrentMultitapChar = 0; |
150 } |
153 } |
151 if (mLongPressHappened) { |
154 if (mLongPressHappened) { |
152 mLastKey = 0; |
155 mLastKey = 0; |
153 return true; |
156 return true; |
154 } |
157 } |
155 } |
158 } |
156 |
159 |
157 if (mInputMethod) { |
160 if (mInputMethod) { |
158 if (mLastKey != buttonId) { |
161 if (mLastKey != buttonId) { |
159 if (mCurrentMultitapChar !=0) { |
162 if (mCurrentMultitapChar !=0) { |
160 if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { |
163 if (!focusObject->characterAllowedInEditor(mCurrentMultitapChar)) { |
161 focusObject->sendCommitString(QString()); |
164 focusObject->sendCommitString(QString()); |
162 } else { |
165 } else { |
163 QChar commitChar(mCurrentMultitapChar); |
166 QChar commitChar(mCurrentMultitapChar); |
164 mCurrentMultitapChar = 0; |
167 mCurrentMultitapChar = 0; |
165 q->commitAndUpdate(commitChar); |
168 q->commitAndUpdate(commitChar); |
166 } |
169 } |
167 } |
170 } |
168 } |
171 } |
169 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk) { |
172 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk) { |
170 mTimer->stop(); |
173 mTimer->stop(); |
171 mTimer->start(HbMultiTapTimerTimeout); |
174 mTimer->start(HbMultiTapTimerTimeout); |
172 } |
175 } |
173 } |
176 } |
174 |
177 |
175 mLastKey = buttonId; |
178 mLastKey = buttonId; |
176 return false; |
179 return false; |
177 } |
180 } |
178 |
181 |
199 |
202 |
200 if (mTimer->isActive() && buttonId == Qt::Key_Shift) { |
203 if (mTimer->isActive() && buttonId == Qt::Key_Shift) { |
201 mTimer->stop(); |
204 mTimer->stop(); |
202 } |
205 } |
203 if (mLastKey != buttonId) { |
206 if (mLastKey != buttonId) { |
204 mMultiTapNum = 0; |
207 mMultiTapNum = 0; |
205 } |
208 } |
206 |
209 |
207 mButtonDown = 0; |
210 mButtonDown = 0; |
208 |
211 |
209 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
212 if (buttonId == HbInputButton::ButtonKeyCodeAsterisk && |
210 mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) { |
213 mInputMethod->currentKeyboardType() != HbKeyboardSctPortrait) { |
211 //Asterisk Key will multitap bettween *,+,p,w |
214 //Asterisk Key will multitap bettween *,+,p,w |
212 //mInputMethod->switchMode(buttonId); |
215 //mInputMethod->switchMode(buttonId); |
213 mLastKey = buttonId; |
216 mLastKey = buttonId; |
214 handleMultitapStarKey(); |
217 handleMultitapStarKey(); |
215 return true; |
218 return true; |
216 } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { |
219 } else if (buttonId == HbInputButton::ButtonKeyCodeSymbol) { |
217 mInputMethod->switchMode(buttonId); |
220 mInputMethod->switchMode(buttonId); |
218 } else if (buttonId == HbInputButton::ButtonKeyCodeAlphabet) { |
221 } else if (buttonId == HbInputButton::ButtonKeyCodeAlphabet) { |
219 mInputMethod->switchMode(buttonId); |
222 mInputMethod->switchMode(buttonId); |
220 mLastKey = buttonId; |
223 mLastKey = buttonId; |
221 return true; |
224 return true; |
222 } else if (buttonId == Qt::Key_Return) { |
225 } else if (buttonId == Qt::Key_Return) { |
223 mInputMethod->closeKeypad(); |
226 mInputMethod->closeKeypad(); |
224 return true; |
227 return true; |
225 } else if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
228 } else if (buttonId == HbInputButton::ButtonKeyCodeShift) { |
226 //Let's commit character "#" on single tap and double tap of shift Key |
229 //Let's commit character "#" on single tap and double tap of shift Key |
227 mLastKey = buttonId; |
230 mLastKey = buttonId; |
228 QChar qc = QChar('#'); |
231 QChar qc = QChar('#'); |
229 q->commitAndUpdate(qc); |
232 q->commitAndUpdate(qc); |
230 return true; |
233 return true; |
231 } else if (buttonId >= 0) { |
234 } else if (buttonId >= 0) { |
232 // Let's see if we can get the handler for this button in the base class. |
235 // Let's see if we can get the handler for this button in the base class. |
233 if (q->HbInputNumericHandler::filterEvent(keyEvent)) { |
236 if (q->HbInputNumericHandler::filterEvent(keyEvent)) { |
234 return true; |
237 return true; |
235 } |
238 } |
236 mLastKey = buttonId; |
239 mLastKey = buttonId; |
237 if (mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait && |
240 if ((mInputMethod->currentKeyboardType() == HbKeyboardSctPortrait || |
|
241 mInputMethod->currentKeyboardType() == HbKeyboardSctUrl || |
|
242 mInputMethod->currentKeyboardType() == HbKeyboardSctEmail) && |
238 handleAlphaEvent(buttonId, mInputMethod->currentKeyboardType())) { |
243 handleAlphaEvent(buttonId, mInputMethod->currentKeyboardType())) { |
239 return true; |
244 return true; |
240 } |
245 } |
241 q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType()); |
246 q->commitFirstMappedNumber(buttonId, mInputMethod->currentKeyboardType()); |
242 return true; |
247 return true; |
245 } |
250 } |
246 |
251 |
247 void HbInputNumeric12KeyHandlerPrivate::_q_timeout() |
252 void HbInputNumeric12KeyHandlerPrivate::_q_timeout() |
248 { |
253 { |
249 mTimer->stop(); |
254 mTimer->stop(); |
250 mMultiTapNum = 0; |
255 mMultiTapNum = 0; |
251 |
256 |
252 HbInputFocusObject *focusedObject = mInputMethod->focusObject(); |
257 HbInputFocusObject *focusedObject = mInputMethod->focusObject(); |
253 if (!focusedObject) { |
258 if (!focusedObject) { |
254 qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0"); |
259 qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0"); |
255 return; |
260 return; |
256 } |
261 } |
257 |
262 |
258 if (!mButtonDown) { |
263 if (!mButtonDown) { |
259 if (mCurrentMultitapChar != 0) { |
264 if (mCurrentMultitapChar != 0) { |
260 focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); |
265 focusedObject->filterAndCommitCharacter(mCurrentMultitapChar); |
261 } |
266 } |
262 } |
267 } |
263 mCurrentMultitapChar = 0; |
268 mCurrentMultitapChar = 0; |
264 } |
269 } |
265 |
270 |
266 HbInputNumeric12KeyHandler::HbInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod) |
271 HbInputNumeric12KeyHandler::HbInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod) |
267 :HbInputNumericHandler( *new HbInputNumeric12KeyHandlerPrivate, inputMethod) |
272 :HbInputNumericHandler( *new HbInputNumeric12KeyHandlerPrivate, inputMethod) |
268 { |
273 { |
299 bool ret = false; |
304 bool ret = false; |
300 switch (action) { |
305 switch (action) { |
301 case HbInputModeHandler::HbInputModeActionCancelButtonPress: |
306 case HbInputModeHandler::HbInputModeActionCancelButtonPress: |
302 case HbInputModeHandler::HbInputModeActionReset: |
307 case HbInputModeHandler::HbInputModeActionReset: |
303 d->mLastKey = 0; |
308 d->mLastKey = 0; |
304 d->mButtonDown = false; |
309 d->mButtonDown = false; |
305 break; |
310 break; |
306 //In case of the numeric editor the character is already committed. |
311 //In case of the numeric editor the character is already committed. |
307 //Need to remove the committed character. |
312 //Need to remove the committed character. |
308 case HbInputModeHandler::HbInputModeActionDeleteAndCommit: { |
313 case HbInputModeHandler::HbInputModeActionDeleteAndCommit: { |
309 HbInputFocusObject *focusObject = 0; |
314 HbInputFocusObject *focusObject = 0; |