src/hbwidgets/widgets/hbpushbutton.cpp
branchGCC_SURGE
changeset 15 f378acbc9cfb
parent 7 923ff622b8b9
child 21 4633027730f5
child 34 ed14f46c0e55
equal deleted inserted replaced
9:730c025d4b77 15:f378acbc9cfb
    40 
    40 
    41 #include <QGraphicsSceneMouseEvent>
    41 #include <QGraphicsSceneMouseEvent>
    42 #include <QTimer>
    42 #include <QTimer>
    43 #include <QGraphicsItem>
    43 #include <QGraphicsItem>
    44 #include <QDebug>
    44 #include <QDebug>
    45 
    45 #include <QCoreApplication>
       
    46 #include <QApplication>
    46 
    47 
    47 /*!
    48 /*!
    48     @beta
    49     @beta
    49     @hbwidgets
    50     @hbwidgets
    50     \class HbPushButton
    51     \class HbPushButton
   215         //only in case of keyboard focus events it will be Visible.
   216         //only in case of keyboard focus events it will be Visible.
   216         focusItem->setVisible( false );
   217         focusItem->setVisible( false );
   217     }
   218     }
   218 }
   219 }
   219 
   220 
   220 
       
   221 
       
   222 void HbPushButtonPrivate::_q_handleLongPress(QPointF point)
       
   223 {
       
   224     Q_Q(HbPushButton);
       
   225     if(!longPress){
       
   226         longPress = true;
       
   227         emit q->longPress( point );
       
   228     }
       
   229 }
       
   230 
       
   231 void HbPushButtonPrivate::_q_handleLongKeyPress( )
   221 void HbPushButtonPrivate::_q_handleLongKeyPress( )
   232 {
   222 {
   233     Q_Q( HbPushButton );
   223     Q_Q( HbPushButton );
   234     if(!longPress) {
   224     if(!longPress) {
   235         longPress = true;
   225         longPress = true;
   380         //updatePrimitives();
   370         //updatePrimitives();
   381         if( d->textItem ) {
   371         if( d->textItem ) {
   382             HbStyleOptionPushButton buttonOption;
   372             HbStyleOptionPushButton buttonOption;
   383             initStyleOption( &buttonOption );
   373             initStyleOption( &buttonOption );
   384             style( )->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption);
   374             style( )->updatePrimitive( d->textItem, HbStyle::P_PushButton_text, &buttonOption);
       
   375             if ( isEnabled() ) {
       
   376                 setProperty("state", "normal");
       
   377             }
   385         }
   378         }
   386         if(doPolish) {
   379         if(doPolish) {
   387             repolish( );
   380             repolish( );
   388         }
   381         }
   389     }
   382     }
   422         // updatePrimitives();
   415         // updatePrimitives();
   423         if( d->additionalTextItem ) {
   416         if( d->additionalTextItem ) {
   424             HbStyleOptionPushButton buttonOption;
   417             HbStyleOptionPushButton buttonOption;
   425             initStyleOption( &buttonOption );
   418             initStyleOption( &buttonOption );
   426             style( )->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption);
   419             style( )->updatePrimitive( d->additionalTextItem, HbStyle::P_PushButton_additionaltext, &buttonOption);
       
   420             if ( isEnabled() ) {
       
   421                 setProperty("state", "normal");
       
   422             }
   427         }
   423         }
   428         if( doPolish ) {
   424         if( doPolish ) {
   429             repolish();
   425             repolish();
   430         }
   426         }
   431     }
   427     }
   454 void HbPushButton::setIcon( const HbIcon &icon )
   450 void HbPushButton::setIcon( const HbIcon &icon )
   455 {
   451 {
   456     Q_D(HbPushButton);
   452     Q_D(HbPushButton);
   457 
   453 
   458     if ( d->icon != icon ) {
   454     if ( d->icon != icon ) {
   459         bool doPolish = icon.isNull( ) || d->icon.isNull();
   455         //checking for d->polished to avoid extra polish loop
       
   456         bool doPolish = (icon.isNull( ) || d->icon.isNull()) && d->polished;
   460         d->icon = icon;
   457         d->icon = icon;
   461         d->createPrimitives( );
   458         d->createPrimitives( );
   462         //updatePrimitives();
   459         //updatePrimitives();
   463         if( d->iconItem ) {
   460         if( d->iconItem ) {
   464             HbStyleOptionPushButton buttonOption;
   461             HbStyleOptionPushButton buttonOption;
   465             initStyleOption( &buttonOption );
   462             initStyleOption( &buttonOption );
   466             style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
   463             style()->updatePrimitive( d->iconItem, HbStyle::P_PushButton_icon, &buttonOption );
       
   464             if ( isEnabled() ) {
       
   465                 setProperty("state", "normal");
       
   466             } 
   467 
   467 
   468         }
   468         }
   469         if( doPolish ) {
   469         if( doPolish ) {
   470             repolish();
   470             repolish();
   471         }
   471         }
   692     HbAbstractButton(dd, parent)
   692     HbAbstractButton(dd, parent)
   693 {
   693 {
   694 }
   694 }
   695 
   695 
   696 /*!
   696 /*!
       
   697     \reimp
   697     Initializes \a option with the values from this HbPushButton. 
   698     Initializes \a option with the values from this HbPushButton. 
   698     This method is useful for subclasses when they need a HbStyleOptionPushButton,
   699     This method is useful for subclasses when they need a HbStyleOptionPushButton,
   699     but don't want to fill in all the information themselves.
   700     but don't want to fill in all the information themselves.
   700  */
   701  */
   701 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const
   702 void HbPushButton::initStyleOption( HbStyleOptionPushButton *option ) const
   745             }
   746             }
   746             break;
   747             break;
   747         case Qt::Key_Up:
   748         case Qt::Key_Up:
   748         case Qt::Key_Left:
   749         case Qt::Key_Left:
   749         case Qt::Key_Right:
   750         case Qt::Key_Right:
   750         case Qt::Key_Down:{
   751         case Qt::Key_Down:
       
   752             if( d->keyNavigation()) {
   751                 d->navigationKeyPress = true;
   753                 d->navigationKeyPress = true;
   752             }
   754             }
   753             break;       
   755             break;       
   754     }
   756     }
   755     HbAbstractButton::keyPressEvent(event);
   757     HbAbstractButton::keyPressEvent(event);
   777             }
   779             }
   778             break;
   780             break;
   779             case Qt::Key_Up:
   781             case Qt::Key_Up:
   780             case Qt::Key_Left:
   782             case Qt::Key_Left:
   781             case Qt::Key_Right:
   783             case Qt::Key_Right:
   782             case Qt::Key_Down:{
   784             case Qt::Key_Down:
       
   785                 if ( d->keyNavigation() ) {
   783                     d->navigationKeyPress = false;
   786                     d->navigationKeyPress = false;
   784                 }
   787                 }
   785             break;       
   788             break;       
   786     }
   789     }
   787     HbAbstractButton::keyReleaseEvent( event );
   790     HbAbstractButton::keyReleaseEvent( event );
   856 #ifdef HB_GESTURE_FW
   859 #ifdef HB_GESTURE_FW
   857 void HbPushButton::gestureEvent( QGestureEvent *event )
   860 void HbPushButton::gestureEvent( QGestureEvent *event )
   858 {
   861 {
   859     Q_D(HbPushButton);
   862     Q_D(HbPushButton);
   860     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
   863     if(HbTapGesture *tap = qobject_cast<HbTapGesture *>(event->gesture(Qt::TapGesture))) {
       
   864         bool hit = hitButton(mapFromScene(event->mapToGraphicsScene(tap->position())));
   861         switch(tap->state()) {
   865         switch(tap->state()) {
   862         case Qt::GestureStarted:{
   866             case Qt::GestureStarted:
       
   867                 if( hit ){
   863 #ifdef HB_EFFECTS
   868 #ifdef HB_EFFECTS
   864                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   869                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "pressed" );
   865 #endif
   870 #endif
       
   871                     if( d->checkable && !d->checked) {
       
   872                         setProperty( "state", "latched" );
       
   873                     }else if(!d->checkable) {
       
   874                         setProperty( "state", "pressed" );
       
   875                     }
       
   876                 }
       
   877                 break;
       
   878             case Qt::GestureUpdated:
       
   879                 if(tap->tapStyleHint() == HbTapGesture::TapAndHold && hit) {
       
   880                     d->longPress = true;
       
   881                     emit longPress( event->mapToGraphicsScene(tap->position()) );
       
   882                 }
       
   883                 break;
       
   884             case Qt::GestureCanceled:
       
   885                 setProperty( "state", "normal" );
       
   886                 break;
       
   887             case Qt::GestureFinished:
       
   888                 if( hit ){
       
   889 #ifdef HB_EFFECTS
       
   890                     HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
       
   891 #endif
       
   892                 }
   866                 if( d->checkable && !d->checked) {
   893                 if( d->checkable && !d->checked) {
   867                     setProperty( "state", "latched" );
   894                     setProperty( "state", "latched" );
   868                 }else if(!d->checkable) {
   895                 }else {
   869                     setProperty( "state", "pressed" );
       
   870                 }
       
   871             }
       
   872             break;
       
   873         case Qt::GestureUpdated:
       
   874             if(tap->tapStyleHint() == HbTapGesture::TapAndHold) {
       
   875                 d->longPress = true;
       
   876                 emit longPress( event->mapToGraphicsScene(tap->position()) );
       
   877             }
       
   878             break;
       
   879         case Qt::GestureCanceled:
       
   880             setProperty( "state", "normal" );
       
   881             break;
       
   882         case Qt::GestureFinished:{
       
   883 #ifdef HB_EFFECTS
       
   884                 HbEffect::start( this, HB_PUSHBUTTON_TYPE, "released" );
       
   885 #endif
       
   886                 if( d->checkable && !d->checked) {
       
   887                     setProperty( "state", "latched" );
       
   888                 }else {                    
       
   889                     setProperty( "state", "normal" );
   896                     setProperty( "state", "normal" );
   890                 }
   897                 }
   891 
   898                 break;
   892             }
   899             default:
   893             break;
   900                 break;
   894         default:
   901         }
   895             break;
   902     }
   896         }
       
   897     }
       
   898 
       
   899     HbAbstractButton::gestureEvent( event );
   903     HbAbstractButton::gestureEvent( event );
   900 
       
   901 }
   904 }
   902 #endif
   905 #endif
   903 
   906 
   904 
   907 
   905 /*!
   908 /*!