void AttitudeIndicator::drawScale(QPainter *painter, const QPointF &center,
    double radius, double origin, double minArc, double maxArc) const
{
    // counter clockwise, radian

    const double dir = (360.0 - origin) * M_PI / 180.0;
    const double offset = 4.0;

    const QPointF p0 = qwtPolar2Pos( center, offset, dir + M_PI );

    const double w = innerRect().width();

    QPainterPath path;
    path.moveTo( qwtPolar2Pos( p0, w, dir - M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), 2 * w, dir + M_PI_2 ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir ) );
    path.lineTo( qwtPolar2Pos( path.currentPosition(), w, dir - M_PI_2 ) );

    painter->save();
    painter->setClipPath( path ); // swallow 180 - 360 degrees

    QwtDial::drawScale(painter,
        center, radius, origin, minArc, maxArc);

    painter->restore();
}
Exemplo n.º 2
0
/*!
  Draw lines

  \param painter Painter
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa draw(), drawLines(), setCurveFitter()
*/
void QwtPolarCurve::drawLines( QPainter *painter,
                               const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                               const QwtDoublePoint &pole, int from, int to ) const
{
  int size = to - from + 1;
  if ( size <= 0 )
    return;

  QwtPolygon polyline;
  if ( d_data->curveFitter )
  {
#if QT_VERSION < 0x040000
    QwtArray<QwtDoublePoint> points( size );
#else
    QwtPolygonF points( size );
#endif
    for ( int j = from; j <= to; j++ )
      points[j - from] = QwtDoublePoint( azimuth( j ), radius( j ) );

    points = d_data->curveFitter->fitCurve( points );

    polyline.resize( points.size() );
    for ( int i = 0; i < ( int )points.size(); i++ )
    {
      const QwtPolarPoint point( points[i].x(), points[i].y() );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }
  else
  {
    polyline.resize( size );

    for ( int i = from; i <= to; i++ )
    {
      const QwtPolarPoint point = sample( i );

      double r = radialMap.xTransform( point.radius() );
      const double a = azimuthMap.xTransform( point.azimuth() );
      polyline.setPoint( i - from, qwtPolar2Pos( pole, r, a ).toPoint() );
    }
  }

  QRect clipRect = painter->window();
  clipRect.setRect( clipRect.x() - 1, clipRect.y() - 1,
                    clipRect.width() + 2, clipRect.height() + 2 );

  polyline = QwtClipper::clipPolygon( clipRect, polyline );

  QwtPainter::drawPolyline( painter, polyline );
}
Exemplo n.º 3
0
/*!
  Draw a needle looking like a ray

  \param painter Painter
  \param palette Palette
  \param colorGroup Color group
  \param center center of the needle
  \param length Length of the needle
  \param width Width of the needle
  \param direction Current Direction
  \param hasKnob With/Without knob
*/
void QwtDialSimpleNeedle::drawRayNeedle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, int width, double direction,
    bool hasKnob )
{
    if ( width <= 0 )
        width = 5;

    direction *= M_PI / 180.0;

    painter->save();

    const QPoint p1( center.x() + 1, center.y() + 2 );
    const QPoint p2 = qwtPolar2Pos( p1, length, direction );

    if ( width == 1 )
    {
        const QColor midColor =
            palette.color( colorGroup, QPalette::Mid );

        painter->setPen( QPen( midColor, 1 ) );
        painter->drawLine( p1, p2 );
    }
    else
    {
        QPolygon pa( 4 );
        pa.setPoint( 0, qwtPolar2Pos( p1, width / 2, direction + M_PI_2 ) );
        pa.setPoint( 1, qwtPolar2Pos( p2, width / 2, direction + M_PI_2 ) );
        pa.setPoint( 2, qwtPolar2Pos( p2, width / 2, direction - M_PI_2 ) );
        pa.setPoint( 3, qwtPolar2Pos( p1, width / 2, direction - M_PI_2 ) );

        painter->setPen( Qt::NoPen );
        painter->setBrush( palette.brush( colorGroup, QPalette::Mid ) );
        painter->drawPolygon( pa );
    }
    if ( hasKnob )
    {
        int knobWidth = qMax( qRound( width * 0.7 ), 5 );
        if ( knobWidth % 2 == 0 )
            knobWidth++;

        drawKnob( painter, center, knobWidth,
            palette.brush( colorGroup, QPalette::Base ),
            false );
    }

    painter->restore();
}
Exemplo n.º 4
0
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.

  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPolarCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, int from, int to ) const
{
    painter->setBrush( symbol.brush() );
    painter->setPen( symbol.pen() );

    const int chunkSize = 500;

    for ( int i = from; i <= to; i += chunkSize )
    {
        const int n = qMin( chunkSize, to - i + 1 );

        QPolygonF points;
        for ( int j = 0; j < n; j++ )
        {
            const QwtPointPolar point = sample( i + j );

            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                const double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );

                points += qwtPolar2Pos( pole, r, a );
            }
            else
            {
                points += pole;
            }
        }

        if ( points.size() > 0 )
            symbol.drawSymbols( painter, points );
    }
}
Exemplo n.º 5
0
/*!
  Draw lines from the pole

  \param painter Painter
  \param canvasRect Contents rect of the canvas in painter coordinates
  \param pole Position of the pole in painter coordinates
  \param radius Length of the lines in painter coordinates
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param values Azimuth values, indicating the direction of the lines
*/
void QwtPolarGrid::drawRays(
  QPainter *painter, const QwtDoubleRect &canvasRect,
  const QwtDoublePoint &pole, double radius,
  const QwtScaleMap &azimuthMap, const QwtValueList &values ) const
{
  for ( int i = 0; i < int( values.size() ); i++ )
  {
    double azimuth = azimuthMap.xTransform( values[i] );
    azimuth = ::fmod( azimuth, 2 * M_PI );

    bool skipLine = false;
    if ( testDisplayFlag( SmartScaleDraw ) )
    {
      const QwtAbstractScaleDraw::ScaleComponent bone =
        QwtAbstractScaleDraw::Backbone;
      if ( isClose( azimuth, 0.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisRight];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI / 2 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisTop];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, M_PI ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisLeft];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
      else if ( isClose( azimuth, 3 * M_PI / 2.0 ) )
      {
        const AxisData &axis = d_data->axisData[QwtPolar::AxisBottom];
        if ( axis.isVisible && axis.scaleDraw->hasComponent( bone ) )
          skipLine = true;
      }
    }
    if ( !skipLine )
    {
      const QwtDoublePoint pos = qwtPolar2Pos( pole, radius, azimuth );

      /*
          Qt4 is horrible slow, when painting primitives,
          with coordinates far outside the visible area.
       */

      QwtPolygon pa( 2 );
      pa.setPoint( 0, pole.toPoint() );
      pa.setPoint( 1, pos.toPoint() );

      if ( testDisplayFlag( ClipGridLines ) )
        pa = QwtClipper::clipPolygon( canvasRect.toRect(), pa );

      QwtPainter::drawPolyline( painter, pa );
    }
  }
}
Exemplo n.º 6
0
/*!
  Draw a needle looking like a ray
*/
void QwtDialSimpleNeedle::drawRayNeedle(
    QPainter *painter, const QColorGroup &cg,
    const QPoint &center, int length, int width, double direction, 
    bool hasKnob)
{
    if ( width <= 0 )
        width = 5;

    direction *= M_PI / 180.0;

    painter->save();

    const QPoint p1(center.x() + 1, center.y() + 2);
    const QPoint p2 = qwtPolar2Pos(p1, length, direction);

    if ( width == 1 )
    {
        painter->setPen(QPen(cg.mid(), 1));
        painter->drawLine(p1, p2);
    }
    else
    {
        QPointArray pa(4);
        pa.setPoint(0, qwtPolar2Pos(p1, width / 2, direction + M_PI_2));
        pa.setPoint(1, qwtPolar2Pos(p2, width / 2, direction + M_PI_2));
        pa.setPoint(2, qwtPolar2Pos(p2, width / 2, direction - M_PI_2));
        pa.setPoint(3, qwtPolar2Pos(p1, width / 2, direction - M_PI_2));

        painter->setPen(Qt::NoPen);
        painter->setBrush(cg.brush(QColorGroup::Mid));
        painter->drawPolygon(pa);
    }
    if ( hasKnob )
    {
        int knobWidth = QMAX(qRound(width * 0.7), 5);
        if ( knobWidth % 2 == 0 )
            knobWidth++;

        drawKnob(painter, center, knobWidth, 
            cg.brush(QColorGroup::Base), FALSE);
    }

    painter->restore();
}
Exemplo n.º 7
0
/*!
  Draw a needle looking like an arrow

  \param painter Painter
  \param palette Palette
  \param colorGroup Color group
  \param center center of the needle
  \param length Length of the needle
  \param width Width of the needle
  \param direction Current Direction
  \param hasKnob With/Without knob
*/
void QwtDialSimpleNeedle::drawArrowNeedle( QPainter *painter,
    const QPalette &palette, QPalette::ColorGroup colorGroup,
    const QPoint &center, int length, int width,
    double direction, bool hasKnob )
{
    direction *= M_PI / 180.0;

    painter->save();

    if ( width <= 0 )
    {
        width = ( int )qMax( length * 0.06, 9.0 );
        if ( width % 2 == 0 )
            width++;
    }

    const int peak = 3;
    const QPoint p1( center.x() + 1, center.y() + 1 );
    const QPoint p2 = qwtPolar2Pos( p1, length - peak, direction );
    const QPoint p3 = qwtPolar2Pos( p1, length, direction );

    QPolygon pa( 5 );
    pa.setPoint( 0, qwtPolar2Pos( p1, width / 2, direction - M_PI_2 ) );
    pa.setPoint( 1, qwtPolar2Pos( p2, 1, direction - M_PI_2 ) );
    pa.setPoint( 2, p3 );
    pa.setPoint( 3, qwtPolar2Pos( p2, 1, direction + M_PI_2 ) );
    pa.setPoint( 4, qwtPolar2Pos( p1, width / 2, direction + M_PI_2 ) );

    painter->setPen( Qt::NoPen );
    painter->setBrush( palette.brush( colorGroup, QPalette::Mid ) );
    painter->drawPolygon( pa );

    QPolygon shadowPa( 3 );

    const int colorOffset = 10;

    int i;
    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint( i, pa[i] );

    const QColor midColor = palette.color( colorGroup, QPalette::Mid );

    painter->setPen( midColor.dark( 100 + colorOffset ) );
    painter->drawPolyline( shadowPa );

    for ( i = 0; i < 3; i++ )
        shadowPa.setPoint( i, pa[i + 2] );

    painter->setPen( midColor.dark( 100 - colorOffset ) );
    painter->drawPolyline( shadowPa );

    if ( hasKnob )
    {
        drawKnob( painter, center, qRound( width * 1.3 ),
            palette.brush( colorGroup, QPalette::Base ),
            false );
    }

    painter->restore();
}
Exemplo n.º 8
0
/*!
  Draw symbols

  \param painter Painter
  \param symbol Curve symbol
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa setSymbol(), draw(), drawCurve()
*/
void QwtPolarCurve::drawSymbols( QPainter *painter, const QwtSymbol &symbol,
                                 const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
                                 const QwtDoublePoint &pole, int from, int to ) const
{
  painter->setBrush( symbol.brush() );
  painter->setPen( symbol.pen() );

  QRect rect;
  rect.setSize( QwtPainter::metricsMap().screenToLayout( symbol.size() ) );

  for ( int i = from; i <= to; i++ )
  {
    const QwtPolarPoint point = sample( i );
    const double r = radialMap.xTransform( point.radius() );
    const double a = azimuthMap.xTransform( point.azimuth() );

    const QPoint pos = qwtPolar2Pos( pole, r, a ).toPoint();

    rect.moveCenter( pos );
    symbol.draw( painter, rect );
  }
}
Exemplo n.º 9
0
QwtArray<QwtDoubleInterval> QwtCircleClipper::clipCircle(
    const QwtDoublePoint &pos, double radius) const
{
    QList<QwtDoublePoint> points;
    for ( int edge = 0; edge < NEdges; edge++ )
        points += cuttingPoints((Edge)edge, pos, radius);

    QwtArray<QwtDoubleInterval> intv;
    if ( points.size() <= 0 )
    {
        QwtDoubleRect cRect(0, 0, 2 * radius, 2* radius);
        cRect.moveCenter(pos);
        if ( contains(cRect) )
            intv += QwtDoubleInterval(0.0, 2 * M_PI);
    }
    else
    {
        QList<double> angles;
        for ( int i = 0; i < points.size(); i++ )
            angles += toAngle(pos, points[i]);
        qSort(angles);

        const int in = contains(qwtPolar2Pos(pos, radius, 
            angles[0] + (angles[1] - angles[0]) / 2));
        if ( in )
        {
            for ( int i = 0; i < angles.size() - 1; i += 2)
                intv += QwtDoubleInterval(angles[i], angles[i+1]);
        }
        else
        {
            for ( int i = 1; i < angles.size() - 1; i += 2)
                intv += QwtDoubleInterval(angles[i], angles[i+1]);
            intv += QwtDoubleInterval(angles.last(), angles.first());
        }
    }

    return intv;
}
Exemplo n.º 10
0
/*!
  Draw lines

  \param painter Painter
  \param azimuthMap Maps azimuth values to values related to 0.0, M_2PI
  \param radialMap Maps radius values into painter coordinates.
  \param pole Position of the pole in painter coordinates
  \param from index of the first point to be painted
  \param to index of the last point to be painted.
  \sa draw(), drawLines(), setCurveFitter()
*/
void QwtPolarCurve::drawLines( QPainter *painter,
    const QwtScaleMap &azimuthMap, const QwtScaleMap &radialMap,
    const QPointF &pole, int from, int to ) const
{
    int size = to - from + 1;
    if ( size <= 0 )
        return;

    QPolygonF polyline;
    if ( d_data->curveFitter )
    {
        QPolygonF points( size );
        for ( int j = from; j <= to; j++ )
        {
            const QwtPointPolar point = sample( j );
            points[j - from] = QPointF( point.azimuth(), point.radius() );
        }

        points = d_data->curveFitter->fitCurve( points );

        polyline.resize( points.size() );

        QPointF *polylineData = polyline.data();
        QPointF *pointsData = points.data();

        for ( int i = 0; i < points.size(); i++ )
        {
            const QwtPointPolar point( pointsData[i].x(), pointsData[i].y() );

            double r = radialMap.transform( point.radius() );
            const double a = azimuthMap.transform( point.azimuth() );

            polylineData[i] = qwtPolar2Pos( pole, r, a );
        }
    }
    else
    {
        polyline.resize( size );
        QPointF *polylineData = polyline.data();

        for ( int i = from; i <= to; i++ )
        {
            QwtPointPolar point = sample( i );
            if ( !qwtInsidePole( radialMap, point.radius() ) )
            {
                double r = radialMap.transform( point.radius() );
                const double a = azimuthMap.transform( point.azimuth() );
                polylineData[i - from] = qwtPolar2Pos( pole, r, a );
            }
            else
            {
                polylineData[i - from] = pole;
            }
        }
    }

    QRectF clipRect;
    if ( painter->hasClipping() )
        clipRect = painter->clipRegion().boundingRect();
    else
    {
        clipRect = painter->window();
        if ( !clipRect.isEmpty() )
            clipRect = painter->transform().inverted().mapRect( clipRect );
    }

    if ( !clipRect.isEmpty() )
    {
        double off = qCeil( qMax( 1.0, painter->pen().widthF() ) );
        clipRect = clipRect.toRect().adjusted( -off, -off, off, off );
        polyline = QwtClipper::clipPolygonF( clipRect, polyline );
    }

    QwtPainter::drawPolyline( painter, polyline );
    painter->drawPolyline( polyline );
}
Exemplo n.º 11
0
/*!
   Draw the rose

   \param painter Painter
   \param palette Palette
   \param center Center of the rose
   \param radius Radius of the rose
   \param north Position pointing to north
   \param width Width of the rose
   \param numThorns Number of thorns
   \param numThornLevels Number of thorn levels
   \param shrinkFactor Factor to shrink the thorns with each level
*/
void QwtSimpleCompassRose::drawRose(
    QPainter *painter, 
#if QT_VERSION < 0x040000
    const QColorGroup &cg,
#else
    const QPalette &palette,
#endif
    const QPoint &center, int radius, double north, double width,
    int numThorns, int numThornLevels, double shrinkFactor)
{
    if ( numThorns < 4 )
        numThorns = 4;

    if ( numThorns % 4 )
        numThorns += 4 - numThorns % 4;

    if ( numThornLevels <= 0 )
        numThornLevels = numThorns / 4;

    if ( shrinkFactor >= 1.0 )
        shrinkFactor = 1.0;

    if ( shrinkFactor <= 0.5 )
        shrinkFactor = 0.5;

    painter->save();

    painter->setPen(Qt::NoPen);

    for ( int j = 1; j <= numThornLevels; j++ )
    {
        double step =  pow(2.0, j) * M_PI / (double)numThorns;
        if ( step > M_PI_2 )
            break;

        double r = radius;
        for ( int k = 0; k < 3; k++ )
        {
            if ( j + k < numThornLevels )
                r *= shrinkFactor;
        }

        double leafWidth = r * width;
        if ( 2.0 * M_PI / step > 32 )
            leafWidth = 16;

        const double origin = north / 180.0 * M_PI;
        for ( double angle = origin; 
            angle < 2.0 * M_PI + origin; angle += step)
        {
            const QPoint p = qwtPolar2Pos(center, r, angle);
            QPoint p1 = qwtPolar2Pos(center, leafWidth, angle + M_PI_2);
            QPoint p2 = qwtPolar2Pos(center, leafWidth, angle - M_PI_2);

            QwtPolygon pa(3);
            pa.setPoint(0, center);
            pa.setPoint(1, p);

            QPoint p3 = qwtPolar2Pos(center, r, angle + step / 2.0);
            p1 = cutPoint(center, p3, p1, p);
            pa.setPoint(2, p1);
#if QT_VERSION < 0x040000
            painter->setBrush(cg.brush(QColorGroup::Dark));
#else
            painter->setBrush(palette.brush(QPalette::Dark));
#endif
            painter->drawPolygon(pa);

            QPoint p4 = qwtPolar2Pos(center, r, angle - step / 2.0);
            p2 = cutPoint(center, p4, p2, p);

            pa.setPoint(2, p2);
#if QT_VERSION < 0x040000
            painter->setBrush(cg.brush(QColorGroup::Light));
#else
            painter->setBrush(palette.brush(QPalette::Light));
#endif
            painter->drawPolygon(pa);
        }
    }
    painter->restore();
}
Exemplo n.º 12
0
/*!
   Draw the rose

   \param painter Painter
   \param palette Palette
   \param center Center of the rose
   \param radius Radius of the rose
   \param north Position pointing to north
   \param width Width of the rose
   \param numThorns Number of thorns
   \param numThornLevels Number of thorn levels
   \param shrinkFactor Factor to shrink the thorns with each level
*/
void QwtSimpleCompassRose::drawRose(
    QPainter *painter,
    const QPalette &palette,
    const QPointF &center, double radius, double north, double width,
    int numThorns, int numThornLevels, double shrinkFactor )
{
    if ( numThorns < 4 )
        numThorns = 4;

    if ( numThorns % 4 )
        numThorns += 4 - numThorns % 4;

    if ( numThornLevels <= 0 )
        numThornLevels = numThorns / 4;

    if ( shrinkFactor >= 1.0 )
        shrinkFactor = 1.0;

    if ( shrinkFactor <= 0.5 )
        shrinkFactor = 0.5;

    painter->save();

    painter->setPen( Qt::NoPen );

    for ( int j = 1; j <= numThornLevels; j++ )
    {
        double step =  qPow( 2.0, j ) * M_PI / numThorns;
        if ( step > M_PI_2 )
            break;

        double r = radius;
        for ( int k = 0; k < 3; k++ )
        {
            if ( j + k < numThornLevels )
                r *= shrinkFactor;
        }

        double leafWidth = r * width;
        if ( 2.0 * M_PI / step > 32 )
            leafWidth = 16;

        const double origin = north / 180.0 * M_PI;
        for ( double angle = origin;
            angle < 2.0 * M_PI + origin; angle += step )
        {
            const QPointF p = qwtPolar2Pos( center, r, angle );
            const QPointF p1 = qwtPolar2Pos( center, leafWidth, angle + M_PI_2 );
            const QPointF p2 = qwtPolar2Pos( center, leafWidth, angle - M_PI_2 );
            const QPointF p3 = qwtPolar2Pos( center, r, angle + step / 2.0 );
            const QPointF p4 = qwtPolar2Pos( center, r, angle - step / 2.0 );

            QPainterPath darkPath;
            darkPath.moveTo( center );
            darkPath.lineTo( p );
            darkPath.lineTo( qwtIntersection( center, p3, p1, p ) );

            painter->setBrush( palette.brush( QPalette::Dark ) );
            painter->drawPath( darkPath );

            QPainterPath lightPath;
            lightPath.moveTo( center );
            lightPath.lineTo( p );
            lightPath.lineTo( qwtIntersection( center, p4, p2, p ) );

            painter->setBrush( palette.brush( QPalette::Light ) );
            painter->drawPath( lightPath );
        }
    }
    painter->restore();
}