mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-28 05:34:47 +01:00
Fixed scale size in hi-res prints
This commit is contained in:
parent
8e932b966c
commit
b14eeb58ab
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -132,7 +132,7 @@ void ScaleItem::setUnits(enum Units units)
|
||||
update();
|
||||
}
|
||||
|
||||
void ScaleItem::setDigitalZoom(int zoom)
|
||||
void ScaleItem::setDigitalZoom(qreal zoom)
|
||||
{
|
||||
prepareGeometryChange();
|
||||
_digitalZoom = zoom;
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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(),
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user