src/hbwidgets/widgets/hbgroupboxheadingwidget_p.cpp
changeset 21 4633027730f5
parent 7 923ff622b8b9
child 23 e6ad4ef83b23
equal deleted inserted replaced
7:923ff622b8b9 21:4633027730f5
    91 */
    91 */
    92 void HbGroupBoxHeadingWidget::createPrimitives()
    92 void HbGroupBoxHeadingWidget::createPrimitives()
    93 {
    93 {
    94     if( groupBoxType == GroupBoxCollapsingContainer && groupBox->isCollapsable() ){
    94     if( groupBoxType == GroupBoxCollapsingContainer && groupBox->isCollapsable() ){
    95         if ( !mIconItem ) {
    95         if ( !mIconItem ) {
    96             mIconItem = style( )->createPrimitive( HbStyle::P_GroupBoxHeading_icon , this );
    96             mIconItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_GroupBoxHeading_icon , this );
    97         }
    97         }
    98     }
    98     }
    99     else if ( mIconItem ) {
    99     else if ( mIconItem ) {
   100         delete mIconItem;
   100         delete mIconItem;
   101         mIconItem = 0;
   101         mIconItem = 0;
   103     if ( mTextItem ) {
   103     if ( mTextItem ) {
   104         delete mTextItem;
   104         delete mTextItem;
   105         mTextItem = 0;
   105         mTextItem = 0;
   106     }
   106     }
   107     if ( groupBoxType == GroupBoxCollapsingContainer ) {
   107     if ( groupBoxType == GroupBoxCollapsingContainer ) {
   108         mTextItem = style( )->createPrimitive( HbStyle::P_GroupBoxHeading_text , this );
   108         mTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_GroupBoxHeading_text , this );
   109     }
   109     }
   110     else {
   110     else {
   111         mTextItem = style( )->createPrimitive( HbStyle::P_GroupBoxMarquee_text , this );
   111         mTextItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_GroupBoxMarquee_text , this );
   112     }
   112     }
   113 
   113 
   114     if ( !mBackgroundItem ) {
   114     if ( !mBackgroundItem ) {
   115         mBackgroundItem = style( )->createPrimitive( HbStyle::P_GroupBoxHeading_background , this );
   115         mBackgroundItem = HbStylePrivate::createPrimitive( HbStylePrivate::P_GroupBoxHeading_background , this );
   116         style( )->setItemName( mBackgroundItem , "background" );
   116         HbStyle::setItemName( mBackgroundItem , "background" );
   117     }
   117     }
   118 }
   118 }
   119 
   119 
   120 /*!
   120 /*!
   121     update primitives
   121     update primitives
   124 {
   124 {
   125     HbStyleOptionGroupBox option;
   125     HbStyleOptionGroupBox option;
   126     initStyleOption( &option );
   126     initStyleOption( &option );
   127    
   127    
   128     if ( mIconItem ) {
   128     if ( mIconItem ) {
   129             style( )->updatePrimitive( mIconItem , HbStyle::P_GroupBoxHeading_icon , &option );
   129             HbStylePrivate::updatePrimitive( mIconItem , HbStylePrivate::P_GroupBoxHeading_icon , &option );
   130     }       
   130     }       
   131     if ( mTextItem ) {
   131     if ( mTextItem ) {
   132         if ( groupBoxType == GroupBoxCollapsingContainer ) {
   132         if ( groupBoxType == GroupBoxCollapsingContainer ) {
   133             style( )->updatePrimitive( mTextItem , HbStyle::P_GroupBoxHeading_text , &option );
   133             HbStylePrivate::updatePrimitive( mTextItem , HbStylePrivate::P_GroupBoxHeading_text , &option );
   134         }
   134         }
   135         else {
   135         else {
   136             style( )->updatePrimitive( mTextItem , HbStyle::P_GroupBoxMarquee_text , &option );
   136             HbStylePrivate::updatePrimitive( mTextItem , HbStylePrivate::P_GroupBoxMarquee_text , &option );
   137         }        
   137         }        
   138     }
   138     }
   139     if ( mBackgroundItem ) {
   139     if ( mBackgroundItem ) {
   140         style( )->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &option );
   140         HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_GroupBoxHeading_background , &option );
   141     }
   141     }
   142 }
   142 }
   143 
   143 
   144 /*
   144 /*
   145     internal
   145     internal
   150 
   150 
   151 #ifdef HB_EFFECTS
   151 #ifdef HB_EFFECTS
   152     HbEffectInternal::add( HB_GROUPBOX_HEADING_TYPE,"groupbox_icon_click", "iconclick" );
   152     HbEffectInternal::add( HB_GROUPBOX_HEADING_TYPE,"groupbox_icon_click", "iconclick" );
   153 #endif 
   153 #endif 
   154 
   154 
   155     connect ( this , SIGNAL ( clicked(bool) ) , groupBox , SLOT ( setCollapsed(bool) ) );
   155     connect(this, SIGNAL(clicked(bool)), groupBox, SLOT(setCollapsed(bool)));
   156 }
   156 }
   157 
   157 
   158 /*!
   158 /*!
   159     internal
   159     internal
   160     Sets the groupbox heading widgets type.
   160     Sets the groupbox heading widgets type.
   200         headingText = text;
   200         headingText = text;
   201 
   201 
   202         HbStyleOptionGroupBox groupBoxOption;
   202         HbStyleOptionGroupBox groupBoxOption;
   203         initStyleOption( &groupBoxOption );
   203         initStyleOption( &groupBoxOption );
   204         if ( groupBoxType == GroupBoxCollapsingContainer ) {
   204         if ( groupBoxType == GroupBoxCollapsingContainer ) {
   205             style( )->updatePrimitive( mTextItem , HbStyle::P_GroupBoxHeading_text , &groupBoxOption );
   205             HbStylePrivate::updatePrimitive( mTextItem , HbStylePrivate::P_GroupBoxHeading_text , &groupBoxOption );
   206         }
   206         }
   207         else {
   207         else {
   208            style( )->updatePrimitive( mTextItem , HbStyle::P_GroupBoxMarquee_text , &groupBoxOption );
   208            HbStylePrivate::updatePrimitive( mTextItem , HbStylePrivate::P_GroupBoxMarquee_text , &groupBoxOption );
   209         }
   209         }
   210     }
   210     }
   211 }
   211 }
   212 
   212 
   213 /*!
   213 /*!
   219     if( marqueeEnabled != marquee ){
   219     if( marqueeEnabled != marquee ){
   220         marqueeEnabled  = marquee;
   220         marqueeEnabled  = marquee;
   221 
   221 
   222         HbStyleOptionGroupBox groupBoxOption;
   222         HbStyleOptionGroupBox groupBoxOption;
   223         initStyleOption( &groupBoxOption );
   223         initStyleOption( &groupBoxOption );
   224         style()->updatePrimitive( mTextItem, HbStyle::P_GroupBoxMarquee_text, &groupBoxOption);
   224         HbStylePrivate::updatePrimitive( mTextItem, HbStylePrivate::P_GroupBoxMarquee_text, &groupBoxOption);
   225     }
   225     }
   226 }
   226 }
   227 
   227 
   228 /*!
   228 /*!
   229 
   229 
   234     Will return NULL if \a primitive passed is invalid
   234     Will return NULL if \a primitive passed is invalid
   235 */
   235 */
   236 QGraphicsItem *HbGroupBoxHeadingWidget::primitive( HbStyle::Primitive primitive ) const
   236 QGraphicsItem *HbGroupBoxHeadingWidget::primitive( HbStyle::Primitive primitive ) const
   237 {
   237 {
   238     switch (primitive) {
   238     switch (primitive) {
   239         case HbStyle::P_GroupBoxHeading_icon:
   239         case HbStylePrivate::P_GroupBoxHeading_icon:
   240             return mIconItem;
   240             return mIconItem;
   241         case HbStyle::P_GroupBoxHeading_text:
   241         case HbStylePrivate::P_GroupBoxHeading_text:
   242         case HbStyle::P_GroupBoxMarquee_text:
   242         case HbStylePrivate::P_GroupBoxMarquee_text:
   243             return mTextItem;
   243             return mTextItem;
   244         case HbStyle::P_GroupBoxHeading_background:
   244         case HbStylePrivate::P_GroupBoxHeading_background:
   245             return mBackgroundItem;
   245             return mBackgroundItem;
   246         default:
   246         default:
   247             return 0;
   247             return 0;
   248     }
   248     }
   249 }
   249 }
   318     // background primitive updation, upon mouse press
   318     // background primitive updation, upon mouse press
   319     headingPressed = true;
   319     headingPressed = true;
   320 
   320 
   321     HbStyleOptionGroupBox groupBoxOption;
   321     HbStyleOptionGroupBox groupBoxOption;
   322     initStyleOption( &groupBoxOption );
   322     initStyleOption( &groupBoxOption );
   323     style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
   323     HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_GroupBoxHeading_background , &groupBoxOption );
   324 
   324 
   325     setProperty( "state", "pressed" );
   325     setProperty( "state", "pressed" );
   326 #endif  
   326 #endif  
   327 }
   327 }
   328 
   328 
   354     // background primitive updation, upon mouse release
   354     // background primitive updation, upon mouse release
   355     headingPressed = false;
   355     headingPressed = false;
   356 
   356 
   357     HbStyleOptionGroupBox groupBoxOption;
   357     HbStyleOptionGroupBox groupBoxOption;
   358     initStyleOption( &groupBoxOption );
   358     initStyleOption( &groupBoxOption );
   359     style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
   359     HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_GroupBoxHeading_background , &groupBoxOption );
   360 
   360 
   361     setProperty( "state", "normal" );
   361     setProperty( "state", "normal" );
   362 #endif 
   362 #endif 
   363 }
   363 }
   364 
   364 
   365 #ifdef HB_GESTURE_FW
   365 #ifdef HB_GESTURE_FW
   366 void HbGroupBoxHeadingWidget::gestureEvent(QGestureEvent *event)
   366 void HbGroupBoxHeadingWidget::gestureEvent(QGestureEvent *event)
   367 {
   367 {
   368     if(HbTapGesture *tap = qobject_cast<HbTapGesture*>( event->gesture( Qt::TapGesture ) ) ) {
   368     if(HbTapGesture *tap = qobject_cast<HbTapGesture*>( event->gesture( Qt::TapGesture ) ) ) {
   369         switch( tap->state() ) {
   369         //only in case of collapsing container heading will take events
   370         case Qt::GestureStarted:  //
   370         if(groupBoxType == GroupBoxCollapsingContainer){
   371             {
   371             switch( tap->state() ) {
   372                 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
   372                 case Qt::GestureStarted:  //
   373                 if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
   373                     {
   374                     tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
   374                         scene()->setProperty(HbPrivate::OverridingGesture.latin1(),Qt::TapGesture);
   375                 }
   375                         if (!tap->property(HbPrivate::ThresholdRect.latin1()).toRect().isValid()) {
   376 
   376                             tap->setProperty(HbPrivate::ThresholdRect.latin1(), mapRectToScene(boundingRect()).toRect());
   377                 if ( !(groupBox->isCollapsable( )) ){
   377                         }
   378                     event->ignore( tap );
   378 
   379                     return;
   379                         if ( !(groupBox->isCollapsable( )) ){
   380                 }
   380                             event->ignore( tap );
   381                 if ( groupBox->isCollapsable( ) ) {
   381                             return;
   382                     HbWidgetFeedback::triggered( this, Hb::InstantPressed, Hb::ModifierCollapsedItem );
   382                         }
   383                 }
   383                         if ( groupBox->isCollapsable( ) ) {
   384                 else {
   384                             HbWidgetFeedback::triggered( this, Hb::InstantPressed, Hb::ModifierCollapsedItem );
   385                     HbWidgetFeedback::triggered( this, Hb::InstantPressed );
   385                         }
   386                 }
   386                         else {
   387 
   387                             HbWidgetFeedback::triggered( this, Hb::InstantPressed );
   388                 // background primitive updation, upon mouse press
   388                         }
   389                 headingPressed = true;
   389 
   390 
   390                         // background primitive updation, upon mouse press
   391                 HbStyleOptionGroupBox groupBoxOption;
   391                         headingPressed = true;
   392                 initStyleOption( &groupBoxOption );
   392 
   393                 style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
   393                         HbStyleOptionGroupBox groupBoxOption;
   394 
   394                         initStyleOption( &groupBoxOption );
   395                 setProperty( "state", "pressed" );
   395                         HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_GroupBoxHeading_background , &groupBoxOption );
       
   396 
       
   397                         setProperty( "state", "pressed" );
       
   398                     }
       
   399 
       
   400                     break;
       
   401                 case Qt::GestureCanceled: // Reset state
       
   402                     {
       
   403                         scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   404 
       
   405                         headingPressed = false;
       
   406 
       
   407                         HbStyleOptionGroupBox groupBoxOption;
       
   408                         initStyleOption( &groupBoxOption );
       
   409                         HbStylePrivate::updatePrimitive( mBackgroundItem , HbStylePrivate::P_GroupBoxHeading_background , &groupBoxOption );
       
   410 
       
   411                         setProperty( "state", "normal" );
       
   412                         break;
       
   413                     }
       
   414                 case Qt::GestureFinished: // emit clicked
       
   415                     {
       
   416                         scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   417 
       
   418                         if ( groupBox->isCollapsable( ) ) {
       
   419                             HbWidgetFeedback::triggered( this, Hb::InstantReleased, Hb::ModifierCollapsedItem );
       
   420                         } else {
       
   421                             HbWidgetFeedback::triggered( this, Hb::InstantReleased );
       
   422                         }
       
   423 
       
   424                         if ( this->isUnderMouse() ) {
       
   425                             if ( mIconItem && mIconItem->isUnderMouse( ) ) {
       
   426                             #ifdef HB_EFFECTS
       
   427                                 HbEffect::start( mIconItem, HB_GROUPBOX_HEADING_TYPE, "iconclick" );
       
   428                             #endif
       
   429                             }
       
   430                             emit clicked( !(groupBox->isCollapsed()) );
       
   431                         }
       
   432                         // background primitive updation, upon mouse release
       
   433                         headingPressed = false;
       
   434 
       
   435                         HbStyleOptionGroupBox groupBoxOption;
       
   436                         initStyleOption( &groupBoxOption );
       
   437                         HbStylePrivate::updatePrimitive( mBackgroundItem, HbStylePrivate::P_GroupBoxHeading_background, &groupBoxOption );
       
   438 
       
   439                         setProperty( "state", "normal" );
       
   440                     }
       
   441                     break;
       
   442                 default:
       
   443                     break;
   396             }
   444             }
   397 
   445 
   398             break;
       
   399         case Qt::GestureCanceled: // Reset state
       
   400             {
       
   401                 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   402 
       
   403                 headingPressed = false;
       
   404 
       
   405                 HbStyleOptionGroupBox groupBoxOption;
       
   406                 initStyleOption( &groupBoxOption );
       
   407                 style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
       
   408 
       
   409                 setProperty( "state", "normal" );
       
   410                 break;
       
   411             }
       
   412         case Qt::GestureFinished: // emit clicked
       
   413             {
       
   414                 scene()->setProperty(HbPrivate::OverridingGesture.latin1(),QVariant());
       
   415 
       
   416                 if ( groupBox->isCollapsable( ) ) {
       
   417                     HbWidgetFeedback::triggered( this, Hb::InstantReleased, Hb::ModifierCollapsedItem );
       
   418                 } else {
       
   419                     HbWidgetFeedback::triggered( this, Hb::InstantReleased );
       
   420                 }
       
   421 
       
   422                 if ( this->isUnderMouse() ) {
       
   423                     if ( mIconItem && mIconItem->isUnderMouse( ) ) {
       
   424 #ifdef HB_EFFECTS
       
   425                         HbEffect::start( mIconItem, HB_GROUPBOX_HEADING_TYPE, "iconclick" );
       
   426 #endif
       
   427                     }
       
   428                     emit clicked( !(groupBox->isCollapsed()) );
       
   429                 }
       
   430                 // background primitive updation, upon mouse release
       
   431                 headingPressed = false;
       
   432 
       
   433                 HbStyleOptionGroupBox groupBoxOption;
       
   434                 initStyleOption( &groupBoxOption );
       
   435                 style()->updatePrimitive( mBackgroundItem, HbStyle::P_GroupBoxHeading_background, &groupBoxOption );
       
   436 
       
   437                 setProperty( "state", "normal" );
       
   438             }
       
   439             break;
       
   440         default:
       
   441             break;
       
   442         }
   446         }
   443     }
   447     }
   444 }
   448 }
   445 #endif 
   449 #endif 
   446 
   450