src/hbwidgets/sliders/hbslider.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 "hbslider.h"
       
    27 #include "hbslider_p.h"
       
    28 #include "hbslidercontrol_p.h"
       
    29 #include "hbslidercontrol_p_p.h"
       
    30 #include "hbnamespace_p.h"
       
    31 #include "hbsliderhandle_p.h"
       
    32 
       
    33 #include "hbstyleoptionslider.h"
       
    34 #include "hbslidertickmarkslabel_p.h"
       
    35 #include "hbabstractbutton.h"
       
    36 #include <hbwidgetfeedback.h>
       
    37 #include <QGraphicsItem>
       
    38 #include <QGraphicsSceneEvent>
       
    39 #include <QGraphicsScene>
       
    40 #include <QDebug>
       
    41 
       
    42 #ifdef HB_EFFECTS
       
    43 #include "hbeffect.h"
       
    44 #include "hbeffectinternal_p.h"
       
    45 #define HB_SLIDER_TYPE "HB_SLIDER"
       
    46 #endif
       
    47 
       
    48 
       
    49 /*!
       
    50     @beta
       
    51     @hbwidgets
       
    52     \class HbSlider
       
    53     \brief HbSlider widget provides a generic vertical or horizontal slider.
       
    54 
       
    55     HbSlider is a classic widget for controlling a bounded value.
       
    56     It lets the user move a slider handle along a horizontal or vertical
       
    57     track and translates the handle's position into an integer value
       
    58     within the legal range.
       
    59 
       
    60     \image html hbslider.png A horizontal slider.
       
    61 
       
    62     The most important functions are setValue( ) to set the slider directly
       
    63     to some value; and setMinimum( ) and setMaximum( ) to define the range
       
    64     of the slider.
       
    65 
       
    66     HbSlider consists of elements. The available slider elements are
       
    67     defined by the HbSlider::SliderElement enumeration. A set of elements
       
    68     can be set by setSliderElements( ) and currently existing elements can be
       
    69     queried by sliderElements( ).All elements are optional
       
    70     Example usage:
       
    71     \code
       
    72     HbSlider *slider = new HbSlider( );
       
    73     QList<QVariant> elements;
       
    74     elements << QVariant (HbSlider::IncreaseElement)
       
    75         << QVariant (HbSlider::TrackElement)
       
    76         << QVariant (HbSlider::DecreaseElement)
       
    77         << QVariant (HbSlider::IconElement)
       
    78         << QVariant (HbSlider::TextElement);
       
    79     slider->setSliderElements( elements );
       
    80     QMap<QString , QVariant> map;
       
    81     // Icon path should be valid
       
    82     map.insert(QString("IncreaseElement") , QVariant(":/unittest_hbslider/star_on.png"));
       
    83     map.insert(QString("DecreaseElement") , QVariant(":/unittest_hbslider/star_on2.png"));
       
    84     map.insert(QString("IconElement") , QVariant(":/unittest_hbslider/star_on3.png"));
       
    85     slider->setElementIcons( map );
       
    86     \endcode
       
    87 
       
    88     \image html verticalslider.png A Custom vertical slider with all elements.
       
    89 
       
    90     order in which HbSlider::SliderElement are inserted into QList doesnt matter.
       
    91 
       
    92     HbSlider provides methods for controlling tickmarks.  You can use
       
    93     setTickPosition( ) to indicate where you want the tickmarks to be,
       
    94     setMajorTickInterval( ) and setMinorTickInterval( ) to indicate how
       
    95     many of them you want. The current set tick position and intervals
       
    96     can be queried using the tickPosition( ), majorTickInterval( ) and
       
    97     minorTickInterval( ) functions, respectively.
       
    98 
       
    99     HbSlider provides only integer ranges. Note that although
       
   100     HbSlider handles very large numbers, it becomes difficult for users
       
   101     to use a slider accurately for very large ranges.
       
   102 
       
   103     HbSlider also provide functionality of filling groove ( like progress )
       
   104     of slider. However this functionality is configurable and can be changed by
       
   105     setTrackFilled(), By Default this will be enabled
       
   106 
       
   107     The slider handles keys in the following way:
       
   108     \li Left/Right moves a horizontal slider by one single step.
       
   109     \li Up/Down moves a vertical slider by one single step.
       
   110 
       
   111     Example usage:
       
   112     \dontinclude slider/main.cpp
       
   113     \skip Start of snippet 1
       
   114     \until End of snippet 1
       
   115 
       
   116     \sa HbZoomSlider, HbVolumeSlider
       
   117 */
       
   118 
       
   119 /*!
       
   120     \fn void HbSlider::valueChanged( int value )
       
   121 
       
   122     This signal is emitted when the slider value has changed.
       
   123 
       
   124     \sa hasTracking( )
       
   125 */
       
   126 
       
   127 /*!
       
   128     \fn void HbSlider::sliderPressed( )
       
   129 
       
   130     This signal is emitted when the slider thumb has been pressed.
       
   131 */
       
   132 
       
   133 /*!
       
   134     \fn void HbSlider::sliderReleased( )
       
   135 
       
   136     This signal is emitted when the slider thumb has been released.
       
   137 */
       
   138 
       
   139 /*!
       
   140     \fn void HbSlider::sliderMoved( int value )
       
   141 
       
   142     This signal is emitted when the slider position has changed.
       
   143 
       
   144     \sa hasTracking( )
       
   145 */
       
   146 
       
   147 /*!
       
   148     \fn void HbSlider::rangeChanged( int min, int max )
       
   149 
       
   150     This signal is emitted when the slider range has changed.
       
   151 */
       
   152 
       
   153 /*!
       
   154     \fn void HbSlider::iconPressed( )
       
   155 
       
   156     This signal is emitted when the slider icon has been pressed.
       
   157 */
       
   158 
       
   159 /*!
       
   160     \fn void HbSlider::iconReleased( )
       
   161 
       
   162     This signal is emitted when the slider icon has been released.
       
   163 */
       
   164 
       
   165 /*!
       
   166     \fn void HbSlider::iconClicked( )
       
   167 
       
   168     This signal is emitted when the slider icon has been clicked.
       
   169 */
       
   170 
       
   171 /*!
       
   172     \fn void HbSlider::iconToggled( bool checked )
       
   173 
       
   174     This signal is emitted when the slider icon is checkable and it has been toggled.
       
   175 */
       
   176 
       
   177 /*!
       
   178     \reimp
       
   179     \fn int HbSlider::type( ) const
       
   180  */
       
   181 
       
   182 /*!
       
   183     \enum HbSlider::SliderElement
       
   184 
       
   185     This enum defines available slider elements.
       
   186  */
       
   187 
       
   188 /*!
       
   189     \var HbSlider::IncreaseElement
       
   190 
       
   191     A button to increase the slider value. Usually a plus sign.
       
   192  */
       
   193 
       
   194 /*!
       
   195     \var HbSlider::TrackElement
       
   196 
       
   197     The slider track that consists of a groove, ticks and handle.
       
   198  */
       
   199 
       
   200 /*!
       
   201     \var HbSlider::DecreaseElement
       
   202 
       
   203     A button to decrease the slider value. Usually a minus sign.
       
   204  */
       
   205 
       
   206 /*!
       
   207     \var HbSlider::IconElement
       
   208 
       
   209     An icon element associated to the slider.
       
   210  */
       
   211 
       
   212 /*!
       
   213     \var HbSlider::TextElement
       
   214 
       
   215     A text element associated to the slider.
       
   216  */
       
   217 
       
   218 /*!
       
   219     \enum HbSlider::SnappingMode
       
   220 
       
   221     This enum defines available SnappingModes.
       
   222  */
       
   223 
       
   224 /*!
       
   225     \var HbSlider::NoSnapping
       
   226 
       
   227     slider do not snap incase of NoSnapping but by deault it will be snapped to minrotick.
       
   228  */
       
   229 
       
   230 /*!
       
   231     \var HbSlider::MajorTickSnapping
       
   232 
       
   233     slider snaps to major tick incase of drag.
       
   234  */
       
   235 
       
   236 /*!
       
   237     \var HbSlider::MinorTickSnapping
       
   238 
       
   239     slider snaps to minor tick incase of drag.
       
   240  */
       
   241 
       
   242 HbSliderPrivate::HbSliderPrivate( ) :
       
   243     sliderControl( 0 ),
       
   244     orientation( Qt::Vertical ),
       
   245     pressOnIncrement( false )
       
   246 {
       
   247     elementItemMap.clear();
       
   248 
       
   249 }
       
   250 
       
   251 HbSliderPrivate::~HbSliderPrivate( )
       
   252 {
       
   253 }
       
   254 
       
   255 
       
   256 void HbSliderPrivate::init( )
       
   257 {
       
   258     Q_Q( HbSlider );
       
   259 
       
   260     sliderControl = new HbSliderControl( orientation, q );
       
   261     HbStyle::setItemName( sliderControl, "control" );
       
   262     // delegating signal of slider control to slider
       
   263     q->connect( sliderControl, SIGNAL( valueChanged( int ) ), q,  SIGNAL( valueChanged( int ) ) );
       
   264     q->connect( sliderControl, SIGNAL( sliderPressed( ) ), q, SIGNAL( sliderPressed( ) ) );
       
   265     q->connect( sliderControl, SIGNAL( sliderReleased( ) ), q, SIGNAL( sliderReleased( ) ) );
       
   266     q->connect( sliderControl, SIGNAL( sliderMoved( int ) ), q, SIGNAL( sliderMoved( int ) ) );
       
   267     q->connect( sliderControl, SIGNAL( rangeChanged( int, int ) ), q, SIGNAL( rangeChanged( int, int ) ) );
       
   268     setElements( QList<HbSlider::SliderElement>( ) << HbSlider::TrackElement );
       
   269     HbStyle::setItemName( q,"this" );
       
   270     q->setFlags( QGraphicsItem::ItemIsFocusable );
       
   271     q->setProperty("TickLabelPresent",false);
       
   272 
       
   273 }
       
   274 
       
   275 void HbSliderPrivate::setElements( QList<HbSlider::SliderElement> elementList)
       
   276 {
       
   277     Q_Q( HbSlider);
       
   278     bool oldElementRemoved = false;
       
   279     foreach(HbSlider::SliderElement element,elements){
       
   280         if(!elementList.contains(element)&& elementItemMap.contains(element)) {
       
   281             delete elementItemMap[element].item;
       
   282             delete elementItemMap[element].touchItem;
       
   283             elementItemMap.remove(element);
       
   284             oldElementRemoved = true;
       
   285         }
       
   286     }
       
   287     if(oldElementRemoved) {
       
   288         q->repolish( );
       
   289     }
       
   290     elements = elementList;
       
   291     // this will delete unwanted element and create new element
       
   292     updateElements( );
       
   293     // repolish call is required because new elements might be added
       
   294 }
       
   295 
       
   296 /*!
       
   297     This api creates widget for given element   
       
   298  */
       
   299 void HbSliderPrivate::elementWidget( HbSlider::SliderElement element )
       
   300 {
       
   301     Q_Q( HbSlider );
       
   302     switch ( element ) {
       
   303         case HbSlider::IncreaseElement:
       
   304             // create element only if icon is set on that
       
   305             if ( icons.contains( element) && !elementItemMap.contains(element)){
       
   306                 ItemPrimitive itemPrimStrct;
       
   307                 itemPrimStrct.type = HbStyle::P_SliderElement_increase;
       
   308                 itemPrimStrct.item = q->style( )->createPrimitive(HbStyle::P_SliderElement_increase,q );
       
   309                 HbStyle::setItemName( itemPrimStrct.item, "increment-icon" );                    
       
   310                 itemPrimStrct.touchItem = q->style( )->createPrimitive( HbStyle::P_SliderElement_touchincrease,q );
       
   311                 HbStyle::setItemName( itemPrimStrct.touchItem, "increment-icon-toucharea" );
       
   312                 HbStyleOptionSlider option;
       
   313                 q->initStyleOption( &option );
       
   314                 q->style( )->updatePrimitive (itemPrimStrct.touchItem,HbStyle::P_SliderElement_touchincrease,&option);
       
   315                 elementItemMap[HbSlider::IncreaseElement]=itemPrimStrct;
       
   316                 q->repolish( );
       
   317        
       
   318             }
       
   319             break;
       
   320         case HbSlider::DecreaseElement:
       
   321             // element will not be created if icon is not set on that element
       
   322             if ( icons.contains( element) && !elementItemMap.contains(element)) {
       
   323                 ItemPrimitive itemPrimStrct;
       
   324                 itemPrimStrct.item= q->style( )->createPrimitive(HbStyle::P_SliderElement_decrease,q );
       
   325                 itemPrimStrct.type = HbStyle::P_SliderElement_decrease;
       
   326                 HbStyle::setItemName( itemPrimStrct.item,"decrement-icon" );
       
   327                 itemPrimStrct.touchItem = q->style( )->createPrimitive( HbStyle::P_SliderElement_touchdecrease,q );
       
   328                 HbStyle::setItemName( itemPrimStrct.touchItem, "decrement-icon-toucharea" );
       
   329                 elementItemMap[HbSlider::DecreaseElement]=itemPrimStrct;
       
   330                 HbStyleOptionSlider option;
       
   331                 q->initStyleOption( &option );
       
   332                 q->style( )->updatePrimitive (itemPrimStrct.touchItem,HbStyle::P_SliderElement_touchdecrease,&option);
       
   333                 q->repolish( );
       
   334                            
       
   335             }
       
   336             break;
       
   337         case HbSlider::IconElement:
       
   338             if ( icons.contains( element) && !elementItemMap.contains(element) ) {
       
   339                     ItemPrimitive itemPrimStrct;
       
   340                     itemPrimStrct.item = q->style( )->createPrimitive(HbStyle::P_SliderElement_icon,q );
       
   341                     itemPrimStrct.type = HbStyle::P_SliderElement_icon;
       
   342                     HbStyle::setItemName( itemPrimStrct.item, "icon-icon" );
       
   343                     HbAbstractButton *sliderIcon = new HbAbstractButton( q );
       
   344                     HbStyle::setItemName( sliderIcon, "icon" );
       
   345                     itemPrimStrct.touchItem = sliderIcon;
       
   346                     elementItemMap [HbSlider::IconElement]=itemPrimStrct;
       
   347                     // delegating signal from button to slider
       
   348                     q->connect( sliderIcon, SIGNAL( pressed( ) ), q, SIGNAL( iconPressed( ) ) );
       
   349                     q->connect( sliderIcon, SIGNAL( released( ) ), q, SIGNAL( iconReleased( ) ) );
       
   350                     q->connect( sliderIcon, SIGNAL( clicked( ) ), q, SIGNAL( iconClicked( ) ) );
       
   351                     q->connect( sliderIcon, SIGNAL( toggled( bool ) ), q, SIGNAL( iconToggled( bool ) ) );
       
   352 #ifdef HB_EFFECTS
       
   353                     q->connect( sliderIcon, SIGNAL( pressed( ) ), q, SLOT( _q_startIconPressedEffect( ) ) );
       
   354                     q->connect( sliderIcon, SIGNAL( released( ) ), q,SLOT( _q_startIconReleasedEffect( ) ) );
       
   355 #endif
       
   356                     q->repolish( );
       
   357                
       
   358             }
       
   359             break;
       
   360         case HbSlider::TextElement:
       
   361             if( !sliderTextString.isEmpty( ) && !elementItemMap.contains(element)){
       
   362                 ItemPrimitive itemPrimStrct;
       
   363                 itemPrimStrct.type = HbStyle::P_SliderElement_text;
       
   364                 itemPrimStrct.item = q->style( )->createPrimitive( HbStyle::P_SliderElement_text,q );
       
   365                 HbStyle::setItemName( itemPrimStrct.item,"text_item_element" );
       
   366                 HbAbstractButton *sliderTextButton = new HbAbstractButton( q ); 
       
   367                 HbStyle::setItemName( sliderTextButton, "text_element" );
       
   368                 itemPrimStrct.touchItem = sliderTextButton;   
       
   369                 q->connect( sliderTextButton, SIGNAL( clicked( ) ), q, SIGNAL( textClicked( ) ) );
       
   370 #ifdef HB_EFFECTS
       
   371                 q->connect( sliderTextButton, SIGNAL( clicked( ) ), q, SLOT( _q_startTextClickEffect( ) ) );
       
   372 #endif
       
   373                 q->repolish();
       
   374                 q->setProperty("state", "normal"); 
       
   375                 elementItemMap[HbSlider::TextElement]=itemPrimStrct;
       
   376               }
       
   377             break;
       
   378         default:
       
   379             break;
       
   380     }
       
   381 
       
   382      HbStyleOptionSlider option;
       
   383      q->initStyleOption( &option );
       
   384      option.sliderElementIcon =icons.value(element ); 
       
   385      option.text = sliderTextString; 
       
   386      if (elementItemMap.contains(element)) {
       
   387          q->style( )->updatePrimitive( elementItemMap[element].item,elementItemMap[element].type,&option );
       
   388 
       
   389      }  //return created;
       
   390 }
       
   391 
       
   392 
       
   393 /*!
       
   394     update element will first delete element which are not required
       
   395     and then create new element
       
   396  */
       
   397 void HbSliderPrivate::updateElements( )
       
   398 {
       
   399     foreach ( const HbSlider::SliderElement &element, elements ) {
       
   400         // create new element, this api will not create element widget
       
   401         // if it is already existing
       
   402         elementWidget( element );
       
   403     }
       
   404 }
       
   405 
       
   406 /*!
       
   407      This Api will start incrementing slider value by step size
       
   408      till the time stopReapetAction( ) is not being called or slider
       
   409      value becomes maximum( )
       
   410  */
       
   411 void HbSliderPrivate::startIncrementing( )
       
   412 {
       
   413 #ifdef HB_EFFECTS
       
   414     HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_press", "increasepressed" );
       
   415     HbEffect::start( elementItemMap[HbSlider::IncreaseElement].item, HB_SLIDER_TYPE, "increasepressed" );  
       
   416 #endif
       
   417     // increase slider value by step size
       
   418     sliderControl->triggerAction( HbAbstractSliderControl::SliderSingleStepAdd );
       
   419     // start timer to increase slider value by step
       
   420     sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepAdd,sliderControl->maximum( ) );
       
   421 }
       
   422 
       
   423 /*!
       
   424      This Api will start decrementing slider value by step size
       
   425      till the time stopReapetAction( ) is not being called or slider
       
   426      value becomes minimum( )
       
   427  */
       
   428 void HbSliderPrivate::startDecrementing( )
       
   429 {
       
   430 #ifdef HB_EFFECTS
       
   431     HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_press", "decreasepressed" );
       
   432     HbEffect::start( elementItemMap[HbSlider::DecreaseElement].item, HB_SLIDER_TYPE, "decreasepressed" );  
       
   433 #endif
       
   434     sliderControl->triggerAction( HbAbstractSliderControl::SliderSingleStepSub );
       
   435     sliderControl->setRepeatAction( HbAbstractSliderControl::SliderSingleStepSub,sliderControl->minimum( ) );
       
   436 }
       
   437 
       
   438 /*!
       
   439     stops the reapeating action
       
   440     reapeat action can be increase slider value by step or decrease slider value by step
       
   441  */
       
   442 void HbSliderPrivate::stopRepeatAction( )
       
   443 {
       
   444     sliderControl->setRepeatAction( HbAbstractSliderControl::SliderNoAction ); 
       
   445 }
       
   446 
       
   447 
       
   448 void HbSliderPrivate::setTickLabelPresentProperty( ) 
       
   449 {
       
   450     Q_Q ( HbSlider );
       
   451     if (q->majorTickInterval( ) > 0 && q->tickPosition( ) !=Hb::NoSliderTicks &&
       
   452         (q->majorTickLabels().length() > 0 || 
       
   453             (q->minorTickInterval() > 0 && q->minorTickLabels( ).length() > 0))) {
       
   454                 if(!q->property("TickLabelPresent").toBool()){        
       
   455                     q->setProperty("TickLabelPresent",true);
       
   456                     q->repolish( );
       
   457                 }
       
   458     } else {
       
   459         if( q->property("TickLabelPresent").toBool()){        
       
   460             q->setProperty("TickLabelPresent",false);
       
   461             q->repolish( );
       
   462             }
       
   463     }
       
   464 
       
   465 }
       
   466 
       
   467 #ifdef HB_EFFECTS
       
   468 
       
   469 /*!
       
   470     start effect for on icon press
       
   471  */
       
   472 void HbSliderPrivate::_q_startIconPressedEffect( )
       
   473 {
       
   474     HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_press", "iconpressed" );
       
   475     HbEffect::start( elementItemMap[HbSlider::IconElement].item, HB_SLIDER_TYPE, "iconpressed" );  
       
   476 }
       
   477 
       
   478 /*!
       
   479    start effect on icon release
       
   480  */
       
   481 void HbSliderPrivate::_q_startIconReleasedEffect( )
       
   482 {
       
   483     HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_release", "iconrelease" );
       
   484     HbEffect::start( elementItemMap[HbSlider::IconElement].item, HB_SLIDER_TYPE, "iconrelease" );  
       
   485 }
       
   486 
       
   487 /*!
       
   488    start text click effect
       
   489  */
       
   490 void HbSliderPrivate::_q_startTextClickEffect( )
       
   491 {
       
   492     HbEffectInternal::add( HB_SLIDER_TYPE,"slidertext_click", "textclick" );
       
   493     HbEffect::start( elementItemMap[HbSlider::TextElement].item, HB_SLIDER_TYPE, "textclick" );  
       
   494 }
       
   495 #endif
       
   496 
       
   497 /*!
       
   498     @beta
       
   499     Constructs a slider with \a parent.
       
   500 
       
   501     The orientation is \b Qt::Vertical and the slider contains only track( groove and handle ) element by default.
       
   502 
       
   503     default range for HbSlider is 0 to 100 and singleStepSize is 1
       
   504 
       
   505     \sa setOrientation( ), setElements( )
       
   506 */
       
   507 HbSlider::HbSlider( QGraphicsItem *parent ) :
       
   508     HbWidget( *new HbSliderPrivate, parent )
       
   509 {
       
   510     Q_D( HbSlider );
       
   511     d->q_ptr = this;
       
   512     d->init( );
       
   513 }
       
   514 
       
   515 /*!
       
   516     @beta
       
   517     Constructs a slider with a \a orientation and \a parent.
       
   518 
       
   519     The slider contains only track( groove and handle ) element by default.
       
   520 
       
   521     default range for HbSlider is 0 to 100 and singleStepSize is 1
       
   522 
       
   523     \sa setElements( )
       
   524 */
       
   525 HbSlider::HbSlider( Qt::Orientation orientation, QGraphicsItem *parent ) :
       
   526     HbWidget( *new HbSliderPrivate, parent )
       
   527 {
       
   528     Q_D( HbSlider );
       
   529     d->q_ptr = this;
       
   530     d->init( );
       
   531     setOrientation( orientation );
       
   532 }
       
   533 
       
   534 /*!
       
   535     @beta
       
   536     \internal
       
   537  */
       
   538 HbSlider::HbSlider( HbSliderPrivate &dd, QGraphicsItem *parent ) :
       
   539     HbWidget( dd, parent )
       
   540 {
       
   541     Q_D( HbSlider );
       
   542     d->init( );
       
   543     
       
   544 }
       
   545 
       
   546 /*!
       
   547     Destructs the slider.
       
   548 */
       
   549 HbSlider::~HbSlider( )
       
   550 {
       
   551 }
       
   552 
       
   553 /*!
       
   554     \deprecated
       
   555     Returns the elements of the slider.
       
   556 
       
   557     The slider contains only track element by default.
       
   558 
       
   559     \sa setElements( )
       
   560 */
       
   561 QList<HbSlider::SliderElement> HbSlider::elements( ) const
       
   562 {
       
   563     qDebug("HbSlider::elements() is deprecated. Use sliderElements() instead.");
       
   564     Q_D( const HbSlider );
       
   565     return d->elements;
       
   566 }
       
   567 
       
   568 /*!
       
   569     \deprecated
       
   570     Sets the elements of the slider.
       
   571 
       
   572     \note Duplicate elements will be ignored.
       
   573 
       
   574     \note element order cant be changed
       
   575 
       
   576     \sa elements( )
       
   577 */
       
   578 void HbSlider::setElements( const QList<SliderElement> &elements )
       
   579 {
       
   580     qDebug("HbSlider::setElements is deprecated. Use setSliderElements instead.");
       
   581     Q_D( HbSlider );
       
   582     bool oldElementRemoved = false;
       
   583     foreach(HbSlider::SliderElement element,d->elements){
       
   584         if(!elements.contains(element)&&d->elementItemMap.contains(element)) {
       
   585             delete d->elementItemMap[element].item;
       
   586             delete d->elementItemMap[element].touchItem;
       
   587             d->elementItemMap.remove(element);
       
   588             oldElementRemoved = true;
       
   589         }
       
   590     }
       
   591     if(oldElementRemoved) {
       
   592         repolish( );
       
   593     }
       
   594     d->elements = elements;
       
   595     // this will delete unwanted element and create new element
       
   596     d->updateElements( );
       
   597     // repolish call is required because new elements might be added
       
   598 }
       
   599 
       
   600 
       
   601 /*!
       
   602     @proto
       
   603     Returns the list of slider elements as QVariant 
       
   604     
       
   605     \note it is safe to type-cast element to HbSlider::SliderElement.  
       
   606    
       
   607     The slider contains only track element by default.
       
   608 
       
   609     \sa setSliderElements()
       
   610 */
       
   611 QList<QVariant> HbSlider::sliderElements() const
       
   612 {
       
   613     Q_D( const HbSlider );
       
   614     QList<QVariant> elementList;
       
   615     foreach(HbSlider::SliderElement element,d->elements){
       
   616         elementList.append ( QVariant ( element ) );
       
   617     }
       
   618     return elementList;
       
   619 }
       
   620 
       
   621 /*!
       
   622     @proto
       
   623     Sets the elements of the slider.
       
   624 
       
   625     \note Duplicate elements will be ignored.
       
   626 
       
   627     \note element order cant be changed
       
   628 
       
   629     Eg Usages:
       
   630     HbSlider slider;
       
   631     QList<QVariant> list;
       
   632     list.append( QVariant( HbSlider::IncreaseElement));
       
   633     list.append( QVariant( HbSlider::DecreaseElement));
       
   634     list.append( QVariant( HbSlider::IconElement));
       
   635     slider.setElements( list);
       
   636 
       
   637     The available slider elements are
       
   638     defined by the HbSlider::SliderElement enumeration
       
   639 
       
   640     \sa sliderElements()
       
   641 
       
   642 */
       
   643 void HbSlider::setSliderElements(const QList<QVariant> &elementlist)
       
   644 {
       
   645     Q_D( HbSlider );
       
   646     QList<HbSlider::SliderElement> elements;
       
   647     foreach ( QVariant elementVar , elementlist ) {
       
   648         elements.append( static_cast<HbSlider::SliderElement>(elementVar.toInt()));
       
   649     }
       
   650     d->setElements( elements );
       
   651 }
       
   652 
       
   653 /*!
       
   654     @proto
       
   655     Sets the icons for elements
       
   656 
       
   657     key of \a elements is element name  and value is icon 
       
   658     name to set on given element
       
   659     Use following string for specifying elements
       
   660     "IncreaseElement" for increase element
       
   661     "DecreaseElement" for decrease element
       
   662     "IconElement" for icon element
       
   663     
       
   664     Eg Usage:
       
   665     HbSlider slider;
       
   666     QMap<QString , QVariant> map;
       
   667     map.insert(QString("IncreaseElement") , QVariant(":/unittest_hbslider/star_on.png"));
       
   668      map.insert(QString("DecreaseElement") , QVariant(":/unittest_hbslider/star_on.png"));
       
   669     slider.setElementIcons( map );
       
   670 
       
   671     \warning Setting icon to a non-existing element has no effect.
       
   672 
       
   673     \sa elementIcons() setSliderElements() setElementIcon()
       
   674 */
       
   675 void HbSlider::setElementIcons(const QMap<QString,QVariant> &elements)
       
   676 {
       
   677     Q_D( HbSlider );
       
   678     QMapIterator<QString,QVariant> i(elements);
       
   679     while (i.hasNext()) {
       
   680         i.next();
       
   681         HbIcon icon = HbIcon( i.value().toString());
       
   682         if ( !icon.isNull() ) {
       
   683             if( !i.key().compare("IncreaseElement")) {
       
   684                 d->icons[HbSlider::IncreaseElement] = icon;
       
   685                 if ( d->elements.contains( HbSlider::IncreaseElement ) ) {
       
   686                     // create icon element if it was not existing
       
   687                     d->elementWidget( HbSlider::IncreaseElement ); 
       
   688                 }
       
   689             }
       
   690             else if( !i.key().compare( "DecreaseElement")) {
       
   691                 d->icons[HbSlider::DecreaseElement] = icon;
       
   692                 if ( d->elements.contains( HbSlider::DecreaseElement ) ) {
       
   693                     // create icon element if it was not existing
       
   694                     d->elementWidget( HbSlider::DecreaseElement ); 
       
   695                 }
       
   696             }
       
   697              else if( !i.key().compare( "IconElement")) {
       
   698                 d->icons[HbSlider::IconElement] = icon;
       
   699                 if ( d->elements.contains( HbSlider::IconElement ) ) {
       
   700                     // create icon element if it was not existing
       
   701                     d->elementWidget( HbSlider::IconElement ); 
       
   702                 }
       
   703             }
       
   704         }
       
   705     }
       
   706 }
       
   707 
       
   708 /*!
       
   709     @proto
       
   710     Returns the map , which consist of element name as key and icon name  as value
       
   711 
       
   712     returns NULL map if none of the element has icon
       
   713 
       
   714     \sa setElementIcons()
       
   715 */
       
   716 QMap<QString,QVariant> HbSlider::elementIcons( )const
       
   717 {
       
   718     Q_D( const HbSlider );
       
   719     QMap<QString , QVariant> map;
       
   720     QHashIterator<HbSlider::SliderElement , HbIcon> i(d->icons);
       
   721     while( i.hasNext()) {
       
   722         i.next();
       
   723         QString  name;
       
   724         switch( i.key() ){
       
   725             case IncreaseElement:
       
   726                 name = QString("IncreaseElement");
       
   727                 break;
       
   728             case DecreaseElement:
       
   729                 name = QString("DecreaseElement");
       
   730                 break;
       
   731             case IconElement:
       
   732                 name = QString("IconElement");
       
   733                 break;
       
   734             default:
       
   735                 name = QString("");
       
   736 
       
   737         }
       
   738         map.insert( name, QVariant(i.value().iconName()));
       
   739     }
       
   740     return map;
       
   741 }
       
   742 
       
   743 
       
   744 /*!
       
   745     @beta
       
   746     Returns the slider text.
       
   747 
       
   748     returns empty text if text element does not exist
       
   749 
       
   750     \sa setText( )
       
   751 */
       
   752 QString HbSlider::text( ) const
       
   753 {
       
   754     Q_D( const HbSlider );
       
   755     return d->sliderTextString;
       
   756 }
       
   757 
       
   758 
       
   759 /*!
       
   760     @beta
       
   761     Sets the slider \a text for text element as well as tooltip.
       
   762 
       
   763     tooltip will be visible only if setTooltip( true ) is called.
       
   764 
       
   765     Slider will not take care of localization.
       
   766 
       
   767     \warning Setting text to a non-existing text element has no effect.
       
   768    
       
   769     \sa text( ), setToolTipVisible( ), setToolTipAlignment( )
       
   770 */
       
   771 void HbSlider::setText( const QString &text )
       
   772 {
       
   773     Q_D( HbSlider );
       
   774     if( d->sliderTextString!= text) {
       
   775         d->sliderTextString = text;
       
   776         if ( d->elements.contains( HbSlider::TextElement ))  {
       
   777             d->elementWidget( HbSlider::TextElement );  
       
   778         }
       
   779         // sets text for tooltip also
       
   780         d->sliderControl->setToolTip( text );
       
   781         repolish();
       
   782     }
       
   783 }
       
   784 
       
   785 /*!
       
   786     \deprecated
       
   787     Returns the icon of the \a element.
       
   788 
       
   789     returns NULL if element does not exist or icon was not set for this element
       
   790 
       
   791     \sa setIcon( )
       
   792 */
       
   793 HbIcon HbSlider::icon( SliderElement element ) const
       
   794 {
       
   795     qDebug("HbSlider::icon() is deprecated. Use elementIcons() instead.");
       
   796     Q_D( const HbSlider );
       
   797     return d->icons.value( element );
       
   798 }
       
   799 
       
   800 /*!
       
   801     \deprecated
       
   802     Sets the \a icon if the \a element.
       
   803 
       
   804     Supported elements:
       
   805     \li HbSlider::IncreaseElement
       
   806     \li HbSlider::DecreaseElement
       
   807     \li HbSlider::IconElement
       
   808 
       
   809     \warning Setting icon to a non-existing element has no effect.
       
   810 
       
   811     \sa icon( ) setElements( )
       
   812 */
       
   813 void HbSlider::setIcon( SliderElement element, const HbIcon &icon )
       
   814 {
       
   815     qDebug("HbSlider::setIcon() is deprecated. Use setElementIcons() instead.");
       
   816     Q_D( HbSlider );
       
   817     if ( element != TextElement &&!icon.isNull()) {
       
   818         d->icons[element] = icon;
       
   819         if ( d->elements.contains( element ) ) {
       
   820             // create icon element if it was not existing
       
   821             d->elementWidget( element ); 
       
   822             // update icon primitive
       
   823             
       
   824         } 
       
   825 
       
   826     } else {
       
   827         qWarning( "HbSlider::setIcon: non-supported element or null icon passed" );
       
   828     }
       
   829 }
       
   830 
       
   831 /*!
       
   832     @beta
       
   833     Returns the icon of the \a element.
       
   834 
       
   835     returns NULL if element does not exist or icon was not set for this element
       
   836 
       
   837     \sa setElementIcon( )
       
   838 */
       
   839 HbIcon HbSlider::elementIcon( SliderElement element ) const
       
   840 {
       
   841     Q_D( const HbSlider );
       
   842     return d->icons.value( element );
       
   843 }
       
   844 
       
   845 /*!
       
   846     @beta
       
   847     Sets the \a icon if the \a element.
       
   848 
       
   849     Supported elements:
       
   850     \li HbSlider::IncreaseElement
       
   851     \li HbSlider::DecreaseElement
       
   852     \li HbSlider::IconElement
       
   853 
       
   854     \warning Setting icon to a non-existing element has no effect.
       
   855 
       
   856     \sa elementIcon( ) setElements( )
       
   857 */
       
   858 void HbSlider::setElementIcon( SliderElement element, const HbIcon &icon )
       
   859 {
       
   860     Q_D( HbSlider );
       
   861     if ( element != TextElement &&!icon.isNull()) {
       
   862         d->icons[element] = icon;
       
   863         if ( d->elements.contains( element ) ) {
       
   864             // create icon element if it was not existing
       
   865             d->elementWidget( element ); 
       
   866             // update icon primitive
       
   867             
       
   868         } 
       
   869 
       
   870     } else {
       
   871         qWarning( "HbSlider::setIcon: non-supported element or null icon passed" );
       
   872     }
       
   873 }
       
   874 
       
   875 /*!
       
   876     @beta
       
   877     Returns \c true whether the icon element is checkable.
       
   878 
       
   879     The default value is \c false.
       
   880 
       
   881     \sa setIconCheckable( )
       
   882 */
       
   883 bool HbSlider::isIconCheckable( ) const
       
   884 {
       
   885     Q_D( const HbSlider );
       
   886 
       
   887     if ( d->elementItemMap.contains (HbSlider::IconElement ) ){
       
   888         HbAbstractButton *sliderIcon = 
       
   889             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
   890         return sliderIcon->isCheckable( );
       
   891     }
       
   892     return false;
       
   893 }
       
   894 
       
   895 
       
   896 /*!
       
   897     @beta
       
   898     Sets whether the tooltip is visible .
       
   899 
       
   900     tooltip is different then current value
       
   901 
       
   902     tooltip text can be set by \li setText( ) api
       
   903 
       
   904     if \a value is true then tooltip will be display on thumb drag
       
   905 
       
   906     \sa isToolTipVisible( ) , setText( )
       
   907 */
       
   908 void HbSlider::setToolTipVisible( bool value )
       
   909 {
       
   910     Q_D( const HbSlider );
       
   911     d->sliderControl->setToolTipVisible( value );
       
   912 }
       
   913 
       
   914 
       
   915 /*!
       
   916     @beta
       
   917     Returns \c true if tooltip is visible.
       
   918 
       
   919     The default value is \c false.
       
   920 
       
   921     \sa setToolTipVisible( )
       
   922 */
       
   923 bool HbSlider::isToolTipVisible( )const
       
   924 {
       
   925     Q_D( const HbSlider );
       
   926     return d->sliderControl->isToolTipVisible( );
       
   927 }
       
   928 
       
   929 
       
   930 
       
   931 /*!
       
   932    @beta
       
   933    sets the toolTip Alignment with respect to the thumb.
       
   934 
       
   935     \sa toolTipAlignment( )
       
   936 */
       
   937 void HbSlider::setToolTipAlignment( Qt::Alignment alignment )
       
   938 {
       
   939     Q_D( HbSlider );
       
   940     d->sliderControl->setToolTipAlignment( alignment );
       
   941 }
       
   942 
       
   943 
       
   944 /*!
       
   945     @beta
       
   946     returns the tooltip Alignment with respect to the thumb
       
   947 
       
   948     \sa setToolTipAlignment( )
       
   949 */
       
   950 Qt::Alignment HbSlider::toolTipAlignment( ) const
       
   951 {
       
   952     Q_D( const HbSlider );
       
   953     return d->sliderControl->toolTipAlignment( );
       
   954 }
       
   955 
       
   956 /*!
       
   957     @beta
       
   958     Sets whether the icon element is checkable.
       
   959 
       
   960     checkable icon emits toggled( bool ) signal
       
   961 
       
   962     By default, the icon is not checkable.
       
   963 
       
   964     \sa isIconCheckable( )
       
   965 */
       
   966 void HbSlider::setIconCheckable( bool checkable )
       
   967 {
       
   968     Q_D( HbSlider );
       
   969     if ( d->elementItemMap.contains (HbSlider::IconElement )) {
       
   970         HbAbstractButton *sliderIcon = 
       
   971             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
   972         sliderIcon->setCheckable ( checkable );
       
   973     }
       
   974 }
       
   975 
       
   976 /*!
       
   977     @beta
       
   978     Returns \c true whether the icon element is checked.
       
   979 
       
   980     The default value is \c false.
       
   981 
       
   982     \sa setIconChecked( )
       
   983 */
       
   984 bool HbSlider::isIconChecked( ) const
       
   985 {
       
   986     Q_D( const HbSlider );
       
   987     if ( d->elementItemMap.contains (HbSlider::IconElement ) ){
       
   988         HbAbstractButton *sliderIcon = 
       
   989             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
   990         return sliderIcon->isChecked( );
       
   991     }
       
   992     return false;
       
   993 }
       
   994 
       
   995 /*!
       
   996     @beta
       
   997     Sets whether the icon element is checked or not.
       
   998 
       
   999     \sa isIconChecked( )
       
  1000 */
       
  1001 void HbSlider::setIconChecked( bool checked )
       
  1002 {
       
  1003     Q_D( HbSlider );
       
  1004     if ( d->elementItemMap.contains (HbSlider::IconElement )) {
       
  1005         HbAbstractButton *sliderIcon = 
       
  1006             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
  1007         sliderIcon->setChecked ( checked );
       
  1008     }
       
  1009 }
       
  1010 
       
  1011 /*!
       
  1012     @beta
       
  1013     Returns \c true whether the icon element is enabled.
       
  1014 
       
  1015     The default value is \c true.
       
  1016 
       
  1017     \sa setIconEnabled( )
       
  1018 */
       
  1019 bool HbSlider::isIconEnabled( ) const
       
  1020 {
       
  1021     Q_D( const HbSlider );
       
  1022     if ( d->elementItemMap.contains (HbSlider::IconElement ) ) {
       
  1023         HbAbstractButton *sliderIcon = 
       
  1024             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
  1025         return sliderIcon->isEnabled( );
       
  1026     }
       
  1027     return false;
       
  1028 }
       
  1029 
       
  1030 /*!
       
  1031     @beta
       
  1032     Sets whether the icon element is enabled or not.
       
  1033 
       
  1034     \sa isIconEnabled( )
       
  1035 */
       
  1036 void HbSlider::setIconEnabled( bool enabled )
       
  1037 {
       
  1038     Q_D( HbSlider );
       
  1039     if ( d->elementItemMap.contains (HbSlider::IconElement )) {
       
  1040         HbAbstractButton *sliderIcon = 
       
  1041             static_cast<HbAbstractButton *>(d->elementItemMap[HbSlider::IconElement].touchItem);
       
  1042         sliderIcon->setEnabled ( enabled );
       
  1043         d->elementItemMap[HbSlider::IconElement].item->setEnabled( enabled );
       
  1044 
       
  1045     }
       
  1046 }
       
  1047 
       
  1048 /*!
       
  1049     @beta
       
  1050     Sets the \a orientation of the slider.
       
  1051 
       
  1052     \sa orientation( )
       
  1053 */
       
  1054 void HbSlider::setOrientation( Qt::Orientation orientation )
       
  1055 {
       
  1056     Q_D( HbSlider );
       
  1057     if ( d->orientation != orientation ) {
       
  1058         d->orientation = orientation;
       
  1059         d->sliderControl->setOrientation( orientation );
       
  1060         repolish();
       
  1061     }
       
  1062 }
       
  1063 
       
  1064 /*!
       
  1065     @beta
       
  1066     Returns the orientation of the slider.
       
  1067 
       
  1068     The default value is \c Qt::Vertical.
       
  1069 
       
  1070     \sa setOrientation( )
       
  1071  */
       
  1072 Qt::Orientation HbSlider::orientation( ) const
       
  1073 {
       
  1074     Q_D( const HbSlider );
       
  1075     return d->orientation;
       
  1076 }
       
  1077 
       
  1078 /*!
       
  1079     @beta
       
  1080     Returns \c true whether the slider track is inverted.
       
  1081 
       
  1082     The default value is \c false.
       
  1083 
       
  1084     If this property is \c false, the minimum and maximum will
       
  1085     be shown in its classic position. If the value is \c true,
       
  1086     the minimum and maximum appear at their opposite location.
       
  1087 
       
  1088     \sa setInvertedAppearance( )
       
  1089 */
       
  1090 bool HbSlider::invertedAppearance( ) const
       
  1091 {
       
  1092     Q_D( const HbSlider );
       
  1093     return d->sliderControl->invertedAppearance( );
       
  1094 }
       
  1095 
       
  1096 /*!
       
  1097     @beta
       
  1098     Sets whether the slider track is \a inverted.
       
  1099 
       
  1100     This  holds whether or not a slider shows its values inverted.
       
  1101 
       
  1102     If \a inverted. false ( the default ), the minimum and maximum will be shown in its classic position 
       
  1103     
       
  1104     for the inherited widget. If the value is true, the minimum and maximum appear at
       
  1105     
       
  1106     their opposite location.
       
  1107     
       
  1108     Note: This property makes most sense for sliders.
       
  1109 
       
  1110     \sa invertedAppearance( )
       
  1111 
       
  1112 */
       
  1113 void HbSlider::setInvertedAppearance( bool inverted )
       
  1114 {
       
  1115     Q_D( HbSlider );
       
  1116     d->sliderControl->setInvertedAppearance( inverted );
       
  1117     int dec = d->elements.indexOf( HbSlider::DecreaseElement );
       
  1118     int inc = d->elements.indexOf( HbSlider::IncreaseElement );
       
  1119     if ( dec != -1 && inc != -1 ) {
       
  1120         d->elements.swap( dec, inc );
       
  1121         d->updateElements( );
       
  1122     }
       
  1123 }
       
  1124 
       
  1125 /*!
       
  1126     @beta
       
  1127     Returns the maximum value of the slider.
       
  1128 
       
  1129     The default value is \c 100.
       
  1130 
       
  1131     \sa setMaximum( ), setRange( )
       
  1132 */
       
  1133 int HbSlider::maximum( ) const
       
  1134 {
       
  1135     Q_D( const HbSlider );
       
  1136     return d->sliderControl->maximum( );
       
  1137 }
       
  1138 
       
  1139 /*!
       
  1140     @beta
       
  1141     Sets the maximum value of the slider.
       
  1142 
       
  1143     \note When setting this property, the minimum is adjusted if
       
  1144 
       
  1145     necessary to ensure that the range remains valid.  Also the
       
  1146 
       
  1147     slider's current value is adjusted to be within the new range.
       
  1148 
       
  1149     \sa maximum( )
       
  1150 */
       
  1151 void HbSlider::setMaximum( int max )
       
  1152 {
       
  1153     Q_D( HbSlider );
       
  1154     d->sliderControl->setMaximum( max );
       
  1155 }
       
  1156 
       
  1157 /*!
       
  1158     @beta
       
  1159     Returns the minimum value of the slider.
       
  1160 
       
  1161     The default value is \c 0.
       
  1162 
       
  1163     \sa setMinimum( )
       
  1164 */
       
  1165 int HbSlider::minimum( ) const
       
  1166 {
       
  1167     Q_D( const HbSlider );
       
  1168     return d->sliderControl->minimum( );
       
  1169 }
       
  1170 
       
  1171 /*!
       
  1172     @beta
       
  1173     Sets the minimum value of the slider.
       
  1174 
       
  1175     \note When setting this property, the maximum is adjusted if
       
  1176     necessary to ensure that the range remains valid. Also the
       
  1177     slider's current value is adjusted to be within the new range.
       
  1178 
       
  1179     \sa minimum( )
       
  1180 */
       
  1181 void HbSlider::setMinimum( int min )
       
  1182 {
       
  1183     Q_D( HbSlider );
       
  1184     d->sliderControl->setMinimum( min );
       
  1185 }
       
  1186 
       
  1187 /*!
       
  1188     @beta
       
  1189     This function is provided for convenience.
       
  1190 
       
  1191     Sets the slider's minimum to \a min and its maximum to \a max.
       
  1192 
       
  1193     If maximum is smaller than minimum, minimum becomes the only legal value.
       
  1194 
       
  1195     \sa setMinimum( ), setMaximum( )
       
  1196 */
       
  1197 void HbSlider::setRange( int min, int max )
       
  1198 {
       
  1199     Q_D( HbSlider );
       
  1200     d->sliderControl->setRange( min, max );
       
  1201 }
       
  1202 
       
  1203 /*!
       
  1204     @beta
       
  1205     Returns the page step of the slider.
       
  1206 
       
  1207     The default value is \c 10.
       
  1208 
       
  1209     The larger of two natural steps that a slider provides
       
  1210     and typically corresponds to the user pressing PageUp or PageDown.
       
  1211 
       
  1212     \sa setPageStep( )
       
  1213 */
       
  1214 int HbSlider::pageStep( ) const
       
  1215 {
       
  1216     Q_D( const HbSlider );
       
  1217     return d->sliderControl->pageStep( );
       
  1218 }
       
  1219 
       
  1220 /*!
       
  1221     @beta
       
  1222     Sets the page \a step of the slider.
       
  1223 
       
  1224     \sa pageStep( )
       
  1225 */
       
  1226 void HbSlider::setPageStep( int step )
       
  1227 {
       
  1228     Q_D( HbSlider );
       
  1229     d->sliderControl->setPageStep( step );
       
  1230 }
       
  1231 
       
  1232 /*!
       
  1233     @beta
       
  1234     Returns the single step of the slider.
       
  1235 
       
  1236     The default value is \c 1.
       
  1237 
       
  1238     The smaller of two natural steps that an
       
  1239     abstract sliders provides and typically corresponds to the user
       
  1240     pressing an arrow key.
       
  1241 
       
  1242     \sa setSingleStep( )
       
  1243 */
       
  1244 int HbSlider::singleStep( ) const
       
  1245 {
       
  1246     Q_D( const HbSlider );
       
  1247     return d->sliderControl->singleStep( );
       
  1248 }
       
  1249 
       
  1250 /*!
       
  1251     @beta
       
  1252     Sets the single \a step of the slider.
       
  1253 
       
  1254     \sa singleStep( )
       
  1255 */
       
  1256 void HbSlider::setSingleStep( int step )
       
  1257 {
       
  1258     Q_D( HbSlider );
       
  1259     d->sliderControl->setSingleStep( step );
       
  1260 }
       
  1261 
       
  1262 /*!
       
  1263     @beta
       
  1264     Returns the current slider position.
       
  1265 
       
  1266     If tracking is enabled ( the default ), this is identical to the value.
       
  1267 
       
  1268     \sa setSliderPosition( )
       
  1269 */
       
  1270 int HbSlider::sliderPosition( ) const
       
  1271 {
       
  1272     Q_D( const HbSlider );
       
  1273     return d->sliderControl->sliderPosition( );
       
  1274 }
       
  1275 
       
  1276 /*!
       
  1277     @beta
       
  1278     Sets the current slider position.
       
  1279 
       
  1280     \sa sliderPosition( )
       
  1281 */
       
  1282 void HbSlider::setSliderPosition( int pos )
       
  1283 {
       
  1284     Q_D( HbSlider );
       
  1285     d->sliderControl->setSliderPosition( pos );
       
  1286 }
       
  1287 
       
  1288 /*!
       
  1289     @beta
       
  1290     Returns \c true whether slider tracking is enabled.
       
  1291 
       
  1292     The default value is \c true.
       
  1293 
       
  1294     If tracking is enabled, the slider emits the
       
  1295     valueChanged( ) signal while the slider is being dragged. If
       
  1296     tracking is disabled, the slider emits the valueChanged( ) signal
       
  1297     only when the user releases the slider.
       
  1298 
       
  1299     \sa setTracking( )
       
  1300 */
       
  1301 bool HbSlider::hasTracking( ) const
       
  1302 {
       
  1303     Q_D( const HbSlider );
       
  1304     return d->sliderControl->hasTracking( );
       
  1305 }
       
  1306 
       
  1307 /*!
       
  1308     @beta
       
  1309     Sets whether the slider tracking is enabled.
       
  1310 
       
  1311     \sa hasTracking( )
       
  1312 */
       
  1313 void HbSlider::setTracking( bool enable )
       
  1314 {
       
  1315     Q_D( HbSlider );
       
  1316     d->sliderControl->setTracking( enable );
       
  1317 }
       
  1318 
       
  1319 /*!
       
  1320     @beta
       
  1321     Returns the current value of the slider.
       
  1322 
       
  1323     The default value is \c 0.
       
  1324 */
       
  1325 int HbSlider::value( ) const
       
  1326 {
       
  1327     Q_D( const HbSlider );
       
  1328     return d->sliderControl->value( );
       
  1329 }
       
  1330 
       
  1331 /*!
       
  1332     @beta
       
  1333     Sets the current value of the slider.
       
  1334 
       
  1335     The slider forces the value to be within the legal range: \b
       
  1336     minimum <= \c value <= \b maximum.
       
  1337 
       
  1338     Changing the value also changes the \b sliderPosition.
       
  1339 
       
  1340     \sa value( )
       
  1341 */
       
  1342 void HbSlider::setValue( int value )
       
  1343 {
       
  1344     Q_D( HbSlider );
       
  1345     d->sliderControl->setValue( value );
       
  1346 }
       
  1347 
       
  1348 /*!
       
  1349     @beta
       
  1350     Returns the tickmark position of the slider.
       
  1351 
       
  1352     The default value is \c Hb::NoTicks.
       
  1353 
       
  1354     \sa setTickPosition( )
       
  1355 */
       
  1356 Hb::SliderTickPositions HbSlider::tickPosition( ) const
       
  1357 {
       
  1358     Q_D( const HbSlider );
       
  1359     return d->sliderControl->tickPosition( );
       
  1360 }
       
  1361 
       
  1362 /*!
       
  1363     @beta
       
  1364     Sets the tickmark position of the slider.
       
  1365 
       
  1366     The valid values are described by the Hb::SliderTickPositions enum.
       
  1367 
       
  1368     The default value is Hb::NoTicks.
       
  1369 
       
  1370     Note:: if major tick and minor tick interval is zero
       
  1371     then no ticks will be drawn
       
  1372 
       
  1373     Example usage:
       
  1374     \code
       
  1375     HbSlider *slider = new HbSlider( );
       
  1376     slider->setMinorTickInterval( 10 );
       
  1377     slider->setTickPosition( Hb::SliderTicksRight ) ;
       
  1378     \endcode
       
  1379 
       
  1380     \sa tickPosition( ), setMajorTickInterval( ) , setMinorTickInterval( )
       
  1381  */
       
  1382 void HbSlider::setTickPosition( Hb::SliderTickPositions position )
       
  1383 {
       
  1384     Q_D( HbSlider );
       
  1385     d->sliderControl->setTickPosition( position );
       
  1386     d->setTickLabelPresentProperty( );
       
  1387 }
       
  1388 
       
  1389 /*!
       
  1390     @beta
       
  1391     Returns the SnappingMode of the slider.
       
  1392 
       
  1393     The default value is \c HbSlider::MinorTickSnapping.
       
  1394 
       
  1395     \sa setSnappingMode( ) , HbSlider::SnappingMode.
       
  1396 */
       
  1397 HbSlider::SnappingMode HbSlider::snappingMode( ) const 
       
  1398 {
       
  1399     Q_D( const HbSlider );
       
  1400     return ( HbSlider::SnappingMode )( d->sliderControl->snappingMode( ) );
       
  1401 }
       
  1402 
       
  1403 /*!
       
  1404     @beta
       
  1405     Sets the snappingMode of the slider.
       
  1406 
       
  1407     \sa snappingMode( )
       
  1408 */
       
  1409 void HbSlider::setSnappingMode( SnappingMode mode )
       
  1410 {
       
  1411     Q_D( HbSlider );    
       
  1412     d->sliderControl->setSnappingMode( ( HbSliderControl::SnappingMode )mode );
       
  1413 }
       
  1414 
       
  1415 /*!
       
  1416     @beta
       
  1417     Returns the interval between major tickmarks.
       
  1418 
       
  1419     The default value is \c 0.
       
  1420 
       
  1421     \sa setMajorTickInterval( )
       
  1422 */
       
  1423 int HbSlider::majorTickInterval( ) const
       
  1424 {
       
  1425     Q_D( const HbSlider );
       
  1426     return d->sliderControl->majorTickInterval( );
       
  1427 }
       
  1428 
       
  1429 /*!
       
  1430     @beta
       
  1431     Sets the interval between major tickmarks.
       
  1432 
       
  1433     absolute value will be taken for tick interval
       
  1434 
       
  1435     \default value is 0
       
  1436 
       
  1437     \sa majorTickInterval( )
       
  1438 */
       
  1439 void HbSlider::setMajorTickInterval( int interval )
       
  1440 {
       
  1441     Q_D( HbSlider );
       
  1442     d->sliderControl->setMajorTickInterval( interval );
       
  1443     d->setTickLabelPresentProperty( );
       
  1444 }
       
  1445 
       
  1446 /*!
       
  1447     @beta
       
  1448     Returns the interval between minor tickmarks.
       
  1449 
       
  1450     The default value is \c 0.
       
  1451 
       
  1452     \sa setMinorTickInterval( )
       
  1453 */
       
  1454 int HbSlider::minorTickInterval( ) const
       
  1455 {
       
  1456     Q_D( const HbSlider );
       
  1457     return d->sliderControl->minorTickInterval( );
       
  1458 }
       
  1459 
       
  1460 /*!
       
  1461     @beta
       
  1462     Sets the interval between minor tickmarks.
       
  1463 
       
  1464     absolute value will be taken for tick interval
       
  1465 
       
  1466     \default value is 0
       
  1467 
       
  1468     \sa minorTickInterval( )
       
  1469 */
       
  1470 void HbSlider::setMinorTickInterval( int interval )
       
  1471 {
       
  1472     Q_D( HbSlider );
       
  1473     d->sliderControl->setMinorTickInterval( interval );
       
  1474     d->setTickLabelPresentProperty( );
       
  1475 }
       
  1476 
       
  1477 /*!
       
  1478     @beta
       
  1479     sets the icon path for handle 
       
  1480 
       
  1481     \sa handleIcon( )
       
  1482    
       
  1483 */
       
  1484 void HbSlider::setHandleIcon( const QString& handlePath )
       
  1485 {
       
  1486     Q_D( HbSlider );
       
  1487     d->sliderControl->setHandleIcon( handlePath );
       
  1488 }
       
  1489 
       
  1490 /*!
       
  1491     @beta
       
  1492     returns icon of handle
       
  1493 
       
  1494     \sa handleIcosetHandleIconn( )
       
  1495      
       
  1496 */
       
  1497 QString HbSlider::handleIcon( ) const
       
  1498 {
       
  1499     Q_D( const HbSlider );
       
  1500     return d->sliderControl->handleIcon( );
       
  1501 }
       
  1502 
       
  1503 
       
  1504 /*!
       
  1505     @proto
       
  1506     Sets whether to display progress track or not
       
  1507 
       
  1508     \default value is true
       
  1509 
       
  1510     \sa isTrackFilled( )
       
  1511 */
       
  1512 void HbSlider::setTrackFilled(bool trackVisible )
       
  1513 {
       
  1514     
       
  1515     Q_D( const HbSlider );
       
  1516     return d->sliderControl->setTrackFilled( trackVisible );
       
  1517 
       
  1518 }
       
  1519 
       
  1520 /*!
       
  1521     @proto
       
  1522     returns whether progress track is visible or not
       
  1523 
       
  1524     \sa setTrackFilled( )
       
  1525      
       
  1526 */
       
  1527 bool HbSlider::isTrackFilled() const
       
  1528 {
       
  1529     Q_D( const HbSlider );
       
  1530     return d->sliderControl->isTrackFilled();
       
  1531 
       
  1532 }
       
  1533 
       
  1534 /*!
       
  1535     @beta
       
  1536     Returns the major ticklabels of the slider.
       
  1537   
       
  1538     \sa setMajorTickLabels( )
       
  1539 */
       
  1540 QStringList HbSlider::majorTickLabels( ) const
       
  1541 {
       
  1542     Q_D( const HbSlider );
       
  1543     return d->sliderControl->majorTickLabels( );
       
  1544 }
       
  1545 
       
  1546 /*!
       
  1547     @beta
       
  1548     Sets the major ticklabels of the slider.
       
  1549 
       
  1550     Detailed description:
       
  1551 
       
  1552     Strings from the stringlist will be taken sequentially for drawing
       
  1553     LabelItem,there exists a one-to-one mapping between tickmarkitem &
       
  1554     tickmarklabelitem.
       
  1555 
       
  1556     case 1: if strings provided > tickmarks, labels are drawn for the
       
  1557     strings which maps the tickmarkitems.If there are extra strings 
       
  1558     available in the list beyond 1-1 mapping, those strings will be left out.
       
  1559 
       
  1560     case 2: if strings provided < tickmarks, labels are drawn only for strings
       
  1561     provided.Rest of the tickmarkitems will be drawn without labelItem.
       
  1562 
       
  1563     case 3: If some tickmarkitems to be drawn without labelItem in the middle,
       
  1564     specify empty string ( "" ) for that item  in the string list.
       
  1565 
       
  1566     case 4: if both major & minor tickinterval are same,then only majortickLabel
       
  1567     strings are taken into account for drawing the labelItem
       
  1568 
       
  1569     \sa majorTickLabels( )
       
  1570 */
       
  1571 void HbSlider::setMajorTickLabels( const QStringList &majorTickLabels )
       
  1572 {
       
  1573     Q_D( HbSlider );
       
  1574     d->sliderControl->setMajorTickLabels( majorTickLabels );
       
  1575     d->setTickLabelPresentProperty( );
       
  1576 }
       
  1577 
       
  1578 /*!
       
  1579     @beta
       
  1580     Returns the minor ticklabels of the slider.
       
  1581   
       
  1582     \sa setMinorTickLabels( )
       
  1583 */
       
  1584 QStringList HbSlider::minorTickLabels( ) const
       
  1585 {
       
  1586     Q_D( const HbSlider );
       
  1587     return d->sliderControl->minorTickLabels( );
       
  1588 }
       
  1589 
       
  1590 /*!
       
  1591     @beta
       
  1592     Sets the minor ticklabels of the slider.
       
  1593     see setMajorTickLabels for detailed description
       
  1594 
       
  1595     \sa minorTickLabels( ),setMajorTickLabels( )
       
  1596 */
       
  1597 void HbSlider::setMinorTickLabels( const QStringList &minorTickLabels )
       
  1598 {
       
  1599     Q_D( HbSlider );
       
  1600     d->sliderControl->setMinorTickLabels( minorTickLabels );
       
  1601     d->setTickLabelPresentProperty( );
       
  1602 }
       
  1603 
       
  1604 
       
  1605 /*!
       
  1606     \reimp
       
  1607  */
       
  1608 QGraphicsItem *HbSlider::primitive( HbStyle::Primitive primitive ) const
       
  1609 {
       
  1610     Q_D( const HbSlider );
       
  1611     switch ( primitive ) {
       
  1612         case HbStyle::P_Slider_thumb:
       
  1613             return HbSliderControlPrivate::d_ptr( d->sliderControl )->handle->primitive( 
       
  1614                 HbStyle::P_Slider_thumb );
       
  1615         case HbStyle::P_SliderElement_text:
       
  1616             if (d->elementItemMap.contains (HbSlider::TextElement) ){
       
  1617                 return d->elementItemMap[HbSlider::TextElement].item;
       
  1618             }
       
  1619             break;
       
  1620         case HbStyle::P_SliderElement_icon:
       
  1621             if (d->elementItemMap.contains (HbSlider::IconElement)) {
       
  1622                 return d->elementItemMap[HbSlider::IconElement].item;
       
  1623             }
       
  1624             break;
       
  1625         case HbStyle::P_SliderElement_increase:
       
  1626             if (d->elementItemMap.contains (HbSlider::IncreaseElement)) {
       
  1627                 return d->elementItemMap[HbSlider::IncreaseElement].item;
       
  1628             }
       
  1629             break;
       
  1630         case HbStyle::P_SliderElement_decrease:
       
  1631             if (d->elementItemMap.contains (HbSlider::DecreaseElement)) {
       
  1632                 return d->elementItemMap[HbSlider::DecreaseElement].item;
       
  1633             }
       
  1634             break;
       
  1635         case HbStyle::P_Slider_groove:
       
  1636             return HbSliderControlPrivate::d_ptr( d->sliderControl )->groove;
       
  1637         
       
  1638         case HbStyle::P_SliderElement_touchhandle:
       
  1639             return HbSliderControlPrivate::d_ptr( d->sliderControl )->handle->primitive( 
       
  1640                 HbStyle::P_SliderElement_touchhandle );
       
  1641             
       
  1642         default:
       
  1643             break;
       
  1644     }
       
  1645     return 0;
       
  1646 }
       
  1647 
       
  1648 /*!
       
  1649     \reimp
       
  1650  */
       
  1651 void HbSlider::updatePrimitives( )
       
  1652 {
       
  1653     HbWidget::updatePrimitives();
       
  1654     Q_D( const HbSlider );
       
  1655     HbStyleOptionSlider option;
       
  1656     initStyleOption( &option );
       
  1657 
       
  1658     if ( d->elementItemMap.contains(HbSlider::TextElement)) {
       
  1659         option.text = d->sliderTextString; 
       
  1660         style( )->updatePrimitive( d->elementItemMap[HbSlider::TextElement].item,d->elementItemMap[HbSlider::TextElement].type,&option );
       
  1661     }
       
  1662     if ( d->elementItemMap.contains(HbSlider::IconElement)) {
       
  1663         option.sliderElementIcon =d->icons.value( HbSlider::IconElement ); 
       
  1664         style( )->updatePrimitive( d->elementItemMap[HbSlider::IconElement].item,HbStyle::P_SliderElement_icon,&option );
       
  1665     }
       
  1666     if ( d->elementItemMap.contains(HbSlider::IncreaseElement) ) {
       
  1667         option.sliderElementIcon =d->icons.value( HbSlider::IncreaseElement ); 
       
  1668         style( )->updatePrimitive( d->elementItemMap[HbSlider::IncreaseElement].item,HbStyle::P_SliderElement_increase,&option );
       
  1669         style( )->updatePrimitive(  d->elementItemMap[HbSlider::IncreaseElement].touchItem ,HbStyle::P_SliderElement_touchincrease,&option );
       
  1670 
       
  1671     }
       
  1672     if ( d->elementItemMap.contains (HbSlider::DecreaseElement) ) {
       
  1673         option.sliderElementIcon =d->icons.value( HbSlider::DecreaseElement ); 
       
  1674         style( )->updatePrimitive( d->elementItemMap[HbSlider::DecreaseElement].item,HbStyle::P_SliderElement_decrease,&option );
       
  1675         style( )->updatePrimitive( d->elementItemMap[HbSlider::DecreaseElement].touchItem ,HbStyle::P_SliderElement_touchdecrease,&option );
       
  1676     }
       
  1677     if ( d->sliderControl ) {
       
  1678         d->sliderControl->updatePrimitives( );
       
  1679     }
       
  1680 }
       
  1681 
       
  1682 /*!
       
  1683     \reimp
       
  1684  */
       
  1685 void HbSlider::mousePressEvent( QGraphicsSceneMouseEvent *event )
       
  1686 {
       
  1687     Q_D( HbSlider );
       
  1688     HbWidget::mousePressEvent( event );
       
  1689     if( d->elementItemMap.contains (HbSlider::IncreaseElement) ) {
       
  1690         if ( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) {
       
  1691             // this is used for effect
       
  1692             d->pressOnIncrement  = true;
       
  1693             HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement );
       
  1694             event->accept( );
       
  1695             // increment and start reapeat timer 
       
  1696             d->startIncrementing( );
       
  1697             return;
       
  1698         }
       
  1699     }
       
  1700     if( d->elementItemMap.contains(HbSlider::DecreaseElement) ) {
       
  1701         if ( d->elementItemMap[HbSlider::DecreaseElement].touchItem->isUnderMouse( ) ) {
       
  1702             d->pressOnIncrement  = false;
       
  1703             HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantPressed, Hb::ModifierSliderElement );
       
  1704             event->accept( );
       
  1705             //decrement and start decrement timer
       
  1706             d->startDecrementing( );
       
  1707             return;
       
  1708         }
       
  1709     }
       
  1710 }
       
  1711 
       
  1712 
       
  1713 /*!
       
  1714     \reimp
       
  1715 
       
  1716     This Api start the releae effect.
       
  1717  */
       
  1718 void HbSlider::mouseReleaseEvent( QGraphicsSceneMouseEvent *event )
       
  1719 {
       
  1720     Q_D( HbSlider );
       
  1721     HbWidget::mouseReleaseEvent( event );
       
  1722     if( d->elementItemMap.contains(HbSlider::IncreaseElement) ) {
       
  1723         if ( d->pressOnIncrement ) {
       
  1724             if( d->elementItemMap[HbSlider::IncreaseElement].touchItem->isUnderMouse( ) ) {
       
  1725                 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantReleased, Hb::ModifierSliderElement );
       
  1726             }
       
  1727 #ifdef HB_EFFECTS
       
  1728             HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_release", "increaserelease" );
       
  1729             HbEffect::start( d->elementItemMap[HbSlider::IncreaseElement].item, HB_SLIDER_TYPE, "increaserelease" );  
       
  1730 #endif
       
  1731         }
       
  1732     }
       
  1733     if( d->elementItemMap.contains(HbSlider::DecreaseElement) ) {
       
  1734         if ( !d->pressOnIncrement ) {
       
  1735             if( d->elementItemMap[HbSlider::DecreaseElement].touchItem->isUnderMouse( ) ) {
       
  1736                 HbWidgetFeedback::triggered( d->sliderControl, Hb::InstantReleased, Hb::ModifierSliderElement );
       
  1737             }
       
  1738 #ifdef HB_EFFECTS
       
  1739             HbEffectInternal::add( HB_SLIDER_TYPE,"slidericon_release", "decreaserelease" );
       
  1740             HbEffect::start( d->elementItemMap[HbSlider::DecreaseElement].item, HB_SLIDER_TYPE, "decreaserelease" );  
       
  1741 #endif
       
  1742         }
       
  1743     }
       
  1744     d->stopRepeatAction( );
       
  1745 }
       
  1746 
       
  1747 /*!
       
  1748     \reimp
       
  1749 
       
  1750     This api update the primitive when ever item enable has changed
       
  1751  */
       
  1752 QVariant HbSlider::itemChange( GraphicsItemChange change, const QVariant &value )
       
  1753 {
       
  1754     switch( change )
       
  1755     {
       
  1756         case ItemEnabledHasChanged:
       
  1757             updatePrimitives( );
       
  1758             break;
       
  1759         default:
       
  1760             break;
       
  1761     }
       
  1762     return HbWidget::itemChange( change, value );
       
  1763 }
       
  1764 
       
  1765 /*!
       
  1766     \reimp
       
  1767  */
       
  1768 void HbSlider::focusInEvent( QFocusEvent* event )
       
  1769 {
       
  1770     Q_D( HbSlider );
       
  1771     HbWidget::focusInEvent( event );
       
  1772     d->sliderControl->setFocus( );    
       
  1773 }
       
  1774 
       
  1775 
       
  1776 #include "moc_hbslider.cpp"