From ba856d7eb60a557ee989622a87ee7d48f8b8040d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sat, 9 Sep 2017 10:51:19 +0200 Subject: [PATCH] Adjusted the scale bar (text) size to the remaining content in plot mode --- src/gui.cpp | 2 +- src/pathview.cpp | 22 ++++++++++++++-------- src/pathview.h | 2 +- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/gui.cpp b/src/gui.cpp index 9ab5e90e..5df1ddf4 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1030,7 +1030,7 @@ void GUI::plot(QPrinter *printer) } else gh = 0; _pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() - - (ih + 2*mh + gh)), _options.hiresPrint); + - (ih + 2*mh + gh)), ratio, _options.hiresPrint); if (_graphTabWidget->isVisible() && _options.separateGraphPage) { printer->newPage(); diff --git a/src/pathview.cpp b/src/pathview.cpp index cc66068b..140f5dac 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -471,18 +471,21 @@ void PathView::keyPressEvent(QKeyEvent *event) zoom(z, pos, c); } -void PathView::plot(QPainter *painter, const QRectF &target, bool hires) +void PathView::plot(QPainter *painter, const QRectF &target, qreal scale, + bool hires) { QRect orig, adj; - qreal ratio, diff, origRes; + qreal ratio, diff, origRes, q; QPointF origScene, origPos; Coordinates origLL; + // Enter plot mode setUpdatesEnabled(false); _plot = true; _map->setBlockingMode(true); + // Compute sizes & ratios orig = viewport()->rect(); origPos = _mapScale->pos(); @@ -495,6 +498,7 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires) diff = (orig.height() * ratio) - orig.width(); adj = orig.adjusted(-diff/2, 0, diff/2, 0); } + q = (target.width() / scale) / adj.width(); // Adjust the view for printing if (hires) { @@ -514,14 +518,15 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires) adj.moveCenter(mapFromScene(center)); _mapScale->setResolution(_map->resolution(_map->ll2xy(origLL))); - _mapScale->setDigitalZoom(-log2(s.x())); + _mapScale->setDigitalZoom(-log2(s.x() / q)); _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( - -(SCALE_OFFSET + _mapScale->boundingRect().width()) * s.x(), - -(SCALE_OFFSET + _mapScale->boundingRect().height()) * s.x())))); + -(SCALE_OFFSET + _mapScale->boundingRect().width()) * (s.x() / q), + -(SCALE_OFFSET + _mapScale->boundingRect().height()) * (s.x() / q))))); } else { + _mapScale->setDigitalZoom(-log2(1.0 / q)); _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( - -(SCALE_OFFSET + _mapScale->boundingRect().width()), - -(SCALE_OFFSET + _mapScale->boundingRect().height()))))); + -(SCALE_OFFSET + _mapScale->boundingRect().width()) / q , + -(SCALE_OFFSET + _mapScale->boundingRect().height()) / q)))); } // Print the view @@ -532,11 +537,12 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires) _map->zoomFit(origRes, origLL); rescale(); centerOn(origScene); - _mapScale->setDigitalZoom(0); _mapScale->setResolution(origRes); } + _mapScale->setDigitalZoom(0); _mapScale->setPos(origPos); + // Exit plot mode _map->setBlockingMode(false); _plot = false; setUpdatesEnabled(true); diff --git a/src/pathview.h b/src/pathview.h index c857b135..1ec3a3f6 100644 --- a/src/pathview.h +++ b/src/pathview.h @@ -37,7 +37,7 @@ public: void setMap(Map *map); void setUnits(enum Units units); - void plot(QPainter *painter, const QRectF &target, bool hires); + void plot(QPainter *painter, const QRectF &target, qreal scale, bool hires); int trackCount() const {return _tracks.count();} int routeCount() const {return _routes.count();}