Beispiel #1
0
void PlotZozPicker::drawTracker( QPainter *painter )
{
    if(painter->isActive()) {
        QString text;
        text.sprintf("%.2f, %.2f",
                     trackerText(trackerPosition()).text().split(",",QString::SkipEmptyParts).at(0).toFloat(),
                     trackerText(trackerPosition()).text().split(",",QString::SkipEmptyParts).at(1).toFloat()
                     );
        emit position(text);
    }
}
Beispiel #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();
        }
    }
}
Beispiel #3
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;
}
Beispiel #4
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);
    }
}
Beispiel #5
0
/*!
  Translate a pixel position into a position string

  \param pos Position in pixel coordinates
  \return Position string
*/
QwtText QwtPlotPicker::trackerText(const QPoint &pos) const
{
    return trackerText(invTransform(pos));
}