1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Adjusted the scale bar (text) size to the remaining content in plot mode

This commit is contained in:
Martin Tůma 2017-09-09 10:51:19 +02:00
parent b14eeb58ab
commit ba856d7eb6
3 changed files with 16 additions and 10 deletions

View File

@ -1030,7 +1030,7 @@ void GUI::plot(QPrinter *printer)
} else } else
gh = 0; gh = 0;
_pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height() _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) { if (_graphTabWidget->isVisible() && _options.separateGraphPage) {
printer->newPage(); printer->newPage();

View File

@ -471,18 +471,21 @@ void PathView::keyPressEvent(QKeyEvent *event)
zoom(z, pos, c); 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; QRect orig, adj;
qreal ratio, diff, origRes; qreal ratio, diff, origRes, q;
QPointF origScene, origPos; QPointF origScene, origPos;
Coordinates origLL; Coordinates origLL;
// Enter plot mode
setUpdatesEnabled(false); setUpdatesEnabled(false);
_plot = true; _plot = true;
_map->setBlockingMode(true); _map->setBlockingMode(true);
// Compute sizes & ratios
orig = viewport()->rect(); orig = viewport()->rect();
origPos = _mapScale->pos(); origPos = _mapScale->pos();
@ -495,6 +498,7 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
diff = (orig.height() * ratio) - orig.width(); diff = (orig.height() * ratio) - orig.width();
adj = orig.adjusted(-diff/2, 0, diff/2, 0); adj = orig.adjusted(-diff/2, 0, diff/2, 0);
} }
q = (target.width() / scale) / adj.width();
// Adjust the view for printing // Adjust the view for printing
if (hires) { if (hires) {
@ -514,14 +518,15 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
adj.moveCenter(mapFromScene(center)); adj.moveCenter(mapFromScene(center));
_mapScale->setResolution(_map->resolution(_map->ll2xy(origLL))); _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( _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * s.x(), -(SCALE_OFFSET + _mapScale->boundingRect().width()) * (s.x() / q),
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * s.x())))); -(SCALE_OFFSET + _mapScale->boundingRect().height()) * (s.x() / q)))));
} else { } else {
_mapScale->setDigitalZoom(-log2(1.0 / q));
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint( _mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()), -(SCALE_OFFSET + _mapScale->boundingRect().width()) / q ,
-(SCALE_OFFSET + _mapScale->boundingRect().height()))))); -(SCALE_OFFSET + _mapScale->boundingRect().height()) / q))));
} }
// Print the view // Print the view
@ -532,11 +537,12 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
_map->zoomFit(origRes, origLL); _map->zoomFit(origRes, origLL);
rescale(); rescale();
centerOn(origScene); centerOn(origScene);
_mapScale->setDigitalZoom(0);
_mapScale->setResolution(origRes); _mapScale->setResolution(origRes);
} }
_mapScale->setDigitalZoom(0);
_mapScale->setPos(origPos); _mapScale->setPos(origPos);
// Exit plot mode
_map->setBlockingMode(false); _map->setBlockingMode(false);
_plot = false; _plot = false;
setUpdatesEnabled(true); setUpdatesEnabled(true);

View File

@ -37,7 +37,7 @@ public:
void setMap(Map *map); void setMap(Map *map);
void setUnits(enum Units units); 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 trackCount() const {return _tracks.count();}
int routeCount() const {return _routes.count();} int routeCount() const {return _routes.count();}