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), |
164 void HbPushButtonPrivate::createPrimitives() |
213 void HbPushButtonPrivate::createPrimitives() |
165 { |
214 { |
166 Q_Q(HbPushButton); |
215 Q_Q(HbPushButton); |
167 |
216 |
168 if ( !frameItem ) { |
217 if ( !frameItem ) { |
169 frameItem = q->style()->createPrimitive( HbStyle::P_PushButton_background, q ); |
218 frameItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_background, q ); |
170 } |
219 } |
171 if ( !text.isNull() ) { |
220 if ( !text.isNull() ) { |
172 if ( !textItem ) { |
221 if ( !textItem ) { |
173 textItem = q->style()->createPrimitive( HbStyle::P_PushButton_text, q ); |
222 textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, q ); |
174 } |
223 } |
175 } else { |
224 } else { |
176 if( textItem ){ |
225 if( textItem ){ |
177 delete textItem; |
226 delete textItem; |
178 } |
227 } |
179 textItem = 0; |
228 textItem = 0; |
180 } |
229 } |
181 if ( !additionalText.isNull() ) { |
230 if ( !additionalText.isNull() ) { |
182 if ( !additionalTextItem ) { |
231 if ( !additionalTextItem ) { |
183 additionalTextItem = q->style()->createPrimitive( HbStyle::P_PushButton_additionaltext, q ); |
232 additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, q ); |
184 } |
233 } |
185 } else { |
234 } else { |
186 if( additionalTextItem ){ |
235 if( additionalTextItem ){ |
187 delete additionalTextItem; |
236 delete additionalTextItem; |
188 } |
237 } |
189 additionalTextItem = 0; |
238 additionalTextItem = 0; |
190 } |
239 } |
191 |
240 |
192 if ( !icon.isNull() ) { |
241 if ( !icon.isNull() ) { |
193 if ( !iconItem ) { |
242 if ( !iconItem ) { |
194 iconItem = q->style()->createPrimitive( HbStyle::P_PushButton_icon, q); |
243 iconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_icon, q); |
195 } |
244 } |
196 } else { |
245 } else { |
197 if( iconItem ) { |
246 if( iconItem ) { |
198 delete iconItem; |
247 delete iconItem; |
199 } |
248 } |
200 iconItem = 0; |
249 iconItem = 0; |
201 } |
250 } |
202 |
251 |
203 if( !touchArea ) { |
252 if( !touchArea ) { |
204 touchArea = q->style()->createPrimitive( HbStyle::P_PushButton_toucharea, q ); |
253 touchArea = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_toucharea, q ); |
205 if(QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>(touchArea)) { |
254 if(QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>(touchArea)) { |
206 ta->grabGesture(Qt::TapGesture); |
255 ta->grabGesture(Qt::TapGesture); |
207 q->ungrabGesture(Qt::TapGesture); |
256 q->ungrabGesture(Qt::TapGesture); |
208 } else { |
257 } else { |
209 q->grabGesture(Qt::TapGesture); |
258 q->grabGesture(Qt::TapGesture); |
210 } |
259 } |
211 } |
260 } |
212 |
|
213 if( !focusItem ) { |
|
214 focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q); |
|
215 //focus primitive is will not be visible by default, |
|
216 //only in case of keyboard focus events it will be Visible. |
|
217 focusItem->setVisible( false ); |
|
218 } |
|
219 } |
261 } |
220 |
262 |
221 void HbPushButtonPrivate::_q_handleLongKeyPress( ) |
263 void HbPushButtonPrivate::_q_handleLongKeyPress( ) |
222 { |
264 { |
223 Q_Q( HbPushButton ); |
265 Q_Q( HbPushButton ); |
471 } |
505 } |
472 } |
506 } |
473 } |
507 } |
474 |
508 |
475 /*! |
509 /*! |
476 @beta |
510 Returns the icon shown on a push button. |
477 Returns the icon shown on the button. |
511 |
478 \sa setIcon() |
512 \sa setIcon() |
479 */ |
513 */ |
480 |
514 |
481 HbIcon HbPushButton::icon( ) const |
515 HbIcon HbPushButton::icon( ) const |
482 { |
516 { |
483 Q_D( const HbPushButton ); |
517 Q_D( const HbPushButton ); |
484 return d->icon; |
518 return d->icon; |
485 } |
519 } |
486 |
520 |
487 /*! |
521 /*! |
488 @beta |
522 Sets the alignment for the text. The default alignment is |
489 Set the text alignment for primarytext and additional text. |
523 horizontally and vertically aligned. |
490 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
524 |
491 \sa textAlignment() |
525 \sa textAlignment() |
492 */ |
526 */ |
493 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
527 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
494 { |
528 { |
495 Q_D( HbPushButton ); |
529 Q_D( HbPushButton ); |
496 |
530 |
497 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
531 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
498 if( !d->textItem ) { |
532 if( !d->textItem ) { |
499 //need to create text item if user call alignment api before setText. |
533 //need to create text item if user call alignment api before setText. |
500 d->textItem = style( )->createPrimitive( HbStyle::P_PushButton_text, this); |
534 d->textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, this); |
501 } |
535 } |
502 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
536 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
503 // check for textitem and api protection flag |
537 // check for textitem and api protection flag |
504 if( alignment != d->textAlignment ){ |
538 if( alignment != d->textAlignment ){ |
505 //take the alignment |
539 //take the alignment |
506 d->textAlignment = alignment; |
540 d->textAlignment = alignment; |
507 //set the api protection flag |
541 //set the api protection flag |
508 //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
542 //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
509 d->hasTextAlignment = true; |
543 d->hasTextAlignment = true; |
510 HbStyleOptionPushButton buttonOption; |
544 HbStyleOptionPushButton buttonOption; |
511 initStyleOption( &buttonOption ); |
545 initStyleOption( &buttonOption ); |
512 style()->updatePrimitive( |
546 HbStylePrivate::updatePrimitive( |
513 d->textItem, HbStyle::P_PushButton_text, &buttonOption ); |
547 d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption ); |
514 } |
548 } |
515 d->hasTextAlignment = true; |
549 d->hasTextAlignment = true; |
516 } |
550 } |
517 |
551 |
518 /*! |
552 /*! |
519 @beta |
553 Returns the text alignment for the text. |
520 Returns the text alignment for primary text and additional text |
554 |
521 \sa setTextAlignment() |
555 \sa setTextAlignment() |
522 */ |
556 */ |
523 Qt::Alignment HbPushButton::textAlignment( ) const |
557 Qt::Alignment HbPushButton::textAlignment( ) const |
524 { |
558 { |
525 Q_D(const HbPushButton); |
559 Q_D(const HbPushButton); |
526 return d->textAlignment; |
560 return d->textAlignment; |
527 } |
561 } |
528 |
562 |
529 |
563 |
530 /*! |
564 /*! |
531 @beta |
565 Sets the \a alignment for the additional text. The default alignment is |
532 Set the text alignment for additional text. |
566 horizontally and vertically centered alignment. |
533 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
567 |
534 \sa additionalTextAlignment() |
568 \sa additionalTextAlignment() |
535 */ |
569 */ |
536 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment ) |
570 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment ) |
537 { |
571 { |
538 Q_D( HbPushButton ); |
572 Q_D( HbPushButton ); |
539 |
573 |
540 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
574 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
541 if(!d->additionalTextItem) { |
575 if(!d->additionalTextItem) { |
542 //need to create text item if user call alignment api before setAdditionalText. |
576 //need to create text item if user call alignment api before setAdditionalText. |
543 d->additionalTextItem = style( )->createPrimitive( HbStyle::P_PushButton_additionaltext, this); |
577 d->additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, this); |
544 } |
578 } |
545 // check for textitem and api protection flag |
579 // check for textitem and api protection flag |
546 if( alignment != d->additionalTextAlignment ) { |
580 if( alignment != d->additionalTextAlignment ) { |
547 //take the alignment |
581 //take the alignment |
548 d->additionalTextAlignment = alignment; |
582 d->additionalTextAlignment = alignment; |
549 //set the api protection flag |
583 //set the api protection flag |
550 //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
584 //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
551 d->hasAdditionalTextAlignment = true; |
585 d->hasAdditionalTextAlignment = true; |
552 HbStyleOptionPushButton buttonOption; |
586 HbStyleOptionPushButton buttonOption; |
553 initStyleOption( &buttonOption ); |
587 initStyleOption( &buttonOption ); |
554 style( )->updatePrimitive( |
588 HbStylePrivate::updatePrimitive( |
555 d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption ); |
589 d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption ); |
556 } |
590 } |
557 } |
591 } |
558 |
592 |
559 /*! |
593 /*! |
560 @beta |
594 Returns the text alignment for the additional text. |
561 Returns the text alignment for additional text |
595 |
562 \sa setAdditionalTextAlignment() |
596 \sa setAdditionalTextAlignment() |
563 */ |
597 */ |
564 Qt::Alignment HbPushButton::additionalTextAlignment( ) const |
598 Qt::Alignment HbPushButton::additionalTextAlignment( ) const |
565 { |
599 { |
566 Q_D(const HbPushButton); |
600 Q_D(const HbPushButton); |
567 return d->additionalTextAlignment; |
601 return d->additionalTextAlignment; |
568 } |
602 } |
569 |
603 |
570 /*! |
604 /*! |
571 @beta |
605 Sets the alignment of an icon, a text and an additional text for stretched and non- |
572 Sets the stretched layout for button by default it set to true. setStretched true/false. |
606 stretched layouts of a push button. The push button layouts with \a |
573 For the case icon and text with value false will appear icon and text vertically aligned. |
607 stretched value \c true and \c false (default) are the following: |
574 and with value true will appear icon and text horizontally aligned. |
608 |
575 For the case icon , text and additional text with value false will appear like |
609 - Icon and text: |
576 both text will be vertically aligned and icon will be horizontally. |
610 - \c true: Icon and text are horizontally aligned. |
577 and with value true icon , text and additionaltext will come horizontally aligned in one line |
611 - \c false: Icon and text are vertically aligned. |
578 For the case text and additonaltext(dialer button case ) only value false is applicable and both texts will |
612 - Icon, text and additional text: |
579 appeare vertically |
613 - \c true: Icon and both texts are horizontally aligned in one line. |
580 |
614 - \c false: Both texts are vertically aligned and icon is horizontally aligned. |
|
615 - Text and additonal text (a dialer push button case): |
|
616 - \c true: Not applicable. |
|
617 - \c false: Both texts are vertically aligned. |
|
618 |
581 \sa isStretched() |
619 \sa isStretched() |
582 */ |
620 */ |
583 void HbPushButton::setStretched( bool stretched ) |
621 void HbPushButton::setStretched( bool stretched ) |
584 { |
622 { |
585 Q_D(HbPushButton); |
623 Q_D(HbPushButton); |
588 repolish(); |
626 repolish(); |
589 } |
627 } |
590 } |
628 } |
591 |
629 |
592 /*! |
630 /*! |
593 @beta |
631 Returns \c true if the push button has streteched layout, otherwise returns |
594 Returns the whether button has streteched layout or not. |
632 \c false. |
|
633 |
595 \sa setStretched () |
634 \sa setStretched () |
596 */ |
635 */ |
597 bool HbPushButton::isStretched() const |
636 bool HbPushButton::isStretched() const |
598 { |
637 { |
599 Q_D(const HbPushButton); |
638 Q_D(const HbPushButton); |
600 return d->stretched; |
639 return d->stretched; |
601 } |
640 } |
602 |
641 |
603 /*! |
642 /*! |
604 |
643 |
605 \deprecated HbPushButton::primitive(HbStyle::Primitive) |
644 \deprecated HbPushButton::primitive(HbStyle::Primitive) is deprecated. |
606 is deprecated. |
645 |
607 |
646 |
608 \reimp |
|
609 */ |
647 */ |
610 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
648 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
611 { |
649 { |
612 Q_D( const HbPushButton ); |
650 Q_D( const HbPushButton ); |
613 |
651 |
614 switch ( primitive ) { |
652 switch ( primitive ) { |
615 case HbStyle::P_PushButton_background: |
653 case HbStylePrivate::P_PushButton_background: |
616 return d->frameItem; |
654 return d->frameItem; |
617 case HbStyle::P_PushButton_icon: |
655 case HbStylePrivate::P_PushButton_icon: |
618 return d->iconItem; |
656 return d->iconItem; |
619 case HbStyle::P_PushButton_text: |
657 case HbStylePrivate::P_PushButton_text: |
620 return d->textItem; |
658 return d->textItem; |
621 case HbStyle::P_PushButton_toucharea: |
659 case HbStylePrivate::P_PushButton_toucharea: |
622 return d->touchArea; |
660 return d->touchArea; |
623 case HbStyle::P_PushButton_additionaltext: |
661 case HbStylePrivate::P_PushButton_additionaltext: |
624 return d->additionalTextItem; |
662 return d->additionalTextItem; |
625 case HbStyle::P_PushButton_focus: |
663 case HbStylePrivate::P_PushButton_focus: |
626 return d->focusItem; |
664 return d->focusItem; |
627 default: |
665 default: |
628 return 0; |
666 return 0; |
629 } |
667 } |
630 } |
668 } |
631 |
669 |
632 /*! |
670 /*! |
633 \reimp |
671 |
634 */ |
672 */ |
635 void HbPushButton::recreatePrimitives() |
673 void HbPushButton::recreatePrimitives() |
636 { |
674 { |
637 Q_D( HbPushButton ); |
675 Q_D( HbPushButton ); |
638 HbWidget::recreatePrimitives(); |
676 HbWidget::recreatePrimitives(); |
639 |
677 if ( d->frameItem ) { |
640 delete d->frameItem; |
678 delete d->frameItem; |
641 d->frameItem = 0; |
679 d->frameItem = 0; |
642 delete d->iconItem; |
680 } |
643 d->iconItem = 0; |
681 if ( d->iconItem ) { |
644 delete d->textItem; |
682 delete d->iconItem; |
645 d->textItem = 0; |
683 d->iconItem = 0; |
646 delete d->touchArea; |
684 } |
647 d->touchArea = 0; |
685 if ( d->textItem ) { |
648 delete d->additionalTextItem; |
686 delete d->textItem ; |
649 d->additionalTextItem = 0; |
687 d->textItem = 0; |
650 delete d->focusItem; |
688 } |
651 d->focusItem = 0; |
689 if ( d->touchArea ) { |
652 |
690 delete d->touchArea ; |
|
691 d->touchArea = 0; |
|
692 } |
|
693 if ( d->additionalTextItem ) { |
|
694 delete d->additionalTextItem ; |
|
695 d->additionalTextItem = 0; |
|
696 } |
|
697 if ( d->focusItem ) { |
|
698 delete d->focusItem ; |
|
699 d->focusItem = 0; |
|
700 } |
653 d->createPrimitives( ); |
701 d->createPrimitives( ); |
654 setFrameBackground( 0 ); |
702 setFrameBackground( 0 ); |
655 } |
703 } |
656 /*! |
704 |
657 \reimp |
705 /*! |
|
706 |
658 */ |
707 */ |
659 void HbPushButton::updatePrimitives() |
708 void HbPushButton::updatePrimitives() |
660 { |
709 { |
661 Q_D( HbPushButton ); |
710 Q_D( HbPushButton ); |
662 HbWidget::updatePrimitives( ); |
711 HbWidget::updatePrimitives( ); |
663 |
|
664 HbStyleOptionPushButton buttonOption; |
712 HbStyleOptionPushButton buttonOption; |
665 initStyleOption(&buttonOption); |
713 initStyleOption(&buttonOption); |
|
714 //update the button color property information |
|
715 if ( d->checkable ) { |
|
716 if ( d->checked ) { |
|
717 setProperty( "state", "latched" ); |
|
718 } |
|
719 else { |
|
720 setProperty( "state", "normal" ); |
|
721 } |
|
722 } |
|
723 else{ |
|
724 if ( d->down ) { |
|
725 setProperty( "state", "pressed" ); |
|
726 } |
|
727 else { |
|
728 setProperty( "state", "normal" ); |
|
729 } |
|
730 } |
666 if ( d->textItem ) { |
731 if ( d->textItem ) { |
667 style()->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption ); |
732 HbStylePrivate::updatePrimitive( d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption ); |
668 } |
733 } |
669 if ( d->touchArea ) { |
734 if ( d->touchArea ) { |
670 style()->updatePrimitive( d->touchArea, HbStyle::P_PushButton_toucharea, &buttonOption ); |
735 HbStylePrivate::updatePrimitive( d->touchArea, HbStylePrivate::P_PushButton_toucharea, &buttonOption ); |
671 } |
736 } |
672 if( d->additionalTextItem ) { |
737 if( d->additionalTextItem ) { |
673 style()->updatePrimitive( |
738 HbStylePrivate::updatePrimitive( |
674 d->additionalTextItem,HbStyle::P_PushButton_additionaltext,&buttonOption ); |
739 d->additionalTextItem,HbStylePrivate::P_PushButton_additionaltext,&buttonOption ); |
675 } |
740 } |
676 if ( d->iconItem) { |
741 if ( d->iconItem) { |
677 style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption ); |
742 HbStylePrivate::updatePrimitive( d->iconItem, HbStylePrivate::P_PushButton_icon, &buttonOption ); |
678 } |
743 } |
679 if ( d->frameItem ) { |
744 if ( d->frameItem ) { |
680 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
745 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
681 } |
746 } |
682 // update will happen only for keyevents when focusItem will be visible. |
747 // update will happen only for keyevents when focusItem will be visible. |
683 if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) { |
748 if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) { |
684 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption ); |
749 HbStylePrivate::updatePrimitive( d->focusItem,HbStylePrivate::P_PushButton_focus, &buttonOption ); |
685 } |
750 } |
686 } |
751 } |
687 |
752 |
688 /*! |
753 /*! |
689 \internal |
754 \internal |
814 #endif |
881 #endif |
815 } |
882 } |
816 |
883 |
817 #ifndef HB_GESTURE_FW |
884 #ifndef HB_GESTURE_FW |
818 /*! |
885 /*! |
819 \reimp |
886 |
820 */ |
887 */ |
821 void HbPushButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
888 void HbPushButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
822 { |
889 { |
823 Q_D( HbPushButton ); |
890 Q_D( HbPushButton ); |
824 HbAbstractButton::mouseReleaseEvent( event ); |
891 HbAbstractButton::mouseReleaseEvent( event ); |
825 HbStyleOptionPushButton buttonOption; |
892 HbStyleOptionPushButton buttonOption; |
826 initStyleOption( &buttonOption ); |
893 initStyleOption( &buttonOption ); |
827 if( d->frameItem ) { |
894 if( d->frameItem ) { |
828 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
895 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
829 } |
896 } |
830 #ifdef HB_EFFECTS |
897 #ifdef HB_EFFECTS |
831 if ( hitButton(event->pos()) ) { |
898 if ( hitButton(event->pos()) ) { |
832 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" ); |
899 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" ); |
833 } |
900 } |
834 #endif |
901 #endif |
835 setProperty( "state", "normal" ); |
902 setProperty( "state", "normal" ); |
836 } |
903 } |
837 |
904 |
838 /*! |
905 /*! |
839 \reimp |
906 |
840 */ |
907 */ |
841 void HbPushButton::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) |
908 void HbPushButton::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) |
842 { |
909 { |
843 Q_D( HbPushButton ); |
910 Q_D( HbPushButton ); |
844 HbAbstractButton::mouseMoveEvent( event ); |
911 HbAbstractButton::mouseMoveEvent( event ); |
845 HbStyleOptionPushButton buttonOption; |
912 HbStyleOptionPushButton buttonOption; |
846 initStyleOption( &buttonOption ); |
913 initStyleOption( &buttonOption ); |
847 if( d->frameItem ) { |
914 if( d->frameItem ) { |
848 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
915 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
849 } |
916 } |
850 if (d->down) { |
917 if (d->down) { |
851 setProperty( "state", "pressed" ); |
918 setProperty( "state", "pressed" ); |
852 } else { |
919 } else { |
853 setProperty( "state", "normal" ); |
920 setProperty( "state", "normal" ); |