diff --git a/src/graphview.cpp b/src/graphview.cpp index 84f90ff2..cc75c8ee 100644 --- a/src/graphview.cpp +++ b/src/graphview.cpp @@ -326,9 +326,9 @@ void GraphView::mousePressEvent(QMouseEvent *e) QGraphicsView::mousePressEvent(e); } -void GraphView::plot(QPainter *painter, const QRectF &target, qreal ratio) +void GraphView::plot(QPainter *painter, const QRectF &target, qreal scale) { - QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio); + QSizeF canvas = QSizeF(target.width() / scale, target.height() / scale); setUpdatesEnabled(false); redraw(canvas); diff --git a/src/graphview.h b/src/graphview.h index 2e496b7d..b82a962a 100644 --- a/src/graphview.h +++ b/src/graphview.h @@ -53,7 +53,7 @@ public: qreal sliderPosition() const {return _sliderPos;} void setSliderPosition(qreal pos); - void plot(QPainter *painter, const QRectF &target, qreal ratio); + void plot(QPainter *painter, const QRectF &target, qreal scale); void useOpenGL(bool use); diff --git a/src/pathview.cpp b/src/pathview.cpp index 3c1da6dd..cc66068b 100644 --- a/src/pathview.cpp +++ b/src/pathview.cpp @@ -475,13 +475,16 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires) { QRect orig, adj; qreal ratio, diff, origRes; - QPointF origScene; + QPointF origScene, origPos; Coordinates origLL; setUpdatesEnabled(false); + _plot = true; + _map->setBlockingMode(true); orig = viewport()->rect(); + origPos = _mapScale->pos(); if (orig.height() * (target.width() / target.height()) - orig.width() < 0) { ratio = target.height() / target.width(); @@ -493,44 +496,49 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires) adj = orig.adjusted(-diff/2, 0, diff/2, 0); } + // Adjust the view for printing if (hires) { origScene = mapToScene(orig.center()); origLL = _map->xy2ll(origScene); origRes = _map->resolution(origScene); - QPointF scale(painter->device()->logicalDpiX() + QPointF s(painter->device()->logicalDpiX() / (qreal)metric(QPaintDevice::PdmDpiX), painter->device()->logicalDpiY() / (qreal)metric(QPaintDevice::PdmDpiY)); - adj.setSize(QSize(adj.width() * scale.x(), adj.height() * scale.y())); + adj = QRect(0, 0, adj.width() * s.x(), adj.height() * s.y()); _map->zoomFit(adj.size(), _tr | _rr | _wr); rescale(); QPointF center = contentCenter(); centerOn(center); adj.moveCenter(mapFromScene(center)); + + _mapScale->setResolution(_map->resolution(_map->ll2xy(origLL))); + _mapScale->setDigitalZoom(-log2(s.x())); + _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( + -(SCALE_OFFSET + _mapScale->boundingRect().width()) * s.x(), + -(SCALE_OFFSET + _mapScale->boundingRect().height()) * s.x())))); + } else { + _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( + -(SCALE_OFFSET + _mapScale->boundingRect().width()), + -(SCALE_OFFSET + _mapScale->boundingRect().height()))))); } - _plot = true; - _map->setBlockingMode(true); - - QPointF pos = _mapScale->pos(); - _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( - -(SCALE_OFFSET + _mapScale->boundingRect().width()), - -(SCALE_OFFSET + _mapScale->boundingRect().height()))))); - + // Print the view render(painter, target, adj); - _mapScale->setPos(pos); - - _map->setBlockingMode(false); - _plot = false; - + // Revert view changes to display mode if (hires) { _map->zoomFit(origRes, origLL); rescale(); centerOn(origScene); + _mapScale->setDigitalZoom(0); + _mapScale->setResolution(origRes); } + _mapScale->setPos(origPos); + _map->setBlockingMode(false); + _plot = false; setUpdatesEnabled(true); } diff --git a/src/scaleitem.cpp b/src/scaleitem.cpp index d42a0f1f..c721e8ee 100644 --- a/src/scaleitem.cpp +++ b/src/scaleitem.cpp @@ -132,7 +132,7 @@ void ScaleItem::setUnits(enum Units units) update(); } -void ScaleItem::setDigitalZoom(int zoom) +void ScaleItem::setDigitalZoom(qreal zoom) { prepareGeometryChange(); _digitalZoom = zoom; diff --git a/src/scaleitem.h b/src/scaleitem.h index ac1e5389..405bc020 100644 --- a/src/scaleitem.h +++ b/src/scaleitem.h @@ -15,7 +15,7 @@ public: void setResolution(qreal res); void setUnits(enum Units units); - void setDigitalZoom(int zoom); + void setDigitalZoom(qreal zoom); private: void updateBoundingRect(); @@ -28,7 +28,7 @@ private: Units _units; bool _scale; - int _digitalZoom; + qreal _digitalZoom; QRectF _boundingRect; }; diff --git a/src/trackinfo.cpp b/src/trackinfo.cpp index 14a65b6e..6a50cf57 100644 --- a/src/trackinfo.cpp +++ b/src/trackinfo.cpp @@ -16,9 +16,9 @@ void TrackInfo::insert(const QString &key, const QString &value) _info->insert(key, value); } -void TrackInfo::plot(QPainter *painter, const QRectF &target, qreal ratio) +void TrackInfo::plot(QPainter *painter, const QRectF &target, qreal scale) { - QSizeF canvas = QSizeF(target.width() / ratio, target.height() / ratio); + QSizeF canvas = QSizeF(target.width() / scale, target.height() / scale); QSizeF diff = QSizeF(qAbs(canvas.width() - sceneRect().width()), qAbs(canvas.height() - sceneRect().height())); QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(), diff --git a/src/trackinfo.h b/src/trackinfo.h index e7bd37a3..240b198c 100644 --- a/src/trackinfo.h +++ b/src/trackinfo.h @@ -13,7 +13,7 @@ public: TrackInfo(QObject *parent = 0); void insert(const QString &key, const QString &value); - void plot(QPainter *painter, const QRectF &target, qreal ratio); + void plot(QPainter *painter, const QRectF &target, qreal scale); bool isEmpty() const; QSizeF contentSize() const;