|
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 <QTimer> |
|
27 #include <hbinputmethod.h> |
|
28 #include <hbinputkeymapfactory.h> |
|
29 |
|
30 #include "hbinputnumeric12keyhandler.h" |
|
31 #include "hbinputnumerichandler_p.h" |
|
32 #include "virtual12key.h" |
|
33 #include "hbinputabstractbase.h" |
|
34 |
|
35 class HbInputNumeric12KeyHandlerPrivate: public HbInputNumericHandlerPrivate |
|
36 { |
|
37 Q_DECLARE_PUBLIC(HbInputNumeric12KeyHandler) |
|
38 |
|
39 public: |
|
40 HbInputNumeric12KeyHandlerPrivate(); |
|
41 ~HbInputNumeric12KeyHandlerPrivate(); |
|
42 |
|
43 bool buttonPressed(const QKeyEvent *keyEvent); |
|
44 bool buttonReleased(const QKeyEvent *keyEvent); |
|
45 void _q_timeout(); |
|
46 public: |
|
47 int mLastKey; |
|
48 bool mButtonDown; |
|
49 }; |
|
50 |
|
51 HbInputNumeric12KeyHandlerPrivate::HbInputNumeric12KeyHandlerPrivate(): |
|
52 mLastKey(0), |
|
53 mButtonDown(false) |
|
54 { |
|
55 } |
|
56 |
|
57 HbInputNumeric12KeyHandlerPrivate::~HbInputNumeric12KeyHandlerPrivate() |
|
58 { |
|
59 } |
|
60 |
|
61 bool HbInputNumeric12KeyHandlerPrivate::buttonPressed(const QKeyEvent *keyEvent) |
|
62 { |
|
63 int buttonId = keyEvent->key(); |
|
64 mButtonDown = true; |
|
65 mLastKey = buttonId; |
|
66 mTimer->stop(); |
|
67 if (buttonId == Qt::Key_Control) { |
|
68 mLastKey = buttonId; |
|
69 mTimer->start(HbLongPressTimerTimeout); |
|
70 return true; |
|
71 } else if (buttonId == Qt::Key_Shift) { |
|
72 mTimer->start(HbLongPressTimerTimeout); |
|
73 return true; |
|
74 } |
|
75 return false; |
|
76 } |
|
77 |
|
78 /*! |
|
79 Handles the key release events from the VKB. Launches the SCT with key release event of |
|
80 asterisk. |
|
81 */ |
|
82 bool HbInputNumeric12KeyHandlerPrivate::buttonReleased(const QKeyEvent *keyEvent) |
|
83 { |
|
84 Q_Q(HbInputNumeric12KeyHandler); |
|
85 HbInputFocusObject *focusObject = 0; |
|
86 focusObject = mInputMethod->focusObject(); |
|
87 if (!focusObject || !mButtonDown) { |
|
88 qDebug("HbInputModeHandler::buttonReleased no focusObject ... failed!!"); |
|
89 return false; |
|
90 } |
|
91 if(mTimer->isActive()) { |
|
92 mTimer->stop(); |
|
93 } |
|
94 |
|
95 int buttonId = keyEvent->key(); |
|
96 |
|
97 mButtonDown = false; |
|
98 |
|
99 if (buttonId == Qt::Key_Asterisk || buttonId == Qt::Key_Control) { |
|
100 //Same asterisk key is used for launching candidate list (long key press) |
|
101 //and also for SCT. So, do not launch SCT if candidate list is already launched. |
|
102 mInputMethod->switchMode(buttonId); |
|
103 return true; |
|
104 } else if (buttonId == Qt::Key_Return) { |
|
105 mInputMethod->closeKeypad(); |
|
106 return true; |
|
107 } else if ( buttonId == Qt::Key_Shift && mLastKey == buttonId ) { |
|
108 //Let's commit character "#" on single tap and double tap of shift Key |
|
109 QChar qc(keyEvent->key()); |
|
110 qc = QChar('#'); |
|
111 q->commitAndUpdate(qc); |
|
112 return true; |
|
113 } else if (buttonId >= 0) { |
|
114 // Let's see if we can get the handler for this button in the base class. |
|
115 if (q->HbInputNumericHandler::filterEvent(keyEvent)) { |
|
116 return true; |
|
117 } |
|
118 |
|
119 q->commitFirstMappedNumber(buttonId); |
|
120 return true; |
|
121 } |
|
122 return false; |
|
123 } |
|
124 |
|
125 void HbInputNumeric12KeyHandlerPrivate::_q_timeout() |
|
126 { |
|
127 Q_Q(HbInputNumeric12KeyHandler); |
|
128 mTimer->stop(); |
|
129 |
|
130 HbInputFocusObject *focusedObject = 0; |
|
131 focusedObject = mInputMethod->focusObject(); |
|
132 if (!focusedObject) { |
|
133 qDebug("HbInputNumeric12KeyHandler::timeout focusObject == 0"); |
|
134 return; |
|
135 } |
|
136 //switch to Alpha mode when Long key press of Shift key is received |
|
137 if (mButtonDown) |
|
138 { |
|
139 mButtonDown = false; |
|
140 if (mLastKey == Qt::Key_Shift) { |
|
141 // If the editor is not a number only editor, then activate the alphanumeric keypad |
|
142 if( !focusedObject->editorInterface().isNumericEditor() ) { |
|
143 mInputMethod->switchMode(mLastKey); |
|
144 mLastKey = 0; |
|
145 } |
|
146 else |
|
147 { |
|
148 q->commitAndUpdate(QChar('#')); |
|
149 } |
|
150 } |
|
151 else if (mLastKey == Qt::Key_Control) |
|
152 { |
|
153 mInputMethod->switchMode(Qt::Key_Control); |
|
154 } |
|
155 } |
|
156 } |
|
157 |
|
158 HbInputNumeric12KeyHandler::HbInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod) |
|
159 :HbInputNumericHandler( *new HbInputNumeric12KeyHandlerPrivate, inputMethod) |
|
160 { |
|
161 Q_D(HbInputNumeric12KeyHandler); |
|
162 d->q_ptr = this; |
|
163 } |
|
164 |
|
165 HbInputNumeric12KeyHandler::~HbInputNumeric12KeyHandler() |
|
166 { |
|
167 } |
|
168 |
|
169 /*! |
|
170 filterEvent function for handling different keyevents. |
|
171 */ |
|
172 bool HbInputNumeric12KeyHandler::filterEvent(const QKeyEvent * event) |
|
173 { |
|
174 Q_D(HbInputNumeric12KeyHandler); |
|
175 |
|
176 if (event->type() == QEvent::KeyPress) { |
|
177 return d->buttonPressed(event); |
|
178 } else if (event->type() == QEvent::KeyRelease) { |
|
179 return d->buttonReleased(event); |
|
180 } |
|
181 |
|
182 return false; |
|
183 } |
|
184 |
|
185 /*! |
|
186 Action handler |
|
187 */ |
|
188 bool HbInputNumeric12KeyHandler::actionHandler(HbInputModeAction action) |
|
189 { |
|
190 Q_D(HbInputNumeric12KeyHandler); |
|
191 bool ret = false; |
|
192 switch (action) { |
|
193 case HbInputModeHandler::HbInputModeActionCancelButtonPress: |
|
194 case HbInputModeHandler::HbInputModeActionReset: |
|
195 d->mLastKey = 0; |
|
196 d->mButtonDown = false; |
|
197 d->mTimer->stop(); |
|
198 break; |
|
199 //In case of the numeric editor the character is already committed. |
|
200 //Need to remove the committed character. |
|
201 case HbInputModeHandler::HbInputModeActionDeleteAndCommit: { |
|
202 HbInputFocusObject *focusObject = 0; |
|
203 |
|
204 focusObject = d->mInputMethod->focusObject(); |
|
205 if (!focusObject) { |
|
206 return false; |
|
207 } |
|
208 d->mTimer->stop(); |
|
209 if (focusObject->editorCursorPosition()) { |
|
210 QString empty; |
|
211 QList<QInputMethodEvent::Attribute> list; |
|
212 QInputMethodEvent event(QString(), list); |
|
213 event.setCommitString(empty, -1, 1); |
|
214 focusObject->sendEvent(event); |
|
215 ret = true; |
|
216 } |
|
217 break; |
|
218 } |
|
219 default: { |
|
220 ret = false; |
|
221 } |
|
222 } |
|
223 if(!ret) { |
|
224 ret = HbInputNumericHandler::actionHandler(action); |
|
225 } |
|
226 return ret; |
|
227 } |
|
228 |
|
229 /*! |
|
230 list different input modes. |
|
231 */ |
|
232 void HbInputNumeric12KeyHandler::listInputModes(QVector<HbInputModeProperties>& modes) const |
|
233 { |
|
234 HbInputModeProperties binding; |
|
235 binding.iMode = HbInputModeNumeric; |
|
236 binding.iKeyboard = HbKeyboardVirtual12Key; |
|
237 |
|
238 QList<HbInputLanguage> languages = HbKeymapFactory::availableLanguages(); |
|
239 foreach (HbInputLanguage language, languages) { |
|
240 binding.iLanguage = language; |
|
241 modes.push_back(binding); |
|
242 } |
|
243 } |
|
244 |
|
245 // EOF |