1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-06 06:43:22 +02:00

Fixed PNG export ap artifacts under Qt6

This commit is contained in:
Martin Tůma 2024-09-14 10:20:14 +02:00
parent a2728b6227
commit 524ac8347f

View File

@ -686,7 +686,7 @@ void MapView::keyReleaseEvent(QKeyEvent *event)
void MapView::plot(QPainter *painter, const QRectF &target, qreal scale, void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
Flags flags) Flags flags)
{ {
QRect orig, adj; QRect orig;
qreal ratio, diff, q, p; qreal ratio, diff, q, p;
QPointF scenePos, scalePos, posPos, motionPos; QPointF scenePos, scalePos, posPos, motionPos;
bool hidpi = _hidpi && _deviceRatio > 1.0; bool hidpi = _hidpi && _deviceRatio > 1.0;
@ -699,6 +699,7 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
// Compute sizes & ratios // Compute sizes & ratios
orig = viewport()->rect(); orig = viewport()->rect();
QRectF adj(orig);
scalePos = _mapScale->pos(); scalePos = _mapScale->pos();
posPos = _positionCoordinates->pos(); posPos = _positionCoordinates->pos();
motionPos = _motionInfo->pos(); motionPos = _motionInfo->pos();
@ -706,11 +707,11 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
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();
diff = (orig.width() * ratio) - orig.height(); diff = (orig.width() * ratio) - orig.height();
adj = orig.adjusted(0, -diff/2, 0, diff/2); adj.adjust(0, -diff/2.0, 0, diff/2.0);
} else { } else {
ratio = target.width() / target.height(); ratio = target.width() / target.height();
diff = (orig.height() * ratio) - orig.width(); diff = (orig.height() * ratio) - orig.width();
adj = orig.adjusted(-diff/2, 0, diff/2, 0); adj.adjust(-diff/2.0, 0, diff/2.0, 0);
} }
// Expand the view if plotting into a bitmap // Expand the view if plotting into a bitmap
@ -735,8 +736,8 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
/ (qreal)metric(QPaintDevice::PdmDpiX), / (qreal)metric(QPaintDevice::PdmDpiX),
painter->device()->logicalDpiY() painter->device()->logicalDpiY()
/ (qreal)metric(QPaintDevice::PdmDpiY)); / (qreal)metric(QPaintDevice::PdmDpiY));
adj = QRect(0, 0, adj.width() * s.x(), adj.height() * s.y()); adj = QRectF(0, 0, adj.width() * s.x(), adj.height() * s.y());
_map->zoomFit(adj.size(), _tr | _rr | _wr | _ar); _map->zoomFit(adj.size().toSize(), _tr | _rr | _wr | _ar);
rescale(); rescale();
QPointF center = contentCenter(); QPointF center = contentCenter();
@ -748,20 +749,20 @@ void MapView::plot(QPainter *painter, const QRectF &target, qreal scale,
p = 1 / q; p = 1 / q;
_mapScale->setDigitalZoom(_digitalZoom - log2(p)); _mapScale->setDigitalZoom(_digitalZoom - log2(p));
_mapScale->setPos(mapToScene(adj.bottomRight() + QPoint( _mapScale->setPos(mapToScene(adj.bottomRight().toPoint() + QPoint(
-(SCALE_OFFSET + _mapScale->boundingRect().width()) * p, -(SCALE_OFFSET + _mapScale->boundingRect().width()) * p,
-(SCALE_OFFSET + _mapScale->boundingRect().height()) * p))); -(SCALE_OFFSET + _mapScale->boundingRect().height()) * p)));
_positionCoordinates->setDigitalZoom(_digitalZoom - log2(p)); _positionCoordinates->setDigitalZoom(_digitalZoom - log2(p));
_positionCoordinates->setPos(mapToScene(adj.topLeft() + QPoint( _positionCoordinates->setPos(mapToScene(adj.topLeft().toPoint() + QPoint(
COORDINATES_OFFSET * p, COORDINATES_OFFSET * p,
(COORDINATES_OFFSET + _positionCoordinates->boundingRect().height()) * p))); (COORDINATES_OFFSET + _positionCoordinates->boundingRect().height()) * p)));
_motionInfo->setDigitalZoom(_digitalZoom - log2(p)); _motionInfo->setDigitalZoom(_digitalZoom - log2(p));
_motionInfo->setPos(mapToScene(adj.topRight() + QPoint( _motionInfo->setPos(mapToScene(adj.topRight().toPoint() + QPoint(
(-COORDINATES_OFFSET - _motionInfo->boundingRect().width()) * p, (-COORDINATES_OFFSET - _motionInfo->boundingRect().width()) * p,
(COORDINATES_OFFSET + _motionInfo->boundingRect().height()) * p))); (COORDINATES_OFFSET + _motionInfo->boundingRect().height()) * p)));
// Print the view // Print the view
render(painter, target, adj); render(painter, target, adj.toRect());
// Revert view changes to display mode // Revert view changes to display mode
if (flags & HiRes) { if (flags & HiRes) {