|
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 |
|
27 #include <QTimer> |
|
28 #include <hbinputmethod.h> |
|
29 #include <hbinputkeymapfactory.h> |
|
30 |
|
31 #include "HbHardware12key.h" |
|
32 #include "Hbhardwareinputnumeric12keyhandler.h" |
|
33 #include "hbinputnumerichandler_p.h" |
|
34 #include "hbinputabstractbase.h" |
|
35 |
|
36 class HbHardwareInputNumeric12KeyHandlerPrivate: public HbInputNumericHandlerPrivate |
|
37 { |
|
38 Q_DECLARE_PUBLIC(HbHardwareInputNumeric12KeyHandler) |
|
39 |
|
40 public: |
|
41 HbHardwareInputNumeric12KeyHandlerPrivate(); |
|
42 ~HbHardwareInputNumeric12KeyHandlerPrivate(); |
|
43 |
|
44 bool keyPressed(const QKeyEvent *keyEvent); |
|
45 void _q_timeout(); |
|
46 public: |
|
47 int mLastKey; |
|
48 bool mButtonDown; |
|
49 }; |
|
50 |
|
51 HbHardwareInputNumeric12KeyHandlerPrivate::HbHardwareInputNumeric12KeyHandlerPrivate(): |
|
52 mLastKey(0), |
|
53 mButtonDown(false) |
|
54 { |
|
55 } |
|
56 |
|
57 HbHardwareInputNumeric12KeyHandlerPrivate::~HbHardwareInputNumeric12KeyHandlerPrivate() |
|
58 { |
|
59 } |
|
60 |
|
61 bool HbHardwareInputNumeric12KeyHandlerPrivate::keyPressed(const QKeyEvent *keyEvent) |
|
62 { |
|
63 Q_Q(HbHardwareInputNumeric12KeyHandler); |
|
64 HbInputFocusObject *focusObject = 0; |
|
65 focusObject = mInputMethod->focusObject(); |
|
66 if (!focusObject) { |
|
67 qDebug("HbInputModeHandler::buttonClicked no focusObject ... failed!!"); |
|
68 return false; |
|
69 } |
|
70 |
|
71 int buttonId = keyEvent->key(); |
|
72 |
|
73 if (buttonId == Qt::Key_Return) { |
|
74 |
|
75 return true; |
|
76 } else if (buttonId == Qt::Key_Shift) { |
|
77 |
|
78 if (mTimer->isActive() && (mLastKey == buttonId)){ |
|
79 mTimer->stop(); |
|
80 HbHardware12key *hostInputMethod = qobject_cast<HbHardware12key*>(mInputMethod); |
|
81 if (hostInputMethod) { |
|
82 HbInputState newState; |
|
83 mInputMethod->editorRootState(newState); |
|
84 mInputMethod->activateState(newState); |
|
85 } |
|
86 } else { |
|
87 mTimer->start(HbLongPressTimerTimeout); |
|
88 } |
|
89 mLastKey = buttonId; |
|
90 mButtonDown = true; |
|
91 return true; |
|
92 } else if (buttonId == Qt::Key_Asterisk) { |
|
93 mInputMethod->switchMode(Qt::Key_Asterisk); |
|
94 return true; |
|
95 } |
|
96 |
|
97 // Let's see if we can get the handler for this button in the base class. |
|
98 if (q->HbInputNumericHandler::filterEvent(keyEvent)) { |
|
99 return true; |
|
100 } |
|
101 |
|
102 q->commitFirstMappedNumber(buttonId); |
|
103 return true; |
|
104 } |
|
105 |
|
106 void HbHardwareInputNumeric12KeyHandlerPrivate::_q_timeout() |
|
107 { |
|
108 mTimer->stop(); |
|
109 |
|
110 HbInputFocusObject *focusedObject = 0; |
|
111 focusedObject = mInputMethod->focusObject(); |
|
112 if (!focusedObject) { |
|
113 qDebug("HbHardwareInputNumeric12KeyHandler::timeout focusObject == 0"); |
|
114 return; |
|
115 } |
|
116 //switch to Alpha mode when Long key press of Shift key is received |
|
117 if (mButtonDown && (mLastKey == Qt::Key_Shift )) |
|
118 { |
|
119 mButtonDown = false; |
|
120 // If the editor is not a number only editor, then activate the alphanumeric keypad |
|
121 if( !focusedObject->editorInterface().isNumericEditor() ){ |
|
122 mInputMethod->switchMode(mLastKey); |
|
123 } |
|
124 } |
|
125 return; |
|
126 } |
|
127 |
|
128 HbHardwareInputNumeric12KeyHandler::HbHardwareInputNumeric12KeyHandler(HbInputAbstractMethod* inputMethod) |
|
129 :HbInputNumericHandler( *new HbHardwareInputNumeric12KeyHandlerPrivate, inputMethod) |
|
130 { |
|
131 Q_D(HbHardwareInputNumeric12KeyHandler); |
|
132 d->q_ptr = this; |
|
133 } |
|
134 |
|
135 HbHardwareInputNumeric12KeyHandler::~HbHardwareInputNumeric12KeyHandler() |
|
136 { |
|
137 } |
|
138 |
|
139 /*! |
|
140 filterEvent function for handling different keyevents. |
|
141 */ |
|
142 bool HbHardwareInputNumeric12KeyHandler::filterEvent(const QKeyEvent * event) |
|
143 { |
|
144 Q_D(HbHardwareInputNumeric12KeyHandler); |
|
145 |
|
146 // in numeric mode in itut keypad only KeyPress events are handled. |
|
147 if ((event->type() == QEvent::KeyPress ) |
|
148 || (event->type() == QEvent::KeyRelease && event->key() == Qt::Key_Asterisk)) { |
|
149 return d->keyPressed(event); |
|
150 } |
|
151 return false; |
|
152 } |
|
153 |
|
154 /*! |
|
155 Action handler |
|
156 */ |
|
157 bool HbHardwareInputNumeric12KeyHandler::actionHandler(HbInputModeAction action) |
|
158 { |
|
159 bool ret = false; |
|
160 switch (action) { |
|
161 //In case of the numeric editor the character is already committed. |
|
162 //Need to remove the committed character. |
|
163 case HbInputModeHandler::HbInputModeActionDeleteAndCommit:{ |
|
164 HbInputFocusObject *focusObject = 0; |
|
165 Q_D(HbHardwareInputNumeric12KeyHandler); |
|
166 focusObject = d->mInputMethod->focusObject(); |
|
167 if (!focusObject) { |
|
168 return false; |
|
169 } |
|
170 d->mTimer->stop(); |
|
171 QString empty; |
|
172 QList<QInputMethodEvent::Attribute> list; |
|
173 QInputMethodEvent event(QString(), list); |
|
174 event.setCommitString(empty, -1, 1); |
|
175 focusObject->sendEvent(event); |
|
176 ret = true; |
|
177 } |
|
178 default: { |
|
179 ret = false; |
|
180 } |
|
181 } |
|
182 if(!ret) { |
|
183 ret = HbInputNumericHandler::actionHandler(action); |
|
184 } |
|
185 return ret; |
|
186 } |
|
187 |
|
188 /*! |
|
189 list different input modes. |
|
190 */ |
|
191 void HbHardwareInputNumeric12KeyHandler::listInputModes(QVector<HbInputModeProperties>& modes) const |
|
192 { |
|
193 HbInputModeProperties binding; |
|
194 binding.iMode = HbInputModeNumeric; |
|
195 binding.iKeyboard = HbKeyboard12Key; |
|
196 |
|
197 QVector<int> languages; |
|
198 HbKeyMapFactory::instance()->listLanguages(languages); |
|
199 for (int i = 0; i < languages.count(); i++) { |
|
200 binding.iLanguage = (QLocale::Language)languages.at(i); |
|
201 modes.push_back(binding); |
|
202 } |
|
203 } |
|
204 |
|
205 // EOF |