16 #include <qdrawutil.h> 19 #include <qstyleoption.h> 20 #include <qelapsedtimer.h> 98 setFocusPolicy( Qt::StrongFocus );
99 setSizePolicy( QSizePolicy::Preferred, QSizePolicy::Fixed );
100 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
194 double mouseValue =
valueAt( event->pos() );
203 ms = qMax( ms, 5.0 );
247 bool startFlying =
false;
252 if ( ( std::fabs(
d_data->
speed ) > 0.0 ) && ( ms < 50 ) )
288 QWidget::timerEvent( event );
327 #if QT_VERSION < 0x050e00 328 const QPoint wheelPos =
event->pos();
329 const int wheelDelta =
event->delta();
331 const QPoint wheelPos =
event->position().toPoint();
333 const QPoint delta =
event->angleDelta();
334 const int wheelDelta = ( qAbs( delta.x() ) > qAbs( delta.y() ) )
335 ? delta.x() : delta.y();
349 double increment = 0.0;
351 if ( ( event->modifiers() & Qt::ControlModifier) ||
352 ( event->modifiers() & Qt::ShiftModifier ) )
356 if ( wheelDelta < 0 )
357 increment = -increment;
361 const int numSteps = wheelDelta / 120;
366 increment = -increment;
419 double increment = 0.0;
421 switch ( event->key() )
468 case Qt::Key_PageDown:
489 if ( event->isAccepted() )
492 if ( increment != 0.0 )
522 count = qBound( 6, count, 50 );
554 const int d = qMin( width(), height() ) / 3;
555 borderWidth = qMin( borderWidth, d );
598 return contentsRect().adjusted( bw, bw, -bw, -bw );
645 if ( !testAttribute( Qt::WA_WState_OwnSizePolicy ) )
647 QSizePolicy sp = sizePolicy();
651 setAttribute( Qt::WA_WState_OwnSizePolicy,
false );
706 dx = rect.top() - pos.y();
711 dx = pos.x() - rect.left();
739 QPainter painter(
this );
740 painter.setClipRegion( event->region() );
744 style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter,
this);
746 qDrawShadePanel( &painter,
763 QPainter *painter,
const QRectF &rect )
767 QPalette pal = palette();
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 ) );
777 painter->fillRect( rect, gradient );
781 const QPen lightPen( palette().color( QPalette::Light ),
783 const QPen darkPen( pal.color( QPalette::Dark ),
790 painter->setPen( lightPen );
791 painter->drawLine( QPointF( rect.left(), rect.top() + bw2 ),
792 QPointF( rect.right(), rect.top() + bw2 ) );
794 painter->setPen( darkPen );
795 painter->drawLine( QPointF( rect.left(), rect.bottom() - bw2 ),
796 QPointF( rect.right(), rect.bottom() - bw2 ) );
800 painter->setPen( lightPen );
801 painter->drawLine( QPointF( rect.left() + bw2, rect.top() ),
802 QPointF( rect.left() + bw2, rect.bottom() ) );
804 painter->setPen( darkPen );
805 painter->drawLine( QPointF( rect.right() - bw2, rect.top() ),
806 QPointF( rect.right() - bw2, rect.bottom() ) );
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 );
834 const double loValue =
value() - halfIntv;
835 const double hiValue =
value() + halfIntv;
836 const double tickWidth = 360.0 / double(
d_data->
tickCount ) / cnvFactor;
841 const double radius = rect.width() * 0.5;
853 const double maxpos = rect.right() - 2;
854 const double minpos = rect.left() + 2;
857 for (
double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
858 tickValue < hiValue; tickValue += tickWidth )
861 const double s = qFastSin( angle * cnvFactor );
863 const double off = radius * ( sinArc + s ) / sinArc;
867 tickPos = rect.left() + off;
869 tickPos = rect.right() - off;
871 if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
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 ) );
884 const double radius = rect.height() * 0.5;
895 const double maxpos = rect.bottom() - 2;
896 const double minpos = rect.top() + 2;
898 for (
double tickValue = std::ceil( loValue / tickWidth ) * tickWidth;
899 tickValue < hiValue; tickValue += tickWidth )
902 const double s = qFastSin( angle * cnvFactor );
904 const double off = radius * ( sinArc + s ) / sinArc;
909 tickPos = rect.bottom() - off;
911 tickPos = rect.top() + off;
913 if ( ( tickPos <= maxpos ) && ( tickPos > minpos ) )
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 ) );
1263 if ( value < d_data->
minimum )
1265 value += std::ceil( (
d_data->
minimum - value ) / range ) * range;
1269 value -= std::ceil( ( value -
d_data->
maximum ) / range ) * range;
1284 if ( stepSize > 0.0 )
1287 qRound( ( value -
d_data->
minimum ) / stepSize ) * stepSize;
1289 if ( stepSize > 1e-12 )
1291 if ( qFuzzyCompare( value + 1.0, 1.0 ) )
1308 #include "moc_qwt_wheel.cpp" void setOrientation(Qt::Orientation)
Set the wheel's orientation.
virtual void paintEvent(QPaintEvent *) QWT_OVERRIDE
Qt Paint Event.
virtual void mouseReleaseEvent(QMouseEvent *) QWT_OVERRIDE
Mouse Release Event handler.
virtual QSize minimumSizeHint() const QWT_OVERRIDE
static void drawFocusRect(QPainter *, const QWidget *)
Draw a focus rectangle on a widget using its style.
double totalAngle() const
QSize qwtExpandedToGlobalStrut(const QSize &size)
void setUpdateInterval(int)
Specify the update interval when the wheel is flying.
QWT_CONSTEXPR float qwtMaxF(float a, float b)
virtual void mouseMoveEvent(QMouseEvent *) QWT_OVERRIDE
Mouse Move Event handler.
void setWheelBorderWidth(int)
Set the wheel border width of the wheel.
void setStepAlignment(bool on)
En/Disable step alignment.
virtual void timerEvent(QTimerEvent *) QWT_OVERRIDE
Qt timer event.
double singleStep() const
void setTracking(bool)
En/Disable tracking.
void setTotalAngle(double)
Set the total angle which the wheel can be turned.
QWT_CONSTEXPR float qwtMinF(float a, float b)
int pageStepCount() const
virtual double valueAt(const QPoint &) const
virtual void wheelEvent(QWheelEvent *) QWT_OVERRIDE
Handle wheel events.
double alignedValue(double) const
double boundedValue(double) const
void setWrapping(bool)
En/Disable wrapping.
void setRange(double min, double max)
Set the minimum and maximum values.
double qwtRadians(double degrees)
Translate degrees into radians.
void setWheelWidth(int)
Set the width of the wheel.
bool stepAlignment() const
void setBorderWidth(int)
Set the border width.
Qt::Orientation orientation() const
int updateInterval() const
Qt::Orientation orientation
void setTickCount(int)
Adjust the number of grooves in the wheel's surface.
virtual void mousePressEvent(QMouseEvent *) QWT_OVERRIDE
Mouse press event handler.
virtual void drawWheelBackground(QPainter *, const QRectF &)
virtual void drawTicks(QPainter *, const QRectF &)
int wheelBorderWidth() const
void setValue(double)
Set a new value without adjusting to the step raster.
virtual ~QwtWheel()
Destructor.
void valueChanged(double value)
Notify a change of value.
virtual void keyPressEvent(QKeyEvent *) QWT_OVERRIDE
void setPageStepCount(int)
Set the page step count.
QwtWheel(QWidget *parent=NULL)
Constructor.
void setSingleStep(double)
Set the step size of the counter.
void setMass(double)
Set the slider's mass for flywheel effect.
void wheelMoved(double value)
virtual QSize sizeHint() const QWT_OVERRIDE
void setViewAngle(double)
Specify the visible portion of the wheel.
void stopFlying()
Stop the flying movement of the wheel.
void setInverted(bool)
En/Disable inverted appearance.