diff --git a/libkoviz/bookview_curves.cpp b/libkoviz/bookview_curves.cpp index 89b118a..c01fc6a 100644 --- a/libkoviz/bookview_curves.cpp +++ b/libkoviz/bookview_curves.cpp @@ -309,15 +309,22 @@ void CurvesView::_paintCurve(const QModelIndex& curveIdx, QTransform I; painter.setTransform(I); double top = tbox.y()-fontMetrics().ascent(); + QPoint drawPt; if ( top >= 0 ) { // Draw label over curve - painter.drawText(tbox.topLeft()-QPointF(0,5),label); + drawPt = tbox.topLeft().toPoint()-QPoint(0,5); } else { // Draw label under curve since it would drawn off page - painter.drawText(tbox.topLeft()+ - QPointF(0,fontMetrics().ascent()) - +QPointF(0,5),label); + drawPt = tbox.topLeft().toPoint()+ + QPoint(0,fontMetrics().ascent()) + QPoint(0,5); } + QRect labelRect = painter.fontMetrics().boundingRect(label); + labelRect.moveTo(tbox.topLeft().toPoint()); + if ( labelRect.right() > painter.viewport().right() ) { + // Shift label to left of point so it stays in viewport + drawPt = drawPt - QPoint(labelRect.width(),0); + } + painter.drawText(drawPt,label); painter.setTransform(Tscaled); } else if ( path->elementCount() == 0 ) { diff --git a/libkoviz/layoutitem_curves.cpp b/libkoviz/layoutitem_curves.cpp index ec80e58..0778e36 100644 --- a/libkoviz/layoutitem_curves.cpp +++ b/libkoviz/layoutitem_curves.cpp @@ -340,14 +340,21 @@ void CurvesLayoutItem::_printCoplot(const QTransform& T, // It's a flatline label = QString("Flatline=%1").arg(yString); } - int h = painter->fontMetrics().height(); QColor color( _bookModel->getDataString(curveIdx, "CurveColor","Curve")); QPen pen = painter->pen(); pen.setColor(color); painter->setPen(pen); - painter->drawText( - curveBBox.topLeft()-QPointF(0,h+10),label); + + int h = painter->fontMetrics().descent(); + QPoint drawPt = curveBBox.topLeft().toPoint()-QPoint(0,h); + QRect L = painter->fontMetrics().boundingRect(label); + L.moveTo(drawPt); + if ( L.right() > painter->viewport().right() ) { + // Move label into viewport + drawPt = drawPt - QPoint(L.width(),0); + } + painter->drawText(drawPt,label); } }