|
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 "hbinputbutton.h" |
|
27 |
|
28 /// @cond |
|
29 |
|
30 class HbInputButtonPrivate |
|
31 { |
|
32 public: |
|
33 HbInputButtonPrivate(); |
|
34 HbInputButtonPrivate(int keyCode, const QPoint &position, const QSize &size); |
|
35 HbInputButtonPrivate(HbInputButton::HbInputButtonType type, HbInputButton::HbInputButtonState state, |
|
36 const QPoint &position, const QSize &size, int keyCode, bool autoRepeat, |
|
37 const QList<QString> &texts, const QString &mappedCharacters, const QList<HbIcon> &icons); |
|
38 |
|
39 void setDefaultGraphics(int keyCode); |
|
40 |
|
41 HbInputButton::HbInputButtonType mType; |
|
42 HbInputButton::HbInputButtonState mState; |
|
43 QPoint mPosition; |
|
44 QSize mSize; |
|
45 int mKeyCode; |
|
46 bool mAutoRepeat; |
|
47 QList<QString> mTexts; |
|
48 QString mMappedCharacters; |
|
49 QList<HbIcon> mIcons; |
|
50 QRectF mBoundingRect; |
|
51 }; |
|
52 |
|
53 HbInputButtonPrivate::HbInputButtonPrivate() |
|
54 : mType(HbInputButton::ButtonTypeNormal), mState(HbInputButton::ButtonStateReleased), |
|
55 mPosition(0, 0), mSize(1, 1), mKeyCode(-1), mAutoRepeat(false) |
|
56 { |
|
57 for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) { |
|
58 mTexts.append(""); |
|
59 } |
|
60 |
|
61 for (int i = 0; i < HbInputButton::ButtonIconIndexCount; ++i) { |
|
62 mIcons.append(HbIcon()); |
|
63 } |
|
64 } |
|
65 |
|
66 HbInputButtonPrivate::HbInputButtonPrivate(int keyCode, const QPoint &position, const QSize &size) |
|
67 : mType(HbInputButton::ButtonTypeNormal), mState(HbInputButton::ButtonStateReleased), |
|
68 mPosition(position), mSize(size), mKeyCode(keyCode), mAutoRepeat(false) |
|
69 { |
|
70 for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) { |
|
71 mTexts.append(""); |
|
72 } |
|
73 |
|
74 for (int i = 0; i < HbInputButton::ButtonIconIndexCount; ++i) { |
|
75 mIcons.append(HbIcon()); |
|
76 } |
|
77 |
|
78 if (keyCode != HbInputButton::ButtonKeyCodeCharacter) { |
|
79 mType = HbInputButton::ButtonTypeFunction; |
|
80 } |
|
81 |
|
82 setDefaultGraphics(keyCode); |
|
83 |
|
84 if (mSize.width() < 1) { |
|
85 mSize.setWidth(1); |
|
86 } |
|
87 if (mSize.height() < 1) { |
|
88 mSize.setHeight(1); |
|
89 } |
|
90 |
|
91 if (mKeyCode == HbInputButton::ButtonKeyCodeDelete || mKeyCode == HbInputButton::ButtonKeyCodeSpace) { |
|
92 mAutoRepeat = true; |
|
93 } |
|
94 } |
|
95 |
|
96 HbInputButtonPrivate::HbInputButtonPrivate(HbInputButton::HbInputButtonType type, HbInputButton::HbInputButtonState state, |
|
97 const QPoint &position, const QSize &size, int keyCode, bool autoRepeat, |
|
98 const QList<QString> &texts, const QString &mappedCharacters, const QList<HbIcon> &icons) |
|
99 : mType(type), mState(state), mPosition(position), mSize(size), mKeyCode(keyCode), mAutoRepeat(autoRepeat), |
|
100 mMappedCharacters(mappedCharacters) |
|
101 { |
|
102 for (int i = 0; i < HbInputButton::ButtonTextIndexCount; ++i) { |
|
103 if (i < texts.count()) { |
|
104 mTexts.append(texts.at(i)); |
|
105 } else { |
|
106 mTexts.append(QString()); |
|
107 } |
|
108 } |
|
109 |
|
110 for (int i = 0; i < HbInputButton::ButtonIconIndexCount; ++i) { |
|
111 if (i < icons.count()) { |
|
112 mIcons.append(icons.at(i)); |
|
113 } else { |
|
114 mIcons.append(HbIcon()); |
|
115 } |
|
116 } |
|
117 |
|
118 if (mSize.width() < 1) { |
|
119 mSize.setWidth(1); |
|
120 } |
|
121 if (mSize.height() < 1) { |
|
122 mSize.setHeight(1); |
|
123 } |
|
124 } |
|
125 |
|
126 void HbInputButtonPrivate::setDefaultGraphics(int keyCode) |
|
127 { |
|
128 if (keyCode == HbInputButton::ButtonKeyCodeDelete) { |
|
129 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconDelete)); |
|
130 } else if (keyCode == HbInputButton::ButtonKeyCodeShift) { |
|
131 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconShift)); |
|
132 } else if (keyCode == HbInputButton::ButtonKeyCodeSymbol) { |
|
133 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSymbol)); |
|
134 } else if (keyCode == HbInputButton::ButtonKeyCodeEnter) { |
|
135 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconEnter)); |
|
136 } else if (keyCode == HbInputButton::ButtonKeyCodeSpace) { |
|
137 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSpace)); |
|
138 } else if (keyCode == HbInputButton::ButtonKeyCodeAlphabet) { |
|
139 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconAlphabet)); |
|
140 } else if (keyCode == HbInputButton::ButtonKeyCodePageChange) { |
|
141 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconPageChange)); |
|
142 } else if (keyCode == HbInputButton::ButtonKeyCodeSmiley) { |
|
143 mIcons.replace(HbInputButton::ButtonTextIndexPrimary, HbIcon(HbInputButtonIconSmiley)); |
|
144 } |
|
145 } |
|
146 |
|
147 /// @endcond |
|
148 |
|
149 /*! |
|
150 Constructor |
|
151 */ |
|
152 HbInputButton::HbInputButton() |
|
153 : d_ptr(new HbInputButtonPrivate) |
|
154 { |
|
155 } |
|
156 |
|
157 /*! |
|
158 Constructor |
|
159 |
|
160 keyCode should usually be one of HbInputButtonKeyCode values, but it can also be any other |
|
161 integer value. |
|
162 position is button's position in grid cell units. |
|
163 size is button's size in grid cell units. |
|
164 */ |
|
165 HbInputButton::HbInputButton(int keyCode, const QPoint &position, const QSize &size) |
|
166 : d_ptr(new HbInputButtonPrivate(keyCode, position, size)) |
|
167 { |
|
168 } |
|
169 |
|
170 /*! |
|
171 Destructor |
|
172 */ |
|
173 HbInputButton::~HbInputButton() |
|
174 { |
|
175 delete d_ptr; |
|
176 } |
|
177 |
|
178 /*! |
|
179 Updates buttons type. |
|
180 |
|
181 \sa type |
|
182 */ |
|
183 void HbInputButton::setType(HbInputButtonType type) |
|
184 { |
|
185 Q_D(HbInputButton); |
|
186 |
|
187 d->mType = type; |
|
188 } |
|
189 |
|
190 /*! |
|
191 Returns buttons type. |
|
192 |
|
193 \sa setType |
|
194 */ |
|
195 HbInputButton::HbInputButtonType HbInputButton::type() const |
|
196 { |
|
197 Q_D(const HbInputButton); |
|
198 |
|
199 return d->mType; |
|
200 } |
|
201 |
|
202 /*! |
|
203 Updates buttons state. |
|
204 |
|
205 \sa state |
|
206 */ |
|
207 void HbInputButton::setState(HbInputButtonState state) |
|
208 { |
|
209 Q_D(HbInputButton); |
|
210 |
|
211 d->mState = state; |
|
212 } |
|
213 |
|
214 /*! |
|
215 Returns buttons state. |
|
216 |
|
217 \sa setState |
|
218 */ |
|
219 HbInputButton::HbInputButtonState HbInputButton::state() const |
|
220 { |
|
221 Q_D(const HbInputButton); |
|
222 |
|
223 return d->mState; |
|
224 } |
|
225 |
|
226 /*! |
|
227 Updates buttons position. |
|
228 |
|
229 position is button's position in grid cell units. |
|
230 |
|
231 \sa position |
|
232 */ |
|
233 void HbInputButton::setPosition(const QPoint &position) |
|
234 { |
|
235 Q_D(HbInputButton); |
|
236 |
|
237 d->mPosition = position; |
|
238 } |
|
239 |
|
240 /*! |
|
241 Returns buttons position. |
|
242 |
|
243 \sa setPosition |
|
244 */ |
|
245 QPoint HbInputButton::position() const |
|
246 { |
|
247 Q_D(const HbInputButton); |
|
248 |
|
249 return d->mPosition; |
|
250 } |
|
251 |
|
252 /*! |
|
253 Updates buttons size. |
|
254 |
|
255 size is button's size in grid cell units. |
|
256 |
|
257 \sa size |
|
258 */ |
|
259 void HbInputButton::setSize(const QSize &size) |
|
260 { |
|
261 Q_D(HbInputButton); |
|
262 |
|
263 d->mSize = size; |
|
264 } |
|
265 |
|
266 /*! |
|
267 Returns buttons size. |
|
268 |
|
269 \sa setSize |
|
270 */ |
|
271 QSize HbInputButton::size() const |
|
272 { |
|
273 Q_D(const HbInputButton); |
|
274 |
|
275 return d->mSize; |
|
276 } |
|
277 |
|
278 /*! |
|
279 Updates buttons key code. |
|
280 |
|
281 \sa keyCode |
|
282 */ |
|
283 void HbInputButton::setKeyCode(int keyCode) |
|
284 { |
|
285 Q_D(HbInputButton); |
|
286 |
|
287 d->mKeyCode = keyCode; |
|
288 } |
|
289 |
|
290 /*! |
|
291 Returns buttons key code. |
|
292 |
|
293 \sa setKeyCode |
|
294 */ |
|
295 int HbInputButton::keyCode() const |
|
296 { |
|
297 Q_D(const HbInputButton); |
|
298 |
|
299 return d->mKeyCode; |
|
300 } |
|
301 |
|
302 /*! |
|
303 Updates buttons auto repeat status. |
|
304 |
|
305 \sa autoRepeat |
|
306 */ |
|
307 void HbInputButton::setAutoRepeat(bool autoRepeat) |
|
308 { |
|
309 Q_D(HbInputButton); |
|
310 |
|
311 d->mAutoRepeat = autoRepeat; |
|
312 } |
|
313 |
|
314 /*! |
|
315 Returns buttons auto repeat status. |
|
316 |
|
317 \sa setAutoRepeat |
|
318 */ |
|
319 bool HbInputButton::autoRepeat() const |
|
320 { |
|
321 Q_D(const HbInputButton); |
|
322 |
|
323 return d->mAutoRepeat; |
|
324 } |
|
325 |
|
326 /*! |
|
327 Updates specified button text. |
|
328 |
|
329 \sa setTexts |
|
330 \sa text |
|
331 \sa texts |
|
332 */ |
|
333 void HbInputButton::setText(const QString &text, HbInputButtonTextIndex index) |
|
334 { |
|
335 Q_D(HbInputButton); |
|
336 |
|
337 if (index >= 0 && index < ButtonTextIndexCount) { |
|
338 d->mTexts.replace(index, text); |
|
339 } |
|
340 } |
|
341 |
|
342 /*! |
|
343 Updates all button texts. |
|
344 Button can have three different texts. Text position and size |
|
345 will depend of other buttons texts and icons. If list contains |
|
346 more strings, then the rest will be ignored. Icon with same index |
|
347 than text will override the text. |
|
348 |
|
349 \sa text |
|
350 \sa texts |
|
351 */ |
|
352 void HbInputButton::setTexts(const QList<QString> &texts) |
|
353 { |
|
354 Q_D(HbInputButton); |
|
355 |
|
356 for (int i = 0; i < ButtonTextIndexCount; ++i) { |
|
357 if (i < texts.count()) { |
|
358 d->mTexts.replace(i, texts.at(i)); |
|
359 } else { |
|
360 d->mTexts.replace(i, QString()); |
|
361 } |
|
362 } |
|
363 } |
|
364 |
|
365 /*! |
|
366 Returns specified button text. |
|
367 |
|
368 \sa setText |
|
369 \sa setTexts |
|
370 */ |
|
371 QString HbInputButton::text(HbInputButtonTextIndex index) const |
|
372 { |
|
373 Q_D(const HbInputButton); |
|
374 |
|
375 if (index < 0 || index >= ButtonTextIndexCount) { |
|
376 return QString(); |
|
377 } |
|
378 |
|
379 return d->mTexts.at(index); |
|
380 } |
|
381 |
|
382 /*! |
|
383 Returns all button texts. |
|
384 |
|
385 \sa setText |
|
386 \sa setTexts |
|
387 */ |
|
388 QList<QString> HbInputButton::texts() const |
|
389 { |
|
390 Q_D(const HbInputButton); |
|
391 |
|
392 return d->mTexts; |
|
393 } |
|
394 |
|
395 /*! |
|
396 Updates characters that are mapped to this button. |
|
397 |
|
398 \sa mappedCharacters |
|
399 */ |
|
400 void HbInputButton::setMappedCharacters(const QString &mappedCharacters) |
|
401 { |
|
402 Q_D(HbInputButton); |
|
403 |
|
404 d->mMappedCharacters = mappedCharacters; |
|
405 } |
|
406 |
|
407 /*! |
|
408 Returns characters that are mapped to this button. |
|
409 |
|
410 \sa setMappedCharacters |
|
411 */ |
|
412 QString HbInputButton::mappedCharacters() const |
|
413 { |
|
414 Q_D(const HbInputButton); |
|
415 |
|
416 return d->mMappedCharacters; |
|
417 } |
|
418 |
|
419 /*! |
|
420 Updates specified button icon. |
|
421 |
|
422 \sa setIcons |
|
423 \sa icon |
|
424 \sa icons |
|
425 */ |
|
426 void HbInputButton::setIcon(const HbIcon &icon, HbInputButtonIconIndex index) |
|
427 { |
|
428 Q_D(HbInputButton); |
|
429 |
|
430 if (index >= 0 && index < ButtonIconIndexCount) { |
|
431 d->mIcons.replace(index, icon); |
|
432 } |
|
433 } |
|
434 |
|
435 /*! |
|
436 Updates all button icons. |
|
437 Button can have three different icons. Icon position |
|
438 will depend of other buttons icons and texts. If list contains |
|
439 more icons, then the rest will be ignored. Icon with same index |
|
440 than text will override the text. |
|
441 |
|
442 \sa icon |
|
443 \sa icons |
|
444 */ |
|
445 void HbInputButton::setIcons(const QList<HbIcon> &icons) |
|
446 { |
|
447 Q_D(HbInputButton); |
|
448 |
|
449 for (int i = 0; i < ButtonIconIndexCount; ++i) { |
|
450 if (i < icons.count()) { |
|
451 d->mIcons.replace(i, icons.at(i)); |
|
452 } else { |
|
453 d->mIcons.replace(i, HbIcon()); |
|
454 } |
|
455 } |
|
456 } |
|
457 |
|
458 /*! |
|
459 Returns specified button icon. |
|
460 |
|
461 \sa setIcon |
|
462 \sa setIcons |
|
463 */ |
|
464 HbIcon HbInputButton::icon(HbInputButtonIconIndex index) const |
|
465 { |
|
466 Q_D(const HbInputButton); |
|
467 |
|
468 if (index < 0 || index >= ButtonIconIndexCount) { |
|
469 return HbIcon(); |
|
470 } |
|
471 return d->mIcons.at(index); |
|
472 } |
|
473 |
|
474 /*! |
|
475 Returns all button icon. |
|
476 |
|
477 \sa setIcon |
|
478 \sa setIcons |
|
479 */ |
|
480 QList<HbIcon> HbInputButton::icons() const |
|
481 { |
|
482 Q_D(const HbInputButton); |
|
483 |
|
484 return d->mIcons; |
|
485 } |
|
486 |
|
487 /*! |
|
488 Updates buttons bounding rectangle. |
|
489 |
|
490 \sa boundingRect |
|
491 */ |
|
492 void HbInputButton::setBoundingRect(const QRectF &rect) |
|
493 { |
|
494 Q_D(HbInputButton); |
|
495 |
|
496 d->mBoundingRect = rect; |
|
497 } |
|
498 |
|
499 /*! |
|
500 Returns buttons bounding rectangle. |
|
501 |
|
502 \sa setBoundingRect |
|
503 */ |
|
504 QRectF HbInputButton::boundingRect() const |
|
505 { |
|
506 Q_D(const HbInputButton); |
|
507 |
|
508 return d->mBoundingRect; |
|
509 } |
|
510 |
|
511 // End of file |