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