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


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10