/*! \brief Determine the value corresponding to a specified position Called by QwtAbstractSlider \param pos point */ double QwtKnob::getValue( const QPoint &pos ) { const double dx = rect().center().x() - pos.x(); const double dy = rect().center().y() - pos.y(); const double arc = qAtan2( -dx, dy ) * 180.0 / M_PI; double newValue = 0.5 * ( minValue() + maxValue() ) + ( arc + d_data->nTurns * 360.0 ) * ( maxValue() - minValue() ) / d_data->totalAngle; const double oneTurn = qFabs( maxValue() - minValue() ) * 360.0 / d_data->totalAngle; const double eqValue = value() + mouseOffset(); if ( qFabs( newValue - eqValue ) > 0.5 * oneTurn ) { if ( newValue < eqValue ) newValue += oneTurn; else newValue -= oneTurn; } return newValue; }
/*! \brief Determine the value corresponding to a specified position Called by QwtAbstractSlider \param p point */ double QwtKnob::getValue(const QPoint &p) { const double dx = double((rect().x() + rect().width() / 2) - p.x() ); const double dy = double((rect().y() + rect().height() / 2) - p.y() ); const double arc = atan2(-dx,dy) * 180.0 / M_PI; double newValue = 0.5 * (minValue() + maxValue()) + (arc + d_data->nTurns * 360.0) * (maxValue() - minValue()) / d_data->totalAngle; const double oneTurn = fabs(maxValue() - minValue()) * 360.0 / d_data->totalAngle; const double eqValue = value() + mouseOffset(); if (fabs(newValue - eqValue) > 0.5 * oneTurn) { if (newValue < eqValue) newValue += oneTurn; else newValue -= oneTurn; } return newValue; }
/*! Find the value for a given position \param pos Position \return Value */ double QwtDial::getValue( const QPoint &pos ) { if ( d_data->maxScaleArc == d_data->minScaleArc || maxValue() == minValue() ) return minValue(); double dir = line2Radians( innerRect().center(), pos ) - d_data->origin; if ( dir < 0.0 ) dir += 360.0; if ( mode() == RotateScale ) dir = 360.0 - dir; // The position might be in the area that is outside the scale arc. // We need the range of the scale if it was a complete circle. const double completeCircle = 360.0 / ( d_data->maxScaleArc - d_data->minScaleArc ) * ( maxValue() - minValue() ); double posValue = minValue() + completeCircle * dir / 360.0; if ( scrollMode() == ScrMouse ) { if ( d_data->previousDir >= 0.0 ) // valid direction { // We have to find out whether the mouse is moving // clock or counter clockwise bool clockWise = false; const double angle = dir - d_data->previousDir; if ( ( angle >= 0.0 && angle <= 180.0 ) || angle < -180.0 ) clockWise = true; if ( clockWise ) { if ( dir < d_data->previousDir && mouseOffset() > 0.0 ) { // We passed 360 -> 0 setMouseOffset( mouseOffset() - completeCircle ); } if ( wrapping() ) { if ( posValue - mouseOffset() > maxValue() ) { // We passed maxValue and the value will be set // to minValue. We have to adjust the mouseOffset. setMouseOffset( posValue - minValue() ); } } else { if ( posValue - mouseOffset() > maxValue() || value() == maxValue() ) { // We fix the value at maxValue by adjusting // the mouse offset. setMouseOffset( posValue - maxValue() ); } } } else { if ( dir > d_data->previousDir && mouseOffset() < 0.0 ) { // We passed 0 -> 360 setMouseOffset( mouseOffset() + completeCircle ); } if ( wrapping() ) { if ( posValue - mouseOffset() < minValue() ) { // We passed minValue and the value will be set // to maxValue. We have to adjust the mouseOffset. setMouseOffset( posValue - maxValue() ); } } else { if ( posValue - mouseOffset() < minValue() || value() == minValue() ) { // We fix the value at minValue by adjusting // the mouse offset. setMouseOffset( posValue - minValue() ); } } } } d_data->previousDir = dir; } return posValue; }