src/hbwidgets/widgets/hbpushbutton.cpp
changeset 2 06ff229162e9
parent 1 f7ac710697a9
child 3 11d3954df52a
equal deleted inserted replaced
1:f7ac710697a9 2:06ff229162e9
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbpushbutton.h"
    26 #include "hbpushbutton.h"
    27 #include "hbpushbutton_p.h"
    27 #include "hbpushbutton_p.h"
    28 #include "hbstyle.h"
    28 #include "hbstyle.h"
    29 #include "hbstyleoptionpushbutton.h"
    29 #include "hbstyleoptionpushbutton_p.h"
    30 #include "hbframedrawerpool_p.h"
    30 #include "hbframedrawerpool_p.h"
    31 #include "hbnamespace.h"
    31 #include "hbnamespace.h"
    32 #ifdef HB_EFFECTS
    32 #ifdef HB_EFFECTS
    33 #include "hbeffect.h"
    33 #include "hbeffect.h"
    34 #include "hbeffectinternal_p.h"
    34 #include "hbeffectinternal_p.h"
   131     additionalTextItem(0),
   131     additionalTextItem(0),
   132     touchArea(0),
   132     touchArea(0),
   133     iconItem(0),
   133     iconItem(0),
   134     frameItem(0),
   134     frameItem(0),
   135     focusItem(0),
   135     focusItem(0),
   136     orientation(Qt::Vertical),
       
   137     backgroundFrameDrawer(0),
   136     backgroundFrameDrawer(0),
   138     longPressTimer(0),
   137     longPressTimer(0),
   139     textAlignment(Qt::AlignHCenter | Qt::AlignVCenter ),
   138     textAlignment(Qt::AlignHCenter | Qt::AlignVCenter ),
   140     additionalTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter ),
   139     additionalTextAlignment(Qt::AlignHCenter | Qt::AlignVCenter ),
   141     stretched(false),
   140     stretched(false),
   192     if ( !icon.isNull() ) {
   191     if ( !icon.isNull() ) {
   193         if ( !iconItem ) {
   192         if ( !iconItem ) {
   194             iconItem = q->style()->createPrimitive( HbStyle::P_PushButton_icon, q);
   193             iconItem = q->style()->createPrimitive( HbStyle::P_PushButton_icon, q);
   195         }
   194         }
   196     } else {
   195     } else {
   197         if( iconItem ){
   196         if( iconItem ) {
   198             delete iconItem;
   197             delete iconItem;
   199         }
   198         }
   200         iconItem = 0;
   199         iconItem = 0;
   201     }
   200     }
   202 
   201 
   209             q->grabGesture(Qt::TapGesture);
   208             q->grabGesture(Qt::TapGesture);
   210         }
   209         }
   211     }
   210     }
   212 
   211 
   213     if( !focusItem ) {
   212     if( !focusItem ) {
   214     focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q);
   213         focusItem = q->style()->createPrimitive(HbStyle::P_PushButton_focus, q);
   215     //focus primitive is will not be visible by default, 
   214         //focus primitive is will not be visible by default, 
   216     //only in case of keyboard focus events it will be Visible.
   215         //only in case of keyboard focus events it will be Visible.
   217     focusItem->setVisible( false );
   216         focusItem->setVisible( false );
   218     }
   217     }
   219 }
   218 }
   220 
   219 
   221 
   220 
   222 
   221 
   229     }
   228     }
   230 }
   229 }
   231 
   230 
   232 void HbPushButtonPrivate::_q_handleLongKeyPress( )
   231 void HbPushButtonPrivate::_q_handleLongKeyPress( )
   233 {
   232 {
   234     Q_Q(HbPushButton);
   233     Q_Q( HbPushButton );
   235     if(!longPress){
   234     if(!longPress) {
   236         longPress = true;
   235         longPress = true;
   237         emit q->longPress( q->pos() );
   236         emit q->longPress( q->pos( ) );
   238     }
   237     }
   239 }
   238 }
   240 
   239 
   241 void HbPushButtonPrivate::initialize()
   240 void HbPushButtonPrivate::initialize()
   242 {
   241 {
   243     Q_Q(HbPushButton);
   242     Q_Q( HbPushButton );
   244     q_ptr = q;
   243     q_ptr = q;
   245     createPrimitives();
   244     createPrimitives( );
   246 }
   245 }
   247 
   246 
   248 /*!
   247 /*!
   249     @beta
   248     @beta
   250     Constructs a new HbPushButton with \a parent.
   249     Constructs a new HbPushButton with \a parent.
   251  */
   250  */
   252 HbPushButton::HbPushButton( QGraphicsItem *parent )
   251 HbPushButton::HbPushButton( QGraphicsItem *parent )
   253     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   252     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   254 {
   253 {
   255     Q_D(HbPushButton);
   254     Q_D( HbPushButton );
   256     d->initialize();
   255     d->initialize( );
   257 
   256 
   258     setProperty("state", "normal");
   257     setProperty( "state", "normal" );
   259      
   258      
   260 }
   259 }
   261 
   260 
   262 /*!
   261 /*!
   263     @beta
   262     @beta
   264     Constructs a new HbPushButton with \a text and \a parent.
   263     Constructs a new HbPushButton with \a text and \a parent.
   265  */
   264  */
   266 HbPushButton::HbPushButton(const QString &text, QGraphicsItem *parent)
   265 HbPushButton::HbPushButton( const QString &text, QGraphicsItem *parent )
   267     : HbAbstractButton(*new HbPushButtonPrivate, parent)
   266     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   268 {
   267 {
   269     Q_D(HbPushButton);
   268     Q_D( HbPushButton );
   270     d->text = text;
   269     d->text = text;
   271     d->initialize();
   270     d->initialize( );
   272 
   271 
   273     setProperty("state", "normal");
   272     setProperty( "state", "normal" );
   274      
   273      
   275 
   274 
   276 }
   275 }
   277 
   276 
   278 /*!
   277 /*!
   280     Constructs a new HbPushButton with \a icon, \a text and \a parent.
   279     Constructs a new HbPushButton with \a icon, \a text and \a parent.
   281  */
   280  */
   282 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent )
   281 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent )
   283     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   282     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   284 {
   283 {
   285     Q_D(HbPushButton);
   284     Q_D( HbPushButton );
   286     d->icon = icon;
   285     d->icon = icon;
   287     d->text = text;
   286     d->text = text;
   288     d->initialize();
   287     d->initialize( );
   289 
   288 
   290     setProperty("state", "normal");
   289     setProperty( "state", "normal" );
   291 
   290 
   292 }
       
   293 
       
   294 /*!
       
   295     \deprecated HbPushButton::HbPushButton(const HbIcon&, const QString&, Qt::Orientation, QGraphicsItem*)
       
   296         is deprecated.
       
   297     Constructs a new HbPushButton with \a icon, \a text \a orientation and \a parent.
       
   298  */
       
   299 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text,
       
   300     Qt::Orientation orientation, QGraphicsItem *parent )
       
   301     : HbAbstractButton( *new HbPushButtonPrivate, parent )
       
   302 {
       
   303     Q_D(HbPushButton);
       
   304     d->icon = icon;
       
   305     d->text = text;
       
   306     d->initialize();
       
   307     d->orientation = orientation;
       
   308 
       
   309     setProperty("state", "normal");
       
   310             
       
   311 }
   291 }
   312 
   292 
   313 /*!
   293 /*!
   314     Destructs the push button.
   294     Destructs the push button.
   315  */
   295  */
   316 HbPushButton::~HbPushButton()
   296 HbPushButton::~HbPushButton( )
   317 {
   297 {
   318 
   298 
   319 }
   299 }
   320 
   300 
   321 /*!
   301 /*!
   326 
   306 
   327     \sa background()
   307     \sa background()
   328  */
   308  */
   329 void  HbPushButton::setBackground( const HbIcon &background )
   309 void  HbPushButton::setBackground( const HbIcon &background )
   330 {
   310 {
   331     Q_D(HbPushButton);
   311     Q_D( HbPushButton );
   332     if( !d->frameItem ) {
       
   333        d->createPrimitives();
       
   334     }
       
   335     if ( d->background != background ) {
   312     if ( d->background != background ) {
   336         d->background = background;
   313         d->background = background;
   337         d->backgroundFrameDrawer = 0;
   314         d->backgroundFrameDrawer = 0;
   338         HbStyleOptionPushButton buttonOption;
   315         HbStyleOptionPushButton buttonOption;
   339         initStyleOption( &buttonOption );
   316         initStyleOption( &buttonOption );
   345     @beta
   322     @beta
   346     Returns the background of the button.
   323     Returns the background of the button.
   347 
   324 
   348     \sa setBackground()
   325     \sa setBackground()
   349  */
   326  */
   350 HbIcon HbPushButton::background() const
   327 HbIcon HbPushButton::background( ) const
   351 {
   328 {
   352     Q_D(const HbPushButton);
   329     Q_D( const HbPushButton );
   353     return d->background;
   330     return d->background;
   354 }
   331 }
   355 
   332 
   356 /*!
   333 /*!
   357     @beta
   334     @beta
   362 
   339 
   363     \sa frameBackground()
   340     \sa frameBackground()
   364  */
   341  */
   365 void  HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer )
   342 void  HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer )
   366 {
   343 {
   367     Q_D(HbPushButton);
   344     Q_D( HbPushButton );
   368     if (d->backgroundFrameDrawer != backgroundFrameDrawer) {
   345     if ( d->backgroundFrameDrawer != backgroundFrameDrawer ) {
   369         if( !d->frameItem ) {
   346         d->backgroundFrameDrawer = backgroundFrameDrawer;
   370             d->createPrimitives();
   347         d->background = HbIcon( );
   371         }
       
   372         d->backgroundFrameDrawer=backgroundFrameDrawer;
       
   373         d->background=HbIcon();
       
   374         HbStyleOptionPushButton buttonOption;
   348         HbStyleOptionPushButton buttonOption;
   375         initStyleOption( &buttonOption );
   349         initStyleOption( &buttonOption );
   376         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   350         style( )->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   377     }
   351     }
   378 }
   352 }
   379 
   353 
   380 /*!
   354 /*!
   381     @beta
   355     @beta
   382     Returns the background of the button.
   356     Returns the background of the button.
   383 
   357 
   384     \sa setBackground()
   358     \sa setBackground()
   385  */
   359  */
   386 HbFrameDrawer* HbPushButton::frameBackground() const
   360 HbFrameDrawer *HbPushButton::frameBackground( ) const
   387 {
   361 {
   388     Q_D(const HbPushButton);
   362     Q_D( const HbPushButton );
   389     return ( d->backgroundFrameDrawer );
   363     return ( d->backgroundFrameDrawer );
   390 }
   364 }
   391 
   365 
   392 
   366 
   393 /*!
   367 /*!
   396 
   370 
   397     \sa text()
   371     \sa text()
   398  */
   372  */
   399 void HbPushButton::setText( const QString &text )
   373 void HbPushButton::setText( const QString &text )
   400 {
   374 {
   401     Q_D(HbPushButton);
   375     Q_D( HbPushButton );
   402     if ( d->text != text ) {
   376     if ( d->text != text ) {
   403         bool doPolish = text.isEmpty() || d->text.isEmpty();
   377         bool doPolish = text.isEmpty() || d->text.isEmpty();
   404         d->text = text;
   378         d->text = text;
   405         d->createPrimitives();
   379         d->createPrimitives( );
   406         //updatePrimitives();
   380         //updatePrimitives();
   407         if( d->textItem ){
   381         if( d->textItem ) {
   408             HbStyleOptionPushButton buttonOption;
   382             HbStyleOptionPushButton buttonOption;
   409             initStyleOption(&buttonOption);
   383             initStyleOption( &buttonOption );
   410             style()->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption);
   384             style( )->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption);
   411         }
   385         }
   412         if(doPolish) {
   386         if(doPolish) {
   413             repolish();
   387             repolish( );
   414         }
   388         }
   415     }
   389     }
   416 }
   390 }
   417 
   391 
   418 
   392 
   420     @beta
   394     @beta
   421     Returns the text shown on the button.
   395     Returns the text shown on the button.
   422 
   396 
   423     \sa setText()
   397     \sa setText()
   424  */
   398  */
   425 QString HbPushButton::text() const
   399 QString HbPushButton::text( ) const
   426 {
   400 {
   427     Q_D(const HbPushButton);
   401     Q_D( const HbPushButton );
   428     return d->text;
   402     return d->text;
   429 }
   403 }
   430 
   404 
   431 
   405 
   432 /*!
   406 /*!
   438 
   412 
   439     \sa additionalText()
   413     \sa additionalText()
   440  */
   414  */
   441 void HbPushButton::setAdditionalText( const QString &additionalText )
   415 void HbPushButton::setAdditionalText( const QString &additionalText )
   442 {
   416 {
   443     Q_D(HbPushButton);
   417     Q_D( HbPushButton );
   444     if ( d->additionalText != additionalText ) {
   418     if ( d->additionalText != additionalText ) {
   445         bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty();
   419         bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty();
   446         d->additionalText = additionalText;
   420         d->additionalText = additionalText;
   447         d->createPrimitives();
   421         d->createPrimitives( );
   448         // updatePrimitives();
   422         // updatePrimitives();
   449         if(d->additionalTextItem){
   423         if( d->additionalTextItem ) {
   450             HbStyleOptionPushButton buttonOption;
   424             HbStyleOptionPushButton buttonOption;
   451             initStyleOption(&buttonOption);
   425             initStyleOption( &buttonOption );
   452             style()->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption);
   426             style( )->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption);
   453         }
   427         }
   454         if( doPolish ) {
   428         if( doPolish ) {
   455             repolish();
   429             repolish();
   456         }
   430         }
   457     }
   431     }
   461     @beta
   435     @beta
   462     Returns the additional text shown on the button.
   436     Returns the additional text shown on the button.
   463 
   437 
   464     \sa setAdditionalText()
   438     \sa setAdditionalText()
   465  */
   439  */
   466 QString HbPushButton::additionalText() const
   440 QString HbPushButton::additionalText( ) const
   467 {
   441 {
   468     Q_D(const HbPushButton);
   442     Q_D( const HbPushButton );
   469     return d->additionalText;
   443     return d->additionalText;
   470 }
   444 }
   471 
   445 
   472 /*!
   446 /*!
   473     @beta
   447     @beta
   475 
   449 
   476     \note The icon can contain images for different modes.
   450     \note The icon can contain images for different modes.
   477 
   451 
   478     \sa icon()
   452     \sa icon()
   479  */
   453  */
   480 void HbPushButton::setIcon(const HbIcon &icon)
   454 void HbPushButton::setIcon( const HbIcon &icon )
   481 {
   455 {
   482     Q_D(HbPushButton);
   456     Q_D(HbPushButton);
   483 
   457 
   484     if ( d->icon != icon ) {
   458     if ( d->icon != icon ) {
   485         bool doPolish = icon.isNull() || d->icon.isNull();
   459         bool doPolish = icon.isNull( ) || d->icon.isNull();
   486         d->icon = icon;
   460         d->icon = icon;
   487         d->createPrimitives();
   461         d->createPrimitives( );
   488         //updatePrimitives();
   462         //updatePrimitives();
   489         if(d->iconItem ){
   463         if( d->iconItem ) {
   490             HbStyleOptionPushButton buttonOption;
   464             HbStyleOptionPushButton buttonOption;
   491             initStyleOption( &buttonOption );
   465             initStyleOption( &buttonOption );
   492             style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   466             style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   493 
   467 
   494         }
   468         }
   495         if( doPolish ){
   469         if( doPolish ) {
   496             repolish();
   470             repolish();
   497         }
   471         }
   498     }
   472     }
   499 }
   473 }
   500 
   474 
   502     @beta
   476     @beta
   503     Returns the icon shown on the button.
   477     Returns the icon shown on the button.
   504     \sa setIcon()
   478     \sa setIcon()
   505  */
   479  */
   506 
   480 
   507 HbIcon HbPushButton::icon() const
   481 HbIcon HbPushButton::icon( ) const
   508 {
   482 {
   509     Q_D(const HbPushButton);
   483     Q_D( const HbPushButton );
   510     return d->icon;
   484     return d->icon;
   511 }
   485 }
   512 
   486 
   513 
   487 /*!
   514 /*!
   488     @beta
   515     \deprecated HbPushButton::setOrientation( Qt::Orientation )
       
   516         is deprecated. Please use HbPushButton::setStretched(bool) instead 
       
   517 
       
   518     Set the orientation.Default orientation is Qt::Vertical.
       
   519     In case of icon ,text and additional text it has to be set to Qt::Horizontal.
       
   520     In case of additionalText and text it has to be set to Qt:Vertical.
       
   521     \sa orientation()
       
   522 */
       
   523 void HbPushButton::setOrientation( Qt::Orientation orientation )
       
   524 {
       
   525     Q_D(HbPushButton);
       
   526     if( d->orientation != orientation ) {
       
   527         d->orientation = orientation;
       
   528         // calling setStretchedMode internaly this api is going to be depricated.
       
   529         bool stretched = 
       
   530             (d->orientation == Qt::Vertical)?(false):(true);
       
   531         setStretched( stretched );        
       
   532     }
       
   533     qDebug()<<"This api is deprecated use HbPushButton::setStretched( bool stretched )";
       
   534 }
       
   535 
       
   536 /*!
       
   537     \deprecated HbPushButton::orientation() const
       
   538         is deprecated.Please use bool HbPushButton::isStretched() const instead 
       
   539 
       
   540     Returns orientation of button
       
   541     \sa setOrientation ()
       
   542 */
       
   543 Qt::Orientation HbPushButton::orientation() const
       
   544 {
       
   545     Q_D(const HbPushButton);
       
   546     qDebug()<<"This api is deprecated use bool HbPushButton::isStretched() const";
       
   547     return d->orientation;    
       
   548 }
       
   549 
       
   550 /*!
       
   551     Set the text alignment for primarytext  and additional text.
   489     Set the text alignment for primarytext  and additional text.
   552     The default alignment is Qt::AlignHCenter | Qt::AlignVCenter.
   490     The default alignment is Qt::AlignHCenter | Qt::AlignVCenter.
   553     \sa textAlignment()
   491     \sa textAlignment()
   554 */
   492 */
   555 void HbPushButton::setTextAlignment( Qt::Alignment alignment )
   493 void HbPushButton::setTextAlignment( Qt::Alignment alignment )
   556 {
   494 {
   557     Q_D(HbPushButton); 
   495     Q_D( HbPushButton ); 
   558 
   496 
   559     //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem);		
   497     //HbWidgetBase* textItem = static_cast<HbWidgetBase*>(d->textItem);		
   560     if(!d->textItem){
   498     if( !d->textItem ) {
   561         //need to create text item if user call alignment api before setText.
   499         //need to create text item if user call alignment api before setText.
   562         d->textItem = style()->createPrimitive( HbStyle::P_PushButton_text, this);
   500         d->textItem = style( )->createPrimitive( HbStyle::P_PushButton_text, this);
   563     }
   501     }
   564     //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem);	
   502     //HbWidgetBasePrivate *textItem_p = HbWidgetBasePrivate::d_ptr(textItem);	
   565     // check for textitem and api protection flag
   503     // check for textitem and api protection flag
   566     if(alignment != d->textAlignment ){
   504     if( alignment != d->textAlignment ){
   567         //take the alignment 
   505         //take the alignment 
   568         d->textAlignment = alignment;
   506         d->textAlignment = alignment;
   569         //set the api protection flag 
   507         //set the api protection flag 
   570         //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true);
   508         //HbWidgetBasePrivate::d_ptr(textItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true);
   571         d->hasTextAlignment = true;
   509         d->hasTextAlignment = true;
   576     }
   514     }
   577     d->hasTextAlignment = true;
   515     d->hasTextAlignment = true;
   578 }
   516 }
   579 
   517 
   580 /*!
   518 /*!
       
   519     @beta
   581     Returns the text alignment for primary text and additional text
   520     Returns the text alignment for primary text and additional text
   582     \sa setTextAlignment()
   521     \sa setTextAlignment()
   583 */
   522 */
   584 Qt::Alignment HbPushButton::textAlignment( ) const
   523 Qt::Alignment HbPushButton::textAlignment( ) const
   585 {
   524 {
   587     return d->textAlignment;
   526     return d->textAlignment;
   588 }
   527 }
   589 
   528 
   590 
   529 
   591 /*!
   530 /*!
       
   531     @beta
   592     Set the text alignment for additional text.
   532     Set the text alignment for additional text.
   593     The default alignment is Qt::AlignHCenter | Qt::AlignVCenter.
   533     The default alignment is Qt::AlignHCenter | Qt::AlignVCenter.
   594     \sa additionalTextAlignment()
   534     \sa additionalTextAlignment()
   595 */
   535 */
   596 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment )
   536 void HbPushButton::setAdditionalTextAlignment( Qt::Alignment alignment )
   597 {
   537 {
   598     Q_D(HbPushButton); 
   538     Q_D( HbPushButton ); 
   599 
   539 
   600     //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem);	
   540     //HbWidgetBase* additionalTextItem = static_cast<HbWidgetBase*>(d->additionalTextItem);	
   601     if(!d->additionalTextItem){
   541     if(!d->additionalTextItem) {
   602         //need to create text item if user call alignment api before setAdditionalText.
   542         //need to create text item if user call alignment api before setAdditionalText.
   603         d->additionalTextItem = style()->createPrimitive( HbStyle::P_PushButton_additionaltext, this);
   543         d->additionalTextItem = style( )->createPrimitive( HbStyle::P_PushButton_additionaltext, this);
   604     }
   544     }
   605     // check for textitem and api protection flag
   545     // check for textitem and api protection flag
   606     if(alignment != d->additionalTextAlignment ){
   546     if( alignment != d->additionalTextAlignment ) {
   607         //take the alignment 
   547         //take the alignment 
   608         d->additionalTextAlignment = alignment;
   548         d->additionalTextAlignment = alignment;
   609         //set the api protection flag 
   549         //set the api protection flag 
   610         //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true);
   550         //HbWidgetBasePrivate::d_ptr(additionalTextItem)->setApiProtectionFlag(HbWidgetBasePrivate::AC_TextAlign,true);
   611         d->hasAdditionalTextAlignment = true;
   551         d->hasAdditionalTextAlignment = true;
   612         HbStyleOptionPushButton buttonOption;            
   552         HbStyleOptionPushButton buttonOption;            
   613         initStyleOption( &buttonOption );
   553         initStyleOption( &buttonOption );
   614         style()->updatePrimitive( 
   554         style( )->updatePrimitive( 
   615         d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption );
   555         d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption );
   616     }
   556     }
   617 }
   557 }
   618 
   558 
   619 /*!
   559 /*!
       
   560     @beta
   620     Returns the text alignment for additional text
   561     Returns the text alignment for additional text
   621     \sa setAdditionalTextAlignment()
   562     \sa setAdditionalTextAlignment()
   622 */
   563 */
   623 Qt::Alignment HbPushButton::additionalTextAlignment( ) const
   564 Qt::Alignment HbPushButton::additionalTextAlignment( ) const
   624 {
   565 {
   625     Q_D(const HbPushButton);
   566     Q_D(const HbPushButton);
   626     return d->additionalTextAlignment;
   567     return d->additionalTextAlignment;
   627 }
   568 }
   628 
   569 
   629 /*!
   570 /*!
       
   571     @beta
   630     Sets the stretched layout for button by default it set to true. setStretched true/false.
   572     Sets the stretched layout for button by default it set to true. setStretched true/false.
   631     For the case icon and text with value false will appear icon and text vertically aligned.
   573     For the case icon and text with value false will appear icon and text vertically aligned.
   632     and with value true will appear icon and text horizontally aligned.
   574     and with value true will appear icon and text horizontally aligned.
   633     For the case icon , text and additional text with value false will appear like 
   575     For the case icon , text and additional text with value false will appear like 
   634     both text will be vertically aligned and icon will be horizontally.
   576     both text will be vertically aligned and icon will be horizontally.
   646         repolish();
   588         repolish();
   647     }
   589     }
   648 }
   590 }
   649 
   591 
   650 /*!
   592 /*!
       
   593     @beta
   651     Returns the whether button has streteched layout or not.
   594     Returns the whether button has streteched layout or not.
   652     \sa setStretched ()
   595     \sa setStretched ()
   653 */
   596 */
   654 bool HbPushButton::isStretched() const
   597 bool HbPushButton::isStretched() const
   655 {
   598 {
   662     \deprecated HbPushButton::primitive(HbStyle::Primitive)
   605     \deprecated HbPushButton::primitive(HbStyle::Primitive)
   663         is deprecated.
   606         is deprecated.
   664 
   607 
   665     \reimp
   608     \reimp
   666  */
   609  */
   667 QGraphicsItem* HbPushButton::primitive( HbStyle::Primitive primitive ) const
   610 QGraphicsItem *HbPushButton::primitive( HbStyle::Primitive primitive ) const
   668 {
   611 {
   669     Q_D(const HbPushButton);
   612     Q_D( const HbPushButton );
   670 
   613 
   671     switch (primitive) {
   614     switch ( primitive ) {
   672         case HbStyle::P_PushButton_background:
   615         case HbStyle::P_PushButton_background:
   673             return d->frameItem;
   616             return d->frameItem;
   674         case HbStyle::P_PushButton_icon:
   617         case HbStyle::P_PushButton_icon:
   675             return d->iconItem;
   618             return d->iconItem;
   676         case HbStyle::P_PushButton_text:
   619         case HbStyle::P_PushButton_text:
   689 /*!
   632 /*!
   690     \reimp
   633     \reimp
   691  */
   634  */
   692 void HbPushButton::recreatePrimitives()
   635 void HbPushButton::recreatePrimitives()
   693 {
   636 {
   694    Q_D(HbPushButton);
   637    Q_D( HbPushButton );
   695    HbWidget::recreatePrimitives();
   638    HbWidget::recreatePrimitives();
   696 
   639 
   697    delete d->frameItem;
   640    delete d->frameItem;
   698    d->frameItem = 0;
   641    d->frameItem = 0;
   699    delete d->iconItem;
   642    delete d->iconItem;
   705    delete d->additionalTextItem;
   648    delete d->additionalTextItem;
   706    d->additionalTextItem = 0;
   649    d->additionalTextItem = 0;
   707    delete d->focusItem;
   650    delete d->focusItem;
   708    d->focusItem = 0;
   651    d->focusItem = 0;
   709    
   652    
   710    d->createPrimitives();
   653    d->createPrimitives( );
   711    setFrameBackground(0);
   654    setFrameBackground( 0 );
   712 }
   655 }
   713 /*!
   656 /*!
   714     \reimp
   657     \reimp
   715  */
   658  */
   716 void HbPushButton::updatePrimitives()
   659 void HbPushButton::updatePrimitives()
   717 {
   660 {
   718     Q_D(HbPushButton);
   661     Q_D( HbPushButton );
   719     HbWidget::updatePrimitives();
   662     HbWidget::updatePrimitives( );
   720 
   663 
   721     HbStyleOptionPushButton buttonOption;
   664     HbStyleOptionPushButton buttonOption;
   722     initStyleOption(&buttonOption);
   665     initStyleOption(&buttonOption);
   723     if ( d->textItem ) {
   666     if ( d->textItem ) {
   724         style()->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption );
   667         style()->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption );
   725     }
   668     }
   726     if ( d->touchArea ) {
   669     if ( d->touchArea ) {
   727         style()->updatePrimitive( d->touchArea, HbStyle::P_PushButton_toucharea, &buttonOption );
   670         style()->updatePrimitive( d->touchArea, HbStyle::P_PushButton_toucharea, &buttonOption );
   728     }	
   671     }
   729     if( d->additionalTextItem ){
   672     if( d->additionalTextItem ) {
   730         style()->updatePrimitive(
   673         style()->updatePrimitive(
   731             d->additionalTextItem,HbStyle::P_PushButton_additionaltext,&buttonOption );
   674             d->additionalTextItem,HbStyle::P_PushButton_additionaltext,&buttonOption );
   732     }
   675     }
   733     if ( d->iconItem) {
   676     if ( d->iconItem) {
   734         style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   677         style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   735     }
   678     }
   736     if ( d->frameItem ){
   679     if ( d->frameItem ) {
   737         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   680         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   738     }
   681     }
   739     // update will happen only for keyevents when focusItem will be visible.
   682     // update will happen only for keyevents when focusItem will be visible.
   740     if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) {
   683     if( d->focusItem && hasFocus() && d->focusItem->isVisible() ) {
   741         style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption );
   684         style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption );
   743 }
   686 }
   744 
   687 
   745 /*!
   688 /*!
   746     \internal
   689     \internal
   747  */
   690  */
   748 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem * parent) :
   691 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem *parent) :
   749     HbAbstractButton(dd, parent)
   692     HbAbstractButton(dd, parent)
   750 {
   693 {
   751 }
   694 }
   752 
   695 
   753 /*!
   696 /*!
   754     Initializes \a option with the values from this HbPushButton. 
   697     Initializes \a option with the values from this HbPushButton. 
   755     This method is useful for subclasses when they need a HbStyleOptionPushButton,
   698     This method is useful for subclasses when they need a HbStyleOptionPushButton,
   756     but don't want to fill in all the information themselves.
   699     but don't want to fill in all the information themselves.
   757  */
   700  */
   758 void HbPushButton::initStyleOption(HbStyleOptionPushButton *option) const
   701 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const
   759 {
   702 {
   760     Q_D(const HbPushButton);
   703     Q_D( const HbPushButton );
   761 
   704 
   762     HbAbstractButton::initStyleOption(option);
   705     HbAbstractButton::initStyleOption(option);
   763 
   706 
   764     Q_ASSERT(option);
   707     Q_ASSERT(option);
   765     option->background = d->background;
   708     option->background = d->background;
   769     option->isCheckable = d->checkable;
   712     option->isCheckable = d->checkable;
   770     option->textAlignment = d->textAlignment;
   713     option->textAlignment = d->textAlignment;
   771     option->additionalTextAlignment = d->additionalTextAlignment;
   714     option->additionalTextAlignment = d->additionalTextAlignment;
   772     option->hasTextAlignment = d->hasTextAlignment;
   715     option->hasTextAlignment = d->hasTextAlignment;
   773     option->hasAdditionalTextAlignment = d->hasAdditionalTextAlignment;
   716     option->hasAdditionalTextAlignment = d->hasAdditionalTextAlignment;
   774     if(option->backgroundFrameDrawer) {
   717     if( option->backgroundFrameDrawer ) {
   775         HbFrameDrawerPool::release(option->backgroundFrameDrawer);
   718         HbFrameDrawerPool::release( option->backgroundFrameDrawer );
   776         option->backgroundFrameDrawer = 0;
   719         option->backgroundFrameDrawer = 0;
   777     }
   720     }
   778     option->backgroundFrameDrawer=( d->backgroundFrameDrawer );
   721     option->backgroundFrameDrawer = ( d->backgroundFrameDrawer );
   779 }
   722 }
   780 
   723 
   781 /*!
   724 /*!
   782     \reimp
   725     \reimp
   783  */
   726  */
   784 void HbPushButton::keyPressEvent(QKeyEvent *event)
   727 void HbPushButton::keyPressEvent(QKeyEvent *event)
   785 {
   728 {
   786     Q_D(HbPushButton);
   729     Q_D( HbPushButton );
   787 
   730 
   788     switch (event->key()) {
   731     switch ( event->key() ) {
   789         case Qt::Key_Select:
   732         case Qt::Key_Select:
   790         case Qt::Key_Enter:
   733         case Qt::Key_Enter:
   791         case Qt::Key_Return:{
   734         case Qt::Key_Return:{
   792                 if (!event->isAutoRepeat() && !d->autoRepeat && !d->longPressTimer) {
   735                 if (!event->isAutoRepeat( ) && !d->autoRepeat && !d->longPressTimer) {
   793                     d->longPressTimer = new QTimer();
   736                     d->longPressTimer = new QTimer();
   794                     d->longPressTimer->setInterval(300);
   737                     d->longPressTimer->setInterval(300);
   795                     connect( d->longPressTimer, SIGNAL(timeout()), this, SLOT(_q_handleLongKeyPress()) );
   738                     connect( d->longPressTimer, SIGNAL( timeout() ), this, SLOT(_q_handleLongKeyPress()) );
   796                     d->longPressTimer->start();
   739                     d->longPressTimer->start();
   797                 }else{
   740                 }else {
   798                     #ifdef HB_EFFECTS
   741                     #ifdef HB_EFFECTS
   799                         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   742                         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   800                     #endif
   743                     #endif
   801                 }
   744                 }
   802             }
   745             }
   848     \reimp
   791     \reimp
   849  */
   792  */
   850 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event )
   793 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event )
   851 {
   794 {
   852 #ifndef HB_GESTURE_FW
   795 #ifndef HB_GESTURE_FW
   853     Q_D(HbPushButton);
   796     Q_D( HbPushButton );
   854     HbAbstractButton::mousePressEvent(event);
   797     HbAbstractButton::mousePressEvent( event );
   855     HbStyleOptionPushButton buttonOption;
   798     HbStyleOptionPushButton buttonOption;
   856     initStyleOption( &buttonOption );
   799     initStyleOption( &buttonOption );
   857     if( d->frameItem ){
   800     if( d->frameItem ) {
   858         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   801         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   859     }
   802     }
   860 #ifdef HB_EFFECTS
   803 #ifdef HB_EFFECTS
   861     if ( hitButton(event->pos()) ){
   804     if ( hitButton(event->pos()) ) {
   862         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   805         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   863     }
   806     }
   864 #endif
   807 #endif
   865     setProperty("state", "pressed");    
   808     setProperty( "state", "pressed" );    
   866 #else
   809 #else
   867     Q_UNUSED(event)
   810     Q_UNUSED( event )
   868 #endif
   811 #endif
   869 }
   812 }
   870 
   813 
   871 #ifndef HB_GESTURE_FW
   814 #ifndef HB_GESTURE_FW
   872 /*!
   815 /*!
   873     \reimp
   816     \reimp
   874  */
   817  */
   875 void HbPushButton::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
   818 void HbPushButton::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
   876 {
   819 {
   877     Q_D(HbPushButton);
   820     Q_D( HbPushButton );
   878     HbAbstractButton::mouseReleaseEvent(event);
   821     HbAbstractButton::mouseReleaseEvent( event );
   879     HbStyleOptionPushButton buttonOption;
   822     HbStyleOptionPushButton buttonOption;
   880     initStyleOption( &buttonOption );     
   823     initStyleOption( &buttonOption );     
   881     if( d->frameItem ){
   824     if( d->frameItem ) {
   882         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   825         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   883     }
   826     }
   884 #ifdef HB_EFFECTS
   827 #ifdef HB_EFFECTS
   885     if ( hitButton(event->pos()) ){
   828     if ( hitButton(event->pos()) ) {
   886         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   829         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   887     }
   830     }
   888 #endif
   831 #endif
   889     setProperty("state", "normal"); 
   832     setProperty( "state", "normal" ); 
   890 }
   833 }
   891 
   834 
   892 /*!
   835 /*!
   893     \reimp
   836     \reimp
   894  */
   837  */
   895 void HbPushButton::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
   838 void HbPushButton::mouseMoveEvent( QGraphicsSceneMouseEvent *event )
   896 {
   839 {
   897     Q_D(HbPushButton);
   840     Q_D( HbPushButton );
   898     HbAbstractButton::mouseMoveEvent(event);
   841     HbAbstractButton::mouseMoveEvent( event );
   899     HbStyleOptionPushButton buttonOption;
   842     HbStyleOptionPushButton buttonOption;
   900     initStyleOption( &buttonOption );
   843     initStyleOption( &buttonOption );
   901     if( d->frameItem ){
   844     if( d->frameItem ) {
   902         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   845         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   903     }
   846     }
   904     if (d->down) {
   847     if (d->down) {
   905         setProperty("state", "pressed");
   848         setProperty( "state", "pressed" );
   906     } else {
   849     } else {
   907         setProperty("state", "normal");
   850         setProperty( "state", "normal" );
   908     }
   851     }
   909 }
   852 }
   910 #endif
   853 #endif
   911 
   854 
   912 
   855 
   913 #ifdef HB_GESTURE_FW
   856 #ifdef HB_GESTURE_FW
   914 void HbPushButton::gestureEvent(QGestureEvent *event)
   857 void HbPushButton::gestureEvent( QGestureEvent *event )
   915 {
   858 {
   916     Q_D(HbPushButton);
   859     Q_D(HbPushButton);
   917     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   860     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   918         switch(tap->state()) {
   861         switch(tap->state()) {
   919         case Qt::GestureStarted:{
   862         case Qt::GestureStarted:{
   920 #ifdef HB_EFFECTS
   863 #ifdef HB_EFFECTS
   921                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   864                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   922 #endif
   865 #endif
   923                 if(d->checkable && !d->checked){
   866                 if( d->checkable && !d->checked) {
   924                     setProperty("state", "latched");
   867                     setProperty( "state", "latched" );
   925                 }else if(!d->checkable){
   868                 }else if(!d->checkable) {
   926                     setProperty("state", "pressed");
   869                     setProperty( "state", "pressed" );
   927                 }
   870                 }
   928             }
   871             }
   929             break;
   872             break;
   930         case Qt::GestureUpdated:
   873         case Qt::GestureUpdated:
   931             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
   874             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
   932                 d->longPress = true;
   875                 d->longPress = true;
   933                 emit longPress(event->mapToGraphicsScene(tap->position()));
   876                 emit longPress( event->mapToGraphicsScene(tap->position()) );
   934             }
   877             }
   935             break;
   878             break;
   936         case Qt::GestureCanceled:
   879         case Qt::GestureCanceled:
   937             setProperty("state", "normal");
   880             setProperty( "state", "normal" );
   938             break;
   881             break;
   939         case Qt::GestureFinished:{
   882         case Qt::GestureFinished:{
   940 #ifdef HB_EFFECTS
   883 #ifdef HB_EFFECTS
   941                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   884                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   942 #endif
   885 #endif
   943                 if( d->checkable && !d->checked){
   886                 if( d->checkable && !d->checked) {
   944                     setProperty("state", "latched");
   887                     setProperty( "state", "latched" );
   945                 }else {                    
   888                 }else {                    
   946                     setProperty("state", "normal");
   889                     setProperty( "state", "normal" );
   947                 }
   890                 }
   948 
   891 
   949             }
   892             }
   950             break;
   893             break;
   951         default:
   894         default:
   952             break;
   895             break;
   953         }
   896         }
   954     }
   897     }
   955 
   898 
   956     HbAbstractButton::gestureEvent(event);
   899     HbAbstractButton::gestureEvent( event );
   957 
   900 
   958 }
   901 }
   959 #endif
   902 #endif
   960 
   903 
   961 
   904 
   962 /*!
   905 /*!
   963     \reimp
   906     \reimp
   964  */
   907  */
   965 void HbPushButton::resizeEvent(QGraphicsSceneResizeEvent *event)
   908 void HbPushButton::resizeEvent( QGraphicsSceneResizeEvent *event )
   966 {
   909 {
   967     HbAbstractButton::resizeEvent(event);
   910     HbAbstractButton::resizeEvent( event );
   968 }
   911 }
   969 /*!
   912 /*!
   970   reimp
   913   reimp
   971 
   914 
   972 */
   915 */
   973 void HbPushButton::polish( HbStyleParameters& params )
   916 void HbPushButton::polish( HbStyleParameters &params )
   974 {
   917 {
   975     Q_D( HbPushButton );
   918     Q_D( HbPushButton );
   976     if(d->stretched && (d->textItem && d->additionalTextItem && !d->iconItem)){
   919     if( d->stretched && ( d->textItem && d->additionalTextItem && !d->iconItem ) ) {
   977         d->stretched = false;
   920         d->stretched = false;
   978         qWarning()<<"Warning::Invalid Layout: Text and additonalText horizontal appearance not supported";
   921         qWarning() << "Warning::Invalid Layout: Text and additonalText horizontal appearance not supported";
   979     }
   922     }
   980     HbAbstractButton::polish( params );
   923     HbAbstractButton::polish( params );
   981 }
   924 }
   982 
   925 
   983 
   926 
   984 /*!
   927 /*!
   985     \reimp
   928     \reimp
   986  */
   929  */
   987 void HbPushButton::focusInEvent(QFocusEvent *event)
   930 void HbPushButton::focusInEvent( QFocusEvent *event )
   988 {
   931 {
   989     Q_D(HbPushButton);
   932     Q_D( HbPushButton );
   990     if((event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) 
   933     if( ( event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ) 
   991         && ( d->navigationKeyPress ) ) {
   934         && ( d->navigationKeyPress ) ) {
   992         if(d->focusItem) {
   935         if( d->focusItem ) {
   993             d->focusItem->setVisible(true);
   936             d->focusItem->setVisible( true );
   994             if( hasFocus()){
   937             if( hasFocus() ) {
   995                 HbStyleOptionPushButton buttonOption;
   938                 HbStyleOptionPushButton buttonOption;
   996                 initStyleOption( &buttonOption );
   939                 initStyleOption( &buttonOption );
   997                 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption );
   940                 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption );
   998             }
   941             }
   999         } else {
   942         } else {
  1000             d->focusItem = style()->createPrimitive(HbStyle::P_PushButton_focus, this);
   943             d->focusItem = style()->createPrimitive(HbStyle::P_PushButton_focus, this);
  1001         }
   944         }
  1002     }
   945     }
  1003     HbAbstractButton::focusInEvent(event);
   946     HbAbstractButton::focusInEvent( event );
  1004 }
   947 }
  1005 
   948 
  1006 /*!
   949 /*!
  1007     \reimp
   950     \reimp
  1008  */
   951  */
  1009 void HbPushButton::focusOutEvent(QFocusEvent *event)
   952 void HbPushButton::focusOutEvent( QFocusEvent *event )
  1010 {
   953 {
  1011     Q_D(HbPushButton);
   954     Q_D( HbPushButton );
  1012     if(d->focusItem) {
   955     if( d->focusItem ) {
  1013         d->focusItem->setVisible(false);
   956         d->focusItem->setVisible( false );
  1014     }
   957     }
  1015     HbAbstractButton::focusOutEvent(event);
   958     HbAbstractButton::focusOutEvent( event );
  1016 }
   959 }
  1017 
   960 
  1018 /*!
   961 /*!
  1019     \reimp
   962     \reimp
  1020  */
   963  */
  1037 }
   980 }
  1038 
   981 
  1039 /*!
   982 /*!
  1040   Overloaded hit detection to include touch area
   983   Overloaded hit detection to include touch area
  1041  */
   984  */
  1042 bool HbPushButton::hitButton(const QPointF &pos) const
   985 bool HbPushButton::hitButton( const QPointF &pos ) const
  1043 {
   986 {
  1044     Q_D( const HbPushButton );
   987     Q_D( const HbPushButton );
  1045     QRectF compRect = d->touchArea->boundingRect( );
   988     QRectF compRect = d->touchArea->boundingRect( );
  1046     compRect.translate( d->touchArea->pos() );
   989     compRect.translate( d->touchArea->pos() );
  1047     return compRect.contains( pos );
   990     return compRect.contains( pos );