164 void HbPushButtonPrivate::createPrimitives() |
164 void HbPushButtonPrivate::createPrimitives() |
165 { |
165 { |
166 Q_Q(HbPushButton); |
166 Q_Q(HbPushButton); |
167 |
167 |
168 if ( !frameItem ) { |
168 if ( !frameItem ) { |
169 frameItem = q->style()->createPrimitive( HbStyle::P_PushButton_background, q ); |
169 frameItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_background, q ); |
170 } |
170 } |
171 if ( !text.isNull() ) { |
171 if ( !text.isNull() ) { |
172 if ( !textItem ) { |
172 if ( !textItem ) { |
173 textItem = q->style()->createPrimitive( HbStyle::P_PushButton_text, q ); |
173 textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, q ); |
174 } |
174 } |
175 } else { |
175 } else { |
176 if( textItem ){ |
176 if( textItem ){ |
177 delete textItem; |
177 delete textItem; |
178 } |
178 } |
179 textItem = 0; |
179 textItem = 0; |
180 } |
180 } |
181 if ( !additionalText.isNull() ) { |
181 if ( !additionalText.isNull() ) { |
182 if ( !additionalTextItem ) { |
182 if ( !additionalTextItem ) { |
183 additionalTextItem = q->style()->createPrimitive( HbStyle::P_PushButton_additionaltext, q ); |
183 additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, q ); |
184 } |
184 } |
185 } else { |
185 } else { |
186 if( additionalTextItem ){ |
186 if( additionalTextItem ){ |
187 delete additionalTextItem; |
187 delete additionalTextItem; |
188 } |
188 } |
189 additionalTextItem = 0; |
189 additionalTextItem = 0; |
190 } |
190 } |
191 |
191 |
192 if ( !icon.isNull() ) { |
192 if ( !icon.isNull() ) { |
193 if ( !iconItem ) { |
193 if ( !iconItem ) { |
194 iconItem = q->style()->createPrimitive( HbStyle::P_PushButton_icon, q); |
194 iconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_icon, q); |
195 } |
195 } |
196 } else { |
196 } else { |
197 if( iconItem ) { |
197 if( iconItem ) { |
198 delete iconItem; |
198 delete iconItem; |
199 } |
199 } |
200 iconItem = 0; |
200 iconItem = 0; |
201 } |
201 } |
202 |
202 |
203 if( !touchArea ) { |
203 if( !touchArea ) { |
204 touchArea = q->style()->createPrimitive( HbStyle::P_PushButton_toucharea, q ); |
204 touchArea = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_toucharea, q ); |
205 if(QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>(touchArea)) { |
205 if(QGraphicsObject *ta = qgraphicsitem_cast<QGraphicsObject*>(touchArea)) { |
206 ta->grabGesture(Qt::TapGesture); |
206 ta->grabGesture(Qt::TapGesture); |
207 q->ungrabGesture(Qt::TapGesture); |
207 q->ungrabGesture(Qt::TapGesture); |
208 } else { |
208 } else { |
209 q->grabGesture(Qt::TapGesture); |
209 q->grabGesture(Qt::TapGesture); |
210 } |
210 } |
211 } |
211 } |
212 |
212 |
213 if( !focusItem ) { |
213 if( !focusItem ) { |
214 focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q); |
214 focusItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_PushButton_focus, q); |
215 //focus primitive is will not be visible by default, |
215 //focus primitive is will not be visible by default, |
216 //only in case of keyboard focus events it will be Visible. |
216 //only in case of keyboard focus events it will be Visible. |
217 focusItem->setVisible( false ); |
217 focusItem->setVisible( false ); |
218 } |
218 } |
219 } |
219 } |
302 if ( d->background != background ) { |
302 if ( d->background != background ) { |
303 d->background = background; |
303 d->background = background; |
304 d->backgroundFrameDrawer = 0; |
304 d->backgroundFrameDrawer = 0; |
305 HbStyleOptionPushButton buttonOption; |
305 HbStyleOptionPushButton buttonOption; |
306 initStyleOption( &buttonOption ); |
306 initStyleOption( &buttonOption ); |
307 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
307 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
308 } |
308 } |
309 } |
309 } |
310 |
310 |
311 /*! |
311 /*! |
312 @beta |
312 @beta |
335 if ( d->backgroundFrameDrawer != backgroundFrameDrawer ) { |
335 if ( d->backgroundFrameDrawer != backgroundFrameDrawer ) { |
336 d->backgroundFrameDrawer = backgroundFrameDrawer; |
336 d->backgroundFrameDrawer = backgroundFrameDrawer; |
337 d->background = HbIcon( ); |
337 d->background = HbIcon( ); |
338 HbStyleOptionPushButton buttonOption; |
338 HbStyleOptionPushButton buttonOption; |
339 initStyleOption( &buttonOption ); |
339 initStyleOption( &buttonOption ); |
340 style( )->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
340 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
341 } |
341 } |
342 } |
342 } |
343 |
343 |
344 /*! |
344 /*! |
345 @beta |
345 @beta |
369 d->createPrimitives( ); |
369 d->createPrimitives( ); |
370 //updatePrimitives(); |
370 //updatePrimitives(); |
371 if( d->textItem ) { |
371 if( d->textItem ) { |
372 HbStyleOptionPushButton buttonOption; |
372 HbStyleOptionPushButton buttonOption; |
373 initStyleOption( &buttonOption ); |
373 initStyleOption( &buttonOption ); |
374 style( )->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption); |
374 HbStylePrivate::updatePrimitive( d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption); |
375 if ( isEnabled() ) { |
375 if ( isEnabled() ) { |
376 setProperty("state", "normal"); |
376 setProperty("state", "normal"); |
377 } |
377 } |
378 } |
378 } |
379 if(doPolish) { |
379 if(doPolish) { |
399 /*! |
399 /*! |
400 @beta |
400 @beta |
401 Sets the \a additional text shown on the button. |
401 Sets the \a additional text shown on the button. |
402 Additional text is only shown in case |
402 Additional text is only shown in case |
403 1. with icon and text in Qt::Horizontal alignment. |
403 1. with icon and text in Qt::Horizontal alignment. |
404 2. with additionalText and text in Qt::Vertical alignment. |
404 2. with icon and text where both the texts are aligned vertically and icon placed horizontally in relation to texts. |
|
405 3. with additionalText and text in Qt::Vertical alignment. |
405 |
406 |
406 \sa additionalText() |
407 \sa additionalText() |
407 */ |
408 */ |
408 void HbPushButton::setAdditionalText( const QString &additionalText ) |
409 void HbPushButton::setAdditionalText( const QString &additionalText ) |
409 { |
410 { |
414 d->createPrimitives( ); |
415 d->createPrimitives( ); |
415 // updatePrimitives(); |
416 // updatePrimitives(); |
416 if( d->additionalTextItem ) { |
417 if( d->additionalTextItem ) { |
417 HbStyleOptionPushButton buttonOption; |
418 HbStyleOptionPushButton buttonOption; |
418 initStyleOption( &buttonOption ); |
419 initStyleOption( &buttonOption ); |
419 style( )->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption); |
420 HbStylePrivate::updatePrimitive( d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption); |
420 if ( isEnabled() ) { |
421 if ( isEnabled() ) { |
421 setProperty("state", "normal"); |
422 setProperty("state", "normal"); |
422 } |
423 } |
423 } |
424 } |
424 if( doPolish ) { |
425 if( doPolish ) { |
458 d->createPrimitives( ); |
459 d->createPrimitives( ); |
459 //updatePrimitives(); |
460 //updatePrimitives(); |
460 if( d->iconItem ) { |
461 if( d->iconItem ) { |
461 HbStyleOptionPushButton buttonOption; |
462 HbStyleOptionPushButton buttonOption; |
462 initStyleOption( &buttonOption ); |
463 initStyleOption( &buttonOption ); |
463 style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption ); |
464 HbStylePrivate::updatePrimitive( d->iconItem, HbStylePrivate::P_PushButton_icon, &buttonOption ); |
464 if ( isEnabled() ) { |
465 if ( isEnabled() ) { |
465 setProperty("state", "normal"); |
466 setProperty("state", "normal"); |
466 } |
467 } |
467 |
468 |
468 } |
469 } |
484 return d->icon; |
485 return d->icon; |
485 } |
486 } |
486 |
487 |
487 /*! |
488 /*! |
488 @beta |
489 @beta |
489 Set the text alignment for primarytext and additional text. |
490 Set the text alignment for primarytext. |
490 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
491 The default alignment is Qt::AlignHCenter | Qt::AlignVCenter. |
491 \sa textAlignment() |
492 \sa textAlignment() |
492 */ |
493 */ |
493 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
494 void HbPushButton::setTextAlignment( Qt::Alignment alignment ) |
494 { |
495 { |
495 Q_D( HbPushButton ); |
496 Q_D( HbPushButton ); |
496 |
497 |
497 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
498 //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem); |
498 if( !d->textItem ) { |
499 if( !d->textItem ) { |
499 //need to create text item if user call alignment api before setText. |
500 //need to create text item if user call alignment api before setText. |
500 d->textItem = style( )->createPrimitive( HbStyle::P_PushButton_text, this); |
501 d->textItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_text, this); |
501 } |
502 } |
502 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
503 //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem); |
503 // check for textitem and api protection flag |
504 // check for textitem and api protection flag |
504 if( alignment != d->textAlignment ){ |
505 if( alignment != d->textAlignment ){ |
505 //take the alignment |
506 //take the alignment |
507 //set the api protection flag |
508 //set the api protection flag |
508 //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
509 //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
509 d->hasTextAlignment = true; |
510 d->hasTextAlignment = true; |
510 HbStyleOptionPushButton buttonOption; |
511 HbStyleOptionPushButton buttonOption; |
511 initStyleOption( &buttonOption ); |
512 initStyleOption( &buttonOption ); |
512 style()->updatePrimitive( |
513 HbStylePrivate::updatePrimitive( |
513 d->textItem, HbStyle::P_PushButton_text, &buttonOption ); |
514 d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption ); |
514 } |
515 } |
515 d->hasTextAlignment = true; |
516 d->hasTextAlignment = true; |
516 } |
517 } |
517 |
518 |
518 /*! |
519 /*! |
519 @beta |
520 @beta |
520 Returns the text alignment for primary text and additional text |
521 Returns the text alignment for primary text. |
521 \sa setTextAlignment() |
522 \sa setTextAlignment() |
522 */ |
523 */ |
523 Qt::Alignment HbPushButton::textAlignment( ) const |
524 Qt::Alignment HbPushButton::textAlignment( ) const |
524 { |
525 { |
525 Q_D(const HbPushButton); |
526 Q_D(const HbPushButton); |
538 Q_D( HbPushButton ); |
539 Q_D( HbPushButton ); |
539 |
540 |
540 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
541 //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem); |
541 if(!d->additionalTextItem) { |
542 if(!d->additionalTextItem) { |
542 //need to create text item if user call alignment api before setAdditionalText. |
543 //need to create text item if user call alignment api before setAdditionalText. |
543 d->additionalTextItem = style( )->createPrimitive( HbStyle::P_PushButton_additionaltext, this); |
544 d->additionalTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_PushButton_additionaltext, this); |
544 } |
545 } |
545 // check for textitem and api protection flag |
546 // check for textitem and api protection flag |
546 if( alignment != d->additionalTextAlignment ) { |
547 if( alignment != d->additionalTextAlignment ) { |
547 //take the alignment |
548 //take the alignment |
548 d->additionalTextAlignment = alignment; |
549 d->additionalTextAlignment = alignment; |
549 //set the api protection flag |
550 //set the api protection flag |
550 //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
551 //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true); |
551 d->hasAdditionalTextAlignment = true; |
552 d->hasAdditionalTextAlignment = true; |
552 HbStyleOptionPushButton buttonOption; |
553 HbStyleOptionPushButton buttonOption; |
553 initStyleOption( &buttonOption ); |
554 initStyleOption( &buttonOption ); |
554 style( )->updatePrimitive( |
555 HbStylePrivate::updatePrimitive( |
555 d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption ); |
556 d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption ); |
556 } |
557 } |
557 } |
558 } |
558 |
559 |
559 /*! |
560 /*! |
560 @beta |
561 @beta |
610 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
611 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const |
611 { |
612 { |
612 Q_D( const HbPushButton ); |
613 Q_D( const HbPushButton ); |
613 |
614 |
614 switch ( primitive ) { |
615 switch ( primitive ) { |
615 case HbStyle::P_PushButton_background: |
616 case HbStylePrivate::P_PushButton_background: |
616 return d->frameItem; |
617 return d->frameItem; |
617 case HbStyle::P_PushButton_icon: |
618 case HbStylePrivate::P_PushButton_icon: |
618 return d->iconItem; |
619 return d->iconItem; |
619 case HbStyle::P_PushButton_text: |
620 case HbStylePrivate::P_PushButton_text: |
620 return d->textItem; |
621 return d->textItem; |
621 case HbStyle::P_PushButton_toucharea: |
622 case HbStylePrivate::P_PushButton_toucharea: |
622 return d->touchArea; |
623 return d->touchArea; |
623 case HbStyle::P_PushButton_additionaltext: |
624 case HbStylePrivate::P_PushButton_additionaltext: |
624 return d->additionalTextItem; |
625 return d->additionalTextItem; |
625 case HbStyle::P_PushButton_focus: |
626 case HbStylePrivate::P_PushButton_focus: |
626 return d->focusItem; |
627 return d->focusItem; |
627 default: |
628 default: |
628 return 0; |
629 return 0; |
629 } |
630 } |
630 } |
631 } |
662 HbWidget::updatePrimitives( ); |
663 HbWidget::updatePrimitives( ); |
663 |
664 |
664 HbStyleOptionPushButton buttonOption; |
665 HbStyleOptionPushButton buttonOption; |
665 initStyleOption(&buttonOption); |
666 initStyleOption(&buttonOption); |
666 if ( d->textItem ) { |
667 if ( d->textItem ) { |
667 style()->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption ); |
668 HbStylePrivate::updatePrimitive( d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption ); |
668 } |
669 } |
669 if ( d->touchArea ) { |
670 if ( d->touchArea ) { |
670 style()->updatePrimitive( d->touchArea, HbStyle::P_PushButton_toucharea, &buttonOption ); |
671 HbStylePrivate::updatePrimitive( d->touchArea, HbStylePrivate::P_PushButton_toucharea, &buttonOption ); |
671 } |
672 } |
672 if( d->additionalTextItem ) { |
673 if( d->additionalTextItem ) { |
673 style()->updatePrimitive( |
674 HbStylePrivate::updatePrimitive( |
674 d->additionalTextItem,HbStyle::P_PushButton_additionaltext,&buttonOption ); |
675 d->additionalTextItem,HbStylePrivate::P_PushButton_additionaltext,&buttonOption ); |
675 } |
676 } |
676 if ( d->iconItem) { |
677 if ( d->iconItem) { |
677 style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption ); |
678 HbStylePrivate::updatePrimitive( d->iconItem, HbStylePrivate::P_PushButton_icon, &buttonOption ); |
678 } |
679 } |
679 if ( d->frameItem ) { |
680 if ( d->frameItem ) { |
680 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
681 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
681 } |
682 } |
682 // update will happen only for keyevents when focusItem will be visible. |
683 // update will happen only for keyevents when focusItem will be visible. |
683 if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) { |
684 if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) { |
684 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption ); |
685 HbStylePrivate::updatePrimitive( d->focusItem,HbStylePrivate::P_PushButton_focus, &buttonOption ); |
685 } |
686 } |
686 } |
687 } |
687 |
688 |
688 /*! |
689 /*! |
689 \internal |
690 \internal |
799 Q_D( HbPushButton ); |
800 Q_D( HbPushButton ); |
800 HbAbstractButton::mousePressEvent( event ); |
801 HbAbstractButton::mousePressEvent( event ); |
801 HbStyleOptionPushButton buttonOption; |
802 HbStyleOptionPushButton buttonOption; |
802 initStyleOption( &buttonOption ); |
803 initStyleOption( &buttonOption ); |
803 if( d->frameItem ) { |
804 if( d->frameItem ) { |
804 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
805 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
805 } |
806 } |
806 #ifdef HB_EFFECTS |
807 #ifdef HB_EFFECTS |
807 if ( hitButton(event->pos()) ) { |
808 if ( hitButton(event->pos()) ) { |
808 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" ); |
809 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" ); |
809 } |
810 } |
823 Q_D( HbPushButton ); |
824 Q_D( HbPushButton ); |
824 HbAbstractButton::mouseReleaseEvent( event ); |
825 HbAbstractButton::mouseReleaseEvent( event ); |
825 HbStyleOptionPushButton buttonOption; |
826 HbStyleOptionPushButton buttonOption; |
826 initStyleOption( &buttonOption ); |
827 initStyleOption( &buttonOption ); |
827 if( d->frameItem ) { |
828 if( d->frameItem ) { |
828 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
829 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
829 } |
830 } |
830 #ifdef HB_EFFECTS |
831 #ifdef HB_EFFECTS |
831 if ( hitButton(event->pos()) ) { |
832 if ( hitButton(event->pos()) ) { |
832 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" ); |
833 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" ); |
833 } |
834 } |
843 Q_D( HbPushButton ); |
844 Q_D( HbPushButton ); |
844 HbAbstractButton::mouseMoveEvent( event ); |
845 HbAbstractButton::mouseMoveEvent( event ); |
845 HbStyleOptionPushButton buttonOption; |
846 HbStyleOptionPushButton buttonOption; |
846 initStyleOption( &buttonOption ); |
847 initStyleOption( &buttonOption ); |
847 if( d->frameItem ) { |
848 if( d->frameItem ) { |
848 style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption ); |
849 HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption ); |
849 } |
850 } |
850 if (d->down) { |
851 if (d->down) { |
851 setProperty( "state", "pressed" ); |
852 setProperty( "state", "pressed" ); |
852 } else { |
853 } else { |
853 setProperty( "state", "normal" ); |
854 setProperty( "state", "normal" ); |
938 if( d->focusItem ) { |
939 if( d->focusItem ) { |
939 d->focusItem->setVisible( true ); |
940 d->focusItem->setVisible( true ); |
940 if( hasFocus() ) { |
941 if( hasFocus() ) { |
941 HbStyleOptionPushButton buttonOption; |
942 HbStyleOptionPushButton buttonOption; |
942 initStyleOption( &buttonOption ); |
943 initStyleOption( &buttonOption ); |
943 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption ); |
944 HbStylePrivate::updatePrimitive( d->focusItem,HbStylePrivate::P_PushButton_focus, &buttonOption ); |
944 } |
945 } |
945 } else { |
946 } else { |
946 d->focusItem = style()->createPrimitive(HbStyle::P_PushButton_focus, this); |
947 d->focusItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_PushButton_focus, this); |
947 } |
948 } |
948 } |
949 } |
949 HbAbstractButton::focusInEvent( event ); |
950 HbAbstractButton::focusInEvent( event ); |
950 } |
951 } |
951 |
952 |