|
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 HbInput 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 <QGraphicsGridLayout> |
|
27 |
|
28 #include <hbaction.h> |
|
29 #include <hbinputmethod.h> |
|
30 #include <hbinpututils.h> |
|
31 #include <hbinputvkbhost.h> |
|
32 #include <hbinputsettingproxy.h> |
|
33 #include <hbinputsettingdialog.h> |
|
34 #include <hbinputcommondialogs.h> |
|
35 |
|
36 #include "hbinputvkbwidget_p.h" |
|
37 #include "hbinputhwtoolcluster.h" |
|
38 #include "hbinputtouchkeypadbutton.h" |
|
39 #include "hbinputmodeindicator.h" |
|
40 |
|
41 const QString HbCustomButtonObjName = "Mini VKB custom button "; |
|
42 |
|
43 const int HbMiniVirtualKeypadNumberOfColumn = 5; |
|
44 const qreal HbMiniVirtualKeypadReductionFactor = 4.5; |
|
45 |
|
46 /*! |
|
47 @proto |
|
48 @hbinput |
|
49 \class HbHwToolCluster |
|
50 \brief Implementation of hardware tool cluster. |
|
51 |
|
52 Implementation of hardware tool cluster. |
|
53 |
|
54 \sa HbHwToolCluster |
|
55 \sa HbTouchKeypadButton |
|
56 */ |
|
57 |
|
58 /// @cond |
|
59 |
|
60 class HbHwToolClusterPrivate : HbInputVkbWidgetPrivate |
|
61 { |
|
62 Q_DECLARE_PUBLIC(HbHwToolCluster) |
|
63 |
|
64 public: |
|
65 HbHwToolClusterPrivate(); |
|
66 ~HbHwToolClusterPrivate(); |
|
67 public: |
|
68 HbTouchKeypadButton *mLanguageButton; |
|
69 HbTouchKeypadButton *mInputMethodButton; |
|
70 HbTouchKeypadButton *mPredictionIndicatorButton; |
|
71 }; |
|
72 |
|
73 HbHwToolClusterPrivate::HbHwToolClusterPrivate() : mLanguageButton(0), |
|
74 mInputMethodButton(0), |
|
75 mPredictionIndicatorButton(0) |
|
76 { |
|
77 } |
|
78 |
|
79 HbHwToolClusterPrivate::~HbHwToolClusterPrivate() |
|
80 { |
|
81 } |
|
82 |
|
83 /// @endcond |
|
84 |
|
85 /*! |
|
86 Constructs the object. |
|
87 */ |
|
88 HbHwToolCluster::HbHwToolCluster(HbInputMethod* owner, |
|
89 QGraphicsItem* parent) |
|
90 : HbInputVkbWidget(*new HbHwToolClusterPrivate, parent) |
|
91 { |
|
92 if (0 == owner) { |
|
93 return; |
|
94 } |
|
95 Q_D(HbHwToolCluster); |
|
96 d->q_ptr = this; |
|
97 d->mOwner = owner; |
|
98 } |
|
99 |
|
100 /*! |
|
101 Creates the layout of the mini touch keypad for hardware qwerty. |
|
102 */ |
|
103 void HbHwToolCluster::createLayout() |
|
104 { |
|
105 setupToolCluster(); |
|
106 |
|
107 Q_D(HbHwToolCluster); |
|
108 // The layout is already created. So just return. |
|
109 if ( d->mButtonLayout ) { |
|
110 return; |
|
111 } |
|
112 |
|
113 d->mButtonLayout = new QGraphicsGridLayout(); |
|
114 setContentsMargins(0.0, 0.0, 0.0, 0.0); |
|
115 d->mButtonLayout->setContentsMargins(0.0, 0.0, 0.0, 0.0); |
|
116 d->mButtonLayout->setHorizontalSpacing(HorizontalSpacing); |
|
117 d->mButtonLayout->setVerticalSpacing(VerticalSpacing); |
|
118 d->mButtonLayout->addItem(d->mSettingsButton, 0, 0); // Settings key |
|
119 d->mButtonLayout->addItem(d->mLanguageButton, 0, 1); // language selection |
|
120 d->mButtonLayout->addItem(d->mPredictionIndicatorButton, 0, 2); // prediction indicator |
|
121 d->mButtonLayout->addItem(d->mInputMethodButton, 0, 3); //input method selection key |
|
122 d->mButtonLayout->addItem(d->mApplicationButton, 0, 4); // Application specific key |
|
123 |
|
124 d->mSettingsButton->setObjectName( HbCustomButtonObjName + QString::number(1)); |
|
125 d->mApplicationButton->setObjectName( HbCustomButtonObjName + QString::number(2)); |
|
126 d->mLanguageButton->setObjectName( HbCustomButtonObjName + QString::number(3)); |
|
127 d->mInputMethodButton->setObjectName( HbCustomButtonObjName + QString::number(4)); |
|
128 d->mPredictionIndicatorButton->setObjectName( HbCustomButtonObjName + QString::number(5)); |
|
129 |
|
130 connect(d->mInputMethodButton, SIGNAL(clicked()), this, SLOT(showMethodDialog())); |
|
131 connect(d->mLanguageButton, SIGNAL(clicked()), this, SLOT(showLanguageDialog())); |
|
132 connect(d->mPredictionIndicatorButton, SIGNAL(clicked()), HbInputSettingProxy::instance(), SLOT(togglePrediction())); |
|
133 } |
|
134 |
|
135 |
|
136 /*! |
|
137 Creates the tools cluster for mini VKB layout. |
|
138 */ |
|
139 void HbHwToolCluster::setupToolCluster() |
|
140 { |
|
141 Q_D(HbHwToolCluster); |
|
142 if(!d->mOwner || !d->mOwner->focusObject()) { |
|
143 return; |
|
144 } |
|
145 |
|
146 // Create buttons if they do not exist |
|
147 if (!d->mSettingsButton) { |
|
148 d->mSettingsButton = new HbTouchKeypadButton(this, QString("")); |
|
149 d->mSettingsButton->setIcon(HbIcon(settingsIcon)); |
|
150 d->mSettingsButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
151 d->mSettingsButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
152 |
|
153 connect(d->mSettingsButton, SIGNAL(clicked()), this, SLOT(showSettingsDialog())); |
|
154 } |
|
155 if(!d->mLanguageButton) { |
|
156 d->mLanguageButton = new HbTouchKeypadButton(this, QString("")); |
|
157 d->mLanguageButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
158 d->mLanguageButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
159 } |
|
160 |
|
161 if(!d->mInputMethodButton) { |
|
162 d->mInputMethodButton = new HbTouchKeypadButton(this, QString("")); |
|
163 d->mInputMethodButton->setIcon(HbIcon(inputMethodIcon)); |
|
164 d->mInputMethodButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
165 d->mInputMethodButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
166 } |
|
167 |
|
168 if(!d->mPredictionIndicatorButton) { |
|
169 d->mPredictionIndicatorButton = new HbTouchKeypadButton(this, QString("")); |
|
170 d->mPredictionIndicatorButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
171 d->mPredictionIndicatorButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
172 d->mInputModeIndicator = new HbInputModeIndicator(*d->mPredictionIndicatorButton, this); |
|
173 } else { |
|
174 d->mInputModeIndicator->updateIndicator(); |
|
175 } |
|
176 |
|
177 if(d->mLanguageButton) { |
|
178 // update language button text |
|
179 QString langName = HbInputSettingProxy::instance()->globalInputLanguage().localisedName(); |
|
180 langName.truncate(3); |
|
181 d->mLanguageButton->setText(langName); |
|
182 } |
|
183 |
|
184 // update prediction button status |
|
185 if (HbInputSettingProxy::instance()->predictiveInputStatus()) { |
|
186 d->mPredictionIndicatorButton->setIcon(HbIcon(predictionOffIcon)); |
|
187 } else { |
|
188 d->mPredictionIndicatorButton->setIcon(HbIcon(predictionOnIcon)); |
|
189 } |
|
190 |
|
191 // If there's a application specific button defined, create new button with the properties |
|
192 // or update the existing one. Otherwise create an empty button or clean the properties of an existing one. |
|
193 if (!d->mOwner->focusObject()->editorInterface().actions().isEmpty()) { |
|
194 QList<HbAction*> actions = d->mOwner->focusObject()->editorInterface().actions(); |
|
195 if (d->mApplicationButton) { |
|
196 d->mApplicationButton->setText(actions.first()->text()); |
|
197 d->mApplicationButton->disconnect(SIGNAL(clicked())); |
|
198 } else { |
|
199 d->mApplicationButton = new HbTouchKeypadButton(this, actions.first()->text()); |
|
200 d->mApplicationButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
201 d->mApplicationButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
202 } |
|
203 connect(d->mApplicationButton, SIGNAL(clicked()), actions.first(), SLOT(trigger())); |
|
204 d->mApplicationButton->setIcon(actions.first()->icon()); |
|
205 d->mApplicationButton->setToolTip(actions.first()->toolTip()); |
|
206 } else { |
|
207 if (d->mApplicationButton) { |
|
208 d->mApplicationButton->disconnect(SIGNAL(clicked())); |
|
209 d->mApplicationButton->setText(QString()); |
|
210 d->mApplicationButton->setIcon(HbIcon()); |
|
211 d->mApplicationButton->setToolTip(QString()); |
|
212 } else { |
|
213 d->mApplicationButton = new HbTouchKeypadButton(this, QString()); |
|
214 d->mApplicationButton->setButtonType(HbTouchKeypadButton::HbTouchButtonFunction); |
|
215 d->mApplicationButton->setBackgroundAttributes(HbTouchKeypadButton::HbTouchButtonReleased); |
|
216 } |
|
217 } |
|
218 } |
|
219 |
|
220 /*! |
|
221 Returns keyboard type. |
|
222 */ |
|
223 HbKeyboardType HbHwToolCluster::keyboardType() const |
|
224 { |
|
225 return HbKeyboardQwerty; |
|
226 } |
|
227 |
|
228 /*! |
|
229 Destructs the object. |
|
230 */ |
|
231 HbHwToolCluster::~HbHwToolCluster() |
|
232 { |
|
233 } |
|
234 |
|
235 /*! |
|
236 This is called right before the keypad is about to open. The layout of the |
|
237 keypad happens here. |
|
238 */ |
|
239 void HbHwToolCluster::aboutToOpen(HbVkbHost *host) |
|
240 { |
|
241 Q_D(HbHwToolCluster); |
|
242 HbInputVkbWidget::aboutToOpen(host); |
|
243 |
|
244 QSizeF size = preferredKeyboardSize(); |
|
245 qreal height = size.height() - HbCloseHandleHeight; |
|
246 |
|
247 qreal width = size.width() / (qreal)HbMiniVirtualKeypadNumberOfColumn; |
|
248 for (int i=0; i < HbMiniVirtualKeypadNumberOfColumn ;i++) { |
|
249 d->mButtonLayout->setColumnFixedWidth(i, width); |
|
250 } |
|
251 //There is only one row |
|
252 d->mButtonLayout->setRowFixedHeight(0, height); |
|
253 } |
|
254 |
|
255 /*! |
|
256 Returns preferred keyboard size. HbVkbHost uses this information when it opens the keyboard. |
|
257 */ |
|
258 QSizeF HbHwToolCluster::preferredKeyboardSize() |
|
259 { |
|
260 Q_D(HbHwToolCluster); |
|
261 QSizeF ret = QSizeF(0.0, 0.0); |
|
262 |
|
263 if (d->mCurrentHost) { |
|
264 QSizeF ret; |
|
265 //Get the available keypad area from the VKB host |
|
266 ret = d->mCurrentHost->keyboardArea(); |
|
267 //Since this is a mini VKB, it has a lesser size than the available |
|
268 //area for the keypad. |
|
269 ret.setHeight(ret.height()/HbMiniVirtualKeypadReductionFactor); |
|
270 return ret; |
|
271 } |
|
272 |
|
273 return ret; |
|
274 } |
|
275 |
|
276 /*! |
|
277 Shows the settings dialog |
|
278 */ |
|
279 void HbHwToolCluster::showSettingsDialog() |
|
280 { |
|
281 Q_D(HbHwToolCluster); |
|
282 |
|
283 HbInputSettingDialog::HbSettingItems items = HbInputSettingDialog::HbSettingItemAll; |
|
284 if(d->mOwner->focusObject() && d->mOwner->focusObject()->editorInterface().isNumericEditor()){ |
|
285 items &= (~HbInputSettingDialog::HbSettingItemPrediction); |
|
286 } |
|
287 HbInputSettingDialog* settings = new HbInputSettingDialog(items); |
|
288 settings->exec(); |
|
289 delete settings; |
|
290 } |
|
291 |
|
292 /*! |
|
293 Shows the input method selection dialog. |
|
294 */ |
|
295 void HbHwToolCluster::showMethodDialog() |
|
296 { |
|
297 Q_D(HbHwToolCluster); |
|
298 |
|
299 HbInputMethodDescriptor method |
|
300 = HbInputCommonDialogs::showCustomInputMethodSelectionDialog(HbInputSettingProxy::instance()->globalInputLanguage()); |
|
301 if (!method.isEmpty() && d->mOwner) { |
|
302 d->mOwner->activateInputMethod(method); |
|
303 } |
|
304 } |
|
305 |
|
306 /*! |
|
307 Shows the language selection dialog. |
|
308 */ |
|
309 void HbHwToolCluster::showLanguageDialog() |
|
310 { |
|
311 HbInputLanguage language = |
|
312 HbInputCommonDialogs::showLanguageSelectionDialog(HbInputSettingProxy::instance()->globalInputLanguage().language()); |
|
313 HbInputSettingProxy::instance()->setGlobalInputLanguage(language); |
|
314 } |
|
315 |
|
316 // End of file |
|
317 |