src/hbwidgets/sliders/hbslider.cpp
changeset 3 11d3954df52a
parent 2 06ff229162e9
child 6 c3690ec91ef8
equal deleted inserted replaced
2:06ff229162e9 3:11d3954df52a
    29 #include "hbslidercontrol_p_p.h"
    29 #include "hbslidercontrol_p_p.h"
    30 #include "hbnamespace_p.h"
    30 #include "hbnamespace_p.h"
    31 #include "hbsliderhandle_p.h"
    31 #include "hbsliderhandle_p.h"
    32 
    32 
    33 #include "hbstyleoptionslider_p.h"
    33 #include "hbstyleoptionslider_p.h"
       
    34 #include "hbslidertickmarks_p.h"
    34 #include "hbslidertickmarkslabel_p.h"
    35 #include "hbslidertickmarkslabel_p.h"
    35 #include "hbabstractbutton.h"
    36 #include "hbabstractbutton.h"
    36 #include <hbwidgetfeedback.h>
    37 #include <hbwidgetfeedback.h>
    37 #include <QGraphicsItem>
    38 #include <QGraphicsItem>
    38 #include <QGraphicsSceneEvent>
    39 #include <QGraphicsSceneEvent>
   241  */
   242  */
   242 
   243 
   243 HbSliderPrivate::HbSliderPrivate( ) :
   244 HbSliderPrivate::HbSliderPrivate( ) :
   244     sliderControl( 0 ),
   245     sliderControl( 0 ),
   245     orientation( Qt::Vertical ),
   246     orientation( Qt::Vertical ),
   246     pressOnIncrement( false )
   247     pressOnIncrement( false ),
       
   248     tickmarksLeft( 0 ), // slider left/top tick mark item
       
   249     tickmarksRight( 0 ),// slider right/bottom tick mark item
       
   250     tickmarkslabelLeft( 0 ),// slider left/above tick mark label
       
   251     tickmarkslabelRight ( 0 )// slider right/bottom tick mark label
       
   252 
   247 {
   253 {
   248     elementItemMap.clear();
   254     elementItemMap.clear();
   249 
   255 
   250 }
   256 }
   251 
   257 
   289     }
   295     }
   290     elements = elementList;
   296     elements = elementList;
   291     // this will delete unwanted element and create new element
   297     // this will delete unwanted element and create new element
   292     updateElements( );
   298     updateElements( );
   293     // repolish call is required because new elements might be added
   299     // repolish call is required because new elements might be added
       
   300 }
       
   301 
       
   302 QSizeF HbSliderPrivate::getHandleSize( )
       
   303 {
       
   304    return sliderControl ->getHandleSize();
   294 }
   305 }
   295 
   306 
   296 /*!
   307 /*!
   297     This api creates widget for given element   
   308     This api creates widget for given element   
   298  */
   309  */
   462             }
   473             }
   463     }
   474     }
   464 
   475 
   465 }
   476 }
   466 
   477 
       
   478 
       
   479 
       
   480 
       
   481 void HbSliderPrivate::createTickMarks( )
       
   482 {
       
   483     Q_Q ( HbSlider);
       
   484     bool modified = false;
       
   485     if( q->majorTickInterval( ) <= 0) {
       
   486         return;
       
   487     }
       
   488     if ( q->tickPosition( ) & Hb::SliderTicksLeft) {
       
   489         if (!tickmarksLeft) {
       
   490             tickmarksLeft =  new HbSliderTickmarks(q);
       
   491             tickmarksLeft->setZValue(sliderControl->zValue()-1);
       
   492             tickmarksLeft->setTickPosition (Hb::SliderTicksLeft);
       
   493             modified = true;
       
   494             if ( orientation == Qt::Vertical ) {
       
   495                 HbStyle::setItemName( tickmarksLeft, "tick-marksleft" );
       
   496             } else {
       
   497                 HbStyle::setItemName( tickmarksLeft, "tick-marksabove" );
       
   498             }
       
   499         } 
       
   500 
       
   501     } else if ( tickmarksLeft ) {
       
   502         delete tickmarksLeft;
       
   503         tickmarksLeft = 0;
       
   504         modified = true;
       
   505     }
       
   506     if ( q->tickPosition( ) & Hb::SliderTicksRight) {
       
   507         if (!tickmarksRight) {
       
   508             tickmarksRight =  new HbSliderTickmarks(q);
       
   509             tickmarksRight->setTickPosition (Hb::SliderTicksRight);
       
   510             tickmarksRight->setZValue(sliderControl->zValue()-1);
       
   511             modified = true;
       
   512 
       
   513             if ( orientation == Qt::Vertical ) {
       
   514                 HbStyle::setItemName( tickmarksRight, "tick-marksright" );
       
   515             } else {
       
   516                 HbStyle::setItemName( tickmarksRight, "tick-marksbelow" );
       
   517             }
       
   518         }
       
   519     } else if ( tickmarksRight ) {
       
   520         delete tickmarksRight;
       
   521         tickmarksRight = 0;
       
   522         modified = true;
       
   523     }
       
   524     if ( orientation == Qt::Vertical ) {
       
   525         if ( q->tickPosition( ) & Hb::SliderTicksAbsolute)  {
       
   526             q->setLayoutDirection (Qt::LeftToRight );
       
   527         } else {
       
   528             q->unsetLayoutDirection( );
       
   529         }
       
   530     } else {
       
   531         q->unsetLayoutDirection( );   
       
   532     }
       
   533     
       
   534     if ( modified) {
       
   535         q->repolish( );
       
   536     }
       
   537 }
       
   538 
       
   539 
       
   540 void HbSliderPrivate::createTickLabels( )
       
   541 {   
       
   542     Q_Q(HbSlider);
       
   543     bool modified = false;
       
   544     if( q->majorTickInterval( ) <= 0 || q->majorTickLabels( ).isEmpty( ) ) {
       
   545         return;
       
   546     }
       
   547     if ( q->tickPosition( ) & Hb::SliderTicksLeft) {
       
   548         if (!tickmarkslabelLeft) {
       
   549             modified = true;
       
   550             tickmarkslabelLeft =  new HbSliderTickmarksLabel(q);
       
   551             tickmarkslabelLeft->setTickPosition (Hb::SliderTicksLeft);
       
   552             if ( orientation == Qt::Vertical ) {
       
   553                 HbStyle::setItemName( tickmarkslabelLeft, "tick-textsleft" );
       
   554             } else {
       
   555                 HbStyle::setItemName( tickmarkslabelLeft, "tick-textsabove" );
       
   556             }
       
   557         }
       
   558     } else if ( tickmarkslabelLeft ) {
       
   559         modified = true;
       
   560         delete tickmarkslabelLeft;
       
   561         tickmarkslabelLeft = 0;
       
   562     }
       
   563     if ( q->tickPosition( ) & Hb::SliderTicksRight) {
       
   564         if (!tickmarkslabelRight) {
       
   565             modified = true;
       
   566             tickmarkslabelRight =  new HbSliderTickmarksLabel(q);
       
   567             tickmarkslabelRight->setTickPosition (Hb::SliderTicksRight);
       
   568             if ( orientation == Qt::Vertical ) {
       
   569                 HbStyle::setItemName( tickmarkslabelRight, "tick-textsright" );
       
   570             } else {
       
   571                 HbStyle::setItemName( tickmarkslabelRight, "tick-textsbelow" );
       
   572             }
       
   573         }
       
   574     } else if ( tickmarkslabelRight ) {
       
   575         delete tickmarkslabelRight;
       
   576         modified = true;
       
   577         tickmarkslabelRight = 0;
       
   578     }
       
   579     if ( orientation == Qt::Vertical ) {
       
   580         if ( q->tickPosition( ) & Hb::SliderTicksAbsolute)  {
       
   581             q->setLayoutDirection (Qt::LeftToRight );
       
   582         }
       
   583     }
       
   584     if ( modified ) {
       
   585         q->repolish( );
       
   586     }
       
   587 }
       
   588 
       
   589 
       
   590 void HbSliderPrivate::setTickOrientation()
       
   591 {
       
   592     Q_Q(HbSlider);
       
   593     if ( orientation == Qt::Vertical ) {
       
   594         if ( tickmarksLeft ) {
       
   595             HbStyle::setItemName( tickmarksLeft, "tick-marksleft" );
       
   596         }
       
   597         if ( tickmarksRight) {
       
   598             HbStyle::setItemName( tickmarksRight, "tick-marksright" );
       
   599         }
       
   600         if (tickmarkslabelLeft ) {
       
   601             HbStyle::setItemName( tickmarkslabelLeft, "tick-textsleft" );
       
   602         }
       
   603         if (tickmarkslabelRight ) {
       
   604             HbStyle::setItemName( tickmarkslabelRight, "tick-textsright" );
       
   605         }
       
   606         if ( q->tickPosition( )&Hb::SliderTicksAbsolute) {
       
   607             q->setLayoutDirection (Qt::LeftToRight);
       
   608         }
       
   609     } else {
       
   610         if ( tickmarksLeft ) {
       
   611             HbStyle::setItemName( tickmarksLeft, "tick-marksabove" );
       
   612         }
       
   613         if ( tickmarksRight) {
       
   614             HbStyle::setItemName( tickmarksRight, "tick-marksbelow" );
       
   615         }
       
   616         if (tickmarkslabelLeft ) {
       
   617             HbStyle::setItemName( tickmarkslabelLeft, "tick-textsabove" );
       
   618         }
       
   619         if (tickmarkslabelRight ) {
       
   620             HbStyle::setItemName( tickmarkslabelRight, "tick-textsbelow" );
       
   621         }
       
   622         q->unsetLayoutDirection( );
       
   623 
       
   624 
       
   625     }
       
   626 
       
   627 }
       
   628 
       
   629 
       
   630 
       
   631 
       
   632 
       
   633 /*!
       
   634   \internal
       
   635   Updates tick and Label.
       
   636   */
       
   637 void HbSliderPrivate::updateTickMarks( )
       
   638 {
       
   639     if (tickmarksLeft) {
       
   640         tickmarksLeft->updateTicks();
       
   641     }
       
   642     if (tickmarksRight) {
       
   643         tickmarksRight->updateTicks();
       
   644     }
       
   645 }
       
   646 
       
   647 
       
   648 /*!
       
   649   \internal
       
   650   Updates tick and Label.
       
   651   */
       
   652 void HbSliderPrivate::updateTickLabels( )
       
   653 {
       
   654     if( tickmarkslabelLeft ) {
       
   655         tickmarkslabelLeft->updateTickLabels();
       
   656     }
       
   657     if( tickmarkslabelRight ) {
       
   658         tickmarkslabelRight->updateTickLabels( );
       
   659     }
       
   660 }
       
   661 
       
   662 
       
   663 /*!
       
   664   \internal
       
   665   Updates tick and Label.
       
   666   */
       
   667 void HbSliderPrivate::deleteTickMarks( )
       
   668 {
       
   669     Q_Q ( HbSlider );
       
   670     bool deleted = false;
       
   671     if (tickmarksLeft) {
       
   672         delete tickmarksLeft;
       
   673         tickmarksLeft = 0;
       
   674         deleted = true;
       
   675     }  
       
   676     if (tickmarksRight) {
       
   677         delete tickmarksRight;
       
   678         tickmarksRight = 0;
       
   679         deleted = true;
       
   680     }
       
   681     if ( deleted ) {
       
   682         q->repolish( );
       
   683     }
       
   684 
       
   685 }
       
   686 
       
   687 
       
   688 /*!
       
   689   \internal
       
   690   Updates tick and Label.
       
   691   */
       
   692 void HbSliderPrivate::deleteTickLabels( )
       
   693 {
       
   694 
       
   695     Q_Q(HbSlider);
       
   696     bool deleted = false;
       
   697     if (tickmarkslabelLeft) {
       
   698         delete tickmarkslabelLeft;
       
   699         tickmarkslabelLeft = 0;
       
   700         deleted = true;
       
   701 
       
   702     }  
       
   703     if (tickmarkslabelRight) {
       
   704         delete tickmarkslabelRight;
       
   705         tickmarkslabelRight = 0;
       
   706         deleted = true;
       
   707     }
       
   708     if (deleted) {
       
   709         q->repolish( );
       
   710     }
       
   711 
       
   712  }
       
   713 
   467 #ifdef HB_EFFECTS
   714 #ifdef HB_EFFECTS
   468 
   715 
   469 /*!
   716 /*!
   470     start effect for on icon press
   717     start effect for on icon press
   471  */
   718  */
   549 HbSlider::~HbSlider( )
   796 HbSlider::~HbSlider( )
   550 {
   797 {
   551 }
   798 }
   552 
   799 
   553 /*!
   800 /*!
   554     @proto
   801     @beta
   555     Returns the list of slider elements as QVariant 
   802     Returns the list of slider elements as QVariant 
   556     
   803     
   557     \note it is safe to type-cast element to HbSlider::SliderElement.  
   804     \note it is safe to type-cast element to HbSlider::SliderElement.  
   558    
   805    
   559     The slider contains only track element by default.
   806     The slider contains only track element by default.
   569     }
   816     }
   570     return elementList;
   817     return elementList;
   571 }
   818 }
   572 
   819 
   573 /*!
   820 /*!
   574     @proto
   821     @beta
   575     Sets the elements of the slider.
   822     Sets the elements of the slider.
   576 
   823 
   577     \note Duplicate elements will be ignored.
   824     \note Duplicate elements will be ignored.
   578 
   825 
   579     \note element order cant be changed
   826     \note element order cant be changed
   601     }
   848     }
   602     d->setElements( elements );
   849     d->setElements( elements );
   603 }
   850 }
   604 
   851 
   605 /*!
   852 /*!
   606     @proto
   853     @beta
   607     Sets the icons for elements
   854     Sets the icons for elements
   608 
   855 
   609     key of \a elements is element name  and value is icon 
   856     key of \a elements is element name  and value is icon 
   610     name to set on given element
   857     name to set on given element
   611     Use following string for specifying elements
   858     Use following string for specifying elements
   656         }
   903         }
   657     }
   904     }
   658 }
   905 }
   659 
   906 
   660 /*!
   907 /*!
   661     @proto
   908     @beta
   662     Returns the map , which consist of element name as key and icon name  as value
   909     Returns the map , which consist of element name as key and icon name  as value
   663 
   910 
   664     returns NULL map if none of the element has icon
   911     returns NULL map if none of the element has icon
   665 
   912 
   666     \sa setElementIcons()
   913     \sa setElementIcons()
   961 {
  1208 {
   962     Q_D( HbSlider );
  1209     Q_D( HbSlider );
   963     if ( d->orientation != orientation ) {
  1210     if ( d->orientation != orientation ) {
   964         d->orientation = orientation;
  1211         d->orientation = orientation;
   965         d->sliderControl->setOrientation( orientation );
  1212         d->sliderControl->setOrientation( orientation );
   966         repolish();
  1213         d->setTickOrientation( );
       
  1214         repolish( );
   967     }
  1215     }
   968 }
  1216 }
   969 
  1217 
   970 /*!
  1218 /*!
   971     @beta
  1219     @beta
  1288 void HbSlider::setTickPosition( Hb::SliderTickPositions position )
  1536 void HbSlider::setTickPosition( Hb::SliderTickPositions position )
  1289 {
  1537 {
  1290     Q_D( HbSlider );
  1538     Q_D( HbSlider );
  1291     d->sliderControl->setTickPosition( position );
  1539     d->sliderControl->setTickPosition( position );
  1292     d->setTickLabelPresentProperty( );
  1540     d->setTickLabelPresentProperty( );
       
  1541     d->createTickMarks( );
       
  1542     d->createTickLabels( );
  1293 }
  1543 }
  1294 
  1544 
  1295 /*!
  1545 /*!
  1296     @beta
  1546     @beta
  1297     Returns the SnappingMode of the slider.
  1547     Returns the SnappingMode of the slider.
  1344 */
  1594 */
  1345 void HbSlider::setMajorTickInterval( int interval )
  1595 void HbSlider::setMajorTickInterval( int interval )
  1346 {
  1596 {
  1347     Q_D( HbSlider );
  1597     Q_D( HbSlider );
  1348     d->sliderControl->setMajorTickInterval( interval );
  1598     d->sliderControl->setMajorTickInterval( interval );
       
  1599     if (interval <=0 ) {
       
  1600         d->deleteTickMarks( );
       
  1601         d->deleteTickLabels( );
       
  1602     }
       
  1603     else {
       
  1604         d->createTickMarks( );
       
  1605         d->createTickLabels( );
       
  1606         d->updateTickMarks( );
       
  1607         d->updateTickLabels( );
       
  1608     }
  1349     d->setTickLabelPresentProperty( );
  1609     d->setTickLabelPresentProperty( );
  1350 }
  1610 }
  1351 
  1611 
  1352 /*!
  1612 /*!
  1353     @beta
  1613     @beta
  1375 */
  1635 */
  1376 void HbSlider::setMinorTickInterval( int interval )
  1636 void HbSlider::setMinorTickInterval( int interval )
  1377 {
  1637 {
  1378     Q_D( HbSlider );
  1638     Q_D( HbSlider );
  1379     d->sliderControl->setMinorTickInterval( interval );
  1639     d->sliderControl->setMinorTickInterval( interval );
       
  1640     d->updateTickMarks( );
       
  1641     d->updateTickLabels( );
  1380     d->setTickLabelPresentProperty( );
  1642     d->setTickLabelPresentProperty( );
  1381 }
  1643 }
  1382 
  1644 
  1383 /*!
  1645 /*!
  1384     @beta
  1646     @beta
  1406     return d->sliderControl->handleIcon( );
  1668     return d->sliderControl->handleIcon( );
  1407 }
  1669 }
  1408 
  1670 
  1409 
  1671 
  1410 /*!
  1672 /*!
  1411     @proto
  1673     @beta
  1412     Sets whether to display progress track or not
  1674     Sets whether to display progress track or not
  1413 
  1675 
  1414     \default value is true
  1676     \default value is true
  1415 
  1677 
  1416     \sa isTrackFilled( )
  1678     \sa isTrackFilled( )
  1422     return d->sliderControl->setTrackFilled( trackVisible );
  1684     return d->sliderControl->setTrackFilled( trackVisible );
  1423 
  1685 
  1424 }
  1686 }
  1425 
  1687 
  1426 /*!
  1688 /*!
  1427     @proto
  1689     @beta
  1428     returns whether progress track is visible or not
  1690     returns whether progress track is visible or not
  1429 
  1691 
  1430     \sa setTrackFilled( )
  1692     \sa setTrackFilled( )
  1431      
  1693      
  1432 */
  1694 */
  1476 */
  1738 */
  1477 void HbSlider::setMajorTickLabels( const QStringList &majorTickLabels )
  1739 void HbSlider::setMajorTickLabels( const QStringList &majorTickLabels )
  1478 {
  1740 {
  1479     Q_D( HbSlider );
  1741     Q_D( HbSlider );
  1480     d->sliderControl->setMajorTickLabels( majorTickLabels );
  1742     d->sliderControl->setMajorTickLabels( majorTickLabels );
  1481     d->setTickLabelPresentProperty( );
  1743     if(majorTickLabels.isEmpty( )) {
       
  1744         d->deleteTickLabels( );
       
  1745     } else {
       
  1746         d->createTickLabels( );
       
  1747         d->updateTickLabels( );
       
  1748         d->setTickLabelPresentProperty( );
       
  1749     }
  1482 }
  1750 }
  1483 
  1751 
  1484 /*!
  1752 /*!
  1485     @beta
  1753     @beta
  1486     Returns the minor ticklabels of the slider.
  1754     Returns the minor ticklabels of the slider.
  1502 */
  1770 */
  1503 void HbSlider::setMinorTickLabels( const QStringList &minorTickLabels )
  1771 void HbSlider::setMinorTickLabels( const QStringList &minorTickLabels )
  1504 {
  1772 {
  1505     Q_D( HbSlider );
  1773     Q_D( HbSlider );
  1506     d->sliderControl->setMinorTickLabels( minorTickLabels );
  1774     d->sliderControl->setMinorTickLabels( minorTickLabels );
       
  1775     d->updateTickLabels( );
  1507     d->setTickLabelPresentProperty( );
  1776     d->setTickLabelPresentProperty( );
  1508 }
  1777 }
  1509 
  1778 
  1510 
  1779 
  1511 /*!
  1780 /*!