|
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 "hbslidercontrol_p.h" |
|
27 #include "hbslidercontrol_p_p.h" |
|
28 #include "hbabstractslidercontrol_p.h" |
|
29 #include "hbsliderhandle_p.h" |
|
30 #include "hbstyleoptionslider.h" |
|
31 #include "hbslidertickmarkslabel_p.h" |
|
32 #include "hbslidertickmarkslabel_p.h" |
|
33 #include <hbstyle.h> |
|
34 #include <hbinstance.h> |
|
35 #include <hbtheme.h> |
|
36 #include <hbtooltip.h> |
|
37 #include <hbwidgetfeedback.h> |
|
38 #include <hbgraphicsscene.h> |
|
39 #include <QGraphicsItem> |
|
40 #include <QGraphicsSceneMouseEvent> |
|
41 |
|
42 #ifdef HB_EFFECTS |
|
43 #include "hbeffect.h" |
|
44 #include "hbeffectinternal_p.h" |
|
45 #define HB_SLIDERCONTROL_TYPE "HB_SLIDERCONTROL" |
|
46 #endif |
|
47 |
|
48 |
|
49 /*! |
|
50 private class |
|
51 */ |
|
52 HbSliderControlPrivate::HbSliderControlPrivate( ) : |
|
53 handle( 0 ), // slider handle |
|
54 tickPosition( Hb::NoSliderTicks ), // slider tick position |
|
55 snappingMode( HbSliderControl::MinorTickSnapping ), // snapping mode |
|
56 majorTickInterval( 0 ),// major tick interval |
|
57 minorTickInterval( 0 ),// minor tick interval |
|
58 groove( 0 ), //slider groove |
|
59 progressGroove( 0 ),//progress mask top of groove |
|
60 tickmarksLeft( 0 ), // slider left/top tick mark item |
|
61 tickmarksRight( 0 ),// slider right/bottom tick mark item |
|
62 tickmarkslabelLeft( 0 ),// slider left/above tick mark label |
|
63 tickmarkslabelRight ( 0 ),// slider right/bottom tick mark label |
|
64 displayCurrValueToolTip( false ), // holds whether to show current value tooltip or not |
|
65 toolTipAlignment( Qt::AlignTop|Qt::AlignRight ), // tooltip alignment |
|
66 groovePressed( false ), // hold whether groove is pressed or not |
|
67 setDefault( false ), // holds whther default value for track press is set |
|
68 previousValue( 0 ), // default value for track press |
|
69 trackHandlingEnable( false ),// this variable holds whether track will be interective or not |
|
70 handleMoving( false ), |
|
71 grooveTouchArea ( 0 ), |
|
72 enableProgressTrack ( true ), |
|
73 userDefinedTooltipAlign ( false ) |
|
74 { |
|
75 |
|
76 majorLabel.clear(); |
|
77 minorLabel.clear(); |
|
78 |
|
79 } |
|
80 |
|
81 |
|
82 HbSliderControlPrivate::~HbSliderControlPrivate( ) |
|
83 { |
|
84 |
|
85 |
|
86 } |
|
87 |
|
88 |
|
89 /*! |
|
90 \internal |
|
91 This api created required primitive( handle,groove, touch area ) |
|
92 */ |
|
93 void HbSliderControlPrivate::init( ) |
|
94 { |
|
95 Q_Q( HbSliderControl ); |
|
96 |
|
97 q->enableTrackEventHandling( true ); |
|
98 |
|
99 // creating handle |
|
100 handle = createHandle(); |
|
101 if(handle) { |
|
102 HbStyle::setItemName( handle, "handle" ); |
|
103 } |
|
104 q->setFocusPolicy( Qt::FocusPolicy( ( qApp->style( ) )->styleHint( QStyle::SH_Button_FocusPolicy ) ) ); |
|
105 //creating groove |
|
106 groove = createGroove(); |
|
107 if(groove) { |
|
108 HbStyle::setItemName( groove, "groove" ); |
|
109 } |
|
110 //filled item top of groove |
|
111 if ( enableProgressTrack ) { |
|
112 progressGroove = createProgressGroove(); |
|
113 if(progressGroove) { |
|
114 HbStyle::setItemName( progressGroove, "progressgroove"); |
|
115 } |
|
116 } |
|
117 q->connect( hbInstance->theme( ), SIGNAL( changed( ) ), q, SLOT( updateTheme( ) ) ); |
|
118 q->connect( q , SIGNAL( actionTriggered( int ) ), q , SLOT( showToolTip( ) ) ); |
|
119 q->connect( q , SIGNAL( sliderReleased( ) ), q , SLOT( hideToolTip( ) ) ); |
|
120 q->setFlags( QGraphicsItem::ItemIsFocusable ); |
|
121 } |
|
122 |
|
123 /*! |
|
124 \internal |
|
125 Updates tick and Label. |
|
126 */ |
|
127 void HbSliderControlPrivate::updateTickAndLabel( ) |
|
128 { |
|
129 if (tickmarksLeft) { |
|
130 tickmarksLeft->updateTicks(); |
|
131 } |
|
132 if (tickmarksRight) { |
|
133 tickmarksRight->updateTicks(); |
|
134 } |
|
135 if( tickmarkslabelLeft ) { |
|
136 tickmarkslabelLeft->updateTickLabels(); |
|
137 } |
|
138 if( tickmarkslabelRight ) { |
|
139 tickmarkslabelRight->updateTickLabels( ); |
|
140 } |
|
141 } |
|
142 |
|
143 |
|
144 /*! |
|
145 \internal |
|
146 Updates tick and Label. |
|
147 */ |
|
148 void HbSliderControlPrivate::deleteTickAndLabel( ) |
|
149 { |
|
150 if (tickmarksLeft) { |
|
151 delete tickmarksLeft; |
|
152 tickmarksLeft = 0; |
|
153 |
|
154 } |
|
155 if (tickmarksRight) { |
|
156 delete tickmarksRight; |
|
157 tickmarksRight = 0; |
|
158 } |
|
159 |
|
160 |
|
161 if( tickmarkslabelLeft ) { |
|
162 delete tickmarkslabelLeft; |
|
163 tickmarkslabelLeft = 0; |
|
164 } |
|
165 if( tickmarkslabelRight ) { |
|
166 delete tickmarkslabelRight; |
|
167 tickmarkslabelRight = 0; |
|
168 } |
|
169 |
|
170 } |
|
171 |
|
172 /*! |
|
173 \internal |
|
174 This is used to create the handle, is virtual and can be overridden to create different handle. |
|
175 */ |
|
176 HbSliderHandle *HbSliderControlPrivate::createHandle() |
|
177 { |
|
178 Q_Q( HbSliderControl ); |
|
179 HbSliderHandle *handle = new HbSliderHandle( q ); |
|
180 return handle; |
|
181 } |
|
182 |
|
183 /*! |
|
184 \internal |
|
185 This is used to create the groove. can be overrideen by derived class |
|
186 */ |
|
187 QGraphicsItem *HbSliderControlPrivate::createGroove() |
|
188 { |
|
189 Q_Q( HbSliderControl ); |
|
190 QGraphicsItem *groove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive( |
|
191 HbStyle::P_Slider_groove, q ) ); |
|
192 return groove; |
|
193 } |
|
194 /*! |
|
195 \internal |
|
196 This is used to create the masked progress groove. can be overrideen by derived class |
|
197 */ |
|
198 QGraphicsItem *HbSliderControlPrivate::createProgressGroove() |
|
199 { |
|
200 Q_Q( HbSliderControl ); |
|
201 QGraphicsItem *proggroove = qgraphicsitem_cast<QGraphicsItem*>( q->style( )->createPrimitive( |
|
202 HbStyle::P_Slider_progressgroove, q ) );//comes on top of groove |
|
203 return proggroove; |
|
204 } |
|
205 |
|
206 /*! |
|
207 This api adjust the handle within slider area |
|
208 and position it depending upon slider value |
|
209 */ |
|
210 void HbSliderControlPrivate::adjustHandle( ) |
|
211 { |
|
212 Q_Q( HbSliderControl ); |
|
213 handle->adjustSize( ); |
|
214 QRectF bounds = q->boundingRect( ); |
|
215 QRectF handleBounds = handle->boundingRect( ); |
|
216 qreal span = 0; |
|
217 if ( q->orientation( ) == Qt::Horizontal ) { |
|
218 bounds.adjust( 0, 0, -handleBounds.width( ), 0 ); |
|
219 // calculating span |
|
220 span = bounds.width( ); |
|
221 } else { |
|
222 bounds.adjust( 0, 0, 0, -handleBounds.height( ) ); |
|
223 // calculating span |
|
224 span = bounds.height( ); |
|
225 } |
|
226 |
|
227 HbStyleOptionSlider opt; |
|
228 q->initStyleOption( &opt ); |
|
229 // calculating pixel position depending on slider position |
|
230 int pos = QStyle::sliderPositionFromValue( opt.minimum, opt.maximum, |
|
231 opt.sliderValue, static_cast<int>( span ), opt.upsideDown ); |
|
232 // align the rect to the centre of groove |
|
233 QRect rect = QStyle::alignedRect( opt.direction, Qt::AlignCenter, |
|
234 handleBounds.size( ).toSize( ), bounds.toRect( ) ); |
|
235 if ( q->orientation( ) == Qt::Horizontal ) { |
|
236 rect.moveLeft( pos ); |
|
237 } else { |
|
238 rect.moveTop( pos ); |
|
239 } |
|
240 //set handle position |
|
241 handle->forceSetPos( rect.topLeft( ) ); |
|
242 //progress groove should be adjusted whenever handle position is changed |
|
243 if ( progressGroove ) { |
|
244 q->style( )->updatePrimitive( progressGroove, HbStyle::P_Slider_progressgroove, &opt ); |
|
245 } |
|
246 } |
|
247 |
|
248 /*! |
|
249 This api returns true if pos in on handle rect |
|
250 */ |
|
251 bool HbSliderControlPrivate::onHandle( QPointF pos ) |
|
252 { |
|
253 Q_Q( HbSliderControl ); |
|
254 QRectF handleRect = handle->sceneBoundingRect( ); |
|
255 bool result = false; |
|
256 switch ( q->orientation( ) ) { |
|
257 case Qt::Horizontal: |
|
258 if ( handleRect.contains( pos.x( ) , handleRect.y( ) ) ) { |
|
259 result = true; |
|
260 } |
|
261 break; |
|
262 case Qt::Vertical: |
|
263 if ( handleRect.contains( handleRect.x( ),pos.y( ) ) ) { |
|
264 result = true; |
|
265 } |
|
266 break; |
|
267 } |
|
268 return result; |
|
269 } |
|
270 |
|
271 |
|
272 /*! |
|
273 This api returns near by tick to the sliderPosition |
|
274 */ |
|
275 int HbSliderControlPrivate::getNearbyTick( ) |
|
276 { |
|
277 Q_Q( HbSliderControl ); |
|
278 // calculating slider position with respect to minimum( ) |
|
279 int correctedSliderPos = q->sliderPosition( ) - q->minimum( ); |
|
280 // if snapping mode is NoSnapping then there is no need to calculate |
|
281 //near by tick |
|
282 if ( !( snappingMode & HbSliderControl::NoSnapping ) ) { |
|
283 if ( snappingMode & HbSliderControl::MinorTickSnapping ) { |
|
284 if ( minorTickInterval > 0 ) { |
|
285 // calculating tick number |
|
286 int tickNumber = correctedSliderPos / minorTickInterval; |
|
287 // check if reminder is grater then half of |
|
288 //tick interval then increment tick number by 1 |
|
289 if ( ( correctedSliderPos % minorTickInterval ) >= qRound( minorTickInterval/2.0 ) ) { |
|
290 if ( ( ( tickNumber+1 ) * minorTickInterval ) <= ( q->maximum( ) - q->minimum( ) ) ) { |
|
291 tickNumber++; |
|
292 } |
|
293 } |
|
294 // return sliderPosition of near by tick |
|
295 return ( ( tickNumber * minorTickInterval ) + q->minimum( ) ); |
|
296 } |
|
297 } else { |
|
298 if ( majorTickInterval > 0 ) { |
|
299 // calculating tick number |
|
300 int tickNumber = correctedSliderPos / majorTickInterval; |
|
301 // check if reminder is grater then half of |
|
302 //tick interval then increment tick number by 1 |
|
303 if ( ( correctedSliderPos % majorTickInterval ) >= qRound( majorTickInterval/2.0 ) ) { |
|
304 if ( ( ( tickNumber+1 ) * majorTickInterval ) <= ( q->maximum( ) - q->minimum( ) ) ) { |
|
305 tickNumber++; |
|
306 } |
|
307 } |
|
308 // return sliderPosition of near by tick |
|
309 return ( ( tickNumber * majorTickInterval ) + q->minimum( ) ); |
|
310 } |
|
311 } |
|
312 } |
|
313 // return sliderPosition( ) if snapping mode is NoSnapping |
|
314 return ( q->sliderPosition( ) ); |
|
315 } |
|
316 |
|
317 void HbSliderControlPrivate::createSliderTicks( ) |
|
318 { |
|
319 |
|
320 Q_Q ( HbSliderControl); |
|
321 if (! tickmarksLeft) { |
|
322 tickmarksLeft = new HbSliderTickmarks(q); |
|
323 tickmarksLeft->setTickPosition (Hb::SliderTicksLeft); |
|
324 } |
|
325 if (!tickmarksRight) { |
|
326 tickmarksRight = new HbSliderTickmarks(q); |
|
327 tickmarksRight->setTickPosition ( Hb::SliderTicksRight); |
|
328 } |
|
329 if ( orientation == Qt::Vertical ) { |
|
330 HbStyle::setItemName( tickmarksLeft, "tick-marksleft" ); |
|
331 HbStyle::setItemName( tickmarksRight, "tick-marksright" ); |
|
332 } else { |
|
333 HbStyle::setItemName( tickmarksLeft, "tick-marksabove" ); |
|
334 HbStyle::setItemName( tickmarksRight, "tick-marksbelow" ); |
|
335 } |
|
336 } |
|
337 |
|
338 void HbSliderControlPrivate::positionTickMarks( ) |
|
339 { |
|
340 Q_Q (HbSliderControl); |
|
341 if (!tickmarksLeft||!tickmarksRight) { |
|
342 return; |
|
343 } |
|
344 // SliderTickLeft and SliderTicksAbove value is same |
|
345 if ( tickPosition & Hb::SliderTicksLeft) { |
|
346 tickmarksLeft->createIcons(true); |
|
347 } else { |
|
348 tickmarksLeft->createIcons(false); |
|
349 } |
|
350 if ( tickPosition & Hb::SliderTicksRight ) { |
|
351 tickmarksRight->createIcons(true); |
|
352 } else { |
|
353 tickmarksRight->createIcons(false); |
|
354 } |
|
355 if ( orientation == Qt::Vertical ) { |
|
356 if ( tickPosition & Hb::SliderTicksAbsolute) { |
|
357 q->setLayoutDirection (Qt::LeftToRight ); |
|
358 } |
|
359 } |
|
360 } |
|
361 |
|
362 void HbSliderControlPrivate::createSliderTickLabels( ) |
|
363 { |
|
364 Q_Q(HbSliderControl); |
|
365 if (! tickmarkslabelLeft) { |
|
366 tickmarkslabelLeft = new HbSliderTickmarksLabel(q); |
|
367 tickmarkslabelLeft->setTickPosition (Hb::SliderTicksLeft); |
|
368 } |
|
369 if (!tickmarkslabelRight) { |
|
370 tickmarkslabelRight = new HbSliderTickmarksLabel(q); |
|
371 tickmarkslabelRight->setTickPosition (Hb::SliderTicksRight ); |
|
372 } |
|
373 if ( orientation == Qt::Horizontal ) { |
|
374 HbStyle::setItemName( tickmarkslabelLeft, "tick-textsabove" ); |
|
375 HbStyle::setItemName( tickmarkslabelRight, "tick-textsbelow" ); |
|
376 } else { |
|
377 HbStyle::setItemName( tickmarkslabelLeft, "tick-textsleft" ); |
|
378 HbStyle::setItemName( tickmarkslabelRight, "tick-textsright" ); |
|
379 } |
|
380 |
|
381 } |
|
382 |
|
383 |
|
384 void HbSliderControlPrivate::positionTickMarksLabel( ) |
|
385 { |
|
386 if (!tickmarkslabelLeft||!tickmarkslabelRight) { |
|
387 return; |
|
388 } |
|
389 // SliderTickLeft and SliderTicksAbove value is same |
|
390 if ( tickPosition & Hb::SliderTicksLeft) { |
|
391 tickmarkslabelLeft->createText(true); |
|
392 } else { |
|
393 tickmarkslabelLeft->createText(false); |
|
394 } |
|
395 if ( tickPosition & Hb::SliderTicksRight ) { |
|
396 tickmarkslabelRight->createText(true); |
|
397 } else { |
|
398 tickmarkslabelRight->createText(false); |
|
399 } |
|
400 } |
|
401 |
|
402 |
|
403 /*! |
|
404 Constructs a slider control with \a parent. |
|
405 */ |
|
406 HbSliderControl::HbSliderControl( QGraphicsItem *parent ) |
|
407 : HbAbstractSliderControl( *new HbSliderControlPrivate, parent ) |
|
408 { |
|
409 Q_D( HbSliderControl ); |
|
410 d->q_ptr = this; |
|
411 d->init( ); |
|
412 } |
|
413 |
|
414 /*! |
|
415 Constructs a slider control with \a orientation and \a parent. |
|
416 */ |
|
417 HbSliderControl::HbSliderControl( Qt::Orientation orientation, QGraphicsItem *parent ) |
|
418 : HbAbstractSliderControl( *new HbSliderControlPrivate, parent ) |
|
419 { |
|
420 Q_D( HbSliderControl ); |
|
421 d->q_ptr = this; |
|
422 d->init( ); |
|
423 setOrientation( orientation ); |
|
424 } |
|
425 |
|
426 /*! |
|
427 Protected constructor for initialization from derived ctor. |
|
428 */ |
|
429 HbSliderControl::HbSliderControl(HbSliderControlPrivate &dd,QGraphicsItem *parent) |
|
430 :HbAbstractSliderControl(dd,parent) |
|
431 { |
|
432 } |
|
433 |
|
434 /*! |
|
435 When theme is changed this is called. |
|
436 */ |
|
437 void HbSliderControl::updateTheme( ) |
|
438 { |
|
439 Q_D( HbSliderControl ); |
|
440 // HbSliderHandle::boundingRect( ) result depends on current theme |
|
441 d->adjustHandle( ); |
|
442 } |
|
443 |
|
444 |
|
445 /*! |
|
446 Destroys the slider. |
|
447 */ |
|
448 HbSliderControl::~HbSliderControl( ) |
|
449 { |
|
450 |
|
451 } |
|
452 |
|
453 /*! |
|
454 Returns the tickmark position of the slider. |
|
455 |
|
456 The default value is \c Hb::NoTicks. |
|
457 |
|
458 \sa setTickPosition( ) |
|
459 */ |
|
460 Hb::SliderTickPositions HbSliderControl::tickPosition( ) const |
|
461 { |
|
462 Q_D( const HbSliderControl ); |
|
463 return d->tickPosition; |
|
464 } |
|
465 |
|
466 /*! |
|
467 Sets the tickmark position of the slider. |
|
468 |
|
469 \sa tickPosition( ) |
|
470 */ |
|
471 void HbSliderControl::setTickPosition( Hb::SliderTickPositions position ) |
|
472 { |
|
473 Q_D( HbSliderControl ); |
|
474 if ( d->tickPosition != position ) { |
|
475 d->tickPosition = position; |
|
476 unsetLayoutDirection( ); |
|
477 if ( position == Hb::NoSliderTicks) { |
|
478 d->deleteTickAndLabel( ); |
|
479 } else { |
|
480 if ( (!d->tickmarksLeft || !d->tickmarksRight) && d->majorTickInterval > 0) { |
|
481 d->createSliderTicks( ); |
|
482 d->positionTickMarks( ); |
|
483 repolish( ); |
|
484 |
|
485 } |
|
486 if ( (!d->tickmarkslabelLeft || !d->tickmarkslabelRight) && d->majorTickInterval > 0 && |
|
487 (!d->majorLabel.isEmpty( ) || (!d->minorLabel.isEmpty( ) && d->minorTickInterval > 0) ) ) { |
|
488 d->createSliderTickLabels( ); |
|
489 d->positionTickMarksLabel ( ); |
|
490 repolish( ); |
|
491 } |
|
492 d->positionTickMarks( ); |
|
493 d->positionTickMarksLabel( ); |
|
494 } |
|
495 } |
|
496 } |
|
497 |
|
498 /*! |
|
499 Returns the interval between major tickmarks. |
|
500 |
|
501 The default value is \c 0. |
|
502 |
|
503 \sa setMajorTickInterval( ) |
|
504 */ |
|
505 int HbSliderControl::majorTickInterval( ) const |
|
506 { |
|
507 Q_D( const HbSliderControl ); |
|
508 return d->majorTickInterval; |
|
509 } |
|
510 |
|
511 /*! |
|
512 Sets the interval between major tickmarks. |
|
513 |
|
514 Special values: |
|
515 \li a negative value means no major ticks will be drawn |
|
516 \li value \c 0 means that the interval is automatically calculated |
|
517 |
|
518 \sa majorTickInterval( ) |
|
519 */ |
|
520 void HbSliderControl::setMajorTickInterval( int interval ) |
|
521 { |
|
522 Q_D( HbSliderControl ); |
|
523 if ( d->majorTickInterval != interval ) { |
|
524 d->majorTickInterval = qAbs ( interval ); |
|
525 if (interval <= 0 ) { |
|
526 d->deleteTickAndLabel(); |
|
527 repolish(); |
|
528 } else if( d->tickPosition!=Hb::NoSliderTicks) { |
|
529 if( !d->tickmarksLeft || !d->tickmarksRight) { |
|
530 d->createSliderTicks( ); |
|
531 d->positionTickMarks( ); |
|
532 repolish( ); |
|
533 } else { |
|
534 d->tickmarksLeft->updateTicks( ); |
|
535 d->tickmarksRight->updateTicks( ); |
|
536 } |
|
537 if ( (!d->tickmarkslabelRight || !d->tickmarkslabelLeft) && (!d->majorLabel.isEmpty( ) || |
|
538 (d->minorTickInterval >0 &&! d->minorLabel.isEmpty( )))) { |
|
539 d->createSliderTickLabels( ); |
|
540 d->positionTickMarksLabel( ); |
|
541 repolish( ); |
|
542 } |
|
543 |
|
544 if ( d->snappingMode == MajorTickSnapping ) { |
|
545 updateSliderPosToTick( ); |
|
546 } |
|
547 } |
|
548 } |
|
549 } |
|
550 |
|
551 /*! |
|
552 Returns the minor ticklabels of the slider. |
|
553 |
|
554 \sa setMinorTickLabels( ) |
|
555 */ |
|
556 QStringList HbSliderControl::minorTickLabels( ) const |
|
557 { |
|
558 Q_D( const HbSliderControl ); |
|
559 return d->minorLabel; |
|
560 } |
|
561 |
|
562 /*! |
|
563 Sets the interval between minor tickmarks. |
|
564 |
|
565 Special values: |
|
566 \li a negative value means no minor ticks will be drawn |
|
567 \li value \c 0 means that the interval is automatically calculated |
|
568 |
|
569 \sa minorTickInterval( ) |
|
570 */ |
|
571 void HbSliderControl::setMinorTickInterval( int interval ) |
|
572 { |
|
573 Q_D( HbSliderControl ); |
|
574 if ( d->minorTickInterval != interval ) { |
|
575 d->minorTickInterval = qAbs ( interval ); |
|
576 if ( d->tickmarksLeft && d->tickmarksRight ) { |
|
577 d->tickmarksLeft->updateTicks( ); |
|
578 d->tickmarksRight->updateTicks( ); |
|
579 } |
|
580 if ( d->majorTickInterval > 0 && ( !d->minorLabel.isEmpty() && d->minorTickInterval > 0) && |
|
581 (!d->tickmarkslabelLeft || !d->tickmarkslabelRight) && d->tickPosition!=Hb::NoSliderTicks) { |
|
582 d->createSliderTickLabels( ); |
|
583 repolish( ); |
|
584 } |
|
585 if ( d->snappingMode == MinorTickSnapping && d->minorTickInterval > 0 && d->tickPosition!= Hb::NoSliderTicks ) { |
|
586 updateSliderPosToTick( ); |
|
587 } |
|
588 } |
|
589 } |
|
590 |
|
591 /*! |
|
592 Returns the interval between minor tickmarks. |
|
593 |
|
594 The default value is \c 0. |
|
595 |
|
596 \sa setMinorTickInterval( ) |
|
597 */ |
|
598 int HbSliderControl::minorTickInterval( ) const |
|
599 { |
|
600 Q_D( const HbSliderControl ); |
|
601 return d->minorTickInterval; |
|
602 } |
|
603 |
|
604 /*! |
|
605 Sets the major ticklabels of the slider. |
|
606 |
|
607 Detailed description: |
|
608 |
|
609 Strings from the stringlist will be taken sequentially for drawing |
|
610 LabelItem,there exists a one-to-one mapping between tickmarkitem & |
|
611 tickmarklabelitem. |
|
612 |
|
613 case 1: if strings provided > tickmarks, labels are drawn for the |
|
614 strings which maps the tickmarkitems.If there are extra strings |
|
615 available in the list beyond 1-1 mapping, those strings will be left out. |
|
616 |
|
617 case 2: if strings provided < tickmarks, labels are drawn only for strings |
|
618 provided.Rest of the tickmarkitems will be drawn without labelItem. |
|
619 |
|
620 case 3: If some tickmarkitems to be drawn without labelItem in the middle, |
|
621 specify empty string ( "" ) for that item in the string list. |
|
622 |
|
623 case 4: if both major & minor tickinterval are same,then only majortickLabel |
|
624 strings are taken into account for drawing the labelItem |
|
625 |
|
626 \sa majorTickLabels( ) |
|
627 */ |
|
628 void HbSliderControl::setMajorTickLabels( const QStringList &majorTickLabels ) |
|
629 { |
|
630 Q_D( HbSliderControl ); |
|
631 d->majorLabel = majorTickLabels; |
|
632 if (d->majorLabel.isEmpty( ) && (d->minorLabel.isEmpty( )|| d->minorTickInterval <=0) ) { |
|
633 if (d->tickmarkslabelLeft) { |
|
634 delete d->tickmarkslabelLeft; |
|
635 d->tickmarkslabelLeft =0; |
|
636 } |
|
637 if( d->tickmarkslabelRight) { |
|
638 delete d->tickmarkslabelRight; |
|
639 d->tickmarkslabelRight =0; |
|
640 } |
|
641 repolish( ); |
|
642 |
|
643 } else { |
|
644 if ((!d->tickmarkslabelLeft || !d->tickmarkslabelRight) && !d->majorLabel.isEmpty( ) && |
|
645 d->majorTickInterval > 0 && d->tickPosition!=Hb::NoSliderTicks) { |
|
646 d->createSliderTickLabels( ); |
|
647 d->positionTickMarksLabel( ); |
|
648 repolish( ); |
|
649 } else if ( d->tickmarkslabelLeft && d->tickmarkslabelRight ) { |
|
650 d->tickmarkslabelLeft->updateTickLabels( ); |
|
651 d->tickmarkslabelRight->updateTickLabels( ); |
|
652 } |
|
653 } |
|
654 } |
|
655 |
|
656 /*! |
|
657 Returns the minor ticklabels of the slider. |
|
658 |
|
659 \sa setMinorTickLabels( ) |
|
660 */ |
|
661 QStringList HbSliderControl::majorTickLabels( ) const |
|
662 { |
|
663 Q_D( const HbSliderControl ); |
|
664 return d->majorLabel; |
|
665 // return static_cast<HbSliderTickmarksLabel*>( d->tickmarkslabel )->majorTickLabels( ); |
|
666 } |
|
667 |
|
668 /*! |
|
669 Sets the minor ticklabels of the slider. |
|
670 see setMajorTickLabels for detailed description |
|
671 |
|
672 \sa minorTickLabels( ),setMajorTickLabels( ) |
|
673 */ |
|
674 void HbSliderControl::setMinorTickLabels( const QStringList &minorTickLabels ) |
|
675 { |
|
676 Q_D( HbSliderControl ); |
|
677 d->minorLabel = minorTickLabels; |
|
678 if (d->majorLabel.isEmpty( ) && (d->minorLabel.isEmpty( )|| d->minorTickInterval <=0) ) { |
|
679 if (d->tickmarkslabelLeft) { |
|
680 delete d->tickmarkslabelLeft; |
|
681 } |
|
682 if( d->tickmarkslabelRight) { |
|
683 delete d->tickmarkslabelRight; |
|
684 } |
|
685 repolish( ); |
|
686 |
|
687 } else { |
|
688 if ((!d->tickmarkslabelLeft || !d->tickmarkslabelRight) && |
|
689 d->majorTickInterval > 0 && d->tickPosition!=Hb::NoSliderTicks) { |
|
690 d->createSliderTickLabels( ); |
|
691 repolish( ); |
|
692 } else if ( d->tickmarkslabelLeft && d->tickmarkslabelRight) { |
|
693 d->tickmarkslabelLeft->updateTickLabels( ); |
|
694 d->tickmarkslabelRight->updateTickLabels( ); |
|
695 } |
|
696 } |
|
697 } |
|
698 |
|
699 |
|
700 /*! |
|
701 Returns the SnappingMode of the slider. |
|
702 |
|
703 The default value is \c HbSliderControl::MinorTickSnapping. |
|
704 |
|
705 \sa setSnappingMode( ) |
|
706 */ |
|
707 HbSliderControl::SnappingMode HbSliderControl::snappingMode( ) const |
|
708 { |
|
709 Q_D( const HbSliderControl ); |
|
710 return d->snappingMode; |
|
711 } |
|
712 |
|
713 /*! |
|
714 Sets the snappingMode of the slider. |
|
715 |
|
716 \sa snappingMode( ) |
|
717 */ |
|
718 void HbSliderControl::setSnappingMode( SnappingMode mode ) |
|
719 { |
|
720 Q_D( HbSliderControl ); |
|
721 if ( d->snappingMode != mode ) { |
|
722 d->snappingMode = mode; |
|
723 if ( d->snappingMode != NoSnapping ) { |
|
724 updateSliderPosToTick( ); |
|
725 } |
|
726 } |
|
727 } |
|
728 |
|
729 /*! |
|
730 This will enable/disable current value diplay as tooltip |
|
731 on thumb drag |
|
732 */ |
|
733 void HbSliderControl::setToolTipVisible( bool value ) |
|
734 { |
|
735 Q_D( HbSliderControl ); |
|
736 if ( d->displayCurrValueToolTip != value ) { |
|
737 d->displayCurrValueToolTip = value; |
|
738 } |
|
739 } |
|
740 |
|
741 |
|
742 /*! |
|
743 returns whether tooltip is Enable or disable for current value |
|
744 */ |
|
745 bool HbSliderControl::isToolTipVisible( )const |
|
746 { |
|
747 Q_D( const HbSliderControl ); |
|
748 return d->displayCurrValueToolTip; |
|
749 } |
|
750 |
|
751 |
|
752 /*! |
|
753 sets the toolTip Alignment with respect to the thumb |
|
754 */ |
|
755 void HbSliderControl::setToolTipAlignment( Qt::Alignment alignment ) |
|
756 { |
|
757 Q_D( HbSliderControl ); |
|
758 if ( d->toolTipAlignment != alignment ) { |
|
759 d->toolTipAlignment=alignment; |
|
760 d->userDefinedTooltipAlign = true; |
|
761 } |
|
762 } |
|
763 |
|
764 |
|
765 /*! |
|
766 returns the tooltip Alignment with respect to the thumb |
|
767 */ |
|
768 Qt::Alignment HbSliderControl::toolTipAlignment( ) const |
|
769 { |
|
770 Q_D( const HbSliderControl ); |
|
771 return d->toolTipAlignment; |
|
772 } |
|
773 |
|
774 void HbSliderControl::changeEvent( QEvent *event ) |
|
775 { |
|
776 Q_D( HbSliderControl ); |
|
777 switch ( event->type( ) ) { |
|
778 case QEvent::LayoutDirectionChange: |
|
779 d->adjustHandle( ); |
|
780 d->updateTickAndLabel( ); |
|
781 break; |
|
782 case QEvent::StyleChange: |
|
783 // HbSlider::boundingRect( ) result depends on current style |
|
784 d->handle->prepareGeometryChange( ); |
|
785 d->adjustHandle( ); |
|
786 break; |
|
787 default: |
|
788 break; |
|
789 } |
|
790 HbAbstractSliderControl::changeEvent( event ); |
|
791 } |
|
792 |
|
793 /*! |
|
794 This api will hide the tooltip , this will |
|
795 |
|
796 be called on mouse release |
|
797 */ |
|
798 void HbSliderControl::hideToolTip( ) |
|
799 { |
|
800 HbToolTip::hideText( qobject_cast<HbGraphicsScene *>( scene( ) ) ); |
|
801 } |
|
802 |
|
803 |
|
804 /*! |
|
805 This will display tooltip when ever there |
|
806 |
|
807 is thumb drag. |
|
808 |
|
809 */ |
|
810 void HbSliderControl::showToolTip( ) |
|
811 { |
|
812 Q_D( HbSliderControl ); |
|
813 if ( isSliderDown( ) && d->displayCurrValueToolTip ) { |
|
814 HbToolTip::showText( toolTip( ) , d->handle , d->toolTipAlignment ); |
|
815 } |
|
816 } |
|
817 |
|
818 /*! |
|
819 reimp |
|
820 |
|
821 */ |
|
822 void HbSliderControl::mousePressEvent( QGraphicsSceneMouseEvent *event ) |
|
823 { |
|
824 Q_D( HbSliderControl ); |
|
825 HbAbstractSliderControl::mousePressEvent( event ); |
|
826 if ( !d->trackHandlingEnable ) { |
|
827 event->ignore( ); |
|
828 return; |
|
829 } |
|
830 // bound check |
|
831 if ( maximum( ) == minimum( ) || ( event->buttons( ) ^ event->button( ) ) ) { |
|
832 event->ignore( ); |
|
833 return; |
|
834 } |
|
835 #if defined( QT_KEYPAD_NAVIGATION ) && !defined( Q_OS_SYMBIAN ) |
|
836 if ( QApplication::keypadNavigationEnabled( ) ) { |
|
837 setEditFocus( true ); |
|
838 } |
|
839 #endif |
|
840 |
|
841 QRectF bounds = boundingRect( ); |
|
842 QRectF handleBounds = d->handle->boundingRect( ); |
|
843 bounds.adjust( 0, 0, -handleBounds.width( ), -handleBounds.height( ) ); |
|
844 |
|
845 // Define area events are accepted |
|
846 QRectF eventRect = d->grooveTouchArea->sceneBoundingRect( ); |
|
847 // return if point is outside track touch area |
|
848 if ( !eventRect.contains( event->scenePos( ) ) ) { |
|
849 event->ignore( ); |
|
850 return; |
|
851 } |
|
852 event->accept( ); |
|
853 if( d->onHandle( event->scenePos( ) ) ) { |
|
854 HbWidgetFeedback::triggered( this, Hb::InstantPressed, Hb::ModifierSliderHandle ); |
|
855 setSliderDown( true ); |
|
856 d->handle->updatePrimitives( ); |
|
857 d->handleMoving = true; |
|
858 } |
|
859 else { |
|
860 // effect |
|
861 #ifdef HB_EFFECTS |
|
862 if( d->grooveTouchArea->sceneBoundingRect( ).contains( event->scenePos( ) ) ) { |
|
863 if( orientation( ) == Qt::Horizontal ) { |
|
864 // effect for horizontal track press |
|
865 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackpress", "h_trackpress" ); |
|
866 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrpress" ); |
|
867 } |
|
868 else { |
|
869 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackpress", "v_trackpress" ); |
|
870 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackpress" ); |
|
871 } |
|
872 d->handle->updatePrimitives( ); |
|
873 } |
|
874 #endif |
|
875 HbWidgetFeedback::triggered( this, Hb::InstantPressed ); |
|
876 qreal handlePos = 0; |
|
877 qreal span = 0; |
|
878 // calculate handle position and span |
|
879 switch ( orientation( ) ) { |
|
880 case Qt::Horizontal: |
|
881 handlePos = event->pos( ).x( ) - handleBounds.width( ) / 2; |
|
882 span = bounds.width( ); |
|
883 break; |
|
884 case Qt::Vertical: |
|
885 handlePos = event->pos( ).y( ) - handleBounds.height( ) / 2; |
|
886 span = bounds.height( ); |
|
887 break; |
|
888 } |
|
889 |
|
890 HbStyleOptionSlider opt; |
|
891 d->groovePressed = true; |
|
892 initStyleOption( &opt ); |
|
893 // calculate pixel value for event position |
|
894 int pressValue = QStyle::sliderValueFromPosition( opt.minimum, opt.maximum, |
|
895 static_cast<int>( handlePos ),static_cast<int>( span ),opt.upsideDown ); |
|
896 //update the groove and touch item |
|
897 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
|
898 // if default is set then dont increment or decrement slider value |
|
899 // just set default value to slider |
|
900 if ( d->setDefault ) { |
|
901 setValue( d->previousValue ); |
|
902 if ( pressValue > value( ) ) { |
|
903 setRepeatAction( SliderSingleStepAdd, pressValue ); |
|
904 } |
|
905 else { |
|
906 setRepeatAction( SliderSingleStepSub, pressValue ); |
|
907 } |
|
908 d->setDefault = false; |
|
909 } |
|
910 else { |
|
911 if( singleStep( ) != 0 ) { |
|
912 HbWidgetFeedback::continuousTriggered( this, Hb::ContinuousDragged ); |
|
913 } |
|
914 setSliderPosition( pressValue ); |
|
915 triggerAction( SliderMove ); |
|
916 setRepeatAction( SliderNoAction, pressValue ); |
|
917 } |
|
918 } |
|
919 |
|
920 } |
|
921 |
|
922 /*! |
|
923 reimp |
|
924 |
|
925 */ |
|
926 void HbSliderControl::mouseReleaseEvent( QGraphicsSceneMouseEvent *event ) |
|
927 { |
|
928 HbAbstractSliderControl::mouseReleaseEvent( event ); |
|
929 Q_D( HbSliderControl ); |
|
930 d->handleMoving = false; |
|
931 if ( !d->trackHandlingEnable ) { |
|
932 event->ignore( ); |
|
933 return; |
|
934 } |
|
935 if ( d->groovePressed ) { |
|
936 |
|
937 #ifdef HB_EFFECTS |
|
938 if( d->grooveTouchArea->sceneBoundingRect( ).contains( event->scenePos( ) ) ) { |
|
939 if( orientation( ) == Qt::Horizontal ) { |
|
940 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_h_trackrelease", "h_trackrelease" ); |
|
941 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "h_trackrelease" ); |
|
942 } |
|
943 else { |
|
944 HbEffectInternal::add( HB_SLIDERCONTROL_TYPE,"slider_v_trackrelease", "v_trackrelease" ); |
|
945 HbEffect::start( d->groove, HB_SLIDERCONTROL_TYPE, "v_trackrelease" ); |
|
946 } |
|
947 d->handle->updatePrimitives( ); |
|
948 } |
|
949 #endif |
|
950 HbStyleOptionSlider opt; |
|
951 d->groovePressed = false; |
|
952 initStyleOption( &opt ); |
|
953 // update primitive from press to normal |
|
954 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
|
955 } |
|
956 if ( event->buttons( ) ) { |
|
957 event->ignore( ); |
|
958 return; |
|
959 } |
|
960 event->accept( ); |
|
961 // stop the timer |
|
962 setRepeatAction( SliderNoAction ); |
|
963 // snapping |
|
964 if( isSliderDown( ) ) { |
|
965 if ( d->snappingMode != NoSnapping ) { |
|
966 updateSliderPosToTick( ); |
|
967 } |
|
968 if( singleStep( ) != 0 ) { |
|
969 HbWidgetFeedback::continuousStopped( this, Hb::ContinuousDragged ); |
|
970 } |
|
971 HbWidgetFeedback::triggered( this, Hb::InstantReleased, Hb::ModifierSliderHandle ); |
|
972 } else { |
|
973 HbWidgetFeedback::triggered( this, Hb::InstantReleased ); |
|
974 } |
|
975 // update handle |
|
976 setSliderDown( false ); |
|
977 d->handle->updatePrimitives( ); |
|
978 HbToolTip::hideText( qobject_cast<HbGraphicsScene *>( scene( ) ) ); |
|
979 } |
|
980 |
|
981 |
|
982 bool HbSliderControl::sceneEventFilter(QGraphicsItem *obj,QEvent *event) |
|
983 { |
|
984 Q_D(HbSliderControl); |
|
985 if( obj == d->grooveTouchArea) { |
|
986 if (!isEnabled() ) { |
|
987 return false; |
|
988 } |
|
989 if (event->type() == QEvent::GraphicsSceneMousePress){ |
|
990 mousePressEvent((QGraphicsSceneMouseEvent *) event); |
|
991 return true; |
|
992 } |
|
993 else if (event->type() == QEvent::GraphicsSceneMouseRelease){ |
|
994 mouseReleaseEvent((QGraphicsSceneMouseEvent *) event); |
|
995 return true; |
|
996 } |
|
997 } |
|
998 return false; |
|
999 } |
|
1000 |
|
1001 /*! |
|
1002 |
|
1003 */ |
|
1004 void HbSliderControl::releasedOutside( bool outside ) |
|
1005 { |
|
1006 Q_UNUSED( outside ) |
|
1007 emit releasedOutside( ); |
|
1008 } |
|
1009 |
|
1010 /*! |
|
1011 reimp |
|
1012 |
|
1013 */ |
|
1014 void HbSliderControl::resizeEvent( QGraphicsSceneResizeEvent *event ) |
|
1015 { |
|
1016 Q_D( HbSliderControl ); |
|
1017 QGraphicsWidget::resizeEvent( event ); |
|
1018 // for Bug Fix::Ticks are not getting updated after |
|
1019 // element is added to slider |
|
1020 updatePrimitives( ); |
|
1021 repolish(); |
|
1022 d->adjustHandle( ); |
|
1023 d->updateTickAndLabel( ); |
|
1024 } |
|
1025 /*! |
|
1026 reimp |
|
1027 |
|
1028 */ |
|
1029 void HbSliderControl::polish( HbStyleParameters& params ) |
|
1030 { |
|
1031 |
|
1032 Q_D( HbSliderControl ); |
|
1033 HbStyleOptionSlider option; |
|
1034 initStyleOption( &option ); |
|
1035 updatePrimitives( ); |
|
1036 HbAbstractSliderControl::polish( params ); |
|
1037 d->adjustHandle( ); |
|
1038 d->updateTickAndLabel(); |
|
1039 } |
|
1040 |
|
1041 /*! |
|
1042 |
|
1043 */ |
|
1044 void HbSliderControl::initStyleOption( HbStyleOptionSlider *option ) const |
|
1045 { |
|
1046 Q_D( const HbSliderControl ); |
|
1047 if ( !option ) { |
|
1048 return; |
|
1049 } |
|
1050 HbAbstractSliderControl::initStyleOption( option ); |
|
1051 option->subControls = QStyle::SC_None; |
|
1052 option->activeSubControls = QStyle::SC_None; |
|
1053 option->orientation = orientation( ); |
|
1054 option->maximum = maximum( ); |
|
1055 option->minimum = minimum( ); |
|
1056 option->tickPosition = d->tickPosition; |
|
1057 option->tickInterval = d->majorTickInterval; |
|
1058 option->minorTickInterval = d->minorTickInterval; |
|
1059 option->thumbPath = d->handleIcon; |
|
1060 option->upsideDown = ( orientation( ) == Qt::Horizontal ) |
|
1061 ? ( invertedAppearance( ) != ( option->direction == Qt::RightToLeft ) ) |
|
1062 : ( !invertedAppearance( ) ); |
|
1063 // we use the upsideDown option instead |
|
1064 option->direction = Qt::LeftToRight; |
|
1065 option->sliderPosition = sliderPosition( ); |
|
1066 option->sliderValue = value( ); |
|
1067 option->singleStep = singleStep( ); |
|
1068 option->pageStep = pageStep( ); |
|
1069 option->groovePressed = d->groovePressed; |
|
1070 if ( orientation( ) == Qt::Horizontal ) { |
|
1071 option->state |= QStyle::State_Horizontal; |
|
1072 } |
|
1073 option->handleRect = d->handle->boundingRect( ); |
|
1074 QRectF bounds = boundingRect( ); |
|
1075 QRectF handleBounds = d->handle->boundingRect( ); |
|
1076 qreal span = 0; |
|
1077 if ( orientation( ) == Qt::Horizontal ) { |
|
1078 bounds.adjust( 0, 0, -handleBounds.width( )/2, 0 ); |
|
1079 // calculating span |
|
1080 span = bounds.width( ); |
|
1081 } else { |
|
1082 bounds.adjust( 0, 0, 0, -handleBounds.height( )/2 ); |
|
1083 // calculating span |
|
1084 span = bounds.height( ); |
|
1085 } |
|
1086 option->span = span; |
|
1087 } |
|
1088 |
|
1089 /*! |
|
1090 sets the icon path for handle |
|
1091 |
|
1092 /sa handleIcon( ) |
|
1093 |
|
1094 */ |
|
1095 void HbSliderControl::setHandleIcon( const QString &handleIcon ) |
|
1096 { |
|
1097 Q_D( HbSliderControl ); |
|
1098 d->handleIcon=handleIcon; |
|
1099 if( d->handle ) { |
|
1100 d->handle->updatePrimitives( ); |
|
1101 } |
|
1102 } |
|
1103 |
|
1104 /*! |
|
1105 returns icon of handle |
|
1106 |
|
1107 /sa setHandleIcon( ) |
|
1108 */ |
|
1109 QString HbSliderControl::handleIcon( ) const |
|
1110 { |
|
1111 Q_D( const HbSliderControl ); |
|
1112 return d->handleIcon; |
|
1113 } |
|
1114 |
|
1115 |
|
1116 void HbSliderControl::setHandleItem(QGraphicsItem *item) |
|
1117 { |
|
1118 Q_D( HbSliderControl ); |
|
1119 if( d->handle ) { |
|
1120 d->handle->setHandleItem(item); |
|
1121 d->handle->updatePrimitives(); |
|
1122 } |
|
1123 } |
|
1124 |
|
1125 QGraphicsItem* HbSliderControl::handleItem( ) const |
|
1126 { |
|
1127 Q_D( const HbSliderControl ); |
|
1128 if(d->handle) { |
|
1129 return d->handle->handleItem(); |
|
1130 } |
|
1131 return NULL; |
|
1132 } |
|
1133 |
|
1134 void HbSliderControl::setHandleVisible(bool isVisible) |
|
1135 { |
|
1136 Q_D( HbSliderControl ); |
|
1137 if(isVisible) { |
|
1138 d->handle->setVisible(true); |
|
1139 } else { |
|
1140 d->handle->setVisible(false); |
|
1141 } |
|
1142 } |
|
1143 |
|
1144 bool HbSliderControl::handleVisible() const |
|
1145 { |
|
1146 Q_D( const HbSliderControl ); |
|
1147 return d->handle->isVisible(); |
|
1148 } |
|
1149 |
|
1150 /*! |
|
1151 adjust the handle |
|
1152 */ |
|
1153 void HbSliderControl::sliderChange( SliderChange change) |
|
1154 { |
|
1155 Q_D( HbSliderControl ); |
|
1156 HbAbstractSliderControl::sliderChange( change ); |
|
1157 d->adjustHandle( ); |
|
1158 if ( change == SliderOrientationChange ) { |
|
1159 //Layout is not mirrored in vertical orientation with absolute ticks |
|
1160 if ( d->orientation == Qt::Horizontal ) { |
|
1161 } else if ( d->tickPosition&Hb::SliderTicksAbsolute) { |
|
1162 setLayoutDirection (Qt::LeftToRight); |
|
1163 } |
|
1164 if(d->orientation ==Qt::Horizontal) { |
|
1165 unsetLayoutDirection( ); |
|
1166 if (!d->userDefinedTooltipAlign) { |
|
1167 d->toolTipAlignment = ( Qt::AlignTop|Qt::AlignHCenter ); |
|
1168 } |
|
1169 setProperty("orientation",(Qt::Orientation)1); |
|
1170 if ( d->tickmarksLeft && d->tickmarksRight) { |
|
1171 HbStyle::setItemName( d->tickmarksLeft, "tick-marksabove" ); |
|
1172 HbStyle::setItemName( d->tickmarksRight, "tick-marksbelow" ); |
|
1173 } |
|
1174 if ( d->tickmarkslabelLeft && d->tickmarkslabelRight ) { |
|
1175 HbStyle::setItemName( d->tickmarkslabelLeft, "tick-textsabove" ); |
|
1176 HbStyle::setItemName( d->tickmarkslabelRight, "tick-textsbelow" ); |
|
1177 } |
|
1178 |
|
1179 } else { |
|
1180 setProperty("orientation",(Qt::Orientation)2); |
|
1181 if ( d->tickPosition & Hb::SliderTicksAbsolute) { |
|
1182 setLayoutDirection (Qt::LeftToRight); |
|
1183 } |
|
1184 if (!d->userDefinedTooltipAlign) { |
|
1185 d->toolTipAlignment = ( Qt::AlignTop|Qt::AlignRight ); |
|
1186 } |
|
1187 if ( d->tickmarksLeft && d->tickmarksRight) { |
|
1188 HbStyle::setItemName( d->tickmarksLeft, "tick-marksleft" ); |
|
1189 HbStyle::setItemName( d->tickmarksRight, "tick-marksright" ); |
|
1190 if ( d->tickPosition & Hb::SliderTicksAbsolute ) { |
|
1191 setLayoutDirection (Qt::LeftToRight ); |
|
1192 } |
|
1193 } |
|
1194 if ( d->tickmarkslabelLeft && d->tickmarkslabelRight ) { |
|
1195 HbStyle::setItemName( d->tickmarkslabelLeft, "tick-textsleft" ); |
|
1196 HbStyle::setItemName( d->tickmarkslabelRight, "tick-textsright" ); |
|
1197 } |
|
1198 |
|
1199 } |
|
1200 repolish( ); |
|
1201 if ( d->tickmarkslabelLeft && d->tickmarkslabelRight ) { |
|
1202 d->tickmarkslabelLeft->updateTickLabels( ); |
|
1203 d->tickmarkslabelRight->updateTickLabels( ); |
|
1204 } |
|
1205 |
|
1206 } |
|
1207 } |
|
1208 |
|
1209 |
|
1210 /*! |
|
1211 \reimp |
|
1212 */ |
|
1213 QGraphicsItem * HbSliderControl::primitive( HbStyle::Primitive primitive ) const |
|
1214 { |
|
1215 Q_D( const HbSliderControl ); |
|
1216 switch( primitive ){ |
|
1217 case HbStyle::P_Slider_groove: |
|
1218 return ( d->groove ); |
|
1219 case HbStyle::P_Slider_thumb: |
|
1220 return ( d->handle ); |
|
1221 case HbStyle::P_Slider_progressgroove: |
|
1222 return ( d->progressGroove ); |
|
1223 default:return( NULL ); |
|
1224 } |
|
1225 } |
|
1226 |
|
1227 /*! |
|
1228 reimp |
|
1229 |
|
1230 */ |
|
1231 QVariant HbSliderControl::itemChange( GraphicsItemChange change, const QVariant &value ) |
|
1232 { |
|
1233 Q_D( HbSliderControl ); |
|
1234 if ( change == QGraphicsItem::ItemEnabledHasChanged ) { |
|
1235 updatePrimitives( ); |
|
1236 } |
|
1237 switch( change ) { |
|
1238 case ItemVisibleHasChanged: |
|
1239 if ( !value.toBool( ) ) { |
|
1240 setSliderDown( false ); |
|
1241 setRepeatAction( SliderNoAction ); |
|
1242 updatePrimitives( ); |
|
1243 if ( d->handle ) { |
|
1244 d->handle->updatePrimitives( ); |
|
1245 } |
|
1246 d->groovePressed = false; |
|
1247 } else { |
|
1248 repolish(); |
|
1249 } |
|
1250 break; |
|
1251 case ItemSceneHasChanged: { |
|
1252 // scene event filter for gestures can be installed |
|
1253 // once the widget has been added to the scene |
|
1254 if(!value.isNull() && d->grooveTouchArea) { |
|
1255 d->grooveTouchArea->installSceneEventFilter(this); |
|
1256 } |
|
1257 updatePrimitives(); |
|
1258 } |
|
1259 break; |
|
1260 default: |
|
1261 break; |
|
1262 } |
|
1263 return HbAbstractSliderControl::itemChange( change, value ); |
|
1264 } |
|
1265 |
|
1266 /*! |
|
1267 reimp |
|
1268 consume tooltip event |
|
1269 |
|
1270 */ |
|
1271 bool HbSliderControl::sceneEvent ( QEvent * event ) |
|
1272 { |
|
1273 //eating tooltip event |
|
1274 if ( event->type( ) == QEvent::GraphicsSceneHelp ) { |
|
1275 event->accept( ); |
|
1276 return true; |
|
1277 } |
|
1278 return HbAbstractSliderControl::sceneEvent( event ); |
|
1279 } |
|
1280 |
|
1281 /*! |
|
1282 \reimp |
|
1283 */ |
|
1284 void HbSliderControl::updatePrimitives( ) |
|
1285 { |
|
1286 Q_D( HbSliderControl ); |
|
1287 HbStyleOptionSlider opt; |
|
1288 initStyleOption( &opt ); |
|
1289 if ( isEnabled( ) ) { |
|
1290 opt.state |= QStyle::State_Enabled; |
|
1291 } else { |
|
1292 opt.state &= ~QStyle::State_Enabled; |
|
1293 } |
|
1294 if ( d->groove ) { |
|
1295 style( )->updatePrimitive( d->groove, HbStyle::P_Slider_groove, &opt ); |
|
1296 } |
|
1297 |
|
1298 if ( d->enableProgressTrack ) { |
|
1299 if ( !d->progressGroove ) { |
|
1300 d->progressGroove = d->createProgressGroove(); |
|
1301 if(d->progressGroove) { |
|
1302 HbStyle::setItemName( d->progressGroove, "progressgroove"); |
|
1303 repolish(); |
|
1304 } |
|
1305 } |
|
1306 style( )->updatePrimitive( d->progressGroove, HbStyle::P_Slider_progressgroove, &opt ); |
|
1307 }else if ( d->progressGroove ) { |
|
1308 delete d->progressGroove; |
|
1309 d->progressGroove = 0 ; |
|
1310 } |
|
1311 } |
|
1312 |
|
1313 /*! |
|
1314 Sets the current slider position. |
|
1315 |
|
1316 \sa sliderPosition( ) |
|
1317 */ |
|
1318 void HbSliderControl::setSliderPosition( int value ) |
|
1319 { |
|
1320 Q_D( HbSliderControl ); |
|
1321 bool b = d->displayCurrValueToolTip; |
|
1322 d->displayCurrValueToolTip = false; |
|
1323 HbAbstractSliderControl::setSliderPosition( value ); |
|
1324 d->displayCurrValueToolTip = b; |
|
1325 } |
|
1326 |
|
1327 /*! |
|
1328 snapp slider values |
|
1329 */ |
|
1330 void HbSliderControl::updateSliderPosToTick( ) |
|
1331 { |
|
1332 Q_D( HbSliderControl ); |
|
1333 int nearbyTick = d->getNearbyTick( ); |
|
1334 if ( nearbyTick > sliderPosition( ) ) { |
|
1335 while ( nearbyTick != sliderPosition( ) ) { |
|
1336 int curVal = sliderPosition( ) + 1; |
|
1337 setSliderPosition( curVal ); |
|
1338 } |
|
1339 } else { |
|
1340 while ( nearbyTick != sliderPosition( ) ) { |
|
1341 int curVal = sliderPosition( ) - 1; |
|
1342 setSliderPosition( curVal ); |
|
1343 } |
|
1344 } |
|
1345 } |
|
1346 |
|
1347 /*! |
|
1348 if first parameter is true then on mouse press, set this value to slider , |
|
1349 instead of increasing or decreasing it |
|
1350 */ |
|
1351 void HbSliderControl::setPreviousValue( bool setDefault, int value ) |
|
1352 { |
|
1353 Q_D( HbSliderControl ); |
|
1354 d->setDefault = setDefault; |
|
1355 d->previousValue = value; |
|
1356 } |
|
1357 |
|
1358 /*! |
|
1359 if true is passed then will make track interactive |
|
1360 */ |
|
1361 void HbSliderControl::enableTrackEventHandling( bool enable ) |
|
1362 { |
|
1363 Q_D( HbSliderControl ); |
|
1364 if ( d->trackHandlingEnable == enable ) { |
|
1365 return; |
|
1366 } |
|
1367 if ( enable ) { |
|
1368 //creating groove touch area |
|
1369 d->grooveTouchArea = qgraphicsitem_cast<QGraphicsItem*>( style( )->createPrimitive( |
|
1370 HbStyle::P_SliderElement_touchgroove, this ) ); |
|
1371 if ( d->grooveTouchArea ) { |
|
1372 HbStyle::setItemName( d->grooveTouchArea, "groovetoucharea" ); |
|
1373 } |
|
1374 if( scene()) { |
|
1375 d->grooveTouchArea->installSceneEventFilter(this); |
|
1376 } |
|
1377 |
|
1378 } |
|
1379 else if ( d->grooveTouchArea ) { |
|
1380 d->grooveTouchArea->removeSceneEventFilter( this ); |
|
1381 delete d->grooveTouchArea; |
|
1382 d->grooveTouchArea = NULL; |
|
1383 } |
|
1384 d->trackHandlingEnable = enable ; |
|
1385 } |
|
1386 |
|
1387 /*! |
|
1388 returns true if track interactive otherwise return false |
|
1389 */ |
|
1390 bool HbSliderControl::isTrackEventHandlingEnabled ( ) |
|
1391 { |
|
1392 Q_D( HbSliderControl ); |
|
1393 return d->trackHandlingEnable ; |
|
1394 } |
|
1395 |
|
1396 void HbSliderControl::setTrackFilled(bool trackVisible ) |
|
1397 { |
|
1398 |
|
1399 Q_D( HbSliderControl ); |
|
1400 if ( d->enableProgressTrack != trackVisible ) { |
|
1401 d->enableProgressTrack = trackVisible; |
|
1402 updatePrimitives(); |
|
1403 } |
|
1404 |
|
1405 } |
|
1406 |
|
1407 |
|
1408 bool HbSliderControl::isTrackFilled() const |
|
1409 { |
|
1410 Q_D( const HbSliderControl ); |
|
1411 return d->enableProgressTrack; |
|
1412 } |
|
1413 |