continue;
for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit ) {
- if ( ( p - mapToPoint( **dpit ) ).manhattanLength() <= 4 )
+ if ( ( p - mapToPoint( **dpit ).toPoint() ).manhattanLength() <= 4 )
pts << po;
}
}
PixRect = QRect( 0, 0, newWidth, newHeight );
}
+QPointF KPlotWidget::mapToPoint( const QPointF& p ) const {
+ float px = PixRect.left() + PixRect.width()*( p.x() - DataRect.x() )/DataRect.width();
+ float py = PixRect.top() + PixRect.height()*( DataRect.y() + DataRect.height() - p.y() )/DataRect.height();
+ return QPointF( px, py );
+}
+
void KPlotWidget::paintEvent( QPaintEvent *e ) {
// let QFrame draw its default stuff (like the frame)
QFrame::paintEvent( e );
for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
{
- QPoint q = mapToPoint( **dpit );
- int x1 = q.x() - po->size()/2;
- int y1 = q.y() - po->size()/2;
+ QPointF q = mapToPoint( **dpit );
+ float x1 = q.x() - 0.5*po->size();
+ float y1 = q.y() - 0.5*po->size();
switch( po->param() ) {
case KPlotObject::CIRCLE : p->drawEllipse( x1, y1, po->size(), po->size() ); break;
case KPlotObject::CURVE :
{
p->setPen( QPen( po->color(), po->size(), (Qt::PenStyle)po->param() ) );
- QPolygon poly;
+ QPolygonF poly;
for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
poly << mapToPoint( **dpit );
p->drawPolyline( poly );
break;
}
+ //FIXME: implement non-overlapping labels
case KPlotObject::LABEL : //draw label centered at point in x, and slightly below point in y.
{
- QPoint q = mapToPoint( *(po->points()->first()) );
+ QPointF q = mapToPoint( *(po->points()->first()) );
p->drawText( q.x()-20, q.y()+6, 40, 10, Qt::AlignCenter | Qt::TextDontClip, po->name() );
break;
}
p->setPen( QPen( po->color(), po->size(), (Qt::PenStyle)po->param() ) );
p->setBrush( po->color() );
- QPolygon a( po->count() );
+ QPolygonF a( po->count() );
for ( QList<QPointF*>::ConstIterator dpit = po->points()->begin(); dpit != po->points()->constEnd(); ++dpit )
a << mapToPoint( **dpit );
* Used mainly when drawing.
* @return the coordinate in the pixel coordinate system
*/
- QPoint mapToPoint( const QPointF& p ) const {
- int px = PixRect.left() + int( PixRect.width()*( p.x() - DataRect.x() )/DataRect.width() );
- int py = PixRect.top() + int( PixRect.height()*( DataRect.y() + DataRect.height() - p.y() )/DataRect.height() );
- return QPoint( px, py );
- }
+ QPointF mapToPoint( const QPointF& p ) const;
/**
* Retrieve the pointer to the axis of type @p a.