src/hbwidgets/widgets/hbgroupboxheadingwidget_p.cpp
changeset 0 16d8024aca5e
child 1 f7ac710697a9
equal deleted inserted replaced
-1:000000000000 0:16d8024aca5e
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (developer.feedback@nokia.com)
       
     6 **
       
     7 ** This file is part of the HbWidgets module of the UI Extensions for Mobile.
       
     8 **
       
     9 ** GNU Lesser General Public License Usage
       
    10 ** This file may be used under the terms of the GNU Lesser General Public
       
    11 ** License version 2.1 as published by the Free Software Foundation and
       
    12 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
       
    13 ** Please review the following information to ensure the GNU Lesser General
       
    14 ** Public License version 2.1 requirements will be met:
       
    15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    16 **
       
    17 ** In addition, as a special exception, Nokia gives you certain additional
       
    18 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    20 **
       
    21 ** If you have questions regarding the use of this file, please contact
       
    22 ** Nokia at developer.feedback@nokia.com.
       
    23 **
       
    24 ****************************************************************************/
       
    25 
       
    26 #include "hbgroupboxheadingwidget_p.h"
       
    27 
       
    28 #include <hbstyleoptiongroupbox.h>
       
    29 #include <hbwidgetfeedback.h>
       
    30 
       
    31 #ifdef HB_EFFECTS
       
    32 #include <hbeffect.h>
       
    33 #include "hbeffectinternal_p.h"
       
    34 #define HB_GROUPBOX_HEADING_TYPE "HB_GROUPBOX_HEADING"
       
    35 #endif
       
    36 
       
    37 #include <QGraphicsSceneMouseEvent>
       
    38 
       
    39 /*
       
    40     internal
       
    41     constructs HbGroupBoxHeadingWidget
       
    42 
       
    43     HbGroupBoxHeadingWidget is internal to HbGroupBox, and is applicable to SimpleLabel and
       
    44     CollapsingContainer type.
       
    45     
       
    46     HbGroupBoxHeadingWidget holds the heading text and allows the groupBox to set marquee on it.
       
    47 
       
    48 */
       
    49 HbGroupBoxHeadingWidget::HbGroupBoxHeadingWidget(QGraphicsItem *parent ) :
       
    50     HbWidget(parent),
       
    51     mIconItem( 0 ),
       
    52     mTextItem( 0 ),
       
    53     mBackgroundItem( 0 ),
       
    54     collapsable( true ),
       
    55     collapsed( false),
       
    56     marqueeEnabled( false ),
       
    57     headingPressed(false)
       
    58 {
       
    59     groupBox = qgraphicsitem_cast<HbGroupBox*>( parent );
       
    60     init();
       
    61     setProperty("state", "normal");
       
    62 }
       
    63 
       
    64 /*
       
    65     internal
       
    66     Destructs HbGroupBoxHeadingWidget
       
    67 */
       
    68 HbGroupBoxHeadingWidget::~HbGroupBoxHeadingWidget()
       
    69 {
       
    70 }
       
    71 
       
    72 /*
       
    73     internal
       
    74     init
       
    75 */
       
    76 void HbGroupBoxHeadingWidget::init()
       
    77 {
       
    78     createPrimitives();
       
    79 	
       
    80     if(groupBoxType == GroupBoxCollapsingContainer){
       
    81         createConnection();    
       
    82     }
       
    83 }
       
    84 
       
    85 /*
       
    86   create primitives
       
    87 */
       
    88 void HbGroupBoxHeadingWidget::createPrimitives()
       
    89 {
       
    90     if(groupBoxType == GroupBoxCollapsingContainer && collapsable){
       
    91         if ( !mIconItem ) {
       
    92             mIconItem = style()->createPrimitive( HbStyle::P_GroupBoxHeading_icon , this );
       
    93         }
       
    94     }
       
    95     else if ( mIconItem ) {
       
    96         delete mIconItem;
       
    97         mIconItem = 0;
       
    98     }
       
    99     if ( mTextItem ) {
       
   100         delete mTextItem;
       
   101         mTextItem = 0 ;
       
   102     }
       
   103     if ( groupBoxType == GroupBoxCollapsingContainer ) {
       
   104         mTextItem = style()->createPrimitive( HbStyle::P_GroupBoxHeading_text , this );
       
   105     }
       
   106     else {
       
   107         mTextItem = style()->createPrimitive( HbStyle::P_GroupBoxMarquee_text , this );
       
   108     }
       
   109 
       
   110     if ( !mBackgroundItem ) {
       
   111         mBackgroundItem = style()->createPrimitive( HbStyle::P_GroupBoxHeading_background , this );
       
   112         style()->setItemName( mBackgroundItem , "background" );
       
   113     }
       
   114 }
       
   115 
       
   116 /*!
       
   117     update primitives
       
   118  */
       
   119 void HbGroupBoxHeadingWidget::updatePrimitives()
       
   120 {
       
   121     HbStyleOptionGroupBox option;
       
   122     initStyleOption( &option );
       
   123    
       
   124     if ( mIconItem ) {
       
   125             style()->updatePrimitive( mIconItem , HbStyle::P_GroupBoxHeading_icon , &option );
       
   126     }       
       
   127     if ( mTextItem ) {
       
   128         if ( groupBoxType == GroupBoxCollapsingContainer ) {
       
   129             style()->updatePrimitive( mTextItem , HbStyle::P_GroupBoxHeading_text , &option );
       
   130         }
       
   131         else {
       
   132             style()->updatePrimitive( mTextItem , HbStyle::P_GroupBoxMarquee_text , &option );
       
   133         }        
       
   134     }
       
   135     if ( mBackgroundItem ) {
       
   136         style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &option );
       
   137     }
       
   138 }
       
   139 
       
   140 /*
       
   141     internal
       
   142     creates signal connection for headingwidget based on type
       
   143 */
       
   144 void HbGroupBoxHeadingWidget::createConnection()
       
   145 {
       
   146 
       
   147 #ifdef HB_EFFECTS
       
   148     HbEffectInternal::add(HB_GROUPBOX_HEADING_TYPE,"groupbox_icon_click", "iconclick");
       
   149 #endif 
       
   150 
       
   151     connect ( this , SIGNAL ( clicked(bool) ) , groupBox , SLOT ( setCollapsed(bool) ));
       
   152 }
       
   153 
       
   154 /*!
       
   155     internal
       
   156     Sets the groupbox heading widgets type.
       
   157     Create primitves & connect signals if needed based on type set
       
   158 */
       
   159 void HbGroupBoxHeadingWidget::setType(GroupBoxType type)
       
   160 {
       
   161     if ( groupBoxType == type )
       
   162         return;
       
   163     groupBoxType = type;
       
   164     // setting dynamic properties for type
       
   165     if(groupBoxType == GroupBoxCollapsingContainer)
       
   166         setProperty("groupBoxType",3);
       
   167     else if(groupBoxType == GroupBoxSimpleLabel)
       
   168         setProperty("groupBoxType",1);
       
   169 
       
   170     if(groupBoxType != GroupBoxRichLabel){
       
   171         createPrimitives();
       
   172     }
       
   173 
       
   174     if(groupBoxType == GroupBoxCollapsingContainer){
       
   175         createConnection(); 
       
   176         // collapsed is false by default for CollapsingContainer
       
   177         collapsed = false; 
       
   178         // marquee is disabled by default for CollapsingContainer
       
   179         marqueeEnabled = false;			
       
   180     }
       
   181 
       
   182     if(groupBoxType == GroupBoxSimpleLabel){
       
   183         // marquee is disabled by default for simple label
       
   184         marqueeEnabled = false;			
       
   185     }
       
   186 
       
   187 }
       
   188 
       
   189 /*!
       
   190     internal
       
   191     Sets the groupbox heading widgets text
       
   192 */
       
   193 void HbGroupBoxHeadingWidget::setHeading(const QString &text)
       
   194 {
       
   195     if( headingText == text ) 
       
   196         return;
       
   197 
       
   198     headingText = text;
       
   199 
       
   200     HbStyleOptionGroupBox groupBoxOption;
       
   201     initStyleOption(&groupBoxOption);
       
   202     if ( groupBoxType == GroupBoxCollapsingContainer ) {
       
   203         style()->updatePrimitive( mTextItem , HbStyle::P_GroupBoxHeading_text , &groupBoxOption );
       
   204     }
       
   205     else {
       
   206        style()->updatePrimitive( mTextItem , HbStyle::P_GroupBoxMarquee_text , &groupBoxOption );
       
   207     }
       
   208 }
       
   209 
       
   210 /*!
       
   211     internal
       
   212     Sets marquee for groupbox heading
       
   213 */
       
   214 void HbGroupBoxHeadingWidget::setMarqueeHeading( bool marquee )
       
   215 {
       
   216     if( marqueeEnabled == marquee )
       
   217         return;
       
   218 
       
   219     marqueeEnabled  = marquee;
       
   220 
       
   221     HbStyleOptionGroupBox groupBoxOption;
       
   222     initStyleOption(&groupBoxOption);
       
   223     style()->updatePrimitive( mTextItem, HbStyle::P_GroupBoxMarquee_text, &groupBoxOption);
       
   224 }
       
   225 
       
   226 /*!
       
   227     Returns the pointer for \a primitive passed.
       
   228     Will return NULL if \a primitive passed is invalid
       
   229 */
       
   230 QGraphicsItem* HbGroupBoxHeadingWidget::primitive(HbStyle::Primitive primitive) const
       
   231 {
       
   232     switch (primitive) {
       
   233         case HbStyle::P_GroupBoxHeading_icon:
       
   234             return mIconItem;
       
   235         case HbStyle::P_GroupBoxHeading_text:
       
   236         case HbStyle::P_GroupBoxMarquee_text:
       
   237             return mTextItem;
       
   238         case HbStyle::P_GroupBoxHeading_background:
       
   239             return mBackgroundItem;
       
   240         default:
       
   241             return 0;
       
   242     }
       
   243 }
       
   244 
       
   245 /*!
       
   246     \reimp
       
   247     Initialize \a option with the values from this HbGroupBox. This method
       
   248     is useful for subclasses when they need a HbStyleOptionGroupBox, but don't want
       
   249     to fill in all the information themselves.
       
   250 */
       
   251 void HbGroupBoxHeadingWidget::initStyleOption(HbStyleOptionGroupBox *option) const
       
   252 {
       
   253     HbWidget::initStyleOption( option );
       
   254     option->collapsed = collapsed;
       
   255     option->heading = headingText;
       
   256     option->marqueeEnabled = marqueeEnabled;
       
   257     // state & type info reqd fo background primitve updation
       
   258     if (headingPressed ) {
       
   259         option->state = QStyle::State_On;
       
   260     } else {
       
   261         option->state = QStyle::State_Off;
       
   262     }
       
   263     if(groupBoxType == GroupBoxCollapsingContainer)
       
   264         option->groupBoxType = HbStyleOptionGroupBox::GroupBoxCollapsingContainer;
       
   265     else if(groupBoxType == GroupBoxSimpleLabel)
       
   266         option->groupBoxType = HbStyleOptionGroupBox::GroupBoxSimpleLabel;
       
   267 }
       
   268 
       
   269 /*!
       
   270     \reimp
       
   271  */
       
   272 QVariant HbGroupBoxHeadingWidget::itemChange(GraphicsItemChange change, const QVariant &value)
       
   273 {
       
   274     switch ( change ) {
       
   275         case ItemVisibleHasChanged: {
       
   276             /*if (value.toBool() == true){
       
   277                 if (mTextItem) {
       
   278                     HbStyleOptionGroupBox groupBoxOption;
       
   279                     initStyleOption(&groupBoxOption);
       
   280                     style()->updatePrimitive( mTextItem, HbStyle::P_GroupBoxHeading_text, &groupBoxOption);
       
   281                 }
       
   282             }*/
       
   283             }
       
   284             break;
       
   285 
       
   286         case ItemSceneHasChanged: {
       
   287             if(!value.isNull())
       
   288 
       
   289 
       
   290             updatePrimitives();
       
   291             }
       
   292             break;
       
   293 
       
   294         case ItemChildAddedChange:
       
   295         case ItemChildRemovedChange:
       
   296             repolish();
       
   297             break;
       
   298         default:
       
   299             break;
       
   300     }
       
   301     return HbWidget::itemChange(change, value);
       
   302 }
       
   303 
       
   304 /*!
       
   305     \reimp
       
   306  */
       
   307 void HbGroupBoxHeadingWidget::mousePressEvent(QGraphicsSceneMouseEvent *event)
       
   308 {
       
   309     HbWidget::mousePressEvent( event );
       
   310     if ( !collapsable ){
       
   311         event->ignore();
       
   312         return;
       
   313     }
       
   314 
       
   315     if (collapsable) {
       
   316         HbWidgetFeedback::triggered(this, Hb::InstantPressed, Hb::ModifierCollapsedItem);
       
   317     }
       
   318     else {
       
   319         HbWidgetFeedback::triggered(this, Hb::InstantPressed);
       
   320     }
       
   321 
       
   322     event->accept();
       
   323     // background primitive updation, upon mouse press
       
   324     headingPressed = true;
       
   325 
       
   326     HbStyleOptionGroupBox groupBoxOption;
       
   327     initStyleOption(&groupBoxOption);
       
   328     style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
       
   329 
       
   330     setProperty("state", "pressed");
       
   331 }
       
   332 
       
   333 /*!
       
   334     \reimp
       
   335  */
       
   336 void HbGroupBoxHeadingWidget::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
       
   337 {
       
   338     HbWidget::mouseReleaseEvent( event );
       
   339 
       
   340     if (collapsable) {
       
   341         HbWidgetFeedback::triggered(this, Hb::InstantReleased, Hb::ModifierCollapsedItem);
       
   342     }
       
   343     else {
       
   344         HbWidgetFeedback::triggered(this, Hb::InstantReleased);
       
   345     }
       
   346 
       
   347     if ( this->isUnderMouse() ) {
       
   348         if ( mIconItem && mIconItem->isUnderMouse() ) {
       
   349     #ifdef HB_EFFECTS
       
   350         HbEffect::start( mIconItem, HB_GROUPBOX_HEADING_TYPE, "iconclick");
       
   351     #endif
       
   352         }
       
   353         emit clicked(!collapsed);
       
   354     }
       
   355     // background primitive updation, upon mouse release
       
   356     headingPressed = false;
       
   357 
       
   358     HbStyleOptionGroupBox groupBoxOption;
       
   359     initStyleOption(&groupBoxOption);
       
   360     style()->updatePrimitive( mBackgroundItem , HbStyle::P_GroupBoxHeading_background , &groupBoxOption );
       
   361 
       
   362     setProperty("state", "normal");
       
   363 }
       
   364