Skip to content

Commit bbe34e4

Browse files
Sync Connections tab map view position
1 parent dbc1348 commit bbe34e4

File tree

4 files changed

+37
-9
lines changed

4 files changed

+37
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
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).
66

77
## [Unreleased]
8+
### Changed
9+
- The scroll position of the map view now remains the same between the Connections tab and the Map/Events tabs.
10+
811
### Fixed
912
- Fix warning not appearing when the log file exceeds maximum size.
1013
- Fix unnecessary resources being used to watch files.

include/ui/graphicsview.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,26 @@
44
#include <QGraphicsView>
55
#include <QMouseEvent>
66

7-
class NoScrollGraphicsView : public QGraphicsView
7+
// For general utility features that we add to QGraphicsView
8+
class GraphicsView : public QGraphicsView
89
{
910
Q_OBJECT
1011
public:
11-
NoScrollGraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {}
12+
GraphicsView(QWidget *parent = nullptr) : QGraphicsView(parent) {}
13+
14+
void centerOn(const QGraphicsView *other) {
15+
if (other && other->viewport()) {
16+
QPoint center = other->viewport()->rect().center();
17+
QGraphicsView::centerOn(other->mapToScene(center));
18+
}
19+
}
20+
};
21+
22+
class NoScrollGraphicsView : public GraphicsView
23+
{
24+
Q_OBJECT
25+
public:
26+
NoScrollGraphicsView(QWidget *parent = nullptr) : GraphicsView(parent) {}
1227

1328
protected:
1429
void wheelEvent(QWheelEvent *event) {
@@ -32,11 +47,11 @@ class ClickableGraphicsView : public NoScrollGraphicsView
3247
void clicked(QMouseEvent *event);
3348
};
3449

35-
class ConnectionsView : public QGraphicsView
50+
class ConnectionsView : public GraphicsView
3651
{
3752
Q_OBJECT
3853
public:
39-
ConnectionsView(QWidget *parent = nullptr) : QGraphicsView(parent) {}
54+
ConnectionsView(QWidget *parent = nullptr) : GraphicsView(parent) {}
4055

4156
signals:
4257
void pressedDelete();

include/ui/mapview.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88

99
class Editor;
1010

11-
class MapView : public QGraphicsView
11+
class MapView : public GraphicsView
1212
{
1313
Q_OBJECT
1414

1515
public:
16-
MapView() : QGraphicsView() {}
17-
MapView(QWidget *parent) : QGraphicsView(parent) {}
16+
MapView() : GraphicsView() {}
17+
MapView(QWidget *parent) : GraphicsView(parent) {}
1818

1919
Editor *editor;
2020

src/editor.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,20 @@ void Editor::setEditMode(EditMode editMode) {
177177
this->ui->pushButton_ChangeDimensions->setEnabled(editingLayout);
178178
this->ui->checkBox_smartPaths->setEnabled(editingLayout);
179179

180-
if (this->editMode == EditMode::Events || oldEditMode == EditMode::Events) {
180+
if (this->editMode != oldEditMode) {
181+
// When switching to or from the Connections tab we sync up the two separate map graphics views.
182+
if (this->editMode == EditMode::Connections) {
183+
ui->graphicsView_Connections->centerOn(ui->graphicsView_Map);
184+
} else if (oldEditMode == EditMode::Connections) {
185+
ui->graphicsView_Map->centerOn(ui->graphicsView_Connections);
186+
}
187+
181188
// When switching to or from the Events tab the opacity of the events changes. Redraw the events to reflect that change.
182-
redrawAllEvents();
189+
if (this->editMode == EditMode::Events || oldEditMode == EditMode::Events) {
190+
redrawAllEvents();
191+
}
183192
}
193+
184194
if (this->editMode == EditMode::Events){
185195
updateWarpEventWarnings();
186196
}

0 commit comments

Comments
 (0)