|
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 #include <QTimer> |
|
26 #include <hbinputkeymap.h> |
|
27 #include <hbinputkeymapfactory.h> |
|
28 #include <hbinputsettingproxy.h> |
|
29 |
|
30 #include "hbinputabstractbase.h" |
|
31 #include "hbinputbasichandler_p.h" |
|
32 #include "hbinputmodehandler_p.h" |
|
33 #include "hbhardwareinputbasicqwertyhandler.h" |
|
34 |
|
35 class HbHardwareInputBasicQwertyHandlerPrivate: public HbInputBasicHandlerPrivate |
|
36 { |
|
37 Q_DECLARE_PUBLIC(HbHardwareInputBasicQwertyHandler) |
|
38 public: |
|
39 HbHardwareInputBasicQwertyHandlerPrivate(); |
|
40 ~HbHardwareInputBasicQwertyHandlerPrivate(); |
|
41 |
|
42 // button related operations. |
|
43 bool buttonPressed(const QKeyEvent *event); |
|
44 bool buttonReleased(const QKeyEvent *event); |
|
45 void _q_timeout(); |
|
46 |
|
47 public: |
|
48 HbFnState mFnState; |
|
49 int mButton; |
|
50 HbInputShiftKeyState mShiftKeyState; |
|
51 }; |
|
52 |
|
53 HbHardwareInputBasicQwertyHandlerPrivate::HbHardwareInputBasicQwertyHandlerPrivate() |
|
54 :mFnState(HbFnOff), |
|
55 mButton(0), |
|
56 mShiftKeyState(EKeyPressedNone) |
|
57 { |
|
58 } |
|
59 |
|
60 HbHardwareInputBasicQwertyHandlerPrivate::~HbHardwareInputBasicQwertyHandlerPrivate() |
|
61 { |
|
62 } |
|
63 |
|
64 bool HbHardwareInputBasicQwertyHandlerPrivate::buttonPressed(const QKeyEvent * event) |
|
65 { |
|
66 mButton = event->key(); |
|
67 if (!mTimer->isActive()){ |
|
68 mTimer->start(HbLongPressTimerTimeout); |
|
69 } |
|
70 |
|
71 if (event->key() != Qt::Key_Delete && event->key() != Qt::Key_Backspace) { |
|
72 return true; |
|
73 } else { |
|
74 return false; |
|
75 } |
|
76 } |
|
77 |
|
78 bool HbHardwareInputBasicQwertyHandlerPrivate::buttonReleased(const QKeyEvent * event) |
|
79 { |
|
80 // Kept for handling button released specific logic |
|
81 |
|
82 Q_Q(HbHardwareInputBasicQwertyHandler); |
|
83 HbInputFocusObject *focusObject = 0; |
|
84 focusObject = mInputMethod->focusObject(); |
|
85 if (!focusObject) { |
|
86 qDebug("HbHardwareInputBasicQwertyHandler::virtualButtonClicked : no focused editor widget!"); |
|
87 return false; |
|
88 } |
|
89 |
|
90 // If the timer is not active and it is alpha mode, it is a long press |
|
91 // and handled in another function. So just return. |
|
92 if (mTimer->isActive()) { |
|
93 mTimer->stop(); |
|
94 } |
|
95 int eventKey = event->key(); |
|
96 |
|
97 //Handle long key press here |
|
98 |
|
99 switch(eventKey) { |
|
100 case Qt::Key_Alt: |
|
101 //handle function key (fn key) states here using fn & shift handler helper class |
|
102 break; |
|
103 case Qt::Key_Shift: { |
|
104 //If the shift key state is EShiftKeyPressed and a second shift key press is received before any other |
|
105 //key events, then current text case should not be changed. |
|
106 if (mShiftKeyState){ |
|
107 mShiftKeyState = EKeyPressedNone; |
|
108 } else { |
|
109 mShiftKeyState = EShiftKeyPressed; |
|
110 int currentTextCase = focusObject->editorInterface().textCase(); |
|
111 switch(currentTextCase) { |
|
112 case HbTextCaseLower: |
|
113 focusObject->editorInterface().setTextCase(HbTextCaseUpper); |
|
114 focusObject->syncEditorInterface(); |
|
115 break; |
|
116 case HbTextCaseUpper: |
|
117 case HbTextCaseAutomatic: |
|
118 focusObject->editorInterface().setTextCase(HbTextCaseLower); |
|
119 focusObject->syncEditorInterface(); |
|
120 break; |
|
121 default: |
|
122 break; |
|
123 } |
|
124 } |
|
125 } |
|
126 break; |
|
127 case Qt::Key_Control:{ |
|
128 return true; |
|
129 } |
|
130 |
|
131 break; |
|
132 case Qt::Key_Backspace: |
|
133 case Qt::Key_Delete: { |
|
134 // let's pass the backspace event to the focussed editor. |
|
135 //return q->HbInputBasicHandler::filterEvent(event); |
|
136 break; |
|
137 } |
|
138 case Qt::Key_Return: |
|
139 case Qt::Key_Enter: |
|
140 case Qt::Key_Space: { |
|
141 QChar qc(eventKey); |
|
142 if(Qt::Key_Space == eventKey && (event->modifiers() & Qt::ControlModifier)){ |
|
143 if (HbInputSettingProxy::instance()->predictiveInputStatus()) { |
|
144 HbInputSettingProxy::instance()->setPredictiveInputStatus(0); |
|
145 } else { |
|
146 HbInputSettingProxy::instance()->setPredictiveInputStatus(1); |
|
147 } |
|
148 break; |
|
149 } |
|
150 |
|
151 if (qc == Qt::Key_Enter || qc == Qt::Key_Return) { |
|
152 qc = QChar('\n'); // Editor expects normal line feed. |
|
153 } |
|
154 if(focusObject){ |
|
155 q->commitAndUpdate(qc); |
|
156 } |
|
157 break; |
|
158 } |
|
159 default: { |
|
160 if (q->HbInputBasicHandler::filterEvent(event)) { |
|
161 return true; |
|
162 } |
|
163 QList<QInputMethodEvent::Attribute> list; |
|
164 QString newText; |
|
165 int currentTextCase = focusObject->editorInterface().textCase(); |
|
166 // If function key is pressed, get the functionized |
|
167 |
|
168 QString chars; |
|
169 |
|
170 const HbMappedKey* mappedKey = mKeymap->keyForKeycode(mInputMethod->inputState().keyboard(), eventKey); |
|
171 |
|
172 if (currentTextCase == HbTextCaseLower) |
|
173 chars = mappedKey->characters(HbModifierNone); |
|
174 else |
|
175 chars = mappedKey->characters(HbModifierShiftPressed); |
|
176 |
|
177 if(chars.length()){ |
|
178 q->commitAndUpdate(chars); |
|
179 } |
|
180 |
|
181 // Reset the shift state. |
|
182 if (EShiftKeyPressed == mShiftKeyState) { |
|
183 mShiftKeyState = EKeyPressedNone; |
|
184 int textCase = HbTextCaseLower; |
|
185 HbModifier modifier = HbModifierNone; |
|
186 |
|
187 if (HbTextCaseLower == currentTextCase) { |
|
188 textCase = HbTextCaseUpper; |
|
189 modifier = HbModifierShiftPressed; |
|
190 } |
|
191 focusObject->editorInterface().setTextCase(textCase); |
|
192 focusObject->syncEditorInterface(); |
|
193 } |
|
194 mInputMethod->updateState(); |
|
195 } |
|
196 break; |
|
197 } |
|
198 return true; |
|
199 } |
|
200 |
|
201 void HbHardwareInputBasicQwertyHandlerPrivate::_q_timeout() |
|
202 { |
|
203 mTimer->stop(); |
|
204 qDebug("Timer stoped"); |
|
205 if (mButton == Qt::Key_Shift ){ |
|
206 mShiftKeyState = EShiftKeyPressed; |
|
207 } else { |
|
208 mFnState = HbFnNext; |
|
209 } |
|
210 return; |
|
211 } |
|
212 |
|
213 HbHardwareInputBasicQwertyHandler::HbHardwareInputBasicQwertyHandler(HbInputAbstractMethod* inputMethod) |
|
214 :HbInputBasicHandler(* new HbHardwareInputBasicQwertyHandlerPrivate, inputMethod) |
|
215 { |
|
216 Q_D(HbHardwareInputBasicQwertyHandler); |
|
217 d->q_ptr = this; |
|
218 } |
|
219 |
|
220 |
|
221 /*! |
|
222 This function lists different input modes. |
|
223 */ |
|
224 void HbHardwareInputBasicQwertyHandler::listInputModes(QVector<HbInputModeProperties>& modes) const |
|
225 { |
|
226 HbInputModeProperties binding; |
|
227 binding.iMode = HbInputModeDefault; |
|
228 QList<HbKeyboardType> availableKeyBoards; |
|
229 HbInputSettingProxy::instance()->availableHwKeyboard(availableKeyBoards); |
|
230 foreach(HbKeyboardType keyboardType, availableKeyBoards) { |
|
231 (keyboardType&HbQwertyKeyboardMask) ? binding.iKeyboard = keyboardType : binding.iKeyboard = HbKeyboardNone; |
|
232 if (binding.iKeyboard != HbKeyboardNone) { |
|
233 QList<HbInputLanguage> languages = HbKeymapFactory::availableLanguages(); |
|
234 foreach(HbInputLanguage lang, languages) { |
|
235 binding.iLanguage = lang; |
|
236 modes.push_front(binding); |
|
237 } |
|
238 } |
|
239 } |
|
240 } |
|
241 |
|
242 HbHardwareInputBasicQwertyHandler::~HbHardwareInputBasicQwertyHandler() |
|
243 { |
|
244 } |
|
245 |
|
246 /*! |
|
247 filterEvent function key handling. |
|
248 */ |
|
249 bool HbHardwareInputBasicQwertyHandler::filterEvent(const QKeyEvent* event) |
|
250 { |
|
251 Q_D(HbHardwareInputBasicQwertyHandler); |
|
252 |
|
253 if (!event->isAutoRepeat()) { |
|
254 if ((event->type() == QEvent::KeyRelease) ) { |
|
255 return d->buttonReleased(event); |
|
256 } else { |
|
257 return d->buttonPressed(event); |
|
258 } |
|
259 } |
|
260 return false; |
|
261 } |
|
262 |
|
263 /*! |
|
264 returns true if in inline edit. |
|
265 */ |
|
266 bool HbHardwareInputBasicQwertyHandler::isComposing() const |
|
267 { |
|
268 Q_D(const HbHardwareInputBasicQwertyHandler); |
|
269 return d->mTimer->isActive(); |
|
270 } |
|
271 |
|
272 /*! |
|
273 Action handler |
|
274 */ |
|
275 bool HbHardwareInputBasicQwertyHandler::actionHandler(HbInputModeAction action) |
|
276 { |
|
277 Q_D(HbHardwareInputBasicQwertyHandler); |
|
278 bool ret = true; |
|
279 switch (action) { |
|
280 case HbInputModeActionReset: |
|
281 if (d->mTimer->isActive()) { |
|
282 d->mTimer->stop(); |
|
283 qDebug("Timer stoped"); |
|
284 } |
|
285 break; |
|
286 default: { |
|
287 ret = HbInputBasicHandler::actionHandler(action); |
|
288 } |
|
289 } |
|
290 return ret; |
|
291 } |
|
292 |
|
293 /*! |
|
294 this SLOT is called by input plugin when there is a character selected from character preview pane. |
|
295 */ |
|
296 void HbHardwareInputBasicQwertyHandler::charFromPreviewSelected(QString characters) |
|
297 { |
|
298 Q_D(HbHardwareInputBasicQwertyHandler); |
|
299 if(characters.size() > 0) { |
|
300 sctCharacterSelected(characters[0]); |
|
301 d->mInputMethod->updateState(); |
|
302 } |
|
303 } |
|
304 |
|
305 void HbHardwareInputBasicQwertyHandler::sctCharacterSelected(QChar character) |
|
306 { |
|
307 HbInputModeHandler::sctCharacterSelected(character); |
|
308 } |