src/hbwidgets/sliders/hbslidertickmarks.cpp
changeset 34 ed14f46c0e55
parent 6 c3690ec91ef8
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    43 #include "hbeffectinternal_p.h"
    43 #include "hbeffectinternal_p.h"
    44 #define HB_SLIDER_TYPE "HB_SLIDER"
    44 #define HB_SLIDER_TYPE "HB_SLIDER"
    45 #endif
    45 #endif
    46 
    46 
    47 
    47 
    48 
       
    49 
       
    50 
       
    51 
       
    52 class HbSliderTickmarksPrivate : public HbWidgetPrivate
    48 class HbSliderTickmarksPrivate : public HbWidgetPrivate
    53 {
    49 {
    54     Q_DECLARE_PUBLIC( HbSliderTickmarks )
    50     Q_DECLARE_PUBLIC( HbSliderTickmarks )
    55 
    51 
    56 public:
    52 public:
    57     HbSliderTickmarksPrivate();
    53     HbSliderTickmarksPrivate();
    58     HbStyleOptionSlider sliderOption;
       
    59     QList<QGraphicsWidget *> tickmarkmajorIcons;
    54     QList<QGraphicsWidget *> tickmarkmajorIcons;
    60     QList<QGraphicsWidget *> tickmarkminorIcons;
    55     QList<QGraphicsWidget *> tickmarkminorIcons;
    61     HbSlider *slider;
    56     HbSlider *slider;
    62     Hb::SliderTickPositions tickPosition;
    57     Hb::SliderTickPositions tickPosition;
    63     qreal majorTickWidth;
    58     qreal majorTickWidth;
    66     qreal minorTickHeight;
    61     qreal minorTickHeight;
    67     Qt::Orientation sliderOrientation;
    62     Qt::Orientation sliderOrientation;
    68 };
    63 };
    69 
    64 
    70 
    65 
    71  HbSliderTickmarksPrivate::HbSliderTickmarksPrivate() :HbWidgetPrivate(){
    66 HbSliderTickmarksPrivate::HbSliderTickmarksPrivate() :
    72     tickmarkmajorIcons.clear();
    67     HbWidgetPrivate(), 
    73     tickmarkminorIcons.clear();
    68     slider(0),
    74     slider = 0;
    69     tickPosition(Hb::NoSliderTicks),
    75     tickPosition = Hb::NoSliderTicks;
    70     majorTickWidth(0),
    76     majorTickWidth = 0;
    71     minorTickWidth(0),
    77     minorTickWidth = 0;
    72     majorTickHeight(0),
    78     majorTickHeight = 0;
    73     minorTickHeight(0),
    79     minorTickHeight = 0;
    74     sliderOrientation(Qt::Vertical)
    80     sliderOrientation = Qt::Vertical;
    75  
       
    76 {
    81 }
    77 }
    82 
    78 
    83 void  HbSliderTickmarks::createTicks(  )
    79 void  HbSliderTickmarks::createTicks(  )
    84 {
    80 {
    85     Q_D ( HbSliderTickmarks );
    81     Q_D ( HbSliderTickmarks );
    89     int minorTickInterval =d-> slider->minorTickInterval ( );
    85     int minorTickInterval =d-> slider->minorTickInterval ( );
    90     if (majorTickInterval) {
    86     if (majorTickInterval) {
    91         int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1;
    87         int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1;
    92         int majorIconListLength =  d->tickmarkmajorIcons.length();
    88         int majorIconListLength =  d->tickmarkmajorIcons.length();
    93         for (int i=majorIconListLength;i<totalMajorTicks;i++) {
    89         for (int i=majorIconListLength;i<totalMajorTicks;i++) {
    94             QGraphicsItem *iconItem =style()->createPrimitive(HbStyle::P_SliderTickMark_majoricon, this);
    90             QGraphicsItem *iconItem =HbStylePrivate::createPrimitive(HbStylePrivate::P_SliderTickMark_majoricon, this);
    95             Q_ASSERT(iconItem->isWidget());
    91             Q_ASSERT(iconItem->isWidget());
    96             d->tickmarkmajorIcons.append(static_cast<QGraphicsWidget *>(iconItem));//add newly defind primitive
    92             d->tickmarkmajorIcons.append(static_cast<QGraphicsWidget *>(iconItem));//add newly defind primitive
    97         }
    93         }
    98         while ( totalMajorTicks < d->tickmarkmajorIcons.length() ) {
    94         while ( totalMajorTicks < d->tickmarkmajorIcons.length() ) {
    99             QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at(totalMajorTicks);
    95             QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at(totalMajorTicks);
   111                 }
   107                 }
   112             }
   108             }
   113         }
   109         }
   114         int minorIconListLength =  d->tickmarkminorIcons.length();
   110         int minorIconListLength =  d->tickmarkminorIcons.length();
   115         for (int i=minorIconListLength;i<totalMinorTicks;i++) {
   111         for (int i=minorIconListLength;i<totalMinorTicks;i++) {
   116             QGraphicsItem *iconItem = style()->createPrimitive(HbStyle::P_SliderTickMark_minoricon, this);
   112             QGraphicsItem *iconItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_SliderTickMark_minoricon, this);
   117             Q_ASSERT(iconItem->isWidget());
   113             Q_ASSERT(iconItem->isWidget());
   118             d->tickmarkminorIcons.append(static_cast<QGraphicsWidget *>(iconItem));//add newly defind primitive
   114             d->tickmarkminorIcons.append(static_cast<QGraphicsWidget *>(iconItem));//add newly defind primitive
   119         }
   115         }
   120         while (totalMinorTicks < d->tickmarkminorIcons.length() ){
   116         while (totalMinorTicks < d->tickmarkminorIcons.length() ){
   121             QGraphicsWidget *iconItem = d->tickmarkminorIcons.at(totalMinorTicks);
   117             QGraphicsWidget *iconItem = d->tickmarkminorIcons.at(totalMinorTicks);
   135 
   131 
   136 void HbSliderTickmarks::resizeEvent(QGraphicsSceneResizeEvent *event)
   132 void HbSliderTickmarks::resizeEvent(QGraphicsSceneResizeEvent *event)
   137 {
   133 {
   138     Q_UNUSED (event);
   134     Q_UNUSED (event);
   139     HbWidget::resizeEvent( event );
   135     HbWidget::resizeEvent( event );
   140     repolish();
   136     updateTicks();
   141 }
   137 }
   142 
   138 
   143 
   139 
   144 /*!
   140 /*!
   145     This class is internal to slider ,
   141     This class is internal to slider ,
   147 */
   143 */
   148 
   144 
   149 /*!
   145 /*!
   150     constructor
   146     constructor
   151 */
   147 */
   152 HbSliderTickmarks::HbSliderTickmarks( QGraphicsItem *parent )
   148 HbSliderTickmarks::HbSliderTickmarks(HbSlider *parent)
   153     : HbWidget( *new HbSliderTickmarksPrivate, parent )
   149     : HbWidget( *new HbSliderTickmarksPrivate, parent )
   154 {
   150 {
   155     Q_D( HbSliderTickmarks );
   151     Q_D( HbSliderTickmarks );
   156     d->q_ptr = this;
   152     d->q_ptr = this;
   157     d->slider=dynamic_cast<HbSlider*>( parentItem() );
   153     d->slider = parent;
   158     createTicks();
   154     createTicks();
   159     d->sliderOrientation = d->slider->orientation( );
   155     d->sliderOrientation = d->slider->orientation( );
   160 }
   156 }
   161 
   157 
   162 /*!
   158 /*!
   179     int majorTickInterval = d->slider->majorTickInterval ( );
   175     int majorTickInterval = d->slider->majorTickInterval ( );
   180     int minorTickInterval = d->slider->minorTickInterval ( );
   176     int minorTickInterval = d->slider->minorTickInterval ( );
   181     qreal span = 0;
   177     qreal span = 0;
   182     bool rtlLayout = (((d->slider->orientation()!=Qt::Vertical)&&
   178     bool rtlLayout = (((d->slider->orientation()!=Qt::Vertical)&&
   183         (HbApplication::layoutDirection() == Qt::LeftToRight))?false:true);
   179         (HbApplication::layoutDirection() == Qt::LeftToRight))?false:true);
   184     HbSliderPrivate *sliderPrivate = dynamic_cast<HbSliderPrivate*>(HbSliderPrivate::d_ptr(d->slider));
   180     HbSliderPrivate *sliderPrivate = HbSliderPrivate::d_ptr(d->slider);
   185     QSizeF handleSize(0.0,0.0);
   181     QSizeF handleSize(0.0,0.0);
   186     if( sliderPrivate) {
   182     if( sliderPrivate) {
   187         handleSize = sliderPrivate->getHandleSize( );
   183         handleSize = sliderPrivate->getHandleSize( );
   188     } else {
   184     } else {
   189         return;
   185         return;
   201         for (int i=0;i<totalMajorTicks;i++) {
   197         for (int i=0;i<totalMajorTicks;i++) {
   202              QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at ( i);
   198              QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at ( i);
   203              HbStyleOptionSlider opt;
   199              HbStyleOptionSlider opt;
   204              initStyleOption(&opt);
   200              initStyleOption(&opt);
   205              opt.orientation = d->slider->orientation();
   201              opt.orientation = d->slider->orientation();
   206              style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_majoricon,&opt);
   202              HbStylePrivate::updatePrimitive(iconItem,HbStylePrivate::P_SliderTickMark_majoricon,&opt);
   207             int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   203             int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   208                 minimum+majorTickInterval*i,static_cast<int>( span ), rtlLayout );
   204                 minimum+majorTickInterval*i,static_cast<int>( span ), rtlLayout );
   209 
   205 
   210             qreal correctedPosX = 0;
   206             qreal correctedPosX = 0;
   211             qreal correctedPosY = 0;
   207             qreal correctedPosY = 0;
   230             QGraphicsWidget *iconItem = d->tickmarkminorIcons.at ( minorIndex);
   226             QGraphicsWidget *iconItem = d->tickmarkminorIcons.at ( minorIndex);
   231             minorIndex++;
   227             minorIndex++;
   232             HbStyleOptionSlider opt;
   228             HbStyleOptionSlider opt;
   233             initStyleOption(&opt);
   229             initStyleOption(&opt);
   234             opt.orientation = d->slider->orientation();
   230             opt.orientation = d->slider->orientation();
   235             style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_minoricon,&opt);
   231             HbStylePrivate::updatePrimitive(iconItem,HbStylePrivate::P_SliderTickMark_minoricon,&opt);
   236             int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   232             int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   237                 minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout );
   233                 minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout );
   238             qreal correctedPosX = 0;
   234             qreal correctedPosX = 0;
   239             qreal correctedPosY = 0;
   235             qreal correctedPosY = 0;
   240 
   236 
   245             }
   241             }
   246             iconItem->setGeometry (QRectF( correctedPosX,correctedPosY ,d->majorTickWidth,d->majorTickHeight));
   242             iconItem->setGeometry (QRectF( correctedPosX,correctedPosY ,d->majorTickWidth,d->majorTickHeight));
   247             iconItem->update();
   243             iconItem->update();
   248         }
   244         }
   249     }
   245     }
   250 	update(boundingRect());
   246     update(boundingRect());
   251  }
   247  }
   252 
   248 
   253 /* !
   249 /* !
   254     Sets the position of current tick
   250     Sets the position of current tick
   255 */
   251 */
   285 void HbSliderTickmarks::polish( HbStyleParameters& params )
   281 void HbSliderTickmarks::polish( HbStyleParameters& params )
   286 {
   282 {
   287     Q_D (HbSliderTickmarks);
   283     Q_D (HbSliderTickmarks);
   288     if (d->majorTickHeight == 0 || d->sliderOrientation!= d->slider->orientation() ) {
   284     if (d->majorTickHeight == 0 || d->sliderOrientation!= d->slider->orientation() ) {
   289         d->sliderOrientation = d->slider->orientation();
   285         d->sliderOrientation = d->slider->orientation();
   290 	    params.addParameter("fixed-width-major");
   286         params.addParameter("fixed-width-major");
   291 	    params.addParameter("fixed-height-major");
   287         params.addParameter("fixed-height-major");
   292 	    params.addParameter("fixed-width-minor");
   288         params.addParameter("fixed-width-minor");
   293 	    params.addParameter("fixed-height-minor");
   289         params.addParameter("fixed-height-minor");
   294 	    HbWidget::polish(params);
   290         HbWidget::polish(params);
   295 	    d->majorTickWidth = params.value("fixed-width-major").toReal();
   291         d->majorTickWidth = params.value("fixed-width-major").toReal();
   296 	    d->majorTickHeight = params.value("fixed-height-major").toReal();
   292         d->majorTickHeight = params.value("fixed-height-major").toReal();
   297 	    d->minorTickWidth = params.value("fixed-width-minor").toReal();
   293         d->minorTickWidth = params.value("fixed-width-minor").toReal();
   298 	    d->minorTickHeight = params.value("fixed-height-minor").toReal();
   294         d->minorTickHeight = params.value("fixed-height-minor").toReal();
   299     } else  {
   295     } else  {
   300 	    HbWidget::polish(params);
   296         HbWidget::polish(params);
   301         updateTicks();
   297         //updateTicks();
   302     }
   298     }
   303 }
   299 }
   304 
   300 
   305  //end of file
   301  //end of file
   306 
   302