|
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 <hbdeviceprofile.h> |
|
27 |
|
28 #include <hbinputmethod.h> |
|
29 #include <hbinputkeymap.h> |
|
30 #include <hbinputsettingproxy.h> |
|
31 |
|
32 #include "hbinputqwerty10x4touchkeyboard.h" |
|
33 #include "hbinputqwerty10x4touchkeyboard_p.h" |
|
34 #include "hbinputvkbwidget_p.h" |
|
35 #include "hbinputbuttongroup.h" |
|
36 #include "hbinputbutton.h" |
|
37 #include "hbinputmodeindicator.h" |
|
38 |
|
39 const qreal HbKeyboardHeightInUnits = 34.6; |
|
40 const qreal HbKeyboardWidthInUnits = 95.5; |
|
41 |
|
42 const int HbVirtualQwertyNumberOfRows = 4; |
|
43 const int HbVirtualQwertyNumberOfColumns = 10; |
|
44 const int HbButtonKeyCodeTable[HbVirtualQwertyNumberOfRows * HbVirtualQwertyNumberOfColumns - 1] = |
|
45 { |
|
46 HbInputButton::ButtonKeyCodeCharacter, |
|
47 HbInputButton::ButtonKeyCodeCharacter, |
|
48 HbInputButton::ButtonKeyCodeCharacter, |
|
49 HbInputButton::ButtonKeyCodeCharacter, |
|
50 HbInputButton::ButtonKeyCodeCharacter, |
|
51 HbInputButton::ButtonKeyCodeCharacter, |
|
52 HbInputButton::ButtonKeyCodeCharacter, |
|
53 HbInputButton::ButtonKeyCodeCharacter, |
|
54 HbInputButton::ButtonKeyCodeCharacter, |
|
55 HbInputButton::ButtonKeyCodeCharacter, |
|
56 HbInputButton::ButtonKeyCodeCharacter, |
|
57 HbInputButton::ButtonKeyCodeCharacter, |
|
58 HbInputButton::ButtonKeyCodeCharacter, |
|
59 HbInputButton::ButtonKeyCodeCharacter, |
|
60 HbInputButton::ButtonKeyCodeCharacter, |
|
61 HbInputButton::ButtonKeyCodeCharacter, |
|
62 HbInputButton::ButtonKeyCodeCharacter, |
|
63 HbInputButton::ButtonKeyCodeCharacter, |
|
64 HbInputButton::ButtonKeyCodeCharacter, |
|
65 HbInputButton::ButtonKeyCodeDelete, |
|
66 HbInputButton::ButtonKeyCodeCharacter, |
|
67 HbInputButton::ButtonKeyCodeCharacter, |
|
68 HbInputButton::ButtonKeyCodeCharacter, |
|
69 HbInputButton::ButtonKeyCodeCharacter, |
|
70 HbInputButton::ButtonKeyCodeCharacter, |
|
71 HbInputButton::ButtonKeyCodeCharacter, |
|
72 HbInputButton::ButtonKeyCodeCharacter, |
|
73 HbInputButton::ButtonKeyCodeCharacter, |
|
74 HbInputButton::ButtonKeyCodeCharacter, |
|
75 HbInputButton::ButtonKeyCodeEnter, |
|
76 HbInputButton::ButtonKeyCodeShift, |
|
77 HbInputButton::ButtonKeyCodeSymbol, |
|
78 HbInputButton::ButtonKeyCodeCharacter, |
|
79 HbInputButton::ButtonKeyCodeCharacter, |
|
80 HbInputButton::ButtonKeyCodeSpace, |
|
81 HbInputButton::ButtonKeyCodeCharacter, |
|
82 HbInputButton::ButtonKeyCodeCharacter, |
|
83 HbInputButton::ButtonKeyCodeSettings, |
|
84 HbInputButton::ButtonKeyCodeCustom |
|
85 }; |
|
86 |
|
87 HbQwerty10x4KeyboardPrivate::HbQwerty10x4KeyboardPrivate() |
|
88 { |
|
89 } |
|
90 |
|
91 HbQwerty10x4KeyboardPrivate::~HbQwerty10x4KeyboardPrivate() |
|
92 { |
|
93 } |
|
94 |
|
95 void HbQwerty10x4KeyboardPrivate::init() |
|
96 { |
|
97 Q_Q(HbQwerty10x4Keyboard); |
|
98 |
|
99 HbInputVkbWidgetPrivate::init(); |
|
100 |
|
101 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
|
102 if (buttonGroup) { |
|
103 buttonGroup->setGridSize(QSize(HbVirtualQwertyNumberOfColumns, HbVirtualQwertyNumberOfRows)); |
|
104 |
|
105 int key = 0; |
|
106 QList<HbInputButton*> buttons; |
|
107 for (int i = 0; i < HbVirtualQwertyNumberOfColumns * HbVirtualQwertyNumberOfRows - 1; ++i) { |
|
108 HbInputButton *item = new HbInputButton(HbButtonKeyCodeTable[i], QPoint(key % HbVirtualQwertyNumberOfColumns, key / HbVirtualQwertyNumberOfColumns)); |
|
109 buttons.append(item); |
|
110 |
|
111 if (HbButtonKeyCodeTable[i] == HbInputButton::ButtonKeyCodeSettings) { |
|
112 mInputModeIndicator = new HbInputModeIndicator(item, q); |
|
113 } else if (HbButtonKeyCodeTable[i] == HbInputButton::ButtonKeyCodeSpace) { |
|
114 item->setSize(QSize(2, 1)); |
|
115 ++key; |
|
116 } |
|
117 ++key; |
|
118 } |
|
119 buttonGroup->setButtons(buttons); |
|
120 buttonGroup->setButtonPreviewEnabled(HbInputSettingProxy::instance()->isCharacterPreviewForQwertyEnabled()); |
|
121 buttonGroup->setCharacterSelectionPreviewEnabled(true); |
|
122 |
|
123 QObject::connect(buttonGroup, SIGNAL(buttonPressed(const QKeyEvent&)), q, SLOT(sendKeyPressEvent(const QKeyEvent&))); |
|
124 QObject::connect(buttonGroup, SIGNAL(buttonDoublePressed(const QKeyEvent&)), q, SLOT(sendKeyDoublePressEvent(const QKeyEvent&))); |
|
125 QObject::connect(buttonGroup, SIGNAL(buttonReleased(const QKeyEvent&)), q, SLOT(sendKeyReleaseEvent(const QKeyEvent&))); |
|
126 QObject::connect(buttonGroup, SIGNAL(buttonLongPressed(const QKeyEvent&)), q, SLOT(sendLongPressEvent(const QKeyEvent&))); |
|
127 QObject::connect(buttonGroup, SIGNAL(pressedButtonChanged(const QKeyEvent&, const QKeyEvent&)), q, SLOT(sendKeyChangeEvent(const QKeyEvent&, const QKeyEvent&))); |
|
128 } |
|
129 |
|
130 QObject::connect(q, SIGNAL(flickEvent(HbInputVkbWidget::HbFlickDirection)), buttonGroup, SLOT(cancelButtonPress())); |
|
131 } |
|
132 |
|
133 int HbQwerty10x4KeyboardPrivate::keyCode(int buttonId) |
|
134 { |
|
135 return HbButtonKeyCodeTable[buttonId]; |
|
136 } |
|
137 |
|
138 void HbQwerty10x4KeyboardPrivate::applyEditorConstraints() |
|
139 { |
|
140 Q_Q(HbQwerty10x4Keyboard); |
|
141 |
|
142 HbInputFocusObject *focusedObject = mOwner->focusObject(); |
|
143 if (!focusedObject) { |
|
144 return; |
|
145 } |
|
146 |
|
147 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
|
148 if (buttonGroup) { |
|
149 QList<HbInputButton*> buttons = buttonGroup->buttons(); |
|
150 for (int i = 0; i < buttons.count(); ++i) { |
|
151 if (keyCode(i) == HbInputButton::ButtonKeyCodeCharacter) { |
|
152 HbInputButton *item = buttons.at(i); |
|
153 |
|
154 HbInputButton::HbInputButtonState state = item->state(); |
|
155 QString data = item->text(HbInputButton::ButtonTextIndexPrimary); |
|
156 if (data.isEmpty() || !focusedObject->characterAllowedInEditor(data.at(0))) { |
|
157 state = HbInputButton::ButtonStateDisabled; |
|
158 } else if (item->state() == HbInputButton::ButtonStateDisabled) { |
|
159 state = HbInputButton::ButtonStateReleased; |
|
160 } |
|
161 item->setState(state); |
|
162 } |
|
163 } |
|
164 buttonGroup->setButtons(buttons); |
|
165 } |
|
166 } |
|
167 |
|
168 void HbQwerty10x4KeyboardPrivate::updateButtons() |
|
169 { |
|
170 Q_Q(HbQwerty10x4Keyboard); |
|
171 |
|
172 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(q->contentItem()); |
|
173 if (buttonGroup) { |
|
174 HbInputButton *item = buttonGroup->button(HbInputButton::ButtonKeyCodeShift); |
|
175 if (item && item->state() != HbInputButton::ButtonStateDisabled) { |
|
176 if (mModifiers & HbModifierShiftPressed) { |
|
177 item->setState(HbInputButton::ButtonStateLatched); |
|
178 } else { |
|
179 item->setState(HbInputButton::ButtonStateReleased); |
|
180 } |
|
181 } |
|
182 } |
|
183 |
|
184 HbInputVkbWidgetPrivate::updateButtons(); |
|
185 } |
|
186 |
|
187 /*! |
|
188 Constructs the object. owner is the owning input method implementation. Keymap |
|
189 is key mapping data to be used to display button texts. Key mapping data can be |
|
190 changed later (for example when the input language changes) by calling |
|
191 setKeymap. |
|
192 */ |
|
193 HbQwerty10x4Keyboard::HbQwerty10x4Keyboard(HbInputMethod *owner, const HbKeymap *keymap, QGraphicsItem *parent) |
|
194 : HbInputVkbWidget(*new HbQwerty10x4KeyboardPrivate, parent) |
|
195 { |
|
196 Q_D(HbQwerty10x4Keyboard); |
|
197 d->mOwner = owner; |
|
198 setKeymap(keymap); |
|
199 |
|
200 QObject::connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool))); |
|
201 } |
|
202 |
|
203 /*! |
|
204 Constructs the object. owner is the owning input method implementation. Keymap |
|
205 is key mapping data to be used to display button texts. Key mapping data can be |
|
206 changed later (for example when the input language changes) by calling |
|
207 setKeymap. |
|
208 */ |
|
209 HbQwerty10x4Keyboard::HbQwerty10x4Keyboard(HbQwerty10x4KeyboardPrivate &dd, HbInputMethod *owner, |
|
210 const HbKeymap *keymap, QGraphicsItem *parent) |
|
211 : HbInputVkbWidget(dd, parent) |
|
212 { |
|
213 Q_D(HbQwerty10x4Keyboard); |
|
214 d->mOwner = owner; |
|
215 setKeymap(keymap); |
|
216 |
|
217 QObject::connect(HbInputSettingProxy::instance(), SIGNAL(characterPreviewStateForQwertyChanged(bool)), this, SLOT(updateButtonPreviewStatus(bool))); |
|
218 } |
|
219 |
|
220 /*! |
|
221 Destructs the object. |
|
222 */ |
|
223 HbQwerty10x4Keyboard::~HbQwerty10x4Keyboard() |
|
224 { |
|
225 } |
|
226 |
|
227 /*! |
|
228 Returns keyboard type. |
|
229 */ |
|
230 HbKeyboardType HbQwerty10x4Keyboard::keyboardType() const |
|
231 { |
|
232 return HbKeyboardVirtualQwerty; |
|
233 } |
|
234 |
|
235 /*! |
|
236 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard. |
|
237 */ |
|
238 QSizeF HbQwerty10x4Keyboard::preferredKeyboardSize() |
|
239 { |
|
240 Q_D(HbQwerty10x4Keyboard); |
|
241 |
|
242 QSizeF result; |
|
243 qreal unitValue = HbDeviceProfile::profile(mainWindow()).unitValue(); |
|
244 |
|
245 result.setHeight(HbKeyboardHeightInUnits * unitValue + d->mCloseHandleHeight); |
|
246 result.setWidth(HbKeyboardWidthInUnits * unitValue); |
|
247 |
|
248 return QSizeF(result); |
|
249 } |
|
250 |
|
251 /*! |
|
252 Updates button preview status. |
|
253 */ |
|
254 void HbQwerty10x4Keyboard::updateButtonPreviewStatus(bool status) |
|
255 { |
|
256 HbInputButtonGroup *buttonGroup = static_cast<HbInputButtonGroup*>(contentItem()); |
|
257 if (buttonGroup) { |
|
258 buttonGroup->setButtonPreviewEnabled(status); |
|
259 } |
|
260 } |
|
261 |
|
262 // End of file |