Qwt User's Guide: qwt_wheel.cpp Source File

Qwt User's Guide 6.2.0

qwt_wheel.cpp
1 /******************************************************************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the Qwt License, Version 1.0
8 *****************************************************************************/
9
10 #include "qwt_wheel.h"
11 #include "qwt_math.h"
12 #include "qwt_painter.h"
13 #include "qwt.h"
14
15 #include <qevent.h>
16 #include <qdrawutil.h>
17 #include <qpainter.h>
18 #include <qstyle.h>
19 #include <qstyleoption.h>
20 #include <qelapsedtimer.h>
21 #include <qmath.h>
22
23 class QwtWheel::PrivateData
24 {
25 public:
26 PrivateData()
27 : orientation( Qt::Horizontal )
28 , viewAngle( 175.0 )
29 , totalAngle( 360.0 )
30 , tickCount( 10 )
31 , wheelBorderWidth( 2 )
32 , borderWidth( 2 )
33 , wheelWidth( 20 )
34 , mouseOffset( 0.0 )
35 , updateInterval( 50 )
36 , mass( 0.0 )
37 , timerId( 0 )
38 , speed( 0.0 )
39 , mouseValue( 0.0 )
40 , flyingValue( 0.0 )
41 , minimum( 0.0 )
42 , maximum( 100.0 )
43 , singleStep( 1.0 )
44 , pageStepCount( 1 )
45 , value( 0.0 )
46 , isScrolling( false )
47 , tracking( true )
48 , stepAlignment( true )
49 , pendingValueChanged( false )
50 , inverted( false )
51 , wrapping( false )
52 {
53 }
54
55 Qt::Orientation orientation;
56 double viewAngle;
57 double totalAngle;
58 int tickCount;
59 int wheelBorderWidth;
60 int borderWidth;
61 int wheelWidth;
62
63 double mouseOffset;
64
65 int updateInterval;
66 double mass;
67
68 // for the flying wheel effect
69 int timerId;
70 QElapsedTimer timer;
71 double speed;
72 double mouseValue;
73 double flyingValue;
74
75 double minimum;
76 double maximum;
77
78 double singleStep;
79 int pageStepCount;
80
81 double value;
82
83 bool isScrolling;
84 bool tracking;
85 bool stepAlignment;
86 bool pendingValueChanged; // when not tracking
87 bool inverted;
88 bool wrapping;
89 };
90
92 QwtWheel::QwtWheel( QWidget* parent ):
93 QWidget( parent )
94 {
95 m_data = new PrivateData;
96
97 setFocusPolicy( Qt::StrongFocus );
98 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
99 setAttribute( Qt::WA_WState_OwnSizePolicy, false );
100 }
101
103 QwtWheel::~QwtWheel()
104 {
105 delete m_data;
106 }
107
120 void QwtWheel::setTracking( bool enable )
121 {
122 m_data->tracking = enable;
123 }
124
129 bool QwtWheel::isTracking() const
130 {
131 return m_data->tracking;
132 }
133
142 void QwtWheel::setUpdateInterval( int interval )
143 {
144 m_data->updateInterval = qMax( interval, 50 );
145 }
146
151 int QwtWheel::updateInterval() const
152 {
153 return m_data->updateInterval;
154 }
155
163 void QwtWheel::mousePressEvent( QMouseEvent* event )
164 {
165 stopFlying();
166
167 m_data->isScrolling = wheelRect().contains( event->pos() );
168
169 if ( m_data->isScrolling )
170 {
171 m_data->timer.start();
172 m_data->speed = 0.0;
173 m_data->mouseValue = valueAt( event->pos() );
174 m_data->mouseOffset = m_data->mouseValue - m_data->value;
175 m_data->pendingValueChanged = false;
176
177 Q_EMIT wheelPressed();
178 }
179 }
180
188 void QwtWheel::mouseMoveEvent( QMouseEvent* event )
189 {
190 if ( !m_data->isScrolling )
191 return;
192
193 double mouseValue = valueAt( event->pos() );
194
195 if ( m_data->mass > 0.0 )
196 {
197 double ms = m_data->timer.restart();
198
199 // the interval when mouse move events are posted are somehow
200 // random. To avoid unrealistic speed values we limit ms
201
202 ms = qMax( ms, 5.0 );
203
204 m_data->speed = ( mouseValue - m_data->mouseValue ) / ms;
205 }
206
207 m_data->mouseValue = mouseValue;
208
209 double value = boundedValue( mouseValue - m_data->mouseOffset );
210 if ( m_data->stepAlignment )
211 value = alignedValue( value );
212
213 if ( value != m_data->value )
214 {
215 m_data->value = value;
216
217 update();
218
219 Q_EMIT wheelMoved( m_data->value );
220
221 if ( m_data->tracking )
222 Q_EMIT valueChanged( m_data->value );
223 else
224 m_data->pendingValueChanged = true;
225 }
226 }
227
237 void QwtWheel::mouseReleaseEvent( QMouseEvent* event )
238 {
239 Q_UNUSED( event );
240
241 if ( !m_data->isScrolling )
242 return;
243
244 m_data->isScrolling = false;
245
246 bool startFlying = false;
247
248 if ( m_data->mass > 0.0 )
249 {
250 const qint64 ms = m_data->timer.elapsed();
251 if ( ( std::fabs( m_data->speed ) > 0.0 ) && ( ms < 50 ) )
252 startFlying = true;
253 }
254
255 if ( startFlying )
256 {
257 m_data->flyingValue =
258 boundedValue( m_data->mouseValue - m_data->mouseOffset );
259
260 m_data->timerId = startTimer( m_data->updateInterval );
261 }
262 else
263 {
264 if ( m_data->pendingValueChanged )
265 Q_EMIT valueChanged( m_data->value );
266 }
267
268 m_data->pendingValueChanged = false;
269 m_data->mouseOffset = 0.0;
270
271 Q_EMIT wheelReleased();
272 }
273
283 void QwtWheel::timerEvent( QTimerEvent* event )
284 {
285 if ( event->timerId() != m_data->timerId )
286 {
287 QWidget::timerEvent( event );
288 return;
289 }
290
291 m_data->speed *= std::exp( -m_data->updateInterval * 0.001 / m_data->mass );
292
293 m_data->flyingValue += m_data->speed * m_data->updateInterval;
294 m_data->flyingValue = boundedValue( m_data->flyingValue );
295
296 double value = m_data->flyingValue;
297 if ( m_data->stepAlignment )
298 value = alignedValue( value );
299
300 if ( std::fabs( m_data->speed ) < 0.001 * m_data->singleStep )
301 {
302 // stop if m_data->speed < one step per second
303 stopFlying();
304 }
305
306 if ( value != m_data->value )
307 {
308 m_data->value = value;
309 update();
310
311 if ( m_data->tracking || m_data->timerId == 0 )
312 Q_EMIT valueChanged( m_data->value );
313 }
314 }
315
316
324 void QwtWheel::wheelEvent( QWheelEvent* event )
325 {
326 #if QT_VERSION < 0x050e00
327 const QPoint wheelPos = event->pos();
328 const int wheelDelta = event->delta();
329 #else
330 const QPoint wheelPos = event->position().toPoint();
331
332 const QPoint delta = event->angleDelta();
333 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
334 ? delta.x() : delta.y();
335 #endif
336
337 if ( !wheelRect().contains( wheelPos ) )
338 {
339 event->ignore();
340 return;
341 }
342
343 if ( m_data->isScrolling )
344 return;
345
346 stopFlying();
347
348 double increment = 0.0;
349
350 if ( ( event->modifiers() & Qt::ControlModifier ) ||
351 ( event->modifiers() & Qt::ShiftModifier ) )
352 {
353 // one page regardless of delta
354 increment = m_data->singleStep * m_data->pageStepCount;
355 if ( wheelDelta < 0 )
356 increment = -increment;
357 }
358 else
359 {
360 const int numSteps = wheelDelta / 120;
361 increment = m_data->singleStep * numSteps;
362 }
363
364 if ( m_data->orientation == Qt::Vertical && m_data->inverted )
365 increment = -increment;
366
367 double value = boundedValue( m_data->value + increment );
368
369 if ( m_data->stepAlignment )
370 value = alignedValue( value );
371
372 if ( value != m_data->value )
373 {
374 m_data->value = value;
375 update();
376
377 Q_EMIT valueChanged( m_data->value );
378 Q_EMIT wheelMoved( m_data->value );
379 }
380 }
381
409 void QwtWheel::keyPressEvent( QKeyEvent* event )
410 {
411 if ( m_data->isScrolling )
412 {
413 // don't interfere mouse scrolling
414 return;
415 }
416
417 double value = m_data->value;
418 double increment = 0.0;
419
420 switch ( event->key() )
421 {
422 case Qt::Key_Down:
423 {
424 if ( m_data->orientation == Qt::Vertical && m_data->inverted )
425 increment = m_data->singleStep;
426 else
427 increment = -m_data->singleStep;
428
429 break;
430 }
431 case Qt::Key_Up:
432 {
433 if ( m_data->orientation == Qt::Vertical && m_data->inverted )
434 increment = -m_data->singleStep;
435 else
436 increment = m_data->singleStep;
437
438 break;
439 }
440 case Qt::Key_Left:
441 {
442 if ( m_data->orientation == Qt::Horizontal )
443 {
444 if ( m_data->inverted )
445 increment = m_data->singleStep;
446 else
447 increment = -m_data->singleStep;
448 }
449 break;
450 }
451 case Qt::Key_Right:
452 {
453 if ( m_data->orientation == Qt::Horizontal )
454 {
455 if ( m_data->inverted )
456 increment = -m_data->singleStep;
457 else
458 increment = m_data->singleStep;
459 }
460 break;
461 }
462 case Qt::Key_PageUp:
463 {
464 increment = m_data->pageStepCount * m_data->singleStep;
465 break;
466 }
467 case Qt::Key_PageDown:
468 {
469 increment = -m_data->pageStepCount * m_data->singleStep;
470 break;
471 }
472 case Qt::Key_Home:
473 {
474 value = m_data->minimum;
475 break;
476 }
477 case Qt::Key_End:
478 {
479 value = m_data->maximum;
480 break;
481 }
482 default:;
483 {
484 event->ignore();
485 }
486 }
487
488 if ( event->isAccepted() )
489 stopFlying();
490
491 if ( increment != 0.0 )
492 {
493 value = boundedValue( m_data->value + increment );
494
495 if ( m_data->stepAlignment )
496 value = alignedValue( value );
497 }
498
499 if ( value != m_data->value )
500 {
501 m_data->value = value;
502 update();
503
504 Q_EMIT valueChanged( m_data->value );
505 Q_EMIT wheelMoved( m_data->value );
506 }
507 }
508
519 void QwtWheel::setTickCount( int count )
520 {
521 count = qBound( 6, count, 50 );
522
523 if ( count != m_data->tickCount )
524 {
525 m_data->tickCount = qBound( 6, count, 50 );
526 update();
527 }
528 }
529
534 int QwtWheel::tickCount() const
535 {
536 return m_data->tickCount;
537 }
538
551 void QwtWheel::setWheelBorderWidth( int borderWidth )
552 {
553 const int d = qMin( width(), height() ) / 3;
554 borderWidth = qMin( borderWidth, d );
555 m_data->wheelBorderWidth = qMax( borderWidth, 1 );
556 update();
557 }
558
563 int QwtWheel::wheelBorderWidth() const
564 {
565 return m_data->wheelBorderWidth;
566 }
567
576 void QwtWheel::setBorderWidth( int width )
577 {
578 m_data->borderWidth = qMax( width, 0 );
579 update();
580 }
581
586 int QwtWheel::borderWidth() const
587 {
588 return m_data->borderWidth;
589 }
590
594 QRect QwtWheel::wheelRect() const
595 {
596 const int bw = m_data->borderWidth;
597 return contentsRect().adjusted( bw, bw, -bw, -bw );
598 }
599
613 void QwtWheel::setTotalAngle( double angle )
614 {
615 if ( angle < 0.0 )
616 angle = 0.0;
617
618 m_data->totalAngle = angle;
619 update();
620 }
621
626 double QwtWheel::totalAngle() const
627 {
628 return m_data->totalAngle;
629 }
630
639 void QwtWheel::setOrientation( Qt::Orientation orientation )
640 {
641 if ( m_data->orientation == orientation )
642 return;
643
644 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
645 {
646 QSizePolicy sp = sizePolicy();
647 sp.transpose();
648 setSizePolicy( sp );
649
650 setAttribute( Qt::WA_WState_OwnSizePolicy, false );
651 }
652
653 m_data->orientation = orientation;
654 update();
655 }
656
661 Qt::Orientation QwtWheel::orientation() const
662 {
663 return m_data->orientation;
664 }
665
676 void QwtWheel::setViewAngle( double angle )
677 {
678 m_data->viewAngle = qBound( 10.0, angle, 175.0 );
679 update();
680 }
681
686 double QwtWheel::viewAngle() const
687 {
688 return m_data->viewAngle;
689 }
690
697 double QwtWheel::valueAt( const QPoint& pos ) const
698 {
699 const QRectF rect = wheelRect();
700
701 double w, dx;
702 if ( m_data->orientation == Qt::Vertical )
703 {
704 w = rect.height();
705 dx = rect.top() - pos.y();
706 }
707 else
708 {
709 w = rect.width();
710 dx = pos.x() - rect.left();
711 }
712
713 if ( w == 0.0 )
714 return 0.0;
715
716 if ( m_data->inverted )
717 {
718 dx = w - dx;
719 }
720
721 // w pixels is an arc of viewAngle degrees,
722 // so we convert change in pixels to change in angle
723 const double ang = dx * m_data->viewAngle / w;
724
725 // value range maps to totalAngle degrees,
726 // so convert the change in angle to a change in value
727 const double val = ang * ( maximum() - minimum() ) / m_data->totalAngle;
728
729 return val;
730 }
731
736 void QwtWheel::paintEvent( QPaintEvent* event )
737 {
738 QPainter painter( this );
739 painter.setClipRegion( event->region() );
740
741 QStyleOption opt;
742 opt.initFrom(this);
743 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
744
745 qDrawShadePanel( &painter,
746 contentsRect(), palette(), true, m_data->borderWidth );
747
748 drawWheelBackground( &painter, wheelRect() );
749 drawTicks( &painter, wheelRect() );
750
751 if ( hasFocus() )
752 QwtPainter::drawFocusRect( &painter, this );
753 }
754
761 void QwtWheel::drawWheelBackground(
762 QPainter* painter, const QRectF& rect )
763 {
764 painter->save();
765
766 QPalette pal = palette();
767
768 // draw shaded background
769 QLinearGradient gradient( rect.topLeft(),
770 ( m_data->orientation == Qt::Horizontal ) ? rect.topRight() : rect.bottomLeft() );
771 gradient.setColorAt( 0.0, pal.color( QPalette::Button ) );
772 gradient.setColorAt( 0.2, pal.color( QPalette::Midlight ) );
773 gradient.setColorAt( 0.7, pal.color( QPalette::Mid ) );
774 gradient.setColorAt( 1.0, pal.color( QPalette::Dark ) );
775
776 painter->fillRect( rect, gradient );
777
778 // draw internal border
779
780 const QPen lightPen( palette().color( QPalette::Light ),
781 m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
782 const QPen darkPen( pal.color( QPalette::Dark ),
783 m_data->wheelBorderWidth, Qt::SolidLine, Qt::FlatCap );
784
785 const double bw2 = 0.5 * m_data->wheelBorderWidth;
786
787 if ( m_data->orientation == Qt::Horizontal )
788 {
789 painter->setPen( lightPen );
790 painter->drawLine( QPointF( rect.left(), rect.top() + bw2 ),
791 QPointF( rect.right(), rect.top() + bw2 ) );
792
793 painter->setPen( darkPen );
794 painter->drawLine( QPointF( rect.left(), rect.bottom() - bw2 ),
795 QPointF( rect.right(), rect.bottom() - bw2 ) );
796 }
797 else // Qt::Vertical
798 {
799 painter->setPen( lightPen );
800 painter->drawLine( QPointF( rect.left() + bw2, rect.top() ),
801 QPointF( rect.left() + bw2, rect.bottom() ) );
802
803 painter->setPen( darkPen );
804 painter->drawLine( QPointF( rect.right() - bw2, rect.top() ),
805 QPointF( rect.right() - bw2, rect.bottom() ) );
806 }
807
808 painter->restore();
809 }
810
817 void QwtWheel::drawTicks( QPainter* painter, const QRectF& rect )
818 {
819 const double range = m_data->maximum - m_data->minimum;
820
821 if ( range == 0.0 || m_data->totalAngle == 0.0 )
822 {
823 return;
824 }
825
826 const QPen lightPen( palette().color( QPalette::Light ),
827 0, Qt::SolidLine, Qt::FlatCap );
828 const QPen darkPen( palette().color( QPalette::Dark ),
829 0, Qt::SolidLine, Qt::FlatCap );
830
831 const double cnvFactor = qAbs( m_data->totalAngle / range );
832 const double halfIntv = 0.5 * m_data->viewAngle / cnvFactor;
833 const double loValue = value() - halfIntv;
834 const double hiValue = value() + halfIntv;
835 const double tickWidth = 360.0 / double( m_data->tickCount ) / cnvFactor;
836 const double sinArc = qFastSin( m_data->viewAngle * M_PI / 360.0 );
837
838 if ( m_data->orientation == Qt::Horizontal )
839 {
840 const double radius = rect.width() * 0.5;
841
842 double l1 = rect.top() + m_data->wheelBorderWidth;
843 double l2 = rect.bottom() - m_data->wheelBorderWidth - 1;
844
845 // draw one point over the border if border > 1
846 if ( m_data->wheelBorderWidth > 1 )
847 {
848 l1--;
849 l2++;
850 }
851
852 const double maxpos = rect.right() - 2;
853 const double minpos = rect.left() + 2;
854
855 // draw tick marks
856 for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
857 tickValue < hiValue; tickValue += tickWidth )
858 {
859 const double angle = qwtRadians( tickValue - value() );
860 const double s = qFastSin( angle * cnvFactor );
861
862 const double off = radius * ( sinArc + s ) / sinArc;
863
864 double tickPos;
865 if ( m_data->inverted )
866 tickPos = rect.left() + off;
867 else
868 tickPos = rect.right() - off;
869
870 if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
871 {
872 painter->setPen( darkPen );
873 painter->drawLine( QPointF( tickPos - 1, l1 ),
874 QPointF( tickPos - 1, l2 ) );
875 painter->setPen( lightPen );
876 painter->drawLine( QPointF( tickPos, l1 ),
877 QPointF( tickPos, l2 ) );
878 }
879 }
880 }
881 else // Qt::Vertical
882 {
883 const double radius = rect.height() * 0.5;
884
885 double l1 = rect.left() + m_data->wheelBorderWidth;
886 double l2 = rect.right() - m_data->wheelBorderWidth - 1;
887
888 if ( m_data->wheelBorderWidth > 1 )
889 {
890 l1--;
891 l2++;
892 }
893
894 const double maxpos = rect.bottom() - 2;
895 const double minpos = rect.top() + 2;
896
897 for ( double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
898 tickValue < hiValue; tickValue += tickWidth )
899 {
900 const double angle = qwtRadians( tickValue - value() );
901 const double s = qFastSin( angle * cnvFactor );
902
903 const double off = radius * ( sinArc + s ) / sinArc;
904
905 double tickPos;
906
907 if ( m_data->inverted )
908 tickPos = rect.bottom() - off;
909 else
910 tickPos = rect.top() + off;
911
912 if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
913 {
914 painter->setPen( darkPen );
915 painter->drawLine( QPointF( l1, tickPos - 1 ),
916 QPointF( l2, tickPos - 1 ) );
917 painter->setPen( lightPen );
918 painter->drawLine( QPointF( l1, tickPos ),
919 QPointF( l2, tickPos ) );
920 }
921 }
922 }
923 }
924
934 void QwtWheel::setWheelWidth( int width )
935 {
936 m_data->wheelWidth = width;
937 update();
938 }
939
944 int QwtWheel::wheelWidth() const
945 {
946 return m_data->wheelWidth;
947 }
948
952 QSize QwtWheel::sizeHint() const
953 {
954 const QSize hint = minimumSizeHint();
955 return qwtExpandedToGlobalStrut( hint );
956 }
957
962 QSize QwtWheel::minimumSizeHint() const
963 {
964 QSize sz( 3 * m_data->wheelWidth + 2 * m_data->borderWidth,
965 m_data->wheelWidth + 2 * m_data->borderWidth );
966 if ( m_data->orientation != Qt::Horizontal )
967 sz.transpose();
968
969 return sz;
970 }
971
980 void QwtWheel::setSingleStep( double stepSize )
981 {
982 m_data->singleStep = qwtMaxF( stepSize, 0.0 );
983 }
984
989 double QwtWheel::singleStep() const
990 {
991 return m_data->singleStep;
992 }
993
1004 void QwtWheel::setStepAlignment( bool on )
1005 {
1006 if ( on != m_data->stepAlignment )
1007 {
1008 m_data->stepAlignment = on;
1009 }
1010 }
1011
1016 bool QwtWheel::stepAlignment() const
1017 {
1018 return m_data->stepAlignment;
1019 }
1020
1034 void QwtWheel::setPageStepCount( int count )
1035 {
1036 m_data->pageStepCount = qMax( 0, count );
1037 }
1038
1043 int QwtWheel::pageStepCount() const
1044 {
1045 return m_data->pageStepCount;
1046 }
1047
1059 void QwtWheel::setRange( double min, double max )
1060 {
1061 max = qwtMaxF( min, max );
1062
1063 if ( m_data->minimum == min && m_data->maximum == max )
1064 return;
1065
1066 m_data->minimum = min;
1067 m_data->maximum = max;
1068
1069 if ( m_data->value < min || m_data->value > max )
1070 {
1071 m_data->value = qBound( min, m_data->value, max );
1072
1073 update();
1074 Q_EMIT valueChanged( m_data->value );
1075 }
1076 }
1085 void QwtWheel::setMinimum( double value )
1086 {
1087 setRange( value, maximum() );
1088 }
1089
1094 double QwtWheel::minimum() const
1095 {
1096 return m_data->minimum;
1097 }
1098
1105 void QwtWheel::setMaximum( double value )
1106 {
1107 setRange( minimum(), value );
1108 }
1109
1114 double QwtWheel::maximum() const
1115 {
1116 return m_data->maximum;
1117 }
1118
1127 void QwtWheel::setValue( double value )
1128 {
1129 stopFlying();
1130 m_data->isScrolling = false;
1131
1132 value = qBound( m_data->minimum, value, m_data->maximum );
1133
1134 if ( m_data->value != value )
1135 {
1136 m_data->value = value;
1137
1138 update();
1139 Q_EMIT valueChanged( m_data->value );
1140 }
1141 }
1142
1147 double QwtWheel::value() const
1148 {
1149 return m_data->value;
1150 }
1151
1163 void QwtWheel::setInverted( bool on )
1164 {
1165 if ( m_data->inverted != on )
1166 {
1167 m_data->inverted = on;
1168 update();
1169 }
1170 }
1171
1176 bool QwtWheel::isInverted() const
1177 {
1178 return m_data->inverted;
1179 }
1180
1190 void QwtWheel::setWrapping( bool on )
1191 {
1192 m_data->wrapping = on;
1193 }
1194
1199 bool QwtWheel::wrapping() const
1200 {
1201 return m_data->wrapping;
1202 }
1203
1221 void QwtWheel::setMass( double mass )
1222 {
1223 if ( mass < 0.001 )
1224 {
1225 m_data->mass = 0.0;
1226 }
1227 else
1228 {
1229 m_data->mass = qwtMinF( 100.0, mass );
1230 }
1231
1232 if ( m_data->mass <= 0.0 )
1233 stopFlying();
1234 }
1235
1240 double QwtWheel::mass() const
1241 {
1242 return m_data->mass;
1243 }
1244
1246 void QwtWheel::stopFlying()
1247 {
1248 if ( m_data->timerId != 0 )
1249 {
1250 killTimer( m_data->timerId );
1251 m_data->timerId = 0;
1252 m_data->speed = 0.0;
1253 }
1254 }
1255
1256 double QwtWheel::boundedValue( double value ) const
1257 {
1258 const double range = m_data->maximum - m_data->minimum;
1259
1260 if ( m_data->wrapping && range >= 0.0 )
1261 {
1262 if ( value < m_data->minimum )
1263 {
1264 value += std::ceil( ( m_data->minimum - value ) / range ) * range;
1265 }
1266 else if ( value > m_data->maximum )
1267 {
1268 value -= std::ceil( ( value - m_data->maximum ) / range ) * range;
1269 }
1270 }
1271 else
1272 {
1273 value = qBound( m_data->minimum, value, m_data->maximum );
1274 }
1275
1276 return value;
1277 }
1278
1279 double QwtWheel::alignedValue( double value ) const
1280 {
1281 const double stepSize = m_data->singleStep;
1282
1283 if ( stepSize > 0.0 )
1284 {
1285 value = m_data->minimum +
1286 qRound( ( value - m_data->minimum ) / stepSize ) * stepSize;
1287
1288 if ( stepSize > 1e-12 )
1289 {
1290 if ( qFuzzyCompare( value + 1.0, 1.0 ) )
1291 {
1292 // correct rounding error if value = 0
1293 value = 0.0;
1294 }
1295 else if ( qFuzzyCompare( value, m_data->maximum ) )
1296 {
1297 // correct rounding error at the border
1298 value = m_data->maximum;
1299 }
1300 }
1301 }
1302
1303 return value;
1304 }
1305
1306 #if QWT_MOC_INCLUDE
1307 #include "moc_qwt_wheel.cpp"
1308 #endif
QwtPainter::drawFocusRect
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
Definition: qwt_painter.cpp:815
QwtWheel::paintEvent
virtual void paintEvent(QPaintEvent *) override
Qt Paint Event.
Definition: qwt_wheel.cpp:736
QwtWheel::wheelEvent
virtual void wheelEvent(QWheelEvent *) override
Handle wheel events.
Definition: qwt_wheel.cpp:324
QwtWheel::orientation
Qt::Orientation orientation() const
Definition: qwt_wheel.cpp:661
QwtWheel::stepAlignment
bool stepAlignment() const
Definition: qwt_wheel.cpp:1016
QwtWheel::sizeHint
virtual QSize sizeHint() const override
Definition: qwt_wheel.cpp:952
QwtWheel::setMass
void setMass(double)
Set the slider's mass for flywheel effect.
Definition: qwt_wheel.cpp:1221
QwtWheel::drawWheelBackground
virtual void drawWheelBackground(QPainter *, const QRectF &)
Definition: qwt_wheel.cpp:761
QwtWheel::minimumSizeHint
virtual QSize minimumSizeHint() const override
Definition: qwt_wheel.cpp:962
QwtWheel::setTracking
void setTracking(bool)
En/Disable tracking.
Definition: qwt_wheel.cpp:120
QwtWheel::value
double value() const
Definition: qwt_wheel.cpp:1147
QwtWheel::mouseReleaseEvent
virtual void mouseReleaseEvent(QMouseEvent *) override
Mouse Release Event handler.
Definition: qwt_wheel.cpp:237
QwtWheel::setWheelBorderWidth
void setWheelBorderWidth(int)
Set the wheel border width of the wheel.
Definition: qwt_wheel.cpp:551
QwtWheel::setBorderWidth
void setBorderWidth(int)
Set the border width.
Definition: qwt_wheel.cpp:576
QwtWheel::setRange
void setRange(double min, double max)
Set the minimum and maximum values.
Definition: qwt_wheel.cpp:1059
QwtWheel::~QwtWheel
virtual ~QwtWheel()
Destructor.
Definition: qwt_wheel.cpp:103
QwtWheel::updateInterval
int updateInterval() const
Definition: qwt_wheel.cpp:151
QwtWheel::timerEvent
virtual void timerEvent(QTimerEvent *) override
Qt timer event.
Definition: qwt_wheel.cpp:283
QwtWheel::setUpdateInterval
void setUpdateInterval(int)
Specify the update interval when the wheel is flying.
Definition: qwt_wheel.cpp:142
QwtWheel::setStepAlignment
void setStepAlignment(bool on)
En/Disable step alignment.
Definition: qwt_wheel.cpp:1004
QwtWheel::mouseMoveEvent
virtual void mouseMoveEvent(QMouseEvent *) override
Mouse Move Event handler.
Definition: qwt_wheel.cpp:188
QwtWheel::setSingleStep
void setSingleStep(double)
Set the step size of the counter.
Definition: qwt_wheel.cpp:980
QwtWheel::wheelRect
QRect wheelRect() const
Definition: qwt_wheel.cpp:594
QwtWheel::borderWidth
int borderWidth() const
Definition: qwt_wheel.cpp:586
QwtWheel::setValue
void setValue(double)
Set a new value without adjusting to the step raster.
Definition: qwt_wheel.cpp:1127
QwtWheel::setMinimum
void setMinimum(double)
Definition: qwt_wheel.cpp:1085
QwtWheel::maximum
double maximum() const
Definition: qwt_wheel.cpp:1114
QwtWheel::wheelMoved
void wheelMoved(double value)
QwtWheel::pageStepCount
int pageStepCount() const
Definition: qwt_wheel.cpp:1043
QwtWheel::setViewAngle
void setViewAngle(double)
Specify the visible portion of the wheel.
Definition: qwt_wheel.cpp:676
QwtWheel::mass
double mass() const
Definition: qwt_wheel.cpp:1240
QwtWheel::viewAngle
double viewAngle() const
Definition: qwt_wheel.cpp:686
QwtWheel::mousePressEvent
virtual void mousePressEvent(QMouseEvent *) override
Mouse press event handler.
Definition: qwt_wheel.cpp:163
QwtWheel::QwtWheel
QwtWheel(QWidget *parent=NULL)
Constructor.
Definition: qwt_wheel.cpp:92
QwtWheel::wheelBorderWidth
int wheelBorderWidth() const
Definition: qwt_wheel.cpp:563
QwtWheel::wheelReleased
void wheelReleased()
QwtWheel::valueAt
virtual double valueAt(const QPoint &) const
Definition: qwt_wheel.cpp:697
QwtWheel::wheelPressed
void wheelPressed()
QwtWheel::minimum
double minimum() const
Definition: qwt_wheel.cpp:1094
QwtWheel::drawTicks
virtual void drawTicks(QPainter *, const QRectF &)
Definition: qwt_wheel.cpp:817
QwtWheel::setWheelWidth
void setWheelWidth(int)
Set the width of the wheel.
Definition: qwt_wheel.cpp:934
QwtWheel::isTracking
bool isTracking() const
Definition: qwt_wheel.cpp:129
QwtWheel::setOrientation
void setOrientation(Qt::Orientation)
Set the wheel's orientation.
Definition: qwt_wheel.cpp:639
QwtWheel::valueChanged
void valueChanged(double value)
Notify a change of value.
QwtWheel::setPageStepCount
void setPageStepCount(int)
Set the page step count.
Definition: qwt_wheel.cpp:1034
QwtWheel::setTickCount
void setTickCount(int)
Adjust the number of grooves in the wheel's surface.
Definition: qwt_wheel.cpp:519
QwtWheel::keyPressEvent
virtual void keyPressEvent(QKeyEvent *) override
Definition: qwt_wheel.cpp:409
QwtWheel::setTotalAngle
void setTotalAngle(double)
Set the total angle which the wheel can be turned.
Definition: qwt_wheel.cpp:613
QwtWheel::setWrapping
void setWrapping(bool)
En/Disable wrapping.
Definition: qwt_wheel.cpp:1190
QwtWheel::totalAngle
double totalAngle() const
Definition: qwt_wheel.cpp:626
QwtWheel::wrapping
bool wrapping() const
Definition: qwt_wheel.cpp:1199
QwtWheel::singleStep
double singleStep() const
Definition: qwt_wheel.cpp:989
QwtWheel::isInverted
bool isInverted() const
Definition: qwt_wheel.cpp:1176
QwtWheel::stopFlying
void stopFlying()
Stop the flying movement of the wheel.
Definition: qwt_wheel.cpp:1246
QwtWheel::setInverted
void setInverted(bool)
En/Disable inverted appearance.
Definition: qwt_wheel.cpp:1163
QwtWheel::tickCount
int tickCount() const
Definition: qwt_wheel.cpp:534
QwtWheel::setMaximum
void setMaximum(double)
Definition: qwt_wheel.cpp:1105
QwtWheel::wheelWidth
int wheelWidth() const
Definition: qwt_wheel.cpp:944