/*!
   Draws the label for a major scale tick

   \param painter Painter
   \param value Value

   \sa drawTick(), drawBackbone()
*/
void QwtRoundScaleDraw::drawLabel( QPainter *painter, double value ) const
{
    const QwtText label = tickLabel( painter->font(), value );
    if ( label.isEmpty() )
        return;

    const double tval = scaleMap().transform( value );
    if ( ( tval > d_data->startAngle + 359 * 16 )
        || ( tval < d_data->startAngle - 359 * 16 ) )
    {
        return;
    }

    double radius = d_data->radius;
    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
        hasComponent( QwtAbstractScaleDraw::Backbone ) )
    {
        radius += spacing();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
        radius += tickLength( QwtScaleDiv::MajorTick );

    const QSizeF sz = label.textSize( painter->font() );
    const double arc = tval / 16.0 / 360.0 * 2 * M_PI;

    const double x = d_data->center.x() +
        ( radius + sz.width() / 2.0 ) * qSin( arc );
    const double y = d_data->center.y() -
        ( radius + sz.height() / 2.0 ) * cos( arc );

    const QRectF r( x - sz.width() / 2, y - sz.height() / 2,
        sz.width(), sz.height() );
    label.draw( painter, r );
}
/*!
   Calculate the extent of the scale

   The extent is the distance between the baseline to the outermost
   pixel of the scale draw. radius() + extent() is an upper limit
   for the radius of the bounding circle.

   \param font Font used for painting the labels

   \sa setMinimumExtent(), minimumExtent()
   \warning The implemented algo is not too smart and
            calculates only an upper limit, that might be a
            few pixels too large
*/
double QwtRoundScaleDraw::extent( const QFont &font ) const
{
    double d = 0.0;

    if ( hasComponent( QwtAbstractScaleDraw::Labels ) )
    {
        const QwtScaleDiv &sd = scaleDiv();
        const QList<double> &ticks = sd.ticks( QwtScaleDiv::MajorTick );
        for ( int i = 0; i < ticks.count(); i++ )
        {
            const double value = ticks[i];
            if ( !sd.contains( value ) )
                continue;

            const QwtText label = tickLabel( font, value );
            if ( label.isEmpty() )
                continue;

            const double tval = scaleMap().transform( value );
            if ( ( tval < d_data->startAngle + 360 * 16 )
                && ( tval > d_data->startAngle - 360 * 16 ) )
            {
                const double arc = tval / 16.0 / 360.0 * 2 * M_PI;

                const QSizeF sz = label.textSize( font );
                const double off = qMax( sz.width(), sz.height() );

                double x = off * qSin( arc );
                double y = off * qCos( arc );

                const double dist = qSqrt( x * x + y * y );
                if ( dist > d )
                    d = dist;
            }
        }
    }

    if ( hasComponent( QwtAbstractScaleDraw::Ticks ) )
    {
        d += maxTickLength();
    }

    if ( hasComponent( QwtAbstractScaleDraw::Backbone ) )
    {
        const double pw = qMax( 1, penWidth() );  // penwidth can be zero
        d += pw;
    }

    if ( hasComponent( QwtAbstractScaleDraw::Labels ) &&
        ( hasComponent( QwtAbstractScaleDraw::Ticks ) ||
            hasComponent( QwtAbstractScaleDraw::Backbone ) ) )
    {
        d += spacing();
    }

    d = qMax( d, minimumExtent() );

    return d;
}
/*!
  Find the bounding rect for the label. The coordinates of
  the rect are absolute coordinates ( calculated from pos() ).
  in direction of the tick.

  \param font Font used for painting
  \param value Value

  \sa labelRect()
*/
QRect QwtScaleDraw::boundingLabelRect( const QFont &font, double value ) const
{
    QwtText lbl = tickLabel( font, value );
    if ( lbl.isEmpty() )
        return QRect();

    const QPointF pos = labelPosition( value );
    QSizeF labelSize = lbl.textSize( font );

    const QTransform transform = labelTransformation( pos, labelSize );
    return transform.mapRect( QRect( QPoint( 0, 0 ), labelSize.toSize() ) );
}
Example #4
0
/*!
  Find the bounding rect for the label. The coordinates of
  the rect are absolute coordinates ( calculated from pos() ).
  in direction of the tick.

  \param font Font used for painting
  \param value Value

  \sa labelRect()
*/
QRect QwtScaleDraw::boundingLabelRect(const QFont &font, double value) const
{
    QwtText lbl = tickLabel(font, value);
    if ( lbl.isEmpty() )
        return QRect(); 

    const QPoint pos = labelPosition(value);
    QSize labelSize = lbl.textSize(font);
    if ( labelSize.height() % 2 )
        labelSize.setHeight(labelSize.height() + 1);

    const QwtMatrix m = labelMatrix( pos, labelSize);
    return m.mapRect(QRect(QPoint(0, 0), labelSize));
}
/*!
  Find the bounding rect for the label. The coordinates of
  the rect are relative to spacing + ticklength from the backbone
  in direction of the tick.

  \param font Font used for painting
  \param value Value
*/
QRectF QwtScaleDraw::labelRect( const QFont &font, double value ) const
{
    QwtText lbl = tickLabel( font, value );
    if ( lbl.isEmpty() )
        return QRectF( 0.0, 0.0, 0.0, 0.0 );

    const QPointF pos = labelPosition( value );

    const QSizeF labelSize = lbl.textSize( font );
    const QTransform transform = labelTransformation( pos, labelSize );

    QRectF br = transform.mapRect( QRectF( QPointF( 0, 0 ), labelSize ) );
    br.translate( -pos.x(), -pos.y() );

    return br;
}
/*!
   Draws the label for a major scale tick

   \param painter Painter
   \param value Value

   \sa drawTick(), drawBackbone(), boundingLabelRect()
*/
void QwtScaleDraw::drawLabel( QPainter *painter, double value ) const
{
    QwtText lbl = tickLabel( painter->font(), value );
    if ( lbl.isEmpty() )
        return;

    QPointF pos = labelPosition( value );

    QSizeF labelSize = lbl.textSize( painter->font() );

    const QTransform transform = labelTransformation( pos, labelSize );

    painter->save();
    painter->setWorldTransform( transform, true );

    lbl.draw ( painter, QRect( QPoint( 0, 0 ), labelSize.toSize() ) );

    painter->restore();
}
Example #7
0
void ScaleDraw::drawLabel(QPainter *painter, double value) const
{
    if (!d_plot)
        return;
    ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
	/*QwtScaleEngine *qwtsc_engine=d_plot->axisScaleEngine(axis());
    ScaleEngine *sc_engine =dynamic_cast< ScaleEngine*>(qwtsc_engine);
	if(sc_engine!=NULL)
	{*/	
		if (sc_engine->hasBreak()){
			bool invertedScale = sc_engine->testAttribute(QwtScaleEngine::Inverted);
			if (invertedScale && sc_engine->axisBreakRight() == value)
				return;
			if (!invertedScale && sc_engine->axisBreakLeft() == value)
				return;
		}
	//}

		QwtText lbl = tickLabel(painter->font(), value);
		if (lbl.isEmpty())
			return;

		const QPoint pos = labelPosition(value);

		QSize labelSize = lbl.textSize(painter->font());
		if ( labelSize.height() % 2 )
			labelSize.setHeight(labelSize.height() + 1);

		const QMatrix m = labelMatrix(pos, labelSize);

		painter->save();
		painter->setMatrix(m, true);
		if (d_selected)
			lbl.setBackgroundPen(QPen(Qt::blue));
		else
			lbl.setBackgroundPen(QPen(Qt::NoPen));

		lbl.draw(painter, QRect(QPoint(0, 0), labelSize));
		painter->restore();
}
Example #8
0
/*!
  Find the bounding rect for the label. The coordinates of
  the rect are relative to spacing + ticklength from the backbone
  in direction of the tick.

  \param font Font used for painting
  \param value Value
*/
QRect QwtScaleDraw::labelRect(const QFont &font, double value) const
{   
    QwtText lbl = tickLabel(font, value);
    if ( lbl.isEmpty() )
        return QRect(0, 0, 0, 0);

    const QPoint pos = labelPosition(value);

    QSize labelSize = lbl.textSize(font);
    if ( labelSize.height() % 2 )
    {
        labelSize.setHeight(labelSize.height() + 1);
    }

    const QwtMatrix m = labelMatrix(pos, labelSize);

#if 0
    QRect br = QwtMetricsMap::translate(m, QRect(QPoint(0, 0), labelSize));
#else
    QwtPolygon pol(4);
    pol.setPoint(0, 0, 0); 
    pol.setPoint(1, 0, labelSize.height() - 1 );
    pol.setPoint(2, labelSize.width() - 1, 0);
    pol.setPoint(3, labelSize.width() - 1, labelSize.height() - 1 );

    pol = QwtMetricsMap::translate(m, pol);
    QRect br = pol.boundingRect();
#endif

#if QT_VERSION < 0x040000
    br.moveBy(-pos.x(), -pos.y());
#else
    br.translate(-pos.x(), -pos.y());
#endif

    return br;
}
Example #9
0
/*! 
   Draws the label for a major scale tick

   \param painter Painter
   \param value Value

   \sa drawTick(), drawBackbone(), boundingLabelRect()
*/
void QwtScaleDraw::drawLabel(QPainter *painter, double value) const
{
    QwtText lbl = tickLabel(painter->font(), value);
    if ( lbl.isEmpty() )
        return; 

    const QPoint pos = labelPosition(value);

    QSize labelSize = lbl.textSize(painter->font());
    if ( labelSize.height() % 2 )
        labelSize.setHeight(labelSize.height() + 1);
    
    const QwtMatrix m = labelMatrix( pos, labelSize);

    painter->save();
#if QT_VERSION < 0x040000
    painter->setWorldMatrix(m, true);
#else
    painter->setMatrix(m, true);
#endif

    lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );
    painter->restore();
}
void ScaleDraw::drawLabel(QPainter *painter, double value) const
{
	if (!d_plot)
		return;

	ScaleEngine *sc_engine = (ScaleEngine *)d_plot->axisScaleEngine(axis());
	if (sc_engine->hasBreak() && sc_engine->axisBreakLeft() <= value && sc_engine->axisBreakRight() > value)
		return;

	QwtValueList majTicks = scaleDiv().ticks(QwtScaleDiv::MajorTick);
	if (majTicks.contains(value)){
		switch (d_show_ticks_policy){
			case ShowAll:
			break;

			case HideBegin:
				if (majTicks.first() == value)
					return;
			break;
			case HideEnd:
				if (majTicks.last() == value)
					return;
			break;
			case HideBeginEnd:
				if (majTicks.first() == value || majTicks.last() == value)
					return;
			break;
		}
	}

	QwtText lbl = tickLabel(painter->font(), value);
	if ( lbl.isEmpty() )
		return;

	QPoint pos = labelPosition(value);

	QSize labelSize = lbl.textSize(painter->font());
	if ( labelSize.height() % 2 )
		labelSize.setHeight(labelSize.height() + 1);

	const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
	QwtPainter::resetMetricsMap();

	labelSize = metricsMap.layoutToDevice(labelSize);
	pos = metricsMap.layoutToDevice(pos);

	painter->save();
	painter->setMatrix(labelMatrix( pos, labelSize), true);

	if (d_selected)
		lbl.setBackgroundPen(QPen(Qt::blue));
	else
		lbl.setBackgroundPen(QPen(Qt::NoPen));

	lbl.setRenderFlags(labelAlignment());

	lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );

	QwtPainter::setMetricsMap(metricsMap); // restore metrics map

	painter->restore();
}