changeset 23 | e6ad4ef83b23 |
parent 21 | 4633027730f5 |
child 28 | b7da29130b0e |
21:4633027730f5 | 23:e6ad4ef83b23 |
---|---|
46 #include <QApplication> |
46 #include <QApplication> |
47 |
47 |
48 /*! |
48 /*! |
49 @beta |
49 @beta |
50 @hbwidgets |
50 @hbwidgets |
51 |
|
51 \class HbPushButton |
52 \class HbPushButton |
52 |
53 |
53 \brief The HbPushButton widget provides a button with command. |
54 \brief The HbPushButton class provides a push button widget, which enables the |
54 |
55 user to perform a command. |
55 \image html hbpushbutton.png A pushbutton with text ,icon and tooltip provided . |
56 |
56 |
57 A push button widget enables a user to perform an important command. |
57 A push button enable users to perform important commands easily. |
58 A push button has a rectangular shape and typically there is a text |
58 A push button has a rectangular shape and typically displays a text label describing its command. |
59 describing its command, an icon, and a tooltip shown on the button as in the |
59 Push Button can appear in any container except toolbars where ToolButton HbToolButton is used and palettes. |
60 following picture. |
60 A simple push button can be created as shown in the example below. |
61 |
62 \image html hbpushbutton.png A push button with a text, an icon, and a tooltip. |
|
63 |
|
64 You can set the text and the icon of a push button with HbPushButton() |
|
65 constructors and change them later with setText() and setIcon(). A push |
|
66 button also can have an additional text which you can set with |
|
67 setAdditionalText(). You can set the alignment of the text and additional text |
|
68 with setTextAlignment() and setAdditionalTextAlignment(). The default value |
|
69 for the alignment of the text and additional text is the horizontally and vertically |
|
70 centered alignment. The push button layouts with \a stretched value \c true |
|
71 and \c false (default) are the following: |
|
72 |
|
73 - Icon and text: |
|
74 - \a stretched = \c true: The icon and the text are horizontally aligned. |
|
75 \image html buttonIconTextH.png A stretched push button with an icon and a text. |
|
76 - \a stretched = \c false: The icon and the text are vertically aligned. |
|
77 \image html buttonIconTextV.png A non-stretched push button with an icon and a text. |
|
78 - Icon, text and additional text: |
|
79 - \a stretched = \c true: The icon and both texts are horizontally aligned in one |
|
80 line. |
|
81 \image html buttonIconTextAdditionalTextH.png A stretched push button with an icon, a text and an additional text. |
|
82 - \a stretched = \c false: Both texts are vertically aligned and an icon is |
|
83 horizontally aligned in relation to the texts. |
|
84 \image html buttonIconTextAdditionalTextV.png A non-stretched push button with an icon, a text and an additional text. |
|
85 - Text and additional text |
|
86 - \a stretched = \c true: Not applicable. |
|
87 - \a stretched = \c false: Both texts are vertically aligned. You can use this |
|
88 layout for a dialer or a virtual keypad button, for example. |
|
89 \image html buttonTextAdditional.png A non-stretched push button with a text and an additional text. |
|
90 |
|
91 Note that a push button does not have a stretched layout by default. |
|
92 |
|
93 A toggle button is a special type of a push button. The push button becomes |
|
94 a 'toggle button' -type push button, a 'toggle button' for short, if you set |
|
95 the \c Checkable property value of a push button to \c true. A toggle button |
|
96 can be in \c normal, \c highlighted , \c disabled, or \c latched state (see |
|
97 state descriptions below). Normally you use a toggle button as an on-off |
|
98 button that varies between \c normal (off) and \c latched (on) states as the |
|
99 user presses the toggle button. |
|
100 |
|
101 A push button can have the following states: |
|
102 - normal: the push button does not have focus (i.e. it is not highlighted) |
|
103 but the user can press it down. |
|
104 - highlighted: the push button has focus. |
|
105 - pressed: the push button is pressed down. |
|
106 - latched: the push button stays pressed down even though the user does not |
|
107 press it. |
|
108 - disabled: the user cannot press down the push button. |
|
109 |
|
110 A push button emits the pressed(), released(), clicked() and toggled() |
|
111 signals which are inherited from HbAbstractButton as well as |
|
112 HbPushButton::longPress() signal when a push button is pressed for a long |
|
113 time. You can use a push button in any container except toolbars with |
|
114 HbToolButton objects and palettes. |
|
115 |
|
116 |
|
117 \section _usecases_hbpushbutton Using the HbPushButton class |
|
118 |
|
119 \subsection _uc_hbpushbutton_001 Creating a push button. |
|
120 |
|
121 The following code snippet creates a simple push button. |
|
122 |
|
61 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,16} |
123 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,16} |
62 |
124 |
63 A Push buttons display a textual label. Pushbutton also |
125 \subsection _uc_hbpushbutton_002 Adding buttons to the layout. |
64 can have icon.These can be set using the constructors and changed later using setText(),setIcon( ). |
126 |
65 In addition to this a push button also displays additional text label. |
127 The push button is derived from HbWidget so it can be added to any |
66 Additional text can be set using setAdditionalText(). |
128 QGraphicsLayout object for defining the layout. The following code snippet |
67 Aligning of icon , text and additional text can be changed using setStretched()true/false property. |
129 adds a button with "Stop" text and an another button with an image and "Play" |
68 Default with setStretched()=false it will place icon and text vertically. |
130 text to a QGraphicsLinearLayout object. Note that QGraphicsLinearLayout |
69 |
131 inherits QGraphicsLayout. |
70 \image html buttonIconTextV.png A pushbutton with icon ,text. |
132 |
71 |
|
72 and along with additional text will place icon horizontally to both texts ,where both text comes vertically aligned. |
|
73 |
|
74 \image html buttonIconTextAdditionalTextV.png A pushbutton with icon ,text and additional text. |
|
75 |
|
76 For setStretched()=true, it will stretch layout to have icon and text horizontally,side by side. |
|
77 |
|
78 \image html buttonIconTextH.png A pushbutton with icon ,text. |
|
79 |
|
80 and along with additional text will place all of them to Horizontally in one line . |
|
81 |
|
82 \image html buttonIconTextAdditionalTextH.png A pushbutton with custom icon ,text and additional text. |
|
83 |
|
84 Pushbutton can have both text and additoinal text placed vertically,this can be used in case Dialer button or |
|
85 Virtual key pad buttons with stretched = false.Pushbutton doesn't supports both text in one line |
|
86 stretched = true is not valid. |
|
87 Pushbutton will not have stretch layout by default. |
|
88 |
|
89 \image html buttonTextAdditional.png A pushbutton with additional text and text. |
|
90 |
|
91 Pushbutton can have different states like normal, pressed, disabled, latched and focused. |
|
92 A push button emits the signal clicked() when it is activated by tapping it. |
|
93 Push buttons also provide less commonly used signals, for example, pressed() and |
|
94 released() and emits longPress() on long press. |
|
95 |
|
96 Alignment of the text within the text and additionaltext items can be set using |
|
97 setTextAlignment() and setAdditionalText(), default text alignment is Qt::AlignHCenter | Qt::AlignVCenter |
|
98 |
|
99 The push button is derived from HbWidget so it can be added to any QGraphicsLayout |
|
100 instance for layouting. |
|
101 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,17} |
133 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,17} |
102 |
134 |
103 Push button can also be used as toggle button , following is code snippet |
135 \subsection _uc_hbpushbutton_003 Using a push button as a toggle button. |
104 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,30} |
136 |
105 |
137 The following code snippet creates a push button which is used as a toggle |
106 and onOffButton as |
138 button. The button has a text, an icon, a tooltip, and its \c Checkable |
107 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,29} |
139 property value is set to \c true. |
108 |
140 |
109 Push button will come up with additional text following is code snippet. |
141 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,30} |
110 1. Push button with icon , text and additionalText |
142 |
143 \subsection _uc_hbpushbutton_004 Using a push button as an on-off button. |
|
144 |
|
145 The following code snippet creates a push button which is used as an on-off |
|
146 button. The button has an icon, a text, and a tooltip. |
|
147 |
|
148 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,29} |
|
149 |
|
150 \subsection _uc_hbpushbutton_005 Creating a push button with an icon, a text, and an additional text. |
|
151 |
|
152 The following code snippet creates a push button with with an icon, a text |
|
153 and, an additional text. |
|
154 |
|
111 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,35} |
155 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,35} |
112 |
156 |
113 2. Pushbutton with additionalText and text. |
157 \subsection _uc_hbpushbutton_006 Creating a push button with a text and an additional text. |
158 |
|
159 The following code snippet creates a push button with a text, and an additional text. |
|
160 |
|
114 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,36} |
161 \snippet{ultimatecodesnippet/ultimatecodesnippet.cpp,36} |
115 |
162 |
116 \sa HbAbstractButton , HbToolButton |
163 \sa HbAbstractButton , HbToolButton |
117 */ |
164 */ |
118 |
165 |
119 |
166 |
120 /*! |
167 /*! |
121 \reimp |
168 |
122 \fn int HbPushButton::type() const |
169 \fn int HbPushButton::type() const |
123 */ |
170 */ |
124 |
171 |
125 /*! |
172 /*! |
126 \fn void HbPushButton::longPress( QPointF ) |
173 \fn void HbPushButton::longPress( QPointF ) |
127 This signal is emitted in case of longpress. |
174 |
175 This signal is emitted when the user presses the push button for a long |
|
176 time. |
|
128 */ |
177 */ |
129 |
178 |
130 HbPushButtonPrivate::HbPushButtonPrivate() : |
179 HbPushButtonPrivate::HbPushButtonPrivate() : |
131 textItem(0), |
180 textItem(0), |
132 additionalTextItem(0), |
181 additionalTextItem(0), |
233 q_ptr = q; |
282 q_ptr = q; |
234 createPrimitives( ); |
283 createPrimitives( ); |
235 } |
284 } |
236 |
285 |
237 /*! |
286 /*! |
238 @beta |
287 Constructs a push button with \a parent. |
239 Constructs a new HbPushButton with \a parent. |
|
240 */ |
288 */ |
241 HbPushButton::HbPushButton( QGraphicsItem *parent ) |
289 HbPushButton::HbPushButton( QGraphicsItem *parent ) |
242 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
290 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
243 { |
291 { |
244 Q_D( HbPushButton ); |
292 Q_D( HbPushButton ); |
247 setProperty( "state", "normal" ); |
295 setProperty( "state", "normal" ); |
248 |
296 |
249 } |
297 } |
250 |
298 |
251 /*! |
299 /*! |
252 @beta |
300 Constructs a push button with \a text and \a parent. |
253 Constructs a new HbPushButton with \a text and \a parent. |
|
254 */ |
301 */ |
255 HbPushButton::HbPushButton( const QString &text, QGraphicsItem *parent ) |
302 HbPushButton::HbPushButton( const QString &text, QGraphicsItem *parent ) |
256 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
303 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
257 { |
304 { |
258 Q_D( HbPushButton ); |
305 Q_D( HbPushButton ); |
263 |
310 |
264 |
311 |
265 } |
312 } |
266 |
313 |
267 /*! |
314 /*! |
268 @beta |
315 Constructs a push button with \a icon, \a text, and \a parent. |
269 Constructs a new HbPushButton with \a icon, \a text and \a parent. |
|
270 */ |
316 */ |
271 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent ) |
317 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent ) |
272 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
318 : HbAbstractButton( *new HbPushButtonPrivate, parent ) |
273 { |
319 { |
274 Q_D( HbPushButton ); |
320 Q_D( HbPushButton ); |
279 setProperty( "state", "normal" ); |
325 setProperty( "state", "normal" ); |
280 |
326 |
281 } |
327 } |
282 |
328 |
283 /*! |
329 /*! |
284 Destructs the push button. |
330 Destructor. |
285 */ |
331 */ |
286 HbPushButton::~HbPushButton( ) |
332 HbPushButton::~HbPushButton( ) |
287 { |
333 { |
288 |
334 |
289 } |
335 } |
290 |
336 |
291 /*! |
337 /*! |
292 @beta |
338 Sets the \a background shown on a push button. The background of a push |
293 Sets the \a background of the button. |
339 button can have different images for pressed and released states. |
294 |
|
295 \note The background can contain different images for pressed and released states. |
|
296 |
340 |
297 \sa background() |
341 \sa background() |
298 */ |
342 */ |
299 void HbPushButton::setBackground( const HbIcon &background ) |
343 void HbPushButton::setBackground( const HbIcon &background ) |
300 { |
344 { |
307 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
351 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
308 } |
352 } |
309 } |
353 } |
310 |
354 |
311 /*! |
355 /*! |
312 @beta |
356 Returns the background shown on a push button. |
313 Returns the background of the button. |
|
314 |
357 |
315 \sa setBackground() |
358 \sa setBackground() |
316 */ |
359 */ |
317 HbIcon HbPushButton::background( ) const |
360 HbIcon HbPushButton::background( ) const |
318 { |
361 { |
319 Q_D( const HbPushButton ); |
362 Q_D( const HbPushButton ); |
320 return d->background; |
363 return d->background; |
321 } |
364 } |
322 |
365 |
323 /*! |
366 /*! |
324 @beta |
367 Sets the \a frame background shown on a push button. The frame background |
325 Sets the \a framebackground of the button. |
368 of a push button can have the following types of frame drawers: 9-piece, 3- |
326 |
369 piece horizontal, 3-piece vertical, and single. The ownership is transferred |
327 \note The background can contain different types of frame drawers(Nine piece, |
370 to the push button. |
328 three piece or single).Ownership is transferred to the Pushbutton |
|
329 |
371 |
330 \sa frameBackground() |
372 \sa frameBackground() |
331 */ |
373 */ |
332 void HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer ) |
374 void HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer ) |
333 { |
375 { |
340 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
382 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
341 } |
383 } |
342 } |
384 } |
343 |
385 |
344 /*! |
386 /*! |
345 @beta |
387 Returns the background shown on a push button. |
346 Returns the background of the button. |
|
347 |
388 |
348 \sa setBackground() |
389 \sa setBackground() |
349 */ |
390 */ |
350 HbFrameDrawer *HbPushButton::frameBackground( ) const |
391 HbFrameDrawer *HbPushButton::frameBackground( ) const |
351 { |
392 { |
353 return ( d->backgroundFrameDrawer ); |
394 return ( d->backgroundFrameDrawer ); |
354 } |
395 } |
355 |
396 |
356 |
397 |
357 /*! |
398 /*! |
358 @beta |
399 Sets the \a text shown on a push button. |
359 Sets the \a text shown on the button. |
|
360 |
400 |
361 \sa text() |
401 \sa text() |
362 */ |
402 */ |
363 void HbPushButton::setText( const QString &text ) |
403 void HbPushButton::setText( const QString &text ) |
364 { |
404 { |
382 } |
422 } |
383 } |
423 } |
384 |
424 |
385 |
425 |
386 /*! |
426 /*! |
387 @beta |
427 Returns the text shown on a push button. |
388 Returns the text shown on the button. |
|
389 |
428 |
390 \sa setText() |
429 \sa setText() |
391 */ |
430 */ |
392 QString HbPushButton::text( ) const |
431 QString HbPushButton::text( ) const |
393 { |
432 { |
395 return d->text; |
434 return d->text; |
396 } |
435 } |
397 |
436 |
398 |
437 |
399 /*! |
438 /*! |
400 @beta |
439 Sets the additional text shown on a push button, defined by \a |
401 Sets the \a additional text shown on the button. |
440 additionalText. Additional text is only shown on the button in the following |
402 Additional text is only shown in case |
441 cases: |
403 1. with icon and text in Qt::Horizontal alignment. |
442 |
404 2. with icon and text where both the texts are aligned vertically and icon placed horizontally in relation to texts. |
443 - Icon, text, and additional text are horizontally aligned in one line. |
405 3. with additionalText and text in Qt::Vertical alignment. |
444 - Text and additional text are vertically aligned and icon is horizontally |
445 aligned in relation to the texts. |
|
446 - Text and additional text are vertically aligned. |
|
406 |
447 |
407 \sa additionalText() |
448 \sa additionalText() |
408 */ |
449 */ |
450 |
|
409 void HbPushButton::setAdditionalText( const QString &additionalText ) |
451 void HbPushButton::setAdditionalText( const QString &additionalText ) |
410 { |
452 { |
411 Q_D( HbPushButton ); |
453 Q_D( HbPushButton ); |
412 if ( d->additionalText != additionalText ) { |
454 if ( d->additionalText != additionalText ) { |
413 bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty(); |
455 bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty(); |
427 } |
469 } |
428 } |
470 } |
429 } |
471 } |
430 |
472 |
431 /*! |
473 /*! |
432 @beta |
474 Returns the additional text shown on a push button. |
433 Returns the additional text shown on the button. |
|
434 |
475 |
435 \sa setAdditionalText() |
476 \sa setAdditionalText() |
436 */ |
477 */ |
437 QString HbPushButton::additionalText( ) const |
478 QString HbPushButton::additionalText( ) const |
438 { |
479 { |
439 Q_D( const HbPushButton ); |
480 Q_D( const HbPushButton ); |
440 return d->additionalText; |
481 return d->additionalText; |
441 } |
482 } |
442 |
483 |
443 /*! |
484 /*! |
444 @beta |
485 |
445 Sets the \a icon shown on the button. |
486 Sets the \a icon shown on a push button. Each icon mode can have a |
446 |
487 different image. |
447 \note The icon can contain images for different modes. |
|
448 |
488 |
449 \sa icon() |
489 \sa icon() |
450 */ |
490 */ |
451 void HbPushButton::setIcon( const HbIcon &icon ) |
491 void HbPushButton::setIcon( const HbIcon &icon ) |
452 { |
492 { |
472 } |
512 } |
473 } |
513 } |
474 } |
514 } |
475 |
515 |
476 /*! |
516 /*! |
477 @beta |
517 Returns the icon shown on a push button. |
478 Returns the icon shown on the button. |
518 |
479 \sa setIcon() |
519 \sa setIcon() |
480 */ |
520 */ |
481 |
521 |
482 HbIcon HbPushButton::icon( ) const |
522 HbIcon HbPushButton::icon( ) const |
483 { |
523 { |
484 Q_D( const HbPushButton ); |
524 Q_D( const HbPushButton ); |
485 return d->icon; |
525 return d->icon; |
486 } |
526 } |
487 |
527 |
488 /*! |
528 /*! |
489 @beta |
529 Sets the alignment for the text. The default alignment is |
490 Set the text alignment for primarytext. |
530 horizontally and vertically aligned. |
491 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
531 |
492 \sa textAlignment() |
532 \sa textAlignment() |
493 */ |
533 */ |
494 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
534 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
495 { |
535 { |
496 Q_D( HbPushButton ); |
536 Q_D( HbPushButton ); |
497 |
537 |
498 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
538 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
499 if( !d->textItem ) { |
539 if( !d->textItem ) { |
500 //need to create text item if user call alignment api before setText. |
540 //need to create text item if user call alignment api before setText. |
501 d->textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, this); |
541 d->textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, this); |
502 } |
542 } |
503 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
543 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
504 // check for textitem and api protection flag |
544 // check for textitem and api protection flag |
505 if( alignment != d->textAlignment ){ |
545 if( alignment != d->textAlignment ){ |
506 //take the alignment |
546 //take the alignment |
507 d->textAlignment = alignment; |
547 d->textAlignment = alignment; |
508 //set the api protection flag |
548 //set the api protection flag |
515 } |
555 } |
516 d->hasTextAlignment = true; |
556 d->hasTextAlignment = true; |
517 } |
557 } |
518 |
558 |
519 /*! |
559 /*! |
520 @beta |
560 Returns the text alignment for the text. |
521 Returns the text alignment for primary text. |
561 |
522 \sa setTextAlignment() |
562 \sa setTextAlignment() |
523 */ |
563 */ |
524 Qt::Alignment HbPushButton::textAlignment( ) const |
564 Qt::Alignment HbPushButton::textAlignment( ) const |
525 { |
565 { |
526 Q_D(const HbPushButton); |
566 Q_D(const HbPushButton); |
527 return d->textAlignment; |
567 return d->textAlignment; |
528 } |
568 } |
529 |
569 |
530 |
570 |
531 /*! |
571 /*! |
532 @beta |
572 Sets the \a alignment for the additional text. The default alignment is |
533 Set the text alignment for additional text. |
573 horizontally and vertically centered alignment. |
534 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
574 |
535 \sa additionalTextAlignment() |
575 \sa additionalTextAlignment() |
536 */ |
576 */ |
537 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment ) |
577 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment ) |
538 { |
578 { |
539 Q_D( HbPushButton ); |
579 Q_D( HbPushButton ); |
540 |
580 |
541 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
581 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
542 if(!d->additionalTextItem) { |
582 if(!d->additionalTextItem) { |
543 //need to create text item if user call alignment api before setAdditionalText. |
583 //need to create text item if user call alignment api before setAdditionalText. |
544 d->additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, this); |
584 d->additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, this); |
545 } |
585 } |
546 // check for textitem and api protection flag |
586 // check for textitem and api protection flag |
556 d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption ); |
596 d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption ); |
557 } |
597 } |
558 } |
598 } |
559 |
599 |
560 /*! |
600 /*! |
561 @beta |
601 Returns the text alignment for the additional text. |
562 Returns the text alignment for additional text |
602 |
563 \sa setAdditionalTextAlignment() |
603 \sa setAdditionalTextAlignment() |
564 */ |
604 */ |
565 Qt::Alignment HbPushButton::additionalTextAlignment( ) const |
605 Qt::Alignment HbPushButton::additionalTextAlignment( ) const |
566 { |
606 { |
567 Q_D(const HbPushButton); |
607 Q_D(const HbPushButton); |
568 return d->additionalTextAlignment; |
608 return d->additionalTextAlignment; |
569 } |
609 } |
570 |
610 |
571 /*! |
611 /*! |
572 @beta |
612 Sets the alignment of an icon, a text and an additional text for stretched and non- |
573 Sets the stretched layout for button by default it set to true. setStretched true/false. |
613 stretched layouts of a push button. The push button layouts with \a |
574 For the case icon and text with value false will appear icon and text vertically aligned. |
614 stretched value \c true and \c false (default) are the following: |
575 and with value true will appear icon and text horizontally aligned. |
615 |
576 For the case icon , text and additional text with value false will appear like |
616 - Icon and text: |
577 both text will be vertically aligned and icon will be horizontally. |
617 - \c true: Icon and text are horizontally aligned. |
578 and with value true icon , text and additionaltext will come horizontally aligned in one line |
618 - \c false: Icon and text are vertically aligned. |
579 For the case text and additonaltext(dialer button case ) only value false is applicable and both texts will |
619 - Icon, text and additional text: |
580 appeare vertically |
620 - \c true: Icon and both texts are horizontally aligned in one line. |
581 |
621 - \c false: Both texts are vertically aligned and icon is horizontally aligned. |
622 - Text and additonal text (a dialer push button case): |
|
623 - \c true: Not applicable. |
|
624 - \c false: Both texts are vertically aligned. |
|
625 |
|
582 \sa isStretched() |
626 \sa isStretched() |
583 */ |
627 */ |
584 void HbPushButton::setStretched( bool stretched ) |
628 void HbPushButton::setStretched( bool stretched ) |
585 { |
629 { |
586 Q_D(HbPushButton); |
630 Q_D(HbPushButton); |
589 repolish(); |
633 repolish(); |
590 } |
634 } |
591 } |
635 } |
592 |
636 |
593 /*! |
637 /*! |
594 @beta |
638 Returns \c true if the push button has streteched layout, otherwise returns |
595 Returns the whether button has streteched layout or not. |
639 \c false. |
640 |
|
596 \sa setStretched () |
641 \sa setStretched () |
597 */ |
642 */ |
598 bool HbPushButton::isStretched() const |
643 bool HbPushButton::isStretched() const |
599 { |
644 { |
600 Q_D(const HbPushButton); |
645 Q_D(const HbPushButton); |
601 return d->stretched; |
646 return d->stretched; |
602 } |
647 } |
603 |
648 |
604 /*! |
649 /*! |
605 |
650 |
606 \deprecated HbPushButton::primitive(HbStyle::Primitive) |
651 \deprecated HbPushButton::primitive(HbStyle::Primitive) is deprecated. |
607 is deprecated. |
652 |
608 |
653 |
609 \reimp |
|
610 */ |
654 */ |
611 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
655 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
612 { |
656 { |
613 Q_D( const HbPushButton ); |
657 Q_D( const HbPushButton ); |
614 |
658 |
629 return 0; |
673 return 0; |
630 } |
674 } |
631 } |
675 } |
632 |
676 |
633 /*! |
677 /*! |
634 \reimp |
678 |
635 */ |
679 */ |
636 void HbPushButton::recreatePrimitives() |
680 void HbPushButton::recreatePrimitives() |
637 { |
681 { |
638 Q_D( HbPushButton ); |
682 Q_D( HbPushButton ); |
639 HbWidget::recreatePrimitives(); |
683 HbWidget::recreatePrimitives(); |
640 |
684 |
641 delete d->frameItem; |
685 delete d->frameItem; |
642 d->frameItem = 0; |
686 d->frameItem = 0; |
643 delete d->iconItem; |
687 delete d->iconItem; |
644 d->iconItem = 0; |
688 d->iconItem = 0; |
652 d->focusItem = 0; |
696 d->focusItem = 0; |
653 |
697 |
654 d->createPrimitives( ); |
698 d->createPrimitives( ); |
655 setFrameBackground( 0 ); |
699 setFrameBackground( 0 ); |
656 } |
700 } |
657 /*! |
701 |
658 \reimp |
702 /*! |
703 |
|
659 */ |
704 */ |
660 void HbPushButton::updatePrimitives() |
705 void HbPushButton::updatePrimitives() |
661 { |
706 { |
662 Q_D( HbPushButton ); |
707 Q_D( HbPushButton ); |
663 HbWidget::updatePrimitives( ); |
708 HbWidget::updatePrimitives( ); |
692 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem *parent) : |
737 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem *parent) : |
693 HbAbstractButton(dd, parent) |
738 HbAbstractButton(dd, parent) |
694 { |
739 { |
695 } |
740 } |
696 |
741 |
697 /*! |
742 /*! |
698 \reimp |
743 |
699 Initializes \a option with the values from this HbPushButton. |
744 Initializes the style option push button defined by \a option with the push |
700 This method is useful for subclasses when they need a HbStyleOptionPushButton, |
745 button values. This method is useful for setting the style option push button |
701 but don't want to fill in all the information themselves. |
746 values of the subclasses. |
747 |
|
748 \param option Style option push button to be initialized. |
|
702 */ |
749 */ |
703 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const |
750 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const |
704 { |
751 { |
705 Q_D( const HbPushButton ); |
752 Q_D( const HbPushButton ); |
706 |
753 |
722 } |
769 } |
723 option->backgroundFrameDrawer = ( d->backgroundFrameDrawer ); |
770 option->backgroundFrameDrawer = ( d->backgroundFrameDrawer ); |
724 } |
771 } |
725 |
772 |
726 /*! |
773 /*! |
727 \reimp |
774 |
728 */ |
775 */ |
729 void HbPushButton::keyPressEvent(QKeyEvent *event) |
776 void HbPushButton::keyPressEvent(QKeyEvent *event) |
730 { |
777 { |
731 Q_D( HbPushButton ); |
778 Q_D( HbPushButton ); |
732 |
779 |
758 HbAbstractButton::keyPressEvent(event); |
805 HbAbstractButton::keyPressEvent(event); |
759 } |
806 } |
760 |
807 |
761 |
808 |
762 /*! |
809 /*! |
763 \reimp |
810 |
764 */ |
811 */ |
765 void HbPushButton::keyReleaseEvent(QKeyEvent *event) |
812 void HbPushButton::keyReleaseEvent(QKeyEvent *event) |
766 { |
813 { |
767 Q_D(HbPushButton); |
814 Q_D(HbPushButton); |
768 switch(event->key()){ |
815 switch(event->key()){ |
790 } |
837 } |
791 HbAbstractButton::keyReleaseEvent( event ); |
838 HbAbstractButton::keyReleaseEvent( event ); |
792 } |
839 } |
793 |
840 |
794 /*! |
841 /*! |
795 \reimp |
842 |
796 */ |
843 */ |
797 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
844 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
798 { |
845 { |
799 #ifndef HB_GESTURE_FW |
846 #ifndef HB_GESTURE_FW |
800 Q_D( HbPushButton ); |
847 Q_D( HbPushButton ); |
815 #endif |
862 #endif |
816 } |
863 } |
817 |
864 |
818 #ifndef HB_GESTURE_FW |
865 #ifndef HB_GESTURE_FW |
819 /*! |
866 /*! |
820 \reimp |
867 |
821 */ |
868 */ |
822 void HbPushButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
869 void HbPushButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
823 { |
870 { |
824 Q_D( HbPushButton ); |
871 Q_D( HbPushButton ); |
825 HbAbstractButton::mouseReleaseEvent( event ); |
872 HbAbstractButton::mouseReleaseEvent( event ); |
835 #endif |
882 #endif |
836 setProperty( "state", "normal" ); |
883 setProperty( "state", "normal" ); |
837 } |
884 } |
838 |
885 |
839 /*! |
886 /*! |
840 \reimp |
887 |
841 */ |
888 */ |
842 void HbPushButton::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) |
889 void HbPushButton::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) |
843 { |
890 { |
844 Q_D( HbPushButton ); |
891 Q_D( HbPushButton ); |
845 HbAbstractButton::mouseMoveEvent( event ); |
892 HbAbstractButton::mouseMoveEvent( event ); |
856 } |
903 } |
857 #endif |
904 #endif |
858 |
905 |
859 |
906 |
860 #ifdef HB_GESTURE_FW |
907 #ifdef HB_GESTURE_FW |
908 |
|
861 void HbPushButton::gestureEvent( QGestureEvent *event ) |
909 void HbPushButton::gestureEvent( QGestureEvent *event ) |
862 { |
910 { |
863 Q_D(HbPushButton); |
911 Q_D(HbPushButton); |
864 if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
912 if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) { |
865 bool hit = hitButton(mapFromScene(event->mapToGraphicsScene(tap->position()))); |
913 bool hit = hitButton(mapFromScene(event->mapToGraphicsScene(tap->position()))); |
905 } |
953 } |
906 #endif |
954 #endif |
907 |
955 |
908 |
956 |
909 /*! |
957 /*! |
910 \reimp |
958 |
911 */ |
959 */ |
912 void HbPushButton::resizeEvent( QGraphicsSceneResizeEvent *event ) |
960 void HbPushButton::resizeEvent( QGraphicsSceneResizeEvent *event ) |
913 { |
961 { |
914 HbAbstractButton::resizeEvent( event ); |
962 HbAbstractButton::resizeEvent( event ); |
915 } |
963 } |
916 /*! |
964 |
917 reimp |
965 /*! |
966 |
|
918 |
967 |
919 */ |
968 */ |
920 void HbPushButton::polish( HbStyleParameters ¶ms ) |
969 void HbPushButton::polish( HbStyleParameters ¶ms ) |
921 { |
970 { |
922 Q_D( HbPushButton ); |
971 Q_D( HbPushButton ); |
927 HbAbstractButton::polish( params ); |
976 HbAbstractButton::polish( params ); |
928 } |
977 } |
929 |
978 |
930 |
979 |
931 /*! |
980 /*! |
932 \reimp |
981 |
933 */ |
982 */ |
934 void HbPushButton::focusInEvent( QFocusEvent *event ) |
983 void HbPushButton::focusInEvent( QFocusEvent *event ) |
935 { |
984 { |
936 Q_D( HbPushButton ); |
985 Q_D( HbPushButton ); |
937 if( ( event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ) |
986 if( ( event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ) |
949 } |
998 } |
950 HbAbstractButton::focusInEvent( event ); |
999 HbAbstractButton::focusInEvent( event ); |
951 } |
1000 } |
952 |
1001 |
953 /*! |
1002 /*! |
954 \reimp |
1003 |
955 */ |
1004 */ |
956 void HbPushButton::focusOutEvent( QFocusEvent *event ) |
1005 void HbPushButton::focusOutEvent( QFocusEvent *event ) |
957 { |
1006 { |
958 Q_D( HbPushButton ); |
1007 Q_D( HbPushButton ); |
959 if( d->focusItem ) { |
1008 if( d->focusItem ) { |
961 } |
1010 } |
962 HbAbstractButton::focusOutEvent( event ); |
1011 HbAbstractButton::focusOutEvent( event ); |
963 } |
1012 } |
964 |
1013 |
965 /*! |
1014 /*! |
966 \reimp |
1015 |
967 */ |
1016 */ |
968 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value) |
1017 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value) |
969 { |
1018 { |
970 switch ( change ) { |
1019 switch ( change ) { |
971 case ItemEnabledHasChanged: |
1020 case ItemEnabledHasChanged: |
982 } |
1031 } |
983 return HbAbstractButton::itemChange( change, value ); |
1032 return HbAbstractButton::itemChange( change, value ); |
984 } |
1033 } |
985 |
1034 |
986 /*! |
1035 /*! |
987 Overloaded hit detection to include touch area |
1036 Overloaded hit detection to include touch area. |
988 */ |
1037 */ |
989 bool HbPushButton::hitButton( const QPointF &pos ) const |
1038 bool HbPushButton::hitButton( const QPointF &pos ) const |
990 { |
1039 { |
991 Q_D( const HbPushButton ); |
1040 Q_D( const HbPushButton ); |
992 QRectF compRect = d->touchArea->boundingRect( ); |
1041 QRectF compRect = d->touchArea->boundingRect( ); |