|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (developer.feedback@nokia.com) |
|
6 ** |
|
7 ** This file is part of the HbPlugins module of the UI Extensions for Mobile. |
|
8 ** |
|
9 ** GNU Lesser General Public License Usage |
|
10 ** This file may be used under the terms of the GNU Lesser General Public |
|
11 ** License version 2.1 as published by the Free Software Foundation and |
|
12 ** appearing in the file LICENSE.LGPL included in the packaging of this file. |
|
13 ** Please review the following information to ensure the GNU Lesser General |
|
14 ** Public License version 2.1 requirements will be met: |
|
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
16 ** |
|
17 ** In addition, as a special exception, Nokia gives you certain additional |
|
18 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
20 ** |
|
21 ** If you have questions regarding the use of this file, please contact |
|
22 ** Nokia at developer.feedback@nokia.com. |
|
23 ** |
|
24 ****************************************************************************/ |
|
25 |
|
26 #include "hbhardware12key.h" |
|
27 |
|
28 //Required Qt Headers |
|
29 #include <QLocale> |
|
30 |
|
31 //Required Hb Headers |
|
32 #include <hbinputkeymapfactory.h> |
|
33 #include <hbinputkeymapdata.h> |
|
34 #include <hbinpututils.h> |
|
35 #include <hbinputcommondialogs.h> |
|
36 #include <hbinputsctportrait.h> |
|
37 #include <hbinputeditorinterface.h> |
|
38 #include <hbinputsettingproxy.h> |
|
39 #include <hbinputpredictionfactory.h> |
|
40 #include <hbinputpredictionengine.h> |
|
41 #include <hbinputcandidatelist.h> |
|
42 #include <hbinstance.h> |
|
43 #include <hbmainwindow.h> |
|
44 #include <hbaction.h> |
|
45 #include <hbview.h> |
|
46 |
|
47 //User Includes |
|
48 #include "hbhardwareinputbasic12keyhandler.h" |
|
49 #include "hbhardwareinputprediction12keyhandler.h" |
|
50 #include "hbhardwareinputnumeric12keyhandler.h" |
|
51 |
|
52 //const Declaration |
|
53 const qreal HbAutoComplPopupLeftMargin = 15.0; |
|
54 const qreal HbDeltaWidth = 12.0; |
|
55 |
|
56 // --------------------------------------------------------------------------- |
|
57 // HbHardware12key::HbHardware12key |
|
58 // |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 HbHardware12key::HbHardware12key() : |
|
62 mKeyData(0), |
|
63 mInputMode(HbInputModeNone), |
|
64 mSctKeypad(0), |
|
65 mCandidatePopup(0), |
|
66 mCurrentlyFocused(0), |
|
67 mPrevInputState() |
|
68 { |
|
69 |
|
70 // Assume that this will be the language we're going to use and cache it. |
|
71 mKeyData = HbKeyMapFactory::instance()->keymapDataForLanguage(HbInputSettingProxy::instance()->globalInputLanguage().language()); |
|
72 |
|
73 if (!mKeyData) { |
|
74 qDebug("HbHardware12key: ERROR: Initialization FAILED!"); |
|
75 } |
|
76 initializeModeHandlers(); |
|
77 } |
|
78 |
|
79 |
|
80 void HbHardware12key::initializeModeHandlers() |
|
81 { |
|
82 mBasicModeHandler = new HbHardwareInputBasic12KeyHandler(this); |
|
83 mPredictionModeHandler = new HbHardwareInputPrediction12KeyHandler(this); |
|
84 mNumericModeHandler = new HbHardwareInputNumeric12KeyHandler(this); |
|
85 mActiveModeHandler = mBasicModeHandler; |
|
86 |
|
87 mBasicModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit); |
|
88 mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit); |
|
89 mNumericModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionInit); |
|
90 |
|
91 // let's connect prediction mode handler with latin basic mode handler. It is required incase we Qt::key_0 is pressed in prediction mode |
|
92 // key |
|
93 connect(mPredictionModeHandler, SIGNAL(passFilterEvent(const QKeyEvent *)), mBasicModeHandler, SLOT(filterEvent(const QKeyEvent *))); |
|
94 connect(mPredictionModeHandler, SIGNAL(passActionHandler(HbInputModeAction )), mBasicModeHandler, SLOT(actionHandler(HbInputModeAction ))); |
|
95 |
|
96 } |
|
97 |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // HbHardware12key::~HbHardware12key |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 HbHardware12key::~HbHardware12key() |
|
105 { |
|
106 delete mCandidatePopup; |
|
107 mCandidatePopup = 0; |
|
108 |
|
109 // Free mode handlers |
|
110 delete mBasicModeHandler; |
|
111 mBasicModeHandler = 0; |
|
112 delete mPredictionModeHandler; |
|
113 mPredictionModeHandler = 0; |
|
114 delete mNumericModeHandler; |
|
115 mNumericModeHandler = 0; |
|
116 } |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // HbHardware12key::identifierName |
|
121 // |
|
122 // --------------------------------------------------------------------------- |
|
123 // |
|
124 QString HbHardware12key::identifierName() |
|
125 { |
|
126 return QString("HbHardware12key"); |
|
127 } |
|
128 |
|
129 |
|
130 // --------------------------------------------------------------------------- |
|
131 // HbHardware12key::isComposing |
|
132 // |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 bool HbHardware12key::isComposing() const |
|
136 { |
|
137 qDebug("HbHardware12key::isComposing"); |
|
138 return mActiveModeHandler->isComposing(); |
|
139 } |
|
140 |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // HbHardware12key::language |
|
144 // |
|
145 // --------------------------------------------------------------------------- |
|
146 // |
|
147 QString HbHardware12key::language() |
|
148 { |
|
149 QLocale::Language activeLanguage; |
|
150 activeLanguage = (QLocale::Language)HbInputSettingProxy::instance()->globalInputLanguage().language(); |
|
151 QLocale locale(activeLanguage); |
|
152 return locale.name(); |
|
153 } |
|
154 |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // HbHardware12key::reset |
|
158 // |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void HbHardware12key::reset() |
|
162 { |
|
163 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionReset); |
|
164 } |
|
165 |
|
166 /*! |
|
167 The mouse event handler for the input method. Launches the candidate list if the mouse is clicked on the |
|
168 pre-editing text. |
|
169 */ |
|
170 void HbHardware12key::mouseHandler(int cursorPosition, QMouseEvent* mouseEvent) |
|
171 { |
|
172 qDebug("HbHardware12key::mouseHandler"); |
|
173 mActiveModeHandler->mouseHandler(cursorPosition, mouseEvent); |
|
174 } |
|
175 |
|
176 void HbHardware12key::predictiveInputStatusChanged(int newStatus) |
|
177 { |
|
178 Q_UNUSED(newStatus); |
|
179 //HbInputFocusObject *focusedObject = 0; |
|
180 //focusedObject = focusObject(); |
|
181 //if (!focusedObject) { |
|
182 // qDebug("HbKeyboard12Key::predictiveInputStatusChanged focusObject() failed!!"); |
|
183 // return; |
|
184 //} |
|
185 |
|
186 //HbInputState inputState; |
|
187 //if (mInputMode != HbInputModeLatinPredictive) { |
|
188 // mInputMode = HbInputModeLatinPredictive; |
|
189 // inputState = HbInputState(HbInputModeLatinPredictive, |
|
190 // HbTextCase(focusedObject->editorInterface().textCase()), |
|
191 // HbKeyboard12Key, HbInputSettingProxy::instance()->globalInputLanguage()); |
|
192 // |
|
193 //} else { |
|
194 // mInputMode = HbInputModeLatinBasic; |
|
195 // inputState = HbInputState(HbInputModeLatinBasic, |
|
196 // HbTextCase(focusedObject->editorInterface().textCase()), |
|
197 // HbKeyboard12Key, HbInputSettingProxy::instance()->globalInputLanguage()); |
|
198 |
|
199 //} |
|
200 //activateState(inputState); |
|
201 //focusedObject->editorInterface().setInputMode(mInputMode); |
|
202 //focusedObject->syncEditorInterface(); |
|
203 HbInputFocusObject *focusedObject = focusObject(); |
|
204 if (focusedObject) { |
|
205 // Just refresh the situation. |
|
206 inputStateActivated(inputState()); |
|
207 return; |
|
208 } |
|
209 } |
|
210 |
|
211 |
|
212 |
|
213 /*! |
|
214 Calculates the candidate list position. |
|
215 */ |
|
216 QPoint HbHardware12key::getCandidatePosition() |
|
217 { |
|
218 qreal candListXPos = 0; |
|
219 qreal candListYPos = 0; |
|
220 HbMainWindow *mainWin = hbInstance->allMainWindows().at(0); |
|
221 if (mainWin) { |
|
222 HbView *currView = mainWin->currentView(); |
|
223 |
|
224 QRectF mainRect = mainWin->sceneRect(); |
|
225 QRectF editorRect = focusObject()->editorGeometry(); |
|
226 QSizeF candListSize = mCandidatePopup->size(); |
|
227 |
|
228 QRectF winRect = currView->windowFrameGeometry(); |
|
229 QRectF cursorRect = focusObject()->inputMethodQuery(Qt::ImMicroFocus).toRectF(); |
|
230 |
|
231 candListXPos = mainRect.x() + cursorRect.bottomRight().x() + HbDeltaWidth; |
|
232 candListYPos = winRect.y() + editorRect.y() + cursorRect.y()+ HbDeltaWidth; |
|
233 |
|
234 if((candListXPos + candListSize.width()) > mainRect.width()){ |
|
235 // Doesn't fit in editor, so launch towards the left |
|
236 candListXPos = candListXPos - candListSize.width(); |
|
237 if(candListSize.height() > winRect.height()/3) { |
|
238 // Position vertically at the bottom of the word |
|
239 candListYPos = candListYPos + candListSize.height()/2 + HbDeltaWidth; |
|
240 } |
|
241 } |
|
242 |
|
243 if(candListYPos > (winRect.height()/2)){ |
|
244 // Position vertically on the top of the word |
|
245 candListYPos = candListYPos - (candListSize.height() + HbDeltaWidth); |
|
246 } |
|
247 } |
|
248 return QPoint((int)candListXPos, (int)candListYPos); |
|
249 } |
|
250 |
|
251 /*! |
|
252 Launches the candidate list. |
|
253 */ |
|
254 void HbHardware12key::launchCandidatePopup(QStringList * candidates) |
|
255 { |
|
256 if (!mCandidatePopup) { |
|
257 mCandidatePopup = new HbCandidateList(this); |
|
258 } |
|
259 |
|
260 mCandidatePopup->populateList(*candidates); |
|
261 QPoint pos = getCandidatePosition(); |
|
262 mCandidatePopup->setPos(pos); |
|
263 mCandidatePopup->show(); |
|
264 } |
|
265 |
|
266 /*! |
|
267 this slot is called when the candidate popup is closed |
|
268 */ |
|
269 void HbHardware12key::candidatePopupClosed(int closingKey) |
|
270 { |
|
271 if (mCandidatePopup) { |
|
272 QString currentCandidate = mCandidatePopup->currentCandidate(); |
|
273 if (currentCandidate.size() > 0) { |
|
274 if ((focusObject()->editorInterface().constraints() & HbEditorConstraintAutoCompletingField)) { |
|
275 mBasicModeHandler->autoCompletionPopupClosed(currentCandidate, closingKey); |
|
276 } else { |
|
277 mPredictionModeHandler->candidatePopupClosed(currentCandidate, closingKey); |
|
278 } |
|
279 } |
|
280 } |
|
281 } |
|
282 |
|
283 |
|
284 // --------------------------------------------------------------------------- |
|
285 // HbHardware12key::filterEvent |
|
286 // |
|
287 // --------------------------------------------------------------------------- |
|
288 // |
|
289 bool HbHardware12key::filterEvent(const QEvent *event) |
|
290 { |
|
291 qDebug("HbHardware12key:filterEvent called, event type %d", event->type()); |
|
292 return mActiveModeHandler->filterEvent(event); |
|
293 } |
|
294 |
|
295 |
|
296 |
|
297 // --------------------------------------------------------------------------- |
|
298 // HbHardware12key::listInputModes |
|
299 // |
|
300 // --------------------------------------------------------------------------- |
|
301 // |
|
302 void HbHardware12key::listInputModes(QVector<HbInputModeProperties>& results) |
|
303 { |
|
304 mBasicModeHandler->listInputModes(results); |
|
305 mPredictionModeHandler->listInputModes(results); |
|
306 mNumericModeHandler->listInputModes(results); |
|
307 } |
|
308 |
|
309 |
|
310 // --------------------------------------------------------------------------- |
|
311 // HbHardware12key::focusReceived |
|
312 // |
|
313 // --------------------------------------------------------------------------- |
|
314 // |
|
315 void HbHardware12key::focusReceived() |
|
316 { |
|
317 qDebug("HbHardware12key::focusReceived"); |
|
318 // Inform active mode handler about the focusrecieve event. |
|
319 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved); |
|
320 } |
|
321 |
|
322 |
|
323 // --------------------------------------------------------------------------- |
|
324 // HbHardware12key::focusLost |
|
325 // |
|
326 // --------------------------------------------------------------------------- |
|
327 // |
|
328 void HbHardware12key::focusLost(bool focusSwitch) |
|
329 { |
|
330 Q_UNUSED(focusSwitch); |
|
331 |
|
332 qDebug("HbHardware12key::focusLost"); |
|
333 // inform the active mode handler about the focus lost event. |
|
334 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusLost); |
|
335 } |
|
336 |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // HbHardware12key::sctCharacterSelected |
|
340 // |
|
341 // --------------------------------------------------------------------------- |
|
342 // |
|
343 void HbHardware12key::sctCharacterSelected(QChar character) |
|
344 { |
|
345 qDebug("HbHardware12key::sctCharacterSelected"); |
|
346 mActiveModeHandler->sctCharacterSelected(character); |
|
347 } |
|
348 |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // HbHardware12key::InputLanguageChanged |
|
352 // |
|
353 // --------------------------------------------------------------------------- |
|
354 // |
|
355 void HbHardware12key::inputLanguageChanged(int newLanguage) |
|
356 { |
|
357 qDebug("HbHardware12key::InputLanguageChanged"); |
|
358 |
|
359 mKeyData = HbKeyMapFactory::instance()->keymapDataForLanguage(newLanguage); |
|
360 if (!mKeyData) { |
|
361 qDebug("HbHardware12key: ERROR: Language switch FAILED for language %d", newLanguage); |
|
362 } |
|
363 // let's inform all the mode handlers about the language change. |
|
364 mBasicModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionPrimaryLanguageChanged); |
|
365 mPredictionModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionPrimaryLanguageChanged); |
|
366 |
|
367 } |
|
368 |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // HbHardware12key::inputStateActivated |
|
372 // |
|
373 // --------------------------------------------------------------------------- |
|
374 // |
|
375 void HbHardware12key::inputStateActivated(const HbInputState& newState) |
|
376 { |
|
377 if (!isActiveMethod()) { |
|
378 return; // Just to be sure... |
|
379 } |
|
380 // TODO: Switch editing indicator here.... |
|
381 // SetEditingIndicator(HbEditingIndicatorLatinMultitap); |
|
382 |
|
383 HbInputLanguage lang = activeLanguage(); |
|
384 if (!mKeyData || mKeyData->languageCode() != lang.language()) { |
|
385 mKeyData = HbKeyMapFactory::instance()->keymapDataForLanguage(lang.language()); |
|
386 } |
|
387 |
|
388 if (focusObject()) { |
|
389 focusObject()->syncEditorInterface(); |
|
390 } |
|
391 HbInputModeHandler *previousModeHandler = mActiveModeHandler; |
|
392 if (newState.inputMode() == HbInputModeDefault && usePrediction()) { |
|
393 mActiveModeHandler = mPredictionModeHandler; |
|
394 // by passing HbInputModeActionFocusRecieved we will be setting the candidate list and keypad |
|
395 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionFocusRecieved); |
|
396 } else if (newState.inputMode() == HbInputModeDefault) { |
|
397 mActiveModeHandler = mBasicModeHandler; |
|
398 } else if (newState.inputMode() == HbInputModeNumeric) { |
|
399 mActiveModeHandler = mNumericModeHandler; |
|
400 } |
|
401 |
|
402 // if there is a change in the modehandler we need send a commit in previous mode handler. |
|
403 if (previousModeHandler != mActiveModeHandler) { |
|
404 if (previousModeHandler == mPredictionModeHandler) { |
|
405 previousModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionHideTail); |
|
406 } |
|
407 previousModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionCommit); |
|
408 // lets set candidate list and keypad type to the engine. |
|
409 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetCandidateList); |
|
410 mActiveModeHandler->actionHandler(HbInputModeHandler::HbInputModeActionSetKeypad); |
|
411 } |
|
412 } |
|
413 |
|
414 void HbHardware12key::switchMode(int keyCode) |
|
415 { |
|
416 if (keyCode == Qt::Key_Asterisk){ |
|
417 //TO-DO SCT part |
|
418 //.... |
|
419 } else if ( keyCode == Qt::Key_Shift) { |
|
420 HbInputState inputState = this->inputState(); |
|
421 if (inputState.inputMode() != HbInputModeNumeric ){ |
|
422 mPrevInputState = inputState; |
|
423 inputState.inputMode() = HbInputModeNumeric; |
|
424 this->activateState(inputState); |
|
425 } else { |
|
426 this->activateState( mPrevInputState ); |
|
427 } |
|
428 mInputMode = this->inputState().inputMode(); |
|
429 } |
|
430 } |
|
431 |
|
432 // --------------------------------------------------------------------------- |
|
433 // HbHardware12key::switchSpecialCharacterTable |
|
434 // |
|
435 // --------------------------------------------------------------------------- |
|
436 // |
|
437 int HbHardware12key::switchSpecialCharacterTable() |
|
438 { |
|
439 switchToSctMode(); |
|
440 //Q_UNUSED(receiver); |
|
441 return 0; |
|
442 } |
|
443 |
|
444 /*! |
|
445 Switches the virtual keypad to the SCT input mode. It refreshes the keypad with special characters. |
|
446 */ |
|
447 void HbHardware12key::switchToSctMode() |
|
448 { |
|
449 //TO-DO SCT part |
|
450 //.... |
|
451 } |
|
452 |
|
453 /*! |
|
454 Sets the special character table with the required characters. |
|
455 */ |
|
456 void HbHardware12key::setSpecialCharacters() |
|
457 { |
|
458 QString charSet; |
|
459 #if 0 /* code commented as numeric SCT set is added to the default list */ |
|
460 if (focusObject()->editorInterface().filter() & HbNumberModeFilterMask) { |
|
461 charSet = mKeyData->numericModeSpecialCharacterData(HbKeyboardVirtual12Key); |
|
462 } else { |
|
463 charSet = mKeyData->specialCharacterData(HbKeyboardVirtual12Key); |
|
464 } |
|
465 |
|
466 charSet = mKeyData->specialCharacterData(HbKeyboard12Key); |
|
467 |
|
468 QString filtered; |
|
469 if (focusObject()) { |
|
470 focusObject()->filterStringWithEditorFilter(charSet, filtered); |
|
471 } else { |
|
472 filtered = charSet; |
|
473 } |
|
474 |
|
475 if (filtered.size() > 0) { |
|
476 mSctKeypad->setCharSet(filtered, focusObject()->editorInterface().filter()); |
|
477 } |
|
478 #endif |
|
479 } |
|
480 |
|
481 |
|
482 /*! |
|
483 Slot used by mode handlers to close the candidate popup. |
|
484 */ |
|
485 void HbHardware12key::closeCandidatePopup() |
|
486 { |
|
487 if (mCandidatePopup && mCandidatePopup->isVisible()) { |
|
488 mCandidatePopup->hide(); |
|
489 } |
|
490 } |
|
491 |
|
492 /*! |
|
493 Slot used by mode handlers to close the autocompletion popup. |
|
494 */ |
|
495 void HbHardware12key::closeAutoCompletionPopup() |
|
496 { |
|
497 closeCandidatePopup(); |
|
498 } |
|
499 |
|
500 void HbHardware12key::launchAutoCompletionPopup(QStringList* candidates) |
|
501 { |
|
502 if (!mCandidatePopup) { |
|
503 mCandidatePopup = new HbCandidateList(this); |
|
504 } |
|
505 |
|
506 if (candidates) { |
|
507 if (candidates->count() > 0) { |
|
508 mCandidatePopup->populateList(*candidates); |
|
509 mCandidatePopup->setModal(false); |
|
510 |
|
511 if (focusObject()) { |
|
512 QRectF editorGeom = focusObject()->editorGeometry(); |
|
513 mCandidatePopup->setPos(QPointF(HbAutoComplPopupLeftMargin, editorGeom.top() - mCandidatePopup->size().height())); |
|
514 } |
|
515 |
|
516 // Set width. Currently done like this, later it can be changed to take the string lengths |
|
517 // into account too. |
|
518 HbMainWindow *mainWin = hbInstance->allMainWindows().at(0); |
|
519 if (mainWin) { |
|
520 QRectF mainRect = mainWin->sceneRect(); |
|
521 QSizeF candListSize = mCandidatePopup->size(); |
|
522 candListSize.setWidth(mainRect.width() - (HbAutoComplPopupLeftMargin * 2.0)); |
|
523 mCandidatePopup->resize(candListSize); |
|
524 } |
|
525 |
|
526 mCandidatePopup->setBackgroundFaded(false); |
|
527 mCandidatePopup->show(); |
|
528 } else if (mCandidatePopup->isVisible()) { |
|
529 mCandidatePopup->hide(); |
|
530 } |
|
531 } |
|
532 } |
|
533 |
|
534 /*! |
|
535 Returns true if prediction is on, prediction engine is available and predictions is allowed in current editor. |
|
536 */ |
|
537 bool HbHardware12key::usePrediction() const |
|
538 { |
|
539 HbInputFocusObject *fo = focusObject(); |
|
540 if (HbInputSettingProxy::instance()->predictiveInputStatus() && |
|
541 fo && |
|
542 fo->editorInterface().isPredictionAllowed() && |
|
543 mPredictionModeHandler->isActive()) { |
|
544 return true; |
|
545 } |
|
546 |
|
547 return false; |
|
548 } |
|
549 |
|
550 // End of file |
|
551 |