From bbe34e4983f8f644d1ab4e7a5cdf0ad1699edd9e Mon Sep 17 00:00:00 2001 From: GriffinR Date: Mon, 23 Jun 2025 15:27:19 -0400 Subject: [PATCH] Sync Connections tab map view position --- CHANGELOG.md | 3 +++ include/ui/graphicsview.h | 23 +++++++++++++++++++---- include/ui/mapview.h | 6 +++--- src/editor.cpp | 14 ++++++++++++-- 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aa05f7b..47ac8dc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project somewhat adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). The MAJOR version number is bumped when there are **"Breaking Changes"** in the pret projects. For more on this, see [the manual page on breaking changes](https://huderlem.github.io/porymap/manual/breaking-changes.html). ## [Unreleased] +### Changed +- The scroll position of the map view now remains the same between the Connections tab and the Map/Events tabs. + ### Fixed - Fix warning not appearing when the log file exceeds maximum size. - Fix unnecessary resources being used to watch files. diff --git a/include/ui/graphicsview.h b/include/ui/graphicsview.h index c587d2a9..bf3a7e42 100644 --- a/include/ui/graphicsview.h +++ b/include/ui/graphicsview.h @@ -4,11 +4,26 @@ #include #include -class NoScrollGraphicsView : public QGraphicsView +// For general utility features that we add to QGraphicsView +class GraphicsView : public QGraphicsView { Q_OBJECT public: - NoScrollGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {} + GraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {} + + void centerOn(const QGraphicsView *other) { + if (other && other->viewport()) { + QPoint center = other->viewport()->rect().center(); + QGraphicsView::centerOn(other->mapToScene(center)); + } + } +}; + +class NoScrollGraphicsView : public GraphicsView +{ + Q_OBJECT +public: + NoScrollGraphicsView(QWidget *parent = nullptr) : GraphicsView(parent) {} protected: void wheelEvent(QWheelEvent *event) { @@ -32,11 +47,11 @@ signals: void clicked(QMouseEvent *event); }; -class ConnectionsView : public QGraphicsView +class ConnectionsView : public GraphicsView { Q_OBJECT public: - ConnectionsView(QWidget *parent = nullptr) : QGraphicsView(parent) {} + ConnectionsView(QWidget *parent = nullptr) : GraphicsView(parent) {} signals: void pressedDelete(); diff --git a/include/ui/mapview.h b/include/ui/mapview.h index 5520ec80..023e1cac 100644 --- a/include/ui/mapview.h +++ b/include/ui/mapview.h @@ -8,13 +8,13 @@ class Editor; -class MapView : public QGraphicsView +class MapView : public GraphicsView { Q_OBJECT public: - MapView() : QGraphicsView() {} - MapView(QWidget *parent) : QGraphicsView(parent) {} + MapView() : GraphicsView() {} + MapView(QWidget *parent) : GraphicsView(parent) {} Editor *editor; diff --git a/src/editor.cpp b/src/editor.cpp index 5fb3ef80..3073e66f 100644 --- a/src/editor.cpp +++ b/src/editor.cpp @@ -177,10 +177,20 @@ void Editor::setEditMode(EditMode editMode) { this->ui->pushButton_ChangeDimensions->setEnabled(editingLayout); this->ui->checkBox_smartPaths->setEnabled(editingLayout); - if (this->editMode == EditMode::Events || oldEditMode == EditMode::Events) { + if (this->editMode != oldEditMode) { + // When switching to or from the Connections tab we sync up the two separate map graphics views. + if (this->editMode == EditMode::Connections) { + ui->graphicsView_Connections->centerOn(ui->graphicsView_Map); + } else if (oldEditMode == EditMode::Connections) { + ui->graphicsView_Map->centerOn(ui->graphicsView_Connections); + } + // When switching to or from the Events tab the opacity of the events changes. Redraw the events to reflect that change. - redrawAllEvents(); + if (this->editMode == EditMode::Events || oldEditMode == EditMode::Events) { + redrawAllEvents(); + } } + if (this->editMode == EditMode::Events){ updateWarpEventWarnings(); }