From 82b7fced530ebad3594beae836645152e31a55a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Mon, 10 Jun 2019 19:12:34 +0200 Subject: [PATCH] Removed the annoying map view re-zooming on window resize. Fixes #74 --- src/GUI/gui.cpp | 2 ++ src/GUI/mapview.cpp | 21 ++++++++++----------- src/GUI/mapview.h | 3 ++- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/GUI/gui.cpp b/src/GUI/gui.cpp index fdad0011..437d79fb 100644 --- a/src/GUI/gui.cpp +++ b/src/GUI/gui.cpp @@ -2216,6 +2216,8 @@ void GUI::show() connect(w, SIGNAL(screenChanged(QScreen*)), this, SLOT(screenChanged(QScreen*))); #endif // ENABLE_HIDPI + + _mapView->fitContentToSize(); } void GUI::screenChanged(QScreen *screen) diff --git a/src/GUI/mapview.cpp b/src/GUI/mapview.cpp index d4485c53..ff5d90a7 100644 --- a/src/GUI/mapview.cpp +++ b/src/GUI/mapview.cpp @@ -39,6 +39,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent) setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setRenderHint(QPainter::Antialiasing, true); + setResizeAnchor(QGraphicsView::AnchorViewCenter); setAcceptDrops(false); _mapScale = new ScaleItem(); @@ -901,17 +902,6 @@ void MapView::drawBackground(QPainter *painter, const QRectF &rect) } } -void MapView::resizeEvent(QResizeEvent *event) -{ - QGraphicsView::resizeEvent(event); - - int zoom = _map->zoom(); - if (fitMapZoom() != zoom) - rescale(); - - centerOn(contentCenter()); -} - void MapView::paintEvent(QPaintEvent *event) { QPointF scaleScenePos = mapToScene(rect().bottomRight() + QPoint( @@ -1042,3 +1032,12 @@ void MapView::setProjection(int id) rescale(); centerOn(_map->ll2xy(center)); } + +void MapView::fitContentToSize() +{ + int zoom = _map->zoom(); + if (fitMapZoom() != zoom) + rescale(); + + centerOn(contentCenter()); +} diff --git a/src/GUI/mapview.h b/src/GUI/mapview.h index d47f14da..421e74d3 100644 --- a/src/GUI/mapview.h +++ b/src/GUI/mapview.h @@ -85,6 +85,8 @@ public slots: void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); void setProjection(int id); + void fitContentToSize(); + private slots: void updatePOI(); void reloadMap(); @@ -111,7 +113,6 @@ private: void wheelEvent(QWheelEvent *event); void keyPressEvent(QKeyEvent *event); void drawBackground(QPainter *painter, const QRectF &rect); - void resizeEvent(QResizeEvent *event); void paintEvent(QPaintEvent *event); void scrollContentsBy(int dx, int dy); void mouseMoveEvent(QMouseEvent *event);