src/hbwidgets/sliders/hbslidertickmarkslabel.cpp
changeset 34 ed14f46c0e55
parent 7 923ff622b8b9
equal deleted inserted replaced
31:7516d6d86cf5 34:ed14f46c0e55
    44     Q_DECLARE_PUBLIC( HbSliderTickmarksLabel )
    44     Q_DECLARE_PUBLIC( HbSliderTickmarksLabel )
    45 
    45 
    46 public:
    46 public:
    47     HbSliderTickmarksLabelPrivate();
    47     HbSliderTickmarksLabelPrivate();
    48     void createTickLabels( );
    48     void createTickLabels( );
    49     HbStyleOptionSlider sliderOption;
       
    50     QList<QGraphicsWidget *> tickmarkmajorIconItemsLabel;
    49     QList<QGraphicsWidget *> tickmarkmajorIconItemsLabel;
    51     QList<QGraphicsWidget *> tickmarkminorIconItemsLabel;
    50     QList<QGraphicsWidget *> tickmarkminorIconItemsLabel;
    52     HbSlider *slider;
    51     HbSlider *slider;
    53     Hb::SliderTickPositions tickPosition;
    52     Hb::SliderTickPositions tickPosition;
    54     bool createText;
    53     bool createText;
    55 
       
    56 };
    54 };
    57 
    55 
    58 
    56 
    59  HbSliderTickmarksLabelPrivate::HbSliderTickmarksLabelPrivate() :HbWidgetPrivate(){
    57 HbSliderTickmarksLabelPrivate::HbSliderTickmarksLabelPrivate()  : 
    60     tickmarkmajorIconItemsLabel.clear();
    58     HbWidgetPrivate(),
    61     tickmarkminorIconItemsLabel.clear();
    59     slider(0),
    62     slider = 0;
    60     tickPosition(Hb::NoSliderTicks),
    63     tickPosition = Hb::NoSliderTicks;
    61     createText(true)
    64     createText = true;
    62 {
    65 
       
    66 
       
    67 }
    63 }
    68 
    64 
    69 
    65 
    70 void  HbSliderTickmarksLabelPrivate::createTickLabels(  )
    66 void  HbSliderTickmarksLabelPrivate::createTickLabels(  )
    71 {
    67 {
    86         if (majorLabelList.length( ) < totalMajorTicksLabel ) {
    82         if (majorLabelList.length( ) < totalMajorTicksLabel ) {
    87             totalMajorTicksLabel = majorLabelList.length( );
    83             totalMajorTicksLabel = majorLabelList.length( );
    88         }
    84         }
    89         int majorLabelListLength =  tickmarkmajorIconItemsLabel.length();
    85         int majorLabelListLength =  tickmarkmajorIconItemsLabel.length();
    90         for (int i=majorLabelListLength;i<totalMajorTicksLabel;i++) {
    86         for (int i=majorLabelListLength;i<totalMajorTicksLabel;i++) {
    91             QGraphicsItem *textItem = q->style()->createPrimitive(HbStyle::P_SliderTickMark_majorlabel, q);
    87             QGraphicsItem *textItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_SliderTickMark_majorlabel, q);
    92             textItemCreated = true;
    88             textItemCreated = true;
    93             Q_ASSERT(textItem->isWidget());
    89             Q_ASSERT(textItem->isWidget());
    94             tickmarkmajorIconItemsLabel.append(static_cast<QGraphicsWidget *>(textItem));//add newly defind primitive
    90             tickmarkmajorIconItemsLabel.append(static_cast<QGraphicsWidget *>(textItem));//add newly defind primitive
    95         }
    91         }
    96         while ( totalMajorTicksLabel < tickmarkmajorIconItemsLabel.length() ) {
    92         while ( totalMajorTicksLabel < tickmarkmajorIconItemsLabel.length() ) {
   113             totalMinorTicksLabel = minorLabelList.length( );
   109             totalMinorTicksLabel = minorLabelList.length( );
   114         }
   110         }
   115 
   111 
   116         int minorIconLabelListLength =  tickmarkminorIconItemsLabel.length();
   112         int minorIconLabelListLength =  tickmarkminorIconItemsLabel.length();
   117         for (int i=minorIconLabelListLength;i<totalMinorTicksLabel;i++) {
   113         for (int i=minorIconLabelListLength;i<totalMinorTicksLabel;i++) {
   118             QGraphicsItem *textItem = q->style()->createPrimitive(HbStyle::P_SliderTickMark_minorlabel, q);
   114             QGraphicsItem *textItem = HbStylePrivate::createPrimitive(HbStylePrivate::P_SliderTickMark_minorlabel, q);
   119             textItemCreated = true;
   115             textItemCreated = true;
   120             Q_ASSERT(textItem->isWidget());
   116             Q_ASSERT(textItem->isWidget());
   121             tickmarkminorIconItemsLabel.append(static_cast<QGraphicsWidget *>(textItem));//add newly defind primitive
   117             tickmarkminorIconItemsLabel.append(static_cast<QGraphicsWidget *>(textItem));//add newly defind primitive
   122         }
   118         }
   123         while (totalMinorTicksLabel < tickmarkminorIconItemsLabel.length() ){
   119         while (totalMinorTicksLabel < tickmarkminorIconItemsLabel.length() ){
   139 }
   135 }
   140 
   136 
   141 void HbSliderTickmarksLabel::resizeEvent(QGraphicsSceneResizeEvent *event)
   137 void HbSliderTickmarksLabel::resizeEvent(QGraphicsSceneResizeEvent *event)
   142 {
   138 {
   143     Q_UNUSED (event);
   139     Q_UNUSED (event);
   144     repolish ( );
       
   145     updateTickLabels();
   140     updateTickLabels();
   146     HbWidget::resizeEvent(event);
   141     HbWidget::resizeEvent(event);
   147 }
   142 }
   148 
   143 
   149 void HbSliderTickmarksLabel::updateTickLabels( )
   144 void HbSliderTickmarksLabel::updateTickLabels( )
   158          QGraphicsWidget *textItem = d->tickmarkmajorIconItemsLabel.at ( i);
   153          QGraphicsWidget *textItem = d->tickmarkmajorIconItemsLabel.at ( i);
   159          HbStyleOptionSlider opt;
   154          HbStyleOptionSlider opt;
   160          initStyleOption(&opt);
   155          initStyleOption(&opt);
   161          opt.orientation = d->slider->orientation();
   156          opt.orientation = d->slider->orientation();
   162          opt.text = (d->slider->majorTickLabels( )).at(i);
   157          opt.text = (d->slider->majorTickLabels( )).at(i);
   163          style()->updatePrimitive(textItem,HbStyle::P_SliderTickMark_majorlabel,&opt);
   158          HbStylePrivate::updatePrimitive(textItem,HbStylePrivate::P_SliderTickMark_majorlabel,&opt);
   164 	}
   159     }
   165     int minimum = d->slider->minimum();
   160     int minimum = d->slider->minimum();
   166     int maximum = d->slider->maximum();
   161     int maximum = d->slider->maximum();
   167     int majorTickInterval = d->slider->majorTickInterval ( );
   162     int majorTickInterval = d->slider->majorTickInterval ( );
   168     int minorTickInterval = d->slider->minorTickInterval ( );
   163     int minorTickInterval = d->slider->minorTickInterval ( );
   169     qreal span = 0;
   164     qreal span = 0;
   170     bool rtlLayout = (((d->slider->orientation( ) != Qt::Vertical)
   165     bool rtlLayout = (((d->slider->orientation( ) != Qt::Vertical)
   171         &&(HbApplication::layoutDirection() == Qt::LeftToRight))?false:true);
   166         &&(HbApplication::layoutDirection() == Qt::LeftToRight))?false:true);
   172     HbSliderPrivate *sliderPrivate = dynamic_cast<HbSliderPrivate*>(HbSliderPrivate::d_ptr(d->slider));
   167     HbSliderPrivate *sliderPrivate = HbSliderPrivate::d_ptr(d->slider);
   173     QSizeF handleSize(0.0,0.0);
   168     QSizeF handleSize(0.0,0.0);
   174     if( sliderPrivate) {
   169     if( sliderPrivate) {
   175         handleSize = sliderPrivate->getHandleSize( );
   170         handleSize = sliderPrivate->getHandleSize( );
   176     } else {
   171     } else {
   177         return;
   172         return;
   236                 QGraphicsWidget *textItem = d->tickmarkminorIconItemsLabel.at ( minorIndex);
   231                 QGraphicsWidget *textItem = d->tickmarkminorIconItemsLabel.at ( minorIndex);
   237                 HbStyleOptionSlider opt;
   232                 HbStyleOptionSlider opt;
   238                 initStyleOption(&opt);
   233                 initStyleOption(&opt);
   239                 opt.orientation = d->slider->orientation();
   234                 opt.orientation = d->slider->orientation();
   240                 opt.text = (d->slider->minorTickLabels( )).at(minorIndex);
   235                 opt.text = (d->slider->minorTickLabels( )).at(minorIndex);
   241                 style()->updatePrimitive(textItem,HbStyle::P_SliderTickMark_minorlabel,&opt);
   236                 HbStylePrivate::updatePrimitive(textItem,HbStylePrivate::P_SliderTickMark_minorlabel,&opt);
   242                 minorIndex++;
   237                 minorIndex++;
   243                 int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   238                 int pos = QStyle::sliderPositionFromValue( minimum, maximum,
   244                     minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout );
   239                     minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout );
   245                  if ( d->slider->orientation() == Qt::Horizontal) {
   240                  if ( d->slider->orientation() == Qt::Horizontal) {
   246                     qreal correctedPosX = handleSize.width()/2+pos; 
   241                     qreal correctedPosX = handleSize.width()/2+pos; 
   288 */
   283 */
   289 
   284 
   290 /*!
   285 /*!
   291     constructor
   286     constructor
   292 */
   287 */
   293 HbSliderTickmarksLabel::HbSliderTickmarksLabel( QGraphicsItem *parent )
   288 HbSliderTickmarksLabel::HbSliderTickmarksLabel(HbSlider *parent)
   294     : HbWidget( *new HbSliderTickmarksLabelPrivate, parent )
   289     : HbWidget( *new HbSliderTickmarksLabelPrivate, parent )
   295 {
   290 {
   296     Q_D( HbSliderTickmarksLabel );
   291     Q_D( HbSliderTickmarksLabel );
   297     d->q_ptr = this;
   292     d->q_ptr = this;
   298     d->slider=dynamic_cast<HbSlider*>( parentItem() );
   293     d->slider = parent;
   299     d->createTickLabels();
   294     d->createTickLabels();
   300 #if QT_VERSION >= 0x040600
   295 #if QT_VERSION >= 0x040600
   301     setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
   296     setFlag(QGraphicsItem::ItemSendsGeometryChanges,true);
   302 #endif
   297 #endif
   303 }
   298 }