double QwtAbstractSlider::boundedValue( double value ) const { const double vmin = minimum(); const double vmax = maximum(); if ( d_data->wrapping && vmin != vmax ) { const int fullCircle = 360 * 16; const double pd = scaleMap().pDist(); if ( int( pd / fullCircle ) * fullCircle == pd ) { // full circle scales: min and max are the same const double range = vmax - vmin; if ( value < vmin ) { value += ::ceil( ( vmin - value ) / range ) * range; } else if ( value > vmax ) { value -= ::ceil( ( value - vmax ) / range ) * range; } } else { if ( value < vmin ) value = vmax; else if ( value > vmax ) value = vmin; } } else { value = qBound( vmin, value, vmax ); } return value; }
/*! \brief Determine the value for a new position of the mouse \param pos Mouse position \return Value for the mouse position \sa isScrollPosition() */ double QwtKnob::scrolledTo( const QPoint &pos ) const { double angle = QLineF( rect().center(), pos ).angle(); angle = qwtNormalizeDegrees( angle - d_data->mouseOffset ); if ( scaleMap().pDist() > 360.0 ) { angle = qwtToDegrees( angle ); const double v = scaleMap().transform( value() ); int numTurns = qFloor( ( v - scaleMap().p1() ) / 360.0 ); double valueAngle = qwtNormalizeDegrees( v ); if ( qAbs( valueAngle - angle ) > 180.0 ) { numTurns += ( angle > valueAngle ) ? -1 : 1; } angle += scaleMap().p1() + numTurns * 360.0; if ( !wrapping() ) { const double boundedAngle = qBound( scaleMap().p1(), angle, scaleMap().p2() ); d_data->mouseOffset += ( boundedAngle - angle ); angle = boundedAngle; } } else { angle = qwtToScaleAngle( angle ); double boundedAngle = qBound( scaleMap().p1(), angle, scaleMap().p2() ); if ( !wrapping() ) { const double currentAngle = scaleMap().transform( value() ); if ( ( currentAngle > 90.0 ) && ( boundedAngle < -90.0 ) ) boundedAngle = scaleMap().p2(); else if ( ( currentAngle < -90.0 ) && ( boundedAngle > 90.0 ) ) boundedAngle = scaleMap().p1(); d_data->mouseOffset += ( boundedAngle - angle ); } angle = boundedAngle; } return scaleMap().invTransform( angle ); }
/*! Build a scale map The azimuth map translates between the scale values and angles from [0.0, 2 * PI[. The radial map translates scale values into the distance from the pole. The radial map is calculated from the current geometry of the canvas. \param scaleId Scale index \return Map for the scale on the canvas. With this map pixel coordinates can translated to plot coordinates and vice versa. \sa QwtScaleMap, transform(), invTransform() */ QwtScaleMap QwtPolarPlot::scaleMap( int scaleId ) const { const QwtDoubleRect pr = plotRect(); return scaleMap( scaleId, pr.width() / 2.0 ); }
/*! Calculate the bounding interval of the radial scale that is visible on the canvas. */ QwtDoubleInterval QwtPolarPlot::visibleInterval() const { const QwtScaleDiv *sd = scaleDiv( QwtPolar::Radius ); const QwtDoubleRect cRect = canvas()->contentsRect(); const QwtDoubleRect pRect = plotRect( cRect.toRect() ); if ( cRect.contains( pRect.toRect() ) || !cRect.intersects( pRect ) ) { #if QWT_VERSION < 0x050200 return QwtDoubleInterval( sd->lBound(), sd->hBound() ); #else return QwtDoubleInterval( sd->lowerBound(), sd->upperBound() ); #endif } const QwtDoublePoint pole = pRect.center(); const QwtDoubleRect scaleRect = pRect & cRect; const QwtScaleMap map = scaleMap( QwtPolar::Radius ); double dmin = 0.0; double dmax = 0.0; if ( scaleRect.contains( pole ) ) { dmin = 0.0; QwtDoublePoint corners[4]; corners[0] = scaleRect.bottomRight(); corners[1] = scaleRect.topRight(); corners[2] = scaleRect.topLeft(); corners[3] = scaleRect.bottomLeft(); dmax = 0.0; for ( int i = 0; i < 4; i++ ) { const double dist = qwtDistance( pole, corners[i] ); if ( dist > dmax ) dmax = dist; } } else { if ( pole.x() < scaleRect.left() ) { if ( pole.y() < scaleRect.top() ) { dmin = qwtDistance( pole, scaleRect.topLeft() ); dmax = qwtDistance( pole, scaleRect.bottomRight() ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = qwtDistance( pole, scaleRect.bottomLeft() ); dmax = qwtDistance( pole, scaleRect.topRight() ); } else { dmin = scaleRect.left() - pole.x(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomRight() ), qwtDistance( pole, scaleRect.topRight() ) ); } } else if ( pole.x() > scaleRect.right() ) { if ( pole.y() < scaleRect.top() ) { dmin = qwtDistance( pole, scaleRect.topRight() ); dmax = qwtDistance( pole, scaleRect.bottomLeft() ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = qwtDistance( pole, scaleRect.bottomRight() ); dmax = qwtDistance( pole, scaleRect.topLeft() ); } else { dmin = pole.x() - scaleRect.right(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ), qwtDistance( pole, scaleRect.topLeft() ) ); } } else if ( pole.y() < scaleRect.top() ) { dmin = scaleRect.top() - pole.y(); dmax = qwtMax( qwtDistance( pole, scaleRect.bottomLeft() ), qwtDistance( pole, scaleRect.bottomRight() ) ); } else if ( pole.y() > scaleRect.bottom() ) { dmin = pole.y() - scaleRect.bottom(); dmax = qwtMax( qwtDistance( pole, scaleRect.topLeft() ), qwtDistance( pole, scaleRect.topRight() ) ); } } const double radius = pRect.width() / 2.0; if ( dmax > radius ) dmax = radius; QwtDoubleInterval interval; interval.setMinValue( map.invTransform( dmin ) ); interval.setMaxValue( map.invTransform( dmax ) ); return interval; }
void CBackgroundManager::addMapScale(float scaleDelta, Point centerTilePos) { scaleMap(getMapScale() + scaleDelta, centerTilePos); }
/*! Draw a tick \param painter Painter \param value Value of the tick \param len Length of the tick \sa drawBackbone(), drawLabel() */ void QwtScaleDraw::drawTick( QPainter *painter, double value, double len ) const { if ( len <= 0 ) return; const bool roundingAlignment = QwtPainter::roundingAlignment( painter ); QPointF pos = d_data->pos; double tval = scaleMap().transform( value ); if ( roundingAlignment ) tval = qRound( tval ); const int pw = penWidth(); int a = 0; if ( pw > 1 && roundingAlignment ) a = 1; switch ( alignment() ) { case LeftScale: { double x1 = pos.x() + a; double x2 = pos.x() + a - pw - len; if ( roundingAlignment ) { x1 = qRound( x1 ); x2 = qRound( x2 ); } QwtPainter::drawLine( painter, x1, tval, x2, tval ); break; } case RightScale: { double x1 = pos.x(); double x2 = pos.x() + pw + len; if ( roundingAlignment ) { x1 = qRound( x1 ); x2 = qRound( x2 ); } QwtPainter::drawLine( painter, x1, tval, x2, tval ); break; } case BottomScale: { double y1 = pos.y(); double y2 = pos.y() + pw + len; if ( roundingAlignment ) { y1 = qRound( y1 ); y2 = qRound( y2 ); } QwtPainter::drawLine( painter, tval, y1, tval, y2 ); break; } case TopScale: { double y1 = pos.y() + a; double y2 = pos.y() - pw - len + a; if ( roundingAlignment ) { y1 = qRound( y1 ); y2 = qRound( y2 ); } QwtPainter::drawLine( painter, tval, y1, tval, y2 ); break; } } }
/*! \brief Determine the minimum border distance This member function returns the minimum space needed to draw the mark labels at the scale's endpoints. \param font Font \param start Start border distance \param end End border distance */ void QwtScaleDraw::getBorderDistHint( const QFont &font, int &start, int &end ) const { start = 0; end = 1.0; if ( !hasComponent( QwtAbstractScaleDraw::Labels ) ) return; const QList<double> &ticks = scaleDiv().ticks( QwtScaleDiv::MajorTick ); if ( ticks.count() == 0 ) return; // Find the ticks, that are mapped to the borders. // minTick is the tick, that is mapped to the top/left-most position // in widget coordinates. double minTick = ticks[0]; double minPos = scaleMap().transform( minTick ); double maxTick = minTick; double maxPos = minPos; for ( int i = 1; i < ticks.count(); i++ ) { const double tickPos = scaleMap().transform( ticks[i] ); if ( tickPos < minPos ) { minTick = ticks[i]; minPos = tickPos; } if ( tickPos > scaleMap().transform( maxTick ) ) { maxTick = ticks[i]; maxPos = tickPos; } } double e = 0.0; double s = 0.0; if ( orientation() == Qt::Vertical ) { s = -labelRect( font, minTick ).top(); s -= qAbs( minPos - qRound( scaleMap().p2() ) ); e = labelRect( font, maxTick ).bottom(); e -= qAbs( maxPos - scaleMap().p1() ); } else { s = -labelRect( font, minTick ).left(); s -= qAbs( minPos - scaleMap().p1() ); e = labelRect( font, maxTick ).right(); e -= qAbs( maxPos - scaleMap().p2() ); } if ( s < 0.0 ) s = 0.0; if ( e < 0.0 ) e = 0.0; start = qCeil( s ); end = qCeil( e ); }