/*!
  Minimum size hint needed to display an entry

  \param data Attributes of the legend entry
  \return Minimum size
 */
QSize QwtPlotLegendItem::minimumSize( const QwtLegendData &data ) const
{
    QSize size( 2 * d_data->itemMargin, 2 * d_data->itemMargin );

    if ( !data.isValid() )
        return size;

    const QwtGraphic graphic = data.icon();
    const QwtText text = data.title();

    int w = 0;
    int h = 0;

    if ( !graphic.isNull() )
    {
        w = graphic.width();
        h = graphic.height();
    }

    if ( !text.isEmpty() )
    {
        const QSizeF sz = text.textSize( font() );

        w += qCeil( sz.width() );
        h = qMax( h, qCeil( sz.height() ) );
    }

    if ( graphic.width() > 0 && !text.isEmpty() )
        w += d_data->itemSpacing;

    size += QSize( w, h );
    return size;
}
Example #2
0
void QwtPicker::drawTracker(QPainter *painter) const
{
    const QRect textRect = trackerRect(painter->font());
    if ( !textRect.isEmpty() )
    {
        QwtText label = trackerText(d_data->trackerPosition);
        if ( !label.isEmpty() )
        {
            painter->save();

#if defined(Q_WS_MAC)
            // Antialiased fonts are broken on the Mac.
#if QT_VERSION >= 0x040000 
            painter->setRenderHint(QPainter::TextAntialiasing, false);
#else
            QFont fnt = label.usedFont(painter->font());
            fnt.setStyleStrategy(QFont::NoAntialias);
            label.setFont(fnt);
#endif
#endif
            label.draw(painter, textRect);

            painter->restore();
        }
    }
}
/*!
   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;
}
Example #5
0
/*!
   Calculate the bounding rectangle for the tracker text
   from the current position of the tracker

   \param font Font of the tracker text
   \return Bounding rectangle of the tracker text

   \sa trackerPosition()
*/
QRect QwtPicker::trackerRect( const QFont &font ) const
{
    if ( trackerMode() == AlwaysOff ||
        ( trackerMode() == ActiveOnly && !isActive() ) )
    {
        return QRect();
    }

    if ( d_data->trackerPosition.x() < 0 || d_data->trackerPosition.y() < 0 )
        return QRect();

    QwtText text = trackerText( d_data->trackerPosition );
    if ( text.isEmpty() )
        return QRect();

    const QSizeF textSize = text.textSize( font );
    QRect textRect( 0, 0, qCeil( textSize.width() ), qCeil( textSize.height() ) );

    const QPoint &pos = d_data->trackerPosition;

    int alignment = 0;
    if ( isActive() && d_data->pickedPoints.count() > 1
        && rubberBand() != NoRubberBand )
    {
        const QPoint last =
            d_data->pickedPoints[int( d_data->pickedPoints.count() ) - 2];

        alignment |= ( pos.x() >= last.x() ) ? Qt::AlignRight : Qt::AlignLeft;
        alignment |= ( pos.y() > last.y() ) ? Qt::AlignBottom : Qt::AlignTop;
    }
    else
        alignment = Qt::AlignTop | Qt::AlignRight;

    const int margin = 5;

    int x = pos.x();
    if ( alignment & Qt::AlignLeft )
        x -= textRect.width() + margin;
    else if ( alignment & Qt::AlignRight )
        x += margin;

    int y = pos.y();
    if ( alignment & Qt::AlignBottom )
        y += margin;
    else if ( alignment & Qt::AlignTop )
        y -= textRect.height() + margin;

    textRect.moveTopLeft( QPoint( x, y ) );

    int right = qMin( textRect.right(), pickRect().right() - margin );
    int bottom = qMin( textRect.bottom(), pickRect().bottom() - margin );
    textRect.moveBottomRight( QPoint( right, bottom ) );

    int left = qMax( textRect.left(), pickRect().left() + margin );
    int top = qMax( textRect.top(), pickRect().top() + margin );
    textRect.moveTopLeft( QPoint( left, top ) );

    return textRect;
}
Example #6
0
void QwtPicker::drawTracker(QPainter *painter) const
{
    const QRect textRect = trackerRect(painter);
    if ( !textRect.isEmpty() )
    {
        QwtText label = trackerText(d_data->labelPosition);
        if ( !label.isEmpty() )
            label.draw(painter, textRect);
    }
}
Example #7
0
/*!
  Change the plot's title
  \param title New title
*/
void QwtPolarPlot::setTitle( const QwtText &title )
{
  if ( title != d_data->titleLabel->text() )
  {
    d_data->titleLabel->setText( title );
    if ( !title.isEmpty() )
      d_data->titleLabel->show();
    else
      d_data->titleLabel->hide();
  }
}
/*!
  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 #9
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));
}
Example #10
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
*/
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;
}
/*!
  \return The preferred height, for a width.
  \param data Attributes of the legend entry
  \param width Width
*/
int QwtPlotLegendItem::heightForWidth( 
    const QwtLegendData &data, int width ) const
{
    width -= 2 * d_data->itemMargin;

    const QwtGraphic graphic = data.icon();
    const QwtText text = data.title();

    if ( text.isEmpty() )
        return graphic.height();

    if ( graphic.width() > 0 )
        width -= graphic.width() + d_data->itemSpacing;

    int h = text.heightForWidth( width, font() );
    h += 2 * d_data->itemMargin;

    return qMax( graphic.height(), h );
}
Example #12
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;

    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 #13
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 #14
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;
}
/*!
  Draw an entry on the legend

  \param painter Qt Painter
  \param plotItem Plot item, represented by the entry
  \param data Attributes of the legend entry
  \param rect Bounding rectangle for the entry
 */
void QwtPlotLegendItem::drawLegendData( QPainter *painter,
    const QwtPlotItem *plotItem, const QwtLegendData &data, 
    const QRectF &rect ) const
{
    Q_UNUSED( plotItem );

    const int m = d_data->itemMargin;
    const QRectF r = rect.toRect().adjusted( m, m, -m, -m );

    painter->setClipRect( r, Qt::IntersectClip );

    int titleOff = 0;

    const QwtGraphic graphic = data.icon();
    if ( !graphic.isEmpty() )
    {
        QRectF iconRect( r.topLeft(), graphic.defaultSize() );

        iconRect.moveCenter( 
            QPoint( iconRect.center().x(), rect.center().y() ) );

        graphic.render( painter, iconRect, Qt::KeepAspectRatio );

        titleOff += iconRect.width() + d_data->itemSpacing;
    }

    const QwtText text = data.title();
    if ( !text.isEmpty() )
    {
        painter->setPen( textPen() );
        painter->setFont( font() );

        const QRectF textRect = r.adjusted( titleOff, 0, 0, 0 );
        text.draw( painter, textRect );
    }
}
Example #16
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();
}