//! Determine the value corresponding to a specified point double QwtWheel::getValue( const QPoint &p ) { const QRectF rect = wheelRect(); // The reference position is arbitrary, but the // sign of the offset is important double w, dx; if ( orientation() == Qt::Vertical ) { w = rect.height(); dx = rect.y() - p.y(); } else { w = rect.width(); dx = p.x() - rect.x(); } if ( w == 0.0 ) return 0.0; // w pixels is an arc of viewAngle degrees, // so we convert change in pixels to change in angle const double ang = dx * d_data->viewAngle / w; // value range maps to totalAngle degrees, // so convert the change in angle to a change in value const double val = ang * ( maxValue() - minValue() ) / d_data->totalAngle; // Note, range clamping and rasterizing to step is automatically // handled by QwtAbstractSlider, so we simply return the change in value return val; }
/*! Determine the value corresponding to a specified point \param pos Position \return Value corresponding to pos */ double QwtWheel::valueAt( const QPoint &pos ) const { const QRectF rect = wheelRect(); double w, dx; if ( d_data->orientation == Qt::Vertical ) { w = rect.height(); dx = rect.top() - pos.y(); } else { w = rect.width(); dx = pos.x() - rect.left(); } if ( w == 0.0 ) return 0.0; if ( d_data->inverted ) { dx = w - dx; } // w pixels is an arc of viewAngle degrees, // so we convert change in pixels to change in angle const double ang = dx * d_data->viewAngle / w; // value range maps to totalAngle degrees, // so convert the change in angle to a change in value const double val = ang * ( maximum() - minimum() ) / d_data->totalAngle; return val; }
/*! \brief Qt Paint Event \param event Paint event */ void QwtWheel::paintEvent( QPaintEvent *event ) { QPainter painter( this ); painter.setClipRegion( event->region() ); QStyleOption opt; opt.init(this); style()->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this); qDrawShadePanel( &painter, contentsRect(), palette(), true, d_data->borderWidth ); drawWheelBackground( &painter, wheelRect() ); drawTicks( &painter, wheelRect() ); if ( hasFocus() ) QwtPainter::drawFocusRect( &painter, this ); }
/*! \brief Determine the scrolling mode and direction corresponding to a specified point \param p point \param scrollMode scrolling mode \param direction direction */ void QwtWheel::getScrollMode( const QPoint &p, QwtAbstractSlider::ScrollMode &scrollMode, int &direction ) const { if ( wheelRect().contains( p ) ) scrollMode = QwtAbstractSlider::ScrMouse; else scrollMode = QwtAbstractSlider::ScrNone; direction = 0; }
/*! \brief Handle wheel events In/Decrement the value \param event Wheel event */ void QwtWheel::wheelEvent( QWheelEvent *event ) { if ( !wheelRect().contains( event->pos() ) ) { event->ignore(); return; } if ( d_data->isScrolling ) return; stopFlying(); double increment = 0.0; if ( ( event->modifiers() & Qt::ControlModifier) || ( event->modifiers() & Qt::ShiftModifier ) ) { // one page regardless of delta increment = d_data->singleStep * d_data->pageStepCount; if ( event->delta() < 0 ) increment = -increment; } else { const int numSteps = event->delta() / 120; increment = d_data->singleStep * numSteps; } if ( d_data->orientation == Qt::Vertical && d_data->inverted ) increment = -increment; double value = boundedValue( d_data->value + increment ); if ( d_data->stepAlignment ) value = alignedValue( value ); if ( value != d_data->value ) { d_data->value = value; update(); Q_EMIT valueChanged( d_data->value ); Q_EMIT wheelMoved( d_data->value ); } }
/*! \brief Mouse press event handler Start movement of the wheel. \param event Mouse event */ void QwtWheel::mousePressEvent( QMouseEvent *event ) { stopFlying(); d_data->isScrolling = wheelRect().contains( event->pos() ); if ( d_data->isScrolling ) { d_data->time.start(); d_data->speed = 0.0; d_data->mouseValue = valueAt( event->pos() ); d_data->mouseOffset = d_data->mouseValue - d_data->value; d_data->pendingValueChanged = false; Q_EMIT wheelPressed(); } }