23 ** |
23 ** |
24 ****************************************************************************/ |
24 ****************************************************************************/ |
25 |
25 |
26 #include "hbslidertickmarks_p.h" |
26 #include "hbslidertickmarks_p.h" |
27 #include "hbwidget_p.h" |
27 #include "hbwidget_p.h" |
28 #include "hbslidercontrol_p.h" |
|
29 #include "hbsliderhandle_p.h" |
28 #include "hbsliderhandle_p.h" |
|
29 #include "hbslider_p.h" |
30 #include <hbstyle.h> |
30 #include <hbstyle.h> |
31 #include <hbstyleoptionslider_p.h> |
31 #include <hbstyleoptionslider_p.h> |
32 #include <hbstyle.h> |
32 #include <hbstyle.h> |
33 #include <hbapplication.h> |
33 #include <hbapplication.h> |
34 #include <hbiconitem.h> |
34 #include <hbiconitem.h> |
|
35 #include <hbslider.h> |
35 #include <QList> |
36 #include <QList> |
|
37 #include <QGraphicsItem> |
|
38 #include <QGraphicsSceneEvent> |
|
39 #include <QGraphicsScene> |
|
40 |
|
41 |
|
42 #ifdef HB_EFFECTS |
|
43 #include "hbeffect.h" |
|
44 #include "hbeffectinternal_p.h" |
|
45 #define HB_SLIDER_TYPE "HB_SLIDER" |
|
46 #endif |
36 |
47 |
37 |
48 |
38 |
49 |
39 |
50 |
40 |
51 |
77 { |
87 { |
78 Q_Q ( HbSliderTickmarks ); |
88 Q_Q ( HbSliderTickmarks ); |
79 if(!createIcons){ |
89 if(!createIcons){ |
80 return; |
90 return; |
81 } |
91 } |
82 int minimum = sliderControl->minimum(); |
92 int minimum = slider->minimum(); |
83 int maximum = sliderControl->maximum(); |
93 int maximum = slider->maximum(); |
84 int majorTickInterval = sliderControl->majorTickInterval ( ); |
94 int majorTickInterval = slider->majorTickInterval ( ); |
85 int minorTickInterval = sliderControl->minorTickInterval ( ); |
95 int minorTickInterval = slider->minorTickInterval ( ); |
86 if (majorTickInterval) { |
96 if (majorTickInterval) { |
87 int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1; |
97 int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1; |
88 int majorIconListLength = tickmarkmajorIcons.length(); |
98 int majorIconListLength = tickmarkmajorIcons.length(); |
89 for (int i=majorIconListLength;i<totalMajorTicks;i++) { |
99 for (int i=majorIconListLength;i<totalMajorTicks;i++) { |
90 QGraphicsItem *iconItem = q->style()->createPrimitive(HbStyle::P_SliderTickMark_majoricon, q); |
100 QGraphicsItem *iconItem = q->style()->createPrimitive(HbStyle::P_SliderTickMark_majoricon, q); |
161 HbSliderTickmarks::HbSliderTickmarks( QGraphicsItem *parent ) |
158 HbSliderTickmarks::HbSliderTickmarks( QGraphicsItem *parent ) |
162 : HbWidget( *new HbSliderTickmarksPrivate, parent ) |
159 : HbWidget( *new HbSliderTickmarksPrivate, parent ) |
163 { |
160 { |
164 Q_D( HbSliderTickmarks ); |
161 Q_D( HbSliderTickmarks ); |
165 d->q_ptr = this; |
162 d->q_ptr = this; |
166 d->sliderControl=dynamic_cast<HbSliderControl*>( parentItem() ); |
163 d->slider=dynamic_cast<HbSlider*>( parentItem() ); |
167 d->createTicks(); |
164 d->createTicks(); |
168 } |
165 } |
169 |
166 |
170 /*! |
167 /*! |
171 destructor |
168 destructor |
172 */ |
169 */ |
173 HbSliderTickmarks::~HbSliderTickmarks() |
170 HbSliderTickmarks::~HbSliderTickmarks() |
174 { |
171 { |
175 } |
172 } |
176 |
173 |
177 void HbSliderTickmarks::createIcons( bool create ) |
174 |
178 { |
|
179 |
|
180 Q_D(HbSliderTickmarks); |
|
181 d->createIcons = create; |
|
182 if (!create) { |
|
183 while ( d->tickmarkmajorIcons.length() > 0) { |
|
184 QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at(0); |
|
185 d->tickmarkmajorIcons.removeAll(iconItem); |
|
186 delete iconItem; |
|
187 } |
|
188 while ( d->tickmarkminorIcons.length() > 0) { |
|
189 QGraphicsWidget *iconItem = d->tickmarkminorIcons.at(0); |
|
190 d->tickmarkminorIcons.removeAll(iconItem); |
|
191 delete iconItem; |
|
192 } |
|
193 } else { |
|
194 d->createTicks(); |
|
195 } |
|
196 } |
|
197 /*! |
175 /*! |
198 updates the ticks whenever there is change in position or number of ticks |
176 updates the ticks whenever there is change in position or number of ticks |
199 */ |
177 */ |
200 |
178 |
201 void HbSliderTickmarks::updateTicks( ) |
179 void HbSliderTickmarks::updateTicks( ) |
203 Q_D ( HbSliderTickmarks ); |
181 Q_D ( HbSliderTickmarks ); |
204 if(!d->createIcons) { |
182 if(!d->createIcons) { |
205 return; |
183 return; |
206 } |
184 } |
207 d->createTicks(); |
185 d->createTicks(); |
208 d->updateTickSize(); |
186 int minimum = d->slider->minimum(); |
209 int minimum = d->sliderControl->minimum(); |
187 int maximum = d->slider->maximum(); |
210 int maximum = d->sliderControl->maximum(); |
188 int majorTickInterval = d->slider->majorTickInterval ( ); |
211 int majorTickInterval = d->sliderControl->majorTickInterval ( ); |
189 int minorTickInterval = d->slider->minorTickInterval ( ); |
212 int minorTickInterval = d->sliderControl->minorTickInterval ( ); |
|
213 qreal span = 0; |
190 qreal span = 0; |
214 bool rtlLayout = (((d->sliderControl->orientation()!=Qt::Vertical)&& |
191 bool rtlLayout = (((d->slider->orientation()!=Qt::Vertical)&& |
215 (HbApplication::layoutDirection() == Qt::LeftToRight))?false:true); |
192 (HbApplication::layoutDirection() == Qt::LeftToRight))?false:true); |
216 HbSliderHandle *handle = dynamic_cast <HbSliderHandle *> (d->sliderControl->primitive (HbStyle::P_Slider_thumb)); |
193 HbSliderPrivate *sliderPrivate = dynamic_cast<HbSliderPrivate*>(HbSliderPrivate::d_ptr(d->slider)); |
217 if ( d->sliderControl->orientation() == Qt::Horizontal) { |
194 QSizeF handleSize(0.0,0.0); |
218 span = d->sliderControl->size().width(); |
195 if( sliderPrivate) { |
219 span-=handle->size().width(); |
196 handleSize = sliderPrivate->getHandleSize( ); |
220 } |
197 } else { |
221 if ( d->sliderControl->orientation() == Qt::Vertical) { |
198 return; |
222 span = d->sliderControl->size().height(); |
199 } |
223 span-=handle->size().height(); |
200 if ( d->slider->orientation() == Qt::Horizontal) { |
|
201 span = boundingRect().width(); |
|
202 span-=handleSize.width(); |
|
203 } |
|
204 if ( d->slider->orientation() == Qt::Vertical) { |
|
205 span = boundingRect().height(); |
|
206 span-=handleSize.height(); |
224 } |
207 } |
225 if (majorTickInterval) { |
208 if (majorTickInterval) { |
226 int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1; |
209 int totalMajorTicks = ((maximum-minimum)/majorTickInterval)+1; |
227 for (int i=0;i<totalMajorTicks;i++) { |
210 for (int i=0;i<totalMajorTicks;i++) { |
228 QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at ( i); |
211 QGraphicsWidget *iconItem = d->tickmarkmajorIcons.at ( i); |
229 HbStyleOptionSlider opt; |
212 HbStyleOptionSlider opt; |
230 initStyleOption(&opt); |
213 initStyleOption(&opt); |
231 opt.orientation = d->sliderControl->orientation(); |
214 opt.orientation = d->slider->orientation(); |
232 style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_majoricon,&opt); |
215 style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_majoricon,&opt); |
233 int pos = QStyle::sliderPositionFromValue( minimum, maximum, |
216 int pos = QStyle::sliderPositionFromValue( minimum, maximum, |
234 minimum+majorTickInterval*i,static_cast<int>( span ), rtlLayout ); |
217 minimum+majorTickInterval*i,static_cast<int>( span ), rtlLayout ); |
235 |
218 |
236 if ( d->sliderControl->orientation() == Qt::Horizontal) { |
219 qreal correctedPosX = 0; |
237 qreal correctedPosX = handle->size().width()/2+pos; |
220 qreal correctedPosY = 0; |
238 qreal correctedPosY = 0; |
221 if ( d->slider->orientation() == Qt::Horizontal) { |
239 iconItem->setPos ( correctedPosX,correctedPosY ); |
222 correctedPosX = handleSize.width()/2+pos; |
240 iconItem->update(); |
|
241 } else { |
223 } else { |
242 qreal correctedPosY = handle->size().height()/2+pos; |
224 correctedPosY = handleSize.height()/2+pos; |
243 qreal correctedPosX =0; |
|
244 iconItem->setPos ( correctedPosX,correctedPosY ); |
|
245 iconItem->update(); |
|
246 } |
225 } |
|
226 iconItem->setGeometry (QRectF( correctedPosX,correctedPosY ,d->majorTickWidth,d->majorTickHeight)); |
|
227 iconItem->update(); |
247 } |
228 } |
248 } |
229 } |
249 if (minorTickInterval) { |
230 if (minorTickInterval) { |
250 int totalminorTicks = ((maximum-minimum)/minorTickInterval)+1; |
231 int totalminorTicks = ((maximum-minimum)/minorTickInterval)+1; |
251 int minorIndex = 0; |
232 int minorIndex = 0; |
257 } |
238 } |
258 QGraphicsWidget *iconItem = d->tickmarkminorIcons.at ( minorIndex); |
239 QGraphicsWidget *iconItem = d->tickmarkminorIcons.at ( minorIndex); |
259 minorIndex++; |
240 minorIndex++; |
260 HbStyleOptionSlider opt; |
241 HbStyleOptionSlider opt; |
261 initStyleOption(&opt); |
242 initStyleOption(&opt); |
262 opt.orientation = d->sliderControl->orientation(); |
243 opt.orientation = d->slider->orientation(); |
263 style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_minoricon,&opt); |
244 style()->updatePrimitive(iconItem,HbStyle::P_SliderTickMark_minoricon,&opt); |
264 int pos = QStyle::sliderPositionFromValue( minimum, maximum, |
245 int pos = QStyle::sliderPositionFromValue( minimum, maximum, |
265 minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout ); |
246 minimum+minorTickInterval*i,static_cast<int>( span ), rtlLayout ); |
266 |
247 qreal correctedPosX = 0; |
267 if ( d->sliderControl->orientation() == Qt::Horizontal) { |
248 qreal correctedPosY = 0; |
268 qreal correctedPosX = handle->size().width()/2+pos; |
249 |
269 qreal correctedPosY = 0; |
250 if ( d->slider->orientation() == Qt::Horizontal) { |
270 iconItem->setPos ( correctedPosX,correctedPosY ); |
251 correctedPosX = handleSize.width()/2+pos; |
271 iconItem->update(); |
|
272 |
|
273 } else { |
252 } else { |
274 qreal correctedPosY = handle->size().height()/2+pos; |
253 correctedPosY = handleSize.height()/2+pos; |
275 qreal correctedPosX =0; |
|
276 iconItem->setPos ( correctedPosX,correctedPosY ); |
|
277 iconItem->update(); |
|
278 |
|
279 } |
254 } |
|
255 iconItem->setGeometry (QRectF( correctedPosX,correctedPosY ,d->majorTickWidth,d->majorTickHeight)); |
|
256 iconItem->update(); |
280 } |
257 } |
281 } |
258 } |
282 } |
259 } |
283 |
260 |
284 /* ! |
261 /* ! |