mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 19:55:53 +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);
|
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);
|
setUpdatesEnabled(false);
|
||||||
redraw(canvas);
|
redraw(canvas);
|
||||||
|
@ -53,7 +53,7 @@ public:
|
|||||||
qreal sliderPosition() const {return _sliderPos;}
|
qreal sliderPosition() const {return _sliderPos;}
|
||||||
void setSliderPosition(qreal pos);
|
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);
|
void useOpenGL(bool use);
|
||||||
|
|
||||||
|
@ -475,13 +475,16 @@ void PathView::plot(QPainter *painter, const QRectF &target, bool hires)
|
|||||||
{
|
{
|
||||||
QRect orig, adj;
|
QRect orig, adj;
|
||||||
qreal ratio, diff, origRes;
|
qreal ratio, diff, origRes;
|
||||||
QPointF origScene;
|
QPointF origScene, origPos;
|
||||||
Coordinates origLL;
|
Coordinates origLL;
|
||||||
|
|
||||||
|
|
||||||
setUpdatesEnabled(false);
|
setUpdatesEnabled(false);
|
||||||
|
_plot = true;
|
||||||
|
_map->setBlockingMode(true);
|
||||||
|
|
||||||
orig = viewport()->rect();
|
orig = viewport()->rect();
|
||||||
|
origPos = _mapScale->pos();
|
||||||
|
|
||||||
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
if (orig.height() * (target.width() / target.height()) - orig.width() < 0) {
|
||||||
ratio = target.height() / target.width();
|
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);
|
adj = orig.adjusted(-diff/2, 0, diff/2, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Adjust the view for printing
|
||||||
if (hires) {
|
if (hires) {
|
||||||
origScene = mapToScene(orig.center());
|
origScene = mapToScene(orig.center());
|
||||||
origLL = _map->xy2ll(origScene);
|
origLL = _map->xy2ll(origScene);
|
||||||
origRes = _map->resolution(origScene);
|
origRes = _map->resolution(origScene);
|
||||||
|
|
||||||
QPointF scale(painter->device()->logicalDpiX()
|
QPointF s(painter->device()->logicalDpiX()
|
||||||
/ (qreal)metric(QPaintDevice::PdmDpiX),
|
/ (qreal)metric(QPaintDevice::PdmDpiX),
|
||||||
painter->device()->logicalDpiY()
|
painter->device()->logicalDpiY()
|
||||||
/ (qreal)metric(QPaintDevice::PdmDpiY));
|
/ (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);
|
_map->zoomFit(adj.size(), _tr | _rr | _wr);
|
||||||
rescale();
|
rescale();
|
||||||
QPointF center = contentCenter();
|
QPointF center = contentCenter();
|
||||||
centerOn(center);
|
centerOn(center);
|
||||||
adj.moveCenter(mapFromScene(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;
|
// Print the view
|
||||||
_map->setBlockingMode(true);
|
|
||||||
|
|
||||||
QPointF pos = _mapScale->pos();
|
|
||||||
_mapScale->setPos(mapToScene(QPoint(adj.bottomRight() + QPoint(
|
|
||||||
-(SCALE_OFFSET + _mapScale->boundingRect().width()),
|
|
||||||
-(SCALE_OFFSET + _mapScale->boundingRect().height())))));
|
|
||||||
|
|
||||||
render(painter, target, adj);
|
render(painter, target, adj);
|
||||||
|
|
||||||
_mapScale->setPos(pos);
|
// Revert view changes to display mode
|
||||||
|
|
||||||
_map->setBlockingMode(false);
|
|
||||||
_plot = false;
|
|
||||||
|
|
||||||
if (hires) {
|
if (hires) {
|
||||||
_map->zoomFit(origRes, origLL);
|
_map->zoomFit(origRes, origLL);
|
||||||
rescale();
|
rescale();
|
||||||
centerOn(origScene);
|
centerOn(origScene);
|
||||||
|
_mapScale->setDigitalZoom(0);
|
||||||
|
_mapScale->setResolution(origRes);
|
||||||
}
|
}
|
||||||
|
_mapScale->setPos(origPos);
|
||||||
|
|
||||||
|
_map->setBlockingMode(false);
|
||||||
|
_plot = false;
|
||||||
setUpdatesEnabled(true);
|
setUpdatesEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ void ScaleItem::setUnits(enum Units units)
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScaleItem::setDigitalZoom(int zoom)
|
void ScaleItem::setDigitalZoom(qreal zoom)
|
||||||
{
|
{
|
||||||
prepareGeometryChange();
|
prepareGeometryChange();
|
||||||
_digitalZoom = zoom;
|
_digitalZoom = zoom;
|
||||||
|
@ -15,7 +15,7 @@ public:
|
|||||||
|
|
||||||
void setResolution(qreal res);
|
void setResolution(qreal res);
|
||||||
void setUnits(enum Units units);
|
void setUnits(enum Units units);
|
||||||
void setDigitalZoom(int zoom);
|
void setDigitalZoom(qreal zoom);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateBoundingRect();
|
void updateBoundingRect();
|
||||||
@ -28,7 +28,7 @@ private:
|
|||||||
Units _units;
|
Units _units;
|
||||||
bool _scale;
|
bool _scale;
|
||||||
|
|
||||||
int _digitalZoom;
|
qreal _digitalZoom;
|
||||||
|
|
||||||
QRectF _boundingRect;
|
QRectF _boundingRect;
|
||||||
};
|
};
|
||||||
|
@ -16,9 +16,9 @@ void TrackInfo::insert(const QString &key, const QString &value)
|
|||||||
_info->insert(key, 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()),
|
QSizeF diff = QSizeF(qAbs(canvas.width() - sceneRect().width()),
|
||||||
qAbs(canvas.height() - sceneRect().height()));
|
qAbs(canvas.height() - sceneRect().height()));
|
||||||
QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(),
|
QRectF adj = sceneRect().adjusted(0, -diff.height()/2, diff.width(),
|
||||||
|
@ -13,7 +13,7 @@ public:
|
|||||||
TrackInfo(QObject *parent = 0);
|
TrackInfo(QObject *parent = 0);
|
||||||
|
|
||||||
void insert(const QString &key, const QString &value);
|
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;
|
bool isEmpty() const;
|
||||||
QSizeF contentSize() const;
|
QSizeF contentSize() const;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user