20 ** |
20 ** |
21 ** If you have questions regarding the use of this file, please contact |
21 ** If you have questions regarding the use of this file, please contact |
22 ** Nokia at developer.feedback@nokia.com. |
22 ** Nokia at developer.feedback@nokia.com. |
23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
|
25 #include "hbinputsctkeyboard.h" |
|
26 #include "hbinputsctkeyboard_p.h" |
25 |
27 |
26 #include <math.h> |
28 #include <math.h> |
27 |
29 |
28 #include <hbdeviceprofile.h> |
30 #include <hbdeviceprofile.h> |
29 |
31 |
31 #include <hbinputkeymap.h> |
33 #include <hbinputkeymap.h> |
32 #include <hbinpututils.h> |
34 #include <hbinpututils.h> |
33 #include <hbframedrawer.h> |
35 #include <hbframedrawer.h> |
34 #include <hbinputsettingproxy.h> |
36 #include <hbinputsettingproxy.h> |
35 |
37 |
36 #include "hbinputsctkeyboard.h" |
|
37 #include "hbinputsctkeyboard_p.h" |
|
38 #include "hbinputbuttongroup.h" |
38 #include "hbinputbuttongroup.h" |
39 #include "hbinputbutton.h" |
39 #include "hbinputbutton.h" |
40 |
40 |
41 const qreal HbPortraitKeyboardHeightInUnits = 46.8; |
41 const qreal HbPortraitKeyboardHeightInUnits = 46.8; |
42 const qreal HbPortraitKeyboardWidthInUnits = 53.8; |
42 const qreal HbPortraitKeyboardWidthInUnits = 53.8; |
43 const qreal HbLandscapeKeyboardHeightInUnits = 34.6; |
43 const qreal HbLandscapeKeyboardHeightInUnits = 34.6; |
44 const qreal HbLandscapeKeyboardWidthInUnits = 95.5; |
44 const qreal HbLandscapeKeyboardWidthInUnits = 95.5; |
45 |
45 |
46 const int HbSctPortraitNumberOfRows = 5; |
46 const int HbSctPortraitNumberOfRows = 5; |
47 const int HbSctPortraitNumberOfColumns = 5; |
47 const int HbSctPortraitNumberOfColumns = 5; |
48 const int HbPortraitButtonKeyCodeTable[HbSctPortraitNumberOfRows * HbSctPortraitNumberOfColumns] = |
48 const int HbPortraitButtonKeyCodeTable[HbSctPortraitNumberOfRows *HbSctPortraitNumberOfColumns] = { |
49 { |
|
50 HbInputButton::ButtonKeyCodeCharacter, |
49 HbInputButton::ButtonKeyCodeCharacter, |
51 HbInputButton::ButtonKeyCodeCharacter, |
50 HbInputButton::ButtonKeyCodeCharacter, |
52 HbInputButton::ButtonKeyCodeCharacter, |
51 HbInputButton::ButtonKeyCodeCharacter, |
53 HbInputButton::ButtonKeyCodeCharacter, |
52 HbInputButton::ButtonKeyCodeCharacter, |
54 HbInputButton::ButtonKeyCodeDelete, |
53 HbInputButton::ButtonKeyCodeDelete, |
74 HbInputButton::ButtonKeyCodeCustom |
73 HbInputButton::ButtonKeyCodeCustom |
75 }; |
74 }; |
76 |
75 |
77 const int HbSctLandscapeNumberOfRows = 4; |
76 const int HbSctLandscapeNumberOfRows = 4; |
78 const int HbSctLandscapeNumberOfColumns = 10; |
77 const int HbSctLandscapeNumberOfColumns = 10; |
79 const int HbLandscapeButtonKeyCodeTable[HbSctLandscapeNumberOfRows * HbSctLandscapeNumberOfColumns] = |
78 const int HbLandscapeButtonKeyCodeTable[HbSctLandscapeNumberOfRows *HbSctLandscapeNumberOfColumns] = { |
80 { |
|
81 HbInputButton::ButtonKeyCodeCharacter, |
79 HbInputButton::ButtonKeyCodeCharacter, |
82 HbInputButton::ButtonKeyCodeCharacter, |
80 HbInputButton::ButtonKeyCodeCharacter, |
83 HbInputButton::ButtonKeyCodeCharacter, |
81 HbInputButton::ButtonKeyCodeCharacter, |
84 HbInputButton::ButtonKeyCodeCharacter, |
82 HbInputButton::ButtonKeyCodeCharacter, |
85 HbInputButton::ButtonKeyCodeCharacter, |
83 HbInputButton::ButtonKeyCodeCharacter, |
130 |
128 |
131 \sa HbInputVkbWidget |
129 \sa HbInputVkbWidget |
132 */ |
130 */ |
133 |
131 |
134 HbSctKeyboardPrivate::HbSctKeyboardPrivate() |
132 HbSctKeyboardPrivate::HbSctKeyboardPrivate() |
135 : mType(HbKeyboardSctPortrait), mColumns(0), mRows(0), |
133 : mType(HbKeyboardSctPortrait), mColumns(0), mRows(0), |
136 mCharacterButtons(0), mPages(0), mActivePage(0) |
134 mCharacterButtons(0), mPages(0), mActivePage(0) |
137 { |
135 { |
138 } |
136 } |
139 |
137 |
140 HbSctKeyboardPrivate::~HbSctKeyboardPrivate() |
138 HbSctKeyboardPrivate::~HbSctKeyboardPrivate() |
141 { |
139 { |
149 |
147 |
150 if (HbInputSettingProxy::instance()->activeKeyboard() & HbQwertyKeyboardMask) { |
148 if (HbInputSettingProxy::instance()->activeKeyboard() & HbQwertyKeyboardMask) { |
151 mType = HbKeyboardSctLandscape; |
149 mType = HbKeyboardSctLandscape; |
152 } |
150 } |
153 |
151 |
154 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
152 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem()); |
155 if (buttonGroup) { |
153 if (buttonGroup) { |
156 mColumns = HbSctPortraitNumberOfColumns; |
154 mColumns = HbSctPortraitNumberOfColumns; |
157 mRows = HbSctPortraitNumberOfRows; |
155 mRows = HbSctPortraitNumberOfRows; |
158 if (mType == HbKeyboardSctLandscape) { |
156 if (mType == HbKeyboardSctLandscape) { |
159 mColumns = HbSctLandscapeNumberOfColumns; |
157 mColumns = HbSctLandscapeNumberOfColumns; |
163 } |
161 } |
164 |
162 |
165 buttonGroup->setGridSize(QSize(mColumns, mRows)); |
163 buttonGroup->setGridSize(QSize(mColumns, mRows)); |
166 |
164 |
167 int key = 0; |
165 int key = 0; |
168 QList<HbInputButton*> buttons; |
166 QList<HbInputButton *> buttons; |
169 for (int i = 0; i < mColumns * mRows; ++i) { |
167 for (int i = 0; i < mColumns * mRows; ++i) { |
170 HbInputButton *item = new HbInputButton(keyCode(i), QPoint(key % mColumns, key / mColumns)); |
168 HbInputButton *item = new HbInputButton(keyCode(i), QPoint(key % mColumns, key / mColumns)); |
171 buttons.append(item); |
169 buttons.append(item); |
172 |
170 |
173 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
171 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
174 ++mCharacterButtons; |
172 ++mCharacterButtons; |
175 } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSpace) { |
173 } else if (keyCode(i) == HbInputButton::ButtonKeyCodeSpace) { |
176 item->setSize(QSize(2, 1)); |
174 item->setSize(QSize(2, 1)); |
177 ++key; |
175 ++key; |
184 } |
182 } |
185 ++key; |
183 ++key; |
186 } |
184 } |
187 buttonGroup->setButtons(buttons); |
185 buttonGroup->setButtons(buttons); |
188 |
186 |
189 QObject::connect(buttonGroup, SIGNAL(buttonPressed(const QKeyEvent&)), q, SLOT(sendKeyPressEvent(const QKeyEvent&))); |
187 QObject::connect(buttonGroup, SIGNAL(buttonPressed(const QKeyEvent &)), q, SLOT(sendKeyPressEvent(const QKeyEvent &))); |
190 QObject::connect(buttonGroup, SIGNAL(buttonDoublePressed(const QKeyEvent&)), q, SLOT(sendKeyDoublePressEvent(const QKeyEvent&))); |
188 QObject::connect(buttonGroup, SIGNAL(buttonDoublePressed(const QKeyEvent &)), q, SLOT(sendKeyDoublePressEvent(const QKeyEvent &))); |
191 QObject::connect(buttonGroup, SIGNAL(buttonReleased(const QKeyEvent&)), q, SLOT(sendKeyReleaseEvent(const QKeyEvent&))); |
189 QObject::connect(buttonGroup, SIGNAL(buttonReleased(const QKeyEvent &)), q, SLOT(sendKeyReleaseEvent(const QKeyEvent &))); |
192 QObject::connect(buttonGroup, SIGNAL(buttonLongPressed(const QKeyEvent&)), q, SLOT(sendLongPressEvent(const QKeyEvent&))); |
190 QObject::connect(buttonGroup, SIGNAL(buttonLongPressed(const QKeyEvent &)), q, SLOT(sendLongPressEvent(const QKeyEvent &))); |
193 QObject::connect(buttonGroup, SIGNAL(pressedButtonChanged(const QKeyEvent&, const QKeyEvent&)), q, SLOT(sendKeyChangeEvent(const QKeyEvent&, const QKeyEvent&))); |
191 QObject::connect(buttonGroup, SIGNAL(pressedButtonChanged(const QKeyEvent &, const QKeyEvent &)), q, SLOT(sendKeyChangeEvent(const QKeyEvent &, const QKeyEvent &))); |
194 } |
192 } |
195 |
193 |
196 QObject::connect(q, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), buttonGroup, SLOT(cancelButtonPress())); |
194 QObject::connect(q, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), buttonGroup, SLOT(cancelButtonPress())); |
197 } |
195 } |
198 |
196 |
199 int HbSctKeyboardPrivate::keyCode(int buttonId) |
197 int HbSctKeyboardPrivate::keyCode(int buttonId) |
200 { |
198 { |
212 HbInputFocusObject *focusedObject = mOwner->focusObject(); |
210 HbInputFocusObject *focusedObject = mOwner->focusObject(); |
213 if (!focusedObject) { |
211 if (!focusedObject) { |
214 return; |
212 return; |
215 } |
213 } |
216 |
214 |
217 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
215 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem()); |
218 if (buttonGroup) { |
216 if (buttonGroup) { |
219 QList<HbInputButton*> buttons = buttonGroup->buttons(); |
217 QList<HbInputButton *> buttons = buttonGroup->buttons(); |
220 for (int i = 0; i < buttons.count(); ++i) { |
218 for (int i = 0; i < buttons.count(); ++i) { |
221 HbInputButton *item = buttons.at(i); |
219 HbInputButton *item = buttons.at(i); |
222 |
220 |
223 HbInputButton::HbInputButtonState state = item->state(); |
221 HbInputButton::HbInputButtonState state = item->state(); |
224 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
222 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
255 |
253 |
256 if (mPages > 1) { |
254 if (mPages > 1) { |
257 mFlickAnimation = true; |
255 mFlickAnimation = true; |
258 } |
256 } |
259 |
257 |
260 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
258 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem()); |
261 if (buttonGroup) { |
259 if (buttonGroup) { |
262 int key = mActivePage * mCharacterButtons; |
260 int key = mActivePage * mCharacterButtons; |
263 QList<HbInputButton*> buttons = buttonGroup->buttons(); |
261 QList<HbInputButton *> buttons = buttonGroup->buttons(); |
264 for (int i = 0; i < buttons.count(); ++i) { |
262 for (int i = 0; i < buttons.count(); ++i) { |
265 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
263 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
266 HbInputButton *item = buttons.at(i); |
264 HbInputButton *item = buttons.at(i); |
267 |
265 |
268 if (keyboardMap && key < keyboardMap->keys.count()) { |
266 if (keyboardMap && key < keyboardMap->keys.count()) { |
278 |
276 |
279 void HbSctKeyboardPrivate::updateButtons() |
277 void HbSctKeyboardPrivate::updateButtons() |
280 { |
278 { |
281 Q_Q(HbSctKeyboard); |
279 Q_Q(HbSctKeyboard); |
282 |
280 |
283 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
281 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(q->contentItem()); |
284 if (buttonGroup) { |
282 if (buttonGroup) { |
285 int key = mActivePage * mCharacterButtons; |
283 int key = mActivePage * mCharacterButtons; |
286 QList<HbInputButton*> buttons = buttonGroup->buttons(); |
284 QList<HbInputButton *> buttons = buttonGroup->buttons(); |
287 for (int i = 0; i < buttons.count(); ++i) { |
285 for (int i = 0; i < buttons.count(); ++i) { |
288 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
286 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
289 HbInputButton *item = buttons.at(i); |
287 HbInputButton *item = buttons.at(i); |
290 |
288 |
291 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType()); |
289 const HbKeyboardMap *keyboardMap = mKeymap->keyboard(q->keyboardType()); |
292 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(HbModifierNone)!= QString("")) { |
290 if (keyboardMap && key < keyboardMap->keys.count() && keyboardMap->keys.at(key)->characters(HbModifierNone) != QString("")) { |
293 QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone); |
291 QString keydata = keyboardMap->keys.at(key)->characters(HbModifierNone); |
294 item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary); |
292 item->setText(keydata.at(0), HbInputButton::ButtonTextIndexPrimary); |
295 } else { |
293 } else { |
296 item->setText("", HbInputButton::ButtonTextIndexPrimary); |
294 item->setText("", HbInputButton::ButtonTextIndexPrimary); |
297 } |
295 } |
308 is key mapping data to be used to display button texts. Key mapping data can be |
306 is key mapping data to be used to display button texts. Key mapping data can be |
309 changed later (for example when the input language changes) by calling |
307 changed later (for example when the input language changes) by calling |
310 setKeymap. |
308 setKeymap. |
311 */ |
309 */ |
312 HbSctKeyboard::HbSctKeyboard(HbInputMethod *owner, const HbKeymap *keymap, QGraphicsItem *parent) |
310 HbSctKeyboard::HbSctKeyboard(HbInputMethod *owner, const HbKeymap *keymap, QGraphicsItem *parent) |
313 : HbInputVkbWidget(*new HbSctKeyboardPrivate, parent) |
311 : HbInputVkbWidget(*new HbSctKeyboardPrivate, parent) |
314 { |
312 { |
315 if (!owner) { |
313 if (!owner) { |
316 return; |
314 return; |
317 } |
315 } |
318 Q_D(HbSctKeyboard); |
316 Q_D(HbSctKeyboard); |
319 d->mOwner = owner; |
317 d->mOwner = owner; |
320 setKeymap(keymap); |
318 setKeymap(keymap); |
321 |
319 |
322 const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType()); |
320 const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType()); |
323 if (keyboardMap) { |
321 if (keyboardMap) { |
324 d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons)); |
322 d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons)); |
339 is key mapping data to be used to display button texts. Key mapping data can be |
337 is key mapping data to be used to display button texts. Key mapping data can be |
340 changed later (for example when the input language changes) by calling |
338 changed later (for example when the input language changes) by calling |
341 setKeymap. |
339 setKeymap. |
342 */ |
340 */ |
343 HbSctKeyboard::HbSctKeyboard(HbSctKeyboardPrivate &dd, HbInputMethod *owner, |
341 HbSctKeyboard::HbSctKeyboard(HbSctKeyboardPrivate &dd, HbInputMethod *owner, |
344 const HbKeymap *keymap, QGraphicsItem* parent) |
342 const HbKeymap *keymap, QGraphicsItem *parent) |
345 : HbInputVkbWidget(dd, parent) |
343 : HbInputVkbWidget(dd, parent) |
346 { |
344 { |
347 if (!owner) { |
345 if (!owner) { |
348 return; |
346 return; |
349 } |
347 } |
350 Q_D(HbSctKeyboard); |
348 Q_D(HbSctKeyboard); |
351 d->mOwner = owner; |
349 d->mOwner = owner; |
352 setKeymap(keymap); |
350 setKeymap(keymap); |
353 |
351 |
354 const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType()); |
352 const HbKeyboardMap *keyboardMap = keymap->keyboard(keyboardType()); |
355 if (keyboardMap) { |
353 if (keyboardMap) { |
356 d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons)); |
354 d->mPages = (int)ceil((float)(keyboardMap->keys.count() / d->mCharacterButtons)); |
420 /*! |
418 /*! |
421 Updates button preview status. |
419 Updates button preview status. |
422 */ |
420 */ |
423 void HbSctKeyboard::updateButtonPreviewStatus(bool status) |
421 void HbSctKeyboard::updateButtonPreviewStatus(bool status) |
424 { |
422 { |
425 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(contentItem()); |
423 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup *>(contentItem()); |
426 if (buttonGroup) { |
424 if (buttonGroup) { |
427 buttonGroup->setButtonPreviewEnabled(status); |
425 buttonGroup->setButtonPreviewEnabled(status); |
428 } |
426 } |
429 } |
427 } |
430 |
428 |
431 /*! |
429 /*! |
432 Handles flick gesture |
430 Handles flick gesture |
483 Sends key event to owning input method. |
481 Sends key event to owning input method. |
484 Release event is ignored. |
482 Release event is ignored. |
485 */ |
483 */ |
486 void HbSctKeyboard::sendKeyChangeEvent(const QKeyEvent &releaseEvent, const QKeyEvent &pressEvent) |
484 void HbSctKeyboard::sendKeyChangeEvent(const QKeyEvent &releaseEvent, const QKeyEvent &pressEvent) |
487 { |
485 { |
488 if (pressEvent.key() != HbInputButton::ButtonKeyCodePageChange && |
486 if (pressEvent.key() != HbInputButton::ButtonKeyCodePageChange && |
489 pressEvent.key() != HbInputButton::ButtonKeyCodeSmiley) { |
487 pressEvent.key() != HbInputButton::ButtonKeyCodeSmiley) { |
490 HbInputVkbWidget::sendKeyChangeEvent(releaseEvent, pressEvent); |
488 HbInputVkbWidget::sendKeyChangeEvent(releaseEvent, pressEvent); |
491 } |
489 } |
492 } |
490 } |
493 |
491 |