1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 11:45:53 +01:00

Removed the annoying map view re-zooming on window resize.

Fixes #74
This commit is contained in:
Martin Tůma 2019-06-10 19:12:34 +02:00
parent 3de0ed055a
commit 82b7fced53
3 changed files with 14 additions and 12 deletions

View File

@ -2216,6 +2216,8 @@ void GUI::show()
connect(w, SIGNAL(screenChanged(QScreen*)), this, connect(w, SIGNAL(screenChanged(QScreen*)), this,
SLOT(screenChanged(QScreen*))); SLOT(screenChanged(QScreen*)));
#endif // ENABLE_HIDPI #endif // ENABLE_HIDPI
_mapView->fitContentToSize();
} }
void GUI::screenChanged(QScreen *screen) void GUI::screenChanged(QScreen *screen)

View File

@ -39,6 +39,7 @@ MapView::MapView(Map *map, POI *poi, QWidget *parent)
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setRenderHint(QPainter::Antialiasing, true); setRenderHint(QPainter::Antialiasing, true);
setResizeAnchor(QGraphicsView::AnchorViewCenter);
setAcceptDrops(false); setAcceptDrops(false);
_mapScale = new ScaleItem(); _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) void MapView::paintEvent(QPaintEvent *event)
{ {
QPointF scaleScenePos = mapToScene(rect().bottomRight() + QPoint( QPointF scaleScenePos = mapToScene(rect().bottomRight() + QPoint(
@ -1042,3 +1032,12 @@ void MapView::setProjection(int id)
rescale(); rescale();
centerOn(_map->ll2xy(center)); centerOn(_map->ll2xy(center));
} }
void MapView::fitContentToSize()
{
int zoom = _map->zoom();
if (fitMapZoom() != zoom)
rescale();
centerOn(contentCenter());
}

View File

@ -85,6 +85,8 @@ public slots:
void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio); void setDevicePixelRatio(qreal deviceRatio, qreal mapRatio);
void setProjection(int id); void setProjection(int id);
void fitContentToSize();
private slots: private slots:
void updatePOI(); void updatePOI();
void reloadMap(); void reloadMap();
@ -111,7 +113,6 @@ private:
void wheelEvent(QWheelEvent *event); void wheelEvent(QWheelEvent *event);
void keyPressEvent(QKeyEvent *event); void keyPressEvent(QKeyEvent *event);
void drawBackground(QPainter *painter, const QRectF &rect); void drawBackground(QPainter *painter, const QRectF &rect);
void resizeEvent(QResizeEvent *event);
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
void scrollContentsBy(int dx, int dy); void scrollContentsBy(int dx, int dy);
void mouseMoveEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event);