src/hbwidgets/widgets/hbpushbutton.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    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 );
   233     q_ptr = q;
   275     q_ptr = q;
   234     createPrimitives( );
   276     createPrimitives( );
   235 }
   277 }
   236 
   278 
   237 /*!
   279 /*!
   238     @beta
   280     Constructs a push button with \a parent.
   239     Constructs a new HbPushButton with \a parent.
       
   240  */
   281  */
   241 HbPushButton::HbPushButton( QGraphicsItem *parent )
   282 HbPushButton::HbPushButton( QGraphicsItem *parent )
   242     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   283     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   243 {
   284 {
   244     Q_D( HbPushButton );
   285     Q_D( HbPushButton );
   247     setProperty( "state", "normal" );
   288     setProperty( "state", "normal" );
   248      
   289      
   249 }
   290 }
   250 
   291 
   251 /*!
   292 /*!
   252     @beta
   293     Constructs a push button with \a text and \a parent.
   253     Constructs a new HbPushButton with \a text and \a parent.
       
   254  */
   294  */
   255 HbPushButton::HbPushButton( const QString &text, QGraphicsItem *parent )
   295 HbPushButton::HbPushButton( const QString &text, QGraphicsItem *parent )
   256     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   296     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   257 {
   297 {
   258     Q_D( HbPushButton );
   298     Q_D( HbPushButton );
   263      
   303      
   264 
   304 
   265 }
   305 }
   266 
   306 
   267 /*!
   307 /*!
   268     @beta
   308     Constructs a push button with \a icon, \a text, and \a parent.
   269     Constructs a new HbPushButton with \a icon, \a text and \a parent.
       
   270  */
   309  */
   271 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent )
   310 HbPushButton::HbPushButton( const HbIcon &icon, const QString &text, QGraphicsItem *parent )
   272     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   311     : HbAbstractButton( *new HbPushButtonPrivate, parent )
   273 {
   312 {
   274     Q_D( HbPushButton );
   313     Q_D( HbPushButton );
   279     setProperty( "state", "normal" );
   318     setProperty( "state", "normal" );
   280 
   319 
   281 }
   320 }
   282 
   321 
   283 /*!
   322 /*!
   284     Destructs the push button.
   323     Destructor.
   285  */
   324  */
   286 HbPushButton::~HbPushButton( )
   325 HbPushButton::~HbPushButton( )
   287 {
   326 {
   288 
   327 
   289 }
   328 }
   290 
   329 
   291 /*!
   330 /*!
   292     @beta
   331     Sets the \a background shown on a push button. The background of a push 
   293     Sets the \a background of the button.
   332     button can have different images for pressed and released states.
   294 
       
   295     \note The background can contain different images for pressed and released states.
       
   296 
   333 
   297     \sa background()
   334     \sa background()
   298  */
   335  */
   299 void  HbPushButton::setBackground( const HbIcon &background )
   336 void  HbPushButton::setBackground( const HbIcon &background )
   300 {
   337 {
   302     if ( d->background != background ) {
   339     if ( d->background != background ) {
   303         d->background = background;
   340         d->background = background;
   304         d->backgroundFrameDrawer = 0;
   341         d->backgroundFrameDrawer = 0;
   305         HbStyleOptionPushButton buttonOption;
   342         HbStyleOptionPushButton buttonOption;
   306         initStyleOption( &buttonOption );
   343         initStyleOption( &buttonOption );
   307         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   344         HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption );
   308     }
   345     }
   309 }
   346 }
   310 
   347 
   311 /*!
   348 /*!
   312     @beta
   349     Returns the background shown on a push button.
   313     Returns the background of the button.
       
   314 
   350 
   315     \sa setBackground()
   351     \sa setBackground()
   316  */
   352  */
   317 HbIcon HbPushButton::background( ) const
   353 HbIcon HbPushButton::background( ) const
   318 {
   354 {
   319     Q_D( const HbPushButton );
   355     Q_D( const HbPushButton );
   320     return d->background;
   356     return d->background;
   321 }
   357 }
   322 
   358 
   323 /*!
   359 /*!
   324     @beta
   360     Sets the \a frame background shown on a push button. The frame background 
   325     Sets the \a framebackground of the button.
   361     of a push button can have the following types of frame drawers: 9-piece, 3-
   326 
   362     piece horizontal, 3-piece vertical, and single. The ownership is transferred 
   327     \note The background can contain different types of frame drawers(Nine piece,
   363     to the push button.
   328     three piece or single).Ownership is transferred to the Pushbutton
       
   329 
   364 
   330     \sa frameBackground()
   365     \sa frameBackground()
   331  */
   366  */
   332 void  HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer )
   367 void  HbPushButton::setFrameBackground( HbFrameDrawer *backgroundFrameDrawer )
   333 {
   368 {
   335     if ( d->backgroundFrameDrawer != backgroundFrameDrawer ) {
   370     if ( d->backgroundFrameDrawer != backgroundFrameDrawer ) {
   336         d->backgroundFrameDrawer = backgroundFrameDrawer;
   371         d->backgroundFrameDrawer = backgroundFrameDrawer;
   337         d->background = HbIcon( );
   372         d->background = HbIcon( );
   338         HbStyleOptionPushButton buttonOption;
   373         HbStyleOptionPushButton buttonOption;
   339         initStyleOption( &buttonOption );
   374         initStyleOption( &buttonOption );
   340         style( )->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   375         HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption );
   341     }
   376     }
   342 }
   377 }
   343 
   378 
   344 /*!
   379 /*!
   345     @beta
   380     Returns the background shown on a push button.
   346     Returns the background of the button.
       
   347 
   381 
   348     \sa setBackground()
   382     \sa setBackground()
   349  */
   383  */
   350 HbFrameDrawer *HbPushButton::frameBackground( ) const
   384 HbFrameDrawer *HbPushButton::frameBackground( ) const
   351 {
   385 {
   353     return ( d->backgroundFrameDrawer );
   387     return ( d->backgroundFrameDrawer );
   354 }
   388 }
   355 
   389 
   356 
   390 
   357 /*!
   391 /*!
   358     @beta
   392     Sets the \a text shown on a push button.
   359     Sets the \a text shown on the button.
       
   360 
   393 
   361     \sa text()
   394     \sa text()
   362  */
   395  */
   363 void HbPushButton::setText( const QString &text )
   396 void HbPushButton::setText( const QString &text )
   364 {
   397 {
   369         d->createPrimitives( );
   402         d->createPrimitives( );
   370         //updatePrimitives();
   403         //updatePrimitives();
   371         if( d->textItem ) {
   404         if( d->textItem ) {
   372             HbStyleOptionPushButton buttonOption;
   405             HbStyleOptionPushButton buttonOption;
   373             initStyleOption( &buttonOption );
   406             initStyleOption( &buttonOption );
   374             style( )->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption);
   407             HbStylePrivate::updatePrimitive( d->textItem, HbStylePrivate::P_PushButton_text, &buttonOption);
   375             if ( isEnabled() ) {
   408             if ( isEnabled() ) {
   376                 setProperty("state", "normal");
   409                 setProperty("state", "normal");
   377             }
   410             }
   378         }
   411         }
   379         if(doPolish) {
   412         if(doPolish) {
   382     }
   415     }
   383 }
   416 }
   384 
   417 
   385 
   418 
   386 /*!
   419 /*!
   387     @beta
   420     Returns the text shown on a push button.
   388     Returns the text shown on the button.
       
   389 
   421 
   390     \sa setText()
   422     \sa setText()
   391  */
   423  */
   392 QString HbPushButton::text( ) const
   424 QString HbPushButton::text( ) const
   393 {
   425 {
   395     return d->text;
   427     return d->text;
   396 }
   428 }
   397 
   429 
   398 
   430 
   399 /*!
   431 /*!
   400     @beta
   432     Sets the additional text shown on a push button, defined by \a 
   401     Sets the \a additional text shown on the button.
   433     additionalText. Additional text is only shown on the button in the following 
   402     Additional text is only shown in case 
   434     cases: 
   403     1. with icon and text in Qt::Horizontal alignment.
   435     
   404     2. with additionalText and text in Qt::Vertical alignment.
   436     - Icon, text, and additional text are horizontally aligned in one line.
       
   437     - Text and additional text are vertically aligned and icon is horizontally 
       
   438     aligned in relation to the texts.
       
   439     - Text and additional text are vertically aligned.
   405 
   440 
   406     \sa additionalText()
   441     \sa additionalText()
   407  */
   442  */
       
   443  
   408 void HbPushButton::setAdditionalText( const QString &additionalText )
   444 void HbPushButton::setAdditionalText( const QString &additionalText )
   409 {
   445 {
   410     Q_D( HbPushButton );
   446     Q_D( HbPushButton );
   411     if ( d->additionalText != additionalText ) {
   447     if ( d->additionalText != additionalText ) {
   412         bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty();
   448         bool doPolish = additionalText.isEmpty() || d->additionalText.isEmpty();
   414         d->createPrimitives( );
   450         d->createPrimitives( );
   415         // updatePrimitives();
   451         // updatePrimitives();
   416         if( d->additionalTextItem ) {
   452         if( d->additionalTextItem ) {
   417             HbStyleOptionPushButton buttonOption;
   453             HbStyleOptionPushButton buttonOption;
   418             initStyleOption( &buttonOption );
   454             initStyleOption( &buttonOption );
   419             style( )->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption);
   455             HbStylePrivate::updatePrimitive( d->additionalTextItem, HbStylePrivate::P_PushButton_additionaltext, &buttonOption);
   420             if ( isEnabled() ) {
   456             if ( isEnabled() ) {
   421                 setProperty("state", "normal");
   457                 setProperty("state", "normal");
   422             }
   458             }
   423         }
   459         }
   424         if( doPolish ) {
   460         if( doPolish ) {
   426         }
   462         }
   427     }
   463     }
   428 }
   464 }
   429 
   465 
   430 /*!
   466 /*!
   431     @beta
   467     Returns the additional text shown on a push button.
   432     Returns the additional text shown on the button.
       
   433 
   468 
   434     \sa setAdditionalText()
   469     \sa setAdditionalText()
   435  */
   470  */
   436 QString HbPushButton::additionalText( ) const
   471 QString HbPushButton::additionalText( ) const
   437 {
   472 {
   438     Q_D( const HbPushButton );
   473     Q_D( const HbPushButton );
   439     return d->additionalText;
   474     return d->additionalText;
   440 }
   475 }
   441 
   476 
   442 /*!
   477 /*!
   443     @beta
   478     
   444     Sets the \a icon shown on the button.
   479     Sets the \a icon shown on a push button. Each icon mode can have a 
   445 
   480     different image.
   446     \note The icon can contain images for different modes.
       
   447 
   481 
   448     \sa icon()
   482     \sa icon()
   449  */
   483  */
   450 void HbPushButton::setIcon( const HbIcon &icon )
   484 void HbPushButton::setIcon( const HbIcon &icon )
   451 {
   485 {
   458         d->createPrimitives( );
   492         d->createPrimitives( );
   459         //updatePrimitives();
   493         //updatePrimitives();
   460         if( d->iconItem ) {
   494         if( d->iconItem ) {
   461             HbStyleOptionPushButton buttonOption;
   495             HbStyleOptionPushButton buttonOption;
   462             initStyleOption( &buttonOption );
   496             initStyleOption( &buttonOption );
   463             style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   497             HbStylePrivate::updatePrimitive( d->iconItem, HbStylePrivate::P_PushButton_icon, &buttonOption );
   464             if ( isEnabled() ) {
   498             if ( isEnabled() ) {
   465                 setProperty("state", "normal");
   499                 setProperty("state", "normal");
   466             } 
   500             } 
   467 
   501 
   468         }
   502         }
   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
   691 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem *parent) :
   756 HbPushButton::HbPushButton(HbPushButtonPrivate &dd, QGraphicsItem *parent) :
   692     HbAbstractButton(dd, parent)
   757     HbAbstractButton(dd, parent)
   693 {
   758 {
   694 }
   759 }
   695 
   760 
   696 /*!
   761 /*! 
   697     \reimp
   762 
   698     Initializes \a option with the values from this HbPushButton. 
   763     Initializes the style option push button defined by \a option with the push 
   699     This method is useful for subclasses when they need a HbStyleOptionPushButton,
   764     button values. This method is useful for setting the style option push button 
   700     but don't want to fill in all the information themselves.
   765     values of the subclasses.
       
   766     
       
   767     \param option Style option push button to be initialized.
   701  */
   768  */
   702 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const
   769 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const
   703 {
   770 {
   704     Q_D( const HbPushButton );
   771     Q_D( const HbPushButton );
   705 
   772 
   721     }
   788     }
   722     option->backgroundFrameDrawer = ( d->backgroundFrameDrawer );
   789     option->backgroundFrameDrawer = ( d->backgroundFrameDrawer );
   723 }
   790 }
   724 
   791 
   725 /*!
   792 /*!
   726     \reimp
   793 
   727  */
   794  */
   728 void HbPushButton::keyPressEvent(QKeyEvent *event)
   795 void HbPushButton::keyPressEvent(QKeyEvent *event)
   729 {
   796 {
   730     Q_D( HbPushButton );
   797     Q_D( HbPushButton );
   731 
   798 
   757     HbAbstractButton::keyPressEvent(event);
   824     HbAbstractButton::keyPressEvent(event);
   758 }
   825 }
   759 
   826 
   760 
   827 
   761 /*!
   828 /*!
   762     \reimp
   829 
   763  */
   830  */
   764 void HbPushButton::keyReleaseEvent(QKeyEvent *event)
   831 void HbPushButton::keyReleaseEvent(QKeyEvent *event)
   765 {
   832 {
   766     Q_D(HbPushButton);
   833     Q_D(HbPushButton);
   767     switch(event->key()){
   834     switch(event->key()){
   789     }
   856     }
   790     HbAbstractButton::keyReleaseEvent( event );
   857     HbAbstractButton::keyReleaseEvent( event );
   791 }
   858 }
   792 
   859 
   793 /*!
   860 /*!
   794     \reimp
   861 
   795  */
   862  */
   796 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event )
   863 void HbPushButton::mousePressEvent( QGraphicsSceneMouseEvent *event )
   797 {
   864 {
   798 #ifndef HB_GESTURE_FW
   865 #ifndef HB_GESTURE_FW
   799     Q_D( HbPushButton );
   866     Q_D( HbPushButton );
   800     HbAbstractButton::mousePressEvent( event );
   867     HbAbstractButton::mousePressEvent( event );
   801     HbStyleOptionPushButton buttonOption;
   868     HbStyleOptionPushButton buttonOption;
   802     initStyleOption( &buttonOption );
   869     initStyleOption( &buttonOption );
   803     if( d->frameItem ) {
   870     if( d->frameItem ) {
   804         style()->updatePrimitive( d->frameItem, HbStyle::P_PushButton_background, &buttonOption );
   871         HbStylePrivate::updatePrimitive( d->frameItem, HbStylePrivate::P_PushButton_background, &buttonOption );
   805     }
   872     }
   806 #ifdef HB_EFFECTS
   873 #ifdef HB_EFFECTS
   807     if ( hitButton(event->pos()) ) {
   874     if ( hitButton(event->pos()) ) {
   808         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   875         HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   809     }
   876     }
   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" );
   855 }
   922 }
   856 #endif
   923 #endif
   857 
   924 
   858 
   925 
   859 #ifdef HB_GESTURE_FW
   926 #ifdef HB_GESTURE_FW
       
   927 
   860 void HbPushButton::gestureEvent( QGestureEvent *event )
   928 void HbPushButton::gestureEvent( QGestureEvent *event )
   861 {
   929 {
   862     Q_D(HbPushButton);
   930     Q_D(HbPushButton);
   863     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   931     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   864         bool hit = hitButton(mapFromScene(event->mapToGraphicsScene(tap->position())));
   932         bool hit = hitButton(mapFromScene(event->mapToGraphicsScene(tap->position())));
   866             case Qt::GestureStarted:
   934             case Qt::GestureStarted:
   867                 if( hit ){
   935                 if( hit ){
   868 #ifdef HB_EFFECTS
   936 #ifdef HB_EFFECTS
   869                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   937                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   870 #endif
   938 #endif
   871                     if( d->checkable && !d->checked) {
   939                    /* if( d->checkable && !d->checked) {
   872                         setProperty( "state", "latched" );
   940                         setProperty( "state", "latched" );
   873                     }else if(!d->checkable) {
   941                     }else if(!d->checkable) {
   874                         setProperty( "state", "pressed" );
   942                         setProperty( "state", "pressed" );
   875                     }
   943                     }*/
   876                 }
   944                 }
   877                 break;
   945                 break;
   878             case Qt::GestureUpdated:
   946             case Qt::GestureUpdated:
   879                 if(tap->tapStyleHint() == HbTapGesture::TapAndHold && hit) {
   947                 if(tap->tapStyleHint() == HbTapGesture::TapAndHold && hit) {
   880                     d->longPress = true;
   948                     d->longPress = true;
   888                 if( hit ){
   956                 if( hit ){
   889 #ifdef HB_EFFECTS
   957 #ifdef HB_EFFECTS
   890                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   958                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
   891 #endif
   959 #endif
   892                 }
   960                 }
   893                 if( d->checkable && !d->checked) {
   961                 /*if( d->checkable && !d->checked) {
   894                     setProperty( "state", "latched" );
   962                     setProperty( "state", "latched" );
   895                 }else {
   963                 }else {
   896                     setProperty( "state", "normal" );
   964                     setProperty( "state", "normal" );
   897                 }
   965                 }*/
   898                 break;
   966                 break;
   899             default:
   967             default:
   900                 break;
   968                 break;
   901         }
   969         }
   902     }
   970     }
   904 }
   972 }
   905 #endif
   973 #endif
   906 
   974 
   907 
   975 
   908 /*!
   976 /*!
   909     \reimp
   977     
   910  */
   978  */
   911 void HbPushButton::resizeEvent( QGraphicsSceneResizeEvent *event )
   979 void HbPushButton::resizeEvent( QGraphicsSceneResizeEvent *event )
   912 {
   980 {
   913     HbAbstractButton::resizeEvent( event );
   981     HbAbstractButton::resizeEvent( event );
   914 }
   982 }
   915 /*!
   983 
   916   reimp
   984 /*!
       
   985 
   917 
   986 
   918 */
   987 */
   919 void HbPushButton::polish( HbStyleParameters &params )
   988 void HbPushButton::polish( HbStyleParameters &params )
   920 {
   989 {
   921     Q_D( HbPushButton );
   990     Q_D( HbPushButton );
   926     HbAbstractButton::polish( params );
   995     HbAbstractButton::polish( params );
   927 }
   996 }
   928 
   997 
   929 
   998 
   930 /*!
   999 /*!
   931     \reimp
  1000 
   932  */
  1001  */
   933 void HbPushButton::focusInEvent( QFocusEvent *event )
  1002 void HbPushButton::focusInEvent( QFocusEvent *event )
   934 {
  1003 {
   935     Q_D( HbPushButton );
  1004     Q_D( HbPushButton );
   936     if( ( event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ) 
  1005     if( ( event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason ) 
   937         && ( d->navigationKeyPress ) ) {
  1006         && ( d->navigationKeyPress ) ) {
   938         if( d->focusItem ) {
  1007         if( !d->focusItem ) {
       
  1008             d->focusItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_PushButton_focus, this);
       
  1009         } else {
   939             d->focusItem->setVisible( true );
  1010             d->focusItem->setVisible( true );
   940             if( hasFocus() ) {
  1011             if( hasFocus() ) {
   941                 HbStyleOptionPushButton buttonOption;
  1012                 HbStyleOptionPushButton buttonOption;
   942                 initStyleOption( &buttonOption );
  1013                 initStyleOption( &buttonOption );
   943                 style()->updatePrimitive( d->focusItem,HbStyle::P_PushButton_focus, &buttonOption );
  1014                 HbStylePrivate::updatePrimitive( d->focusItem,HbStylePrivate::P_PushButton_focus, &buttonOption );
   944             }
  1015             }            
   945         } else {
       
   946             d->focusItem = style()->createPrimitive(HbStyle::P_PushButton_focus, this);
       
   947         }
  1016         }
   948     }
  1017     }
   949     HbAbstractButton::focusInEvent( event );
  1018     HbAbstractButton::focusInEvent( event );
   950 }
  1019 }
   951 
  1020 
   952 /*!
  1021 /*!
   953     \reimp
  1022 
   954  */
  1023  */
   955 void HbPushButton::focusOutEvent( QFocusEvent *event )
  1024 void HbPushButton::focusOutEvent( QFocusEvent *event )
   956 {
  1025 {
   957     Q_D( HbPushButton );
  1026     Q_D( HbPushButton );
   958     if( d->focusItem ) {
  1027     if( d->focusItem ) {
   960     }
  1029     }
   961     HbAbstractButton::focusOutEvent( event );
  1030     HbAbstractButton::focusOutEvent( event );
   962 }
  1031 }
   963 
  1032 
   964 /*!
  1033 /*!
   965     \reimp
  1034 
   966  */
  1035  */
   967 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value)
  1036 QVariant HbPushButton::itemChange(GraphicsItemChange change, const QVariant &value)
   968 {
  1037 {
   969     switch ( change ) {
  1038     switch ( change ) {
   970         case ItemEnabledHasChanged:
  1039         case ItemEnabledHasChanged:
   981     }
  1050     }
   982     return HbAbstractButton::itemChange( change, value );
  1051     return HbAbstractButton::itemChange( change, value );
   983 }
  1052 }
   984 
  1053 
   985 /*!
  1054 /*!
   986   Overloaded hit detection to include touch area
  1055   Overloaded hit detection to include touch area.
   987  */
  1056  */
   988 bool HbPushButton::hitButton( const QPointF &pos ) const
  1057 bool HbPushButton::hitButton( const QPointF &pos ) const
   989 {
  1058 {
   990     Q_D( const HbPushButton );
  1059     Q_D( const HbPushButton );
   991     QRectF compRect = d->touchArea->boundingRect( );
  1060     QRectF compRect = d->touchArea->boundingRect( );