diff --git a/src/graph.cpp b/src/graph.cpp index 35b735ca..3a19afc7 100644 --- a/src/graph.cpp +++ b/src/graph.cpp @@ -237,7 +237,7 @@ void Graph::plot(QPainter *painter, const QRectF &target) resize(canvas); _slider->hide(); _info->hide(); - _scene->render(painter, target, QRectF(), Qt::KeepAspectRatioByExpanding); + _scene->render(painter, target, QRectF()); _slider->show(); _info->show(); resize(orig); diff --git a/src/scaleitem.cpp b/src/scaleitem.cpp index a40a1898..5b172377 100644 --- a/src/scaleitem.cpp +++ b/src/scaleitem.cpp @@ -29,7 +29,7 @@ QRectF ScaleItem::boundingRect() const es = fm.tightBoundingRect(QString::number(_length * SEGMENTS)); us = fm.tightBoundingRect(units()); - return QRectF(-ss.width()/2, -(PADDING + ss.height() + fm.descent()), + return QRectF(-ss.width()/2, 0, _width * SEGMENTS + ss.width()/2 + qMax(us.width() + PADDING, es.width()/2), SCALE_HEIGHT + PADDING + ss.height() + 2*fm.descent()); } @@ -43,22 +43,23 @@ void ScaleItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, font.setPixelSize(FONT_SIZE); font.setFamily(FONT_FAMILY); QFontMetrics fm(font); - + QRect br; painter->setFont(font); for (int i = 0; i <= SEGMENTS; i++) { QString label = QString::number(_length * i); - QRect br = fm.tightBoundingRect(label); - painter->drawText(_width * i - br.width()/2, -PADDING, label); + br = fm.tightBoundingRect(label); + painter->drawText(_width * i - br.width()/2, br.height(), label); } - painter->drawText(_width * SEGMENTS + PADDING, SCALE_HEIGHT + fm.descent(), - units()); + painter->drawText(_width * SEGMENTS + PADDING, SCALE_HEIGHT + PADDING + + br.height() + fm.descent(), units()); - painter->drawRect(QRectF(0, 0, SEGMENTS * _width, SCALE_HEIGHT)); + painter->drawRect(QRectF(0, br.height() + PADDING, SEGMENTS * _width, + SCALE_HEIGHT)); for (int i = 0; i < SEGMENTS; i += 2) - painter->fillRect(QRectF(i * _width, 0, _width, SCALE_HEIGHT), - Qt::black); + painter->fillRect(QRectF(i * _width, br.height() + PADDING, _width, + SCALE_HEIGHT), Qt::black); /* painter->setPen(Qt::red); diff --git a/src/track.cpp b/src/track.cpp index fb7f3fae..044652d9 100644 --- a/src/track.cpp +++ b/src/track.cpp @@ -12,8 +12,7 @@ #define MARGIN 10.0 #define TRACK_WIDTH 3 -#define SCALE_OFFSET_X 7 -#define SCALE_OFFSET_Y 15 +#define SCALE_OFFSET 7 Track::Track(QWidget *parent) : QGraphicsView(parent) @@ -247,12 +246,6 @@ void Track::wheelEvent(QWheelEvent *event) resetCachedContent(); } -void Track::showMarkers(bool show) -{ - for (int i = 0; i < _markers.size(); i++) - _markers.at(i)->setVisible(show); -} - void Track::setTrackLineWidth(qreal width) { for (int i = 0; i < _trackPaths.size(); i++) { @@ -264,12 +257,14 @@ void Track::setTrackLineWidth(qreal width) void Track::plot(QPainter *painter, const QRectF &target) { - _scene->removeItem(_mapScale); - - QRectF orig = _scene->itemsBoundingRect(); - QRectF adj; + QRectF orig, adj; qreal ratio, diff; + _scene->removeItem(_mapScale); + orig = _scene->itemsBoundingRect().adjusted(0, 0, 0, + _mapScale->boundingRect().height()); + _scene->addItem(_mapScale); + if (target.width()/target.height() > orig.width()/orig.height()) { ratio = target.width()/target.height(); diff = qAbs((orig.height() * ratio) - orig.width()); @@ -280,13 +275,13 @@ void Track::plot(QPainter *painter, const QRectF &target) adj = orig.adjusted(0, -diff/2, 0, diff/2); } - showMarkers(false); - setTrackLineWidth(0); - _scene->render(painter, target, adj, Qt::KeepAspectRatioByExpanding); - setTrackLineWidth(TRACK_WIDTH * _scale); - showMarkers(true); + _mapScale->setPos(adj.bottomRight() + + QPoint(-_mapScale->boundingRect().width(), + -_mapScale->boundingRect().height())); - _scene->addItem(_mapScale); + setTrackLineWidth(0); + _scene->render(painter, target, adj); + setTrackLineWidth(TRACK_WIDTH * _scale); } enum QPrinter::Orientation Track::orientation() const @@ -391,8 +386,8 @@ void Track::resizeEvent(QResizeEvent *e) void Track::paintEvent(QPaintEvent *e) { - QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET_X, - -SCALE_OFFSET_Y)); + QPointF scenePos = mapToScene(rect().bottomLeft() + QPoint(SCALE_OFFSET, + -(SCALE_OFFSET + _mapScale->boundingRect().height()))); _mapScale->setPos(scenePos); QGraphicsView::paintEvent(e);