diff --git a/forms/mainwindow.ui b/forms/mainwindow.ui
index 8a8757a0..cbb611fe 100644
--- a/forms/mainwindow.ui
+++ b/forms/mainwindow.ui
@@ -2589,7 +2589,7 @@
Qt::Orientation::Horizontal
-
+
0
@@ -3310,9 +3310,14 @@
MapView
- QWidget
+ QGraphicsView
+
+ ConnectionsView
+ QGraphicsView
+
+
MapTree
QTreeView
@@ -3321,7 +3326,7 @@
NoScrollGraphicsView
QGraphicsView
-
+
MapListToolBar
diff --git a/include/editor.h b/include/editor.h
index 82bc5a08..b908b335 100644
--- a/include/editor.h
+++ b/include/editor.h
@@ -95,6 +95,7 @@ public:
void addNewConnection(const QString &mapName, const QString &direction);
void replaceConnection(const QString &mapName, const QString &direction);
void removeConnection(MapConnection* connection);
+ void removeSelectedConnection();
void addNewWildMonGroup(QWidget *window);
void deleteWildMonGroup();
void configureEncounterJSON(QWidget *);
diff --git a/include/ui/connectionpixmapitem.h b/include/ui/connectionpixmapitem.h
index 26b83aa6..32e309f9 100644
--- a/include/ui/connectionpixmapitem.h
+++ b/include/ui/connectionpixmapitem.h
@@ -43,8 +43,6 @@ protected:
virtual void mousePressEvent(QGraphicsSceneMouseEvent*) override;
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*) override;
- virtual void keyPressEvent(QKeyEvent*) override;
- virtual void focusInEvent(QFocusEvent*) override;
signals:
void connectionItemDoubleClicked(MapConnection*);
diff --git a/include/ui/connectionslistitem.h b/include/ui/connectionslistitem.h
index bce05345..1b9713cf 100644
--- a/include/ui/connectionslistitem.h
+++ b/include/ui/connectionslistitem.h
@@ -36,7 +36,6 @@ private:
protected:
virtual void mousePressEvent(QMouseEvent*) override;
- virtual void keyPressEvent(QKeyEvent*) override;
virtual bool eventFilter(QObject*, QEvent *event) override;
signals:
diff --git a/include/ui/graphicsview.h b/include/ui/graphicsview.h
index 92771cf7..0ca36239 100644
--- a/include/ui/graphicsview.h
+++ b/include/ui/graphicsview.h
@@ -32,6 +32,19 @@ signals:
void clicked(QMouseEvent *event);
};
+class ConnectionsView : public QGraphicsView
+{
+ Q_OBJECT
+public:
+ ConnectionsView(QWidget *parent = nullptr) : QGraphicsView(parent) {}
+
+signals:
+ void pressedDelete();
+
+protected:
+ virtual void keyPressEvent(QKeyEvent *event) override;
+};
+
class Editor;
// TODO: This should just be MapView. It makes map-based assumptions, and no other class inherits GraphicsView.
diff --git a/src/editor.cpp b/src/editor.cpp
index ea74c5bb..39ad3647 100644
--- a/src/editor.cpp
+++ b/src/editor.cpp
@@ -848,6 +848,11 @@ void Editor::removeConnection(MapConnection *connection) {
this->map->commit(new MapConnectionRemove(this->map, connection));
}
+void Editor::removeSelectedConnection() {
+ if (selected_connection_item)
+ removeConnection(selected_connection_item->connection);
+}
+
void Editor::removeConnectionPixmap(MapConnection *connection) {
if (!connection)
return;
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index feadc6e8..60bb3e80 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -352,6 +352,7 @@ void MainWindow::initEditor() {
connect(this->editor, &Editor::tilesetUpdated, this, &Scripting::cb_TilesetUpdated);
connect(ui->newEventToolButton, &NewEventToolButton::newEventAdded, this->editor, &Editor::addNewEvent);
connect(ui->toolButton_deleteEvent, &QAbstractButton::clicked, this->editor, &Editor::deleteSelectedEvents);
+ connect(ui->graphicsView_Connections, &ConnectionsView::pressedDelete, this->editor, &Editor::removeSelectedConnection);
this->loadUserSettings();
diff --git a/src/ui/connectionpixmapitem.cpp b/src/ui/connectionpixmapitem.cpp
index ac755ff8..7ea5f820 100644
--- a/src/ui/connectionpixmapitem.cpp
+++ b/src/ui/connectionpixmapitem.cpp
@@ -9,7 +9,6 @@ ConnectionPixmapItem::ConnectionPixmapItem(MapConnection* connection)
connection(connection)
{
this->setEditable(true);
- setFlag(ItemIsFocusable, true);
this->basePixmap = pixmap();
updateOrigin();
render(false);
@@ -118,10 +117,6 @@ bool ConnectionPixmapItem::getEditable() {
}
void ConnectionPixmapItem::setSelected(bool selected) {
- if (selected && !hasFocus()) {
- setFocus(Qt::OtherFocusReason);
- }
-
if (this->selected == selected)
return;
this->selected = selected;
@@ -131,7 +126,7 @@ void ConnectionPixmapItem::setSelected(bool selected) {
}
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
- setFocus(Qt::MouseFocusReason);
+ this->setSelected(true);
}
void ConnectionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
@@ -142,20 +137,3 @@ void ConnectionPixmapItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) {
void ConnectionPixmapItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *) {
emit connectionItemDoubleClicked(this->connection);
}
-
-// TODO: Rather than listening for this here and on the list item, listen for it on the connections graphics view,
-// and delete whichever map connections are currently selected. This should fix our weird focus requirements in here.
-void ConnectionPixmapItem::keyPressEvent(QKeyEvent* event) {
- if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) {
- emit deleteRequested(this->connection);
- } else {
- QGraphicsPixmapItem::keyPressEvent(event);
- }
-}
-
-void ConnectionPixmapItem::focusInEvent(QFocusEvent* event) {
- if (!this->getEditable())
- return;
- this->setSelected(true);
- QGraphicsPixmapItem::focusInEvent(event);
-}
diff --git a/src/ui/connectionslistitem.cpp b/src/ui/connectionslistitem.cpp
index b6c533be..0ba27223 100644
--- a/src/ui/connectionslistitem.cpp
+++ b/src/ui/connectionslistitem.cpp
@@ -129,12 +129,3 @@ void ConnectionsListItem::commitRemove() {
if (this->map)
this->map->commit(new MapConnectionRemove(this->map, this->connection));
}
-
-void ConnectionsListItem::keyPressEvent(QKeyEvent* event) {
- if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) {
- commitRemove();
- event->accept();
- } else {
- QFrame::keyPressEvent(event);
- }
-}
diff --git a/src/ui/graphicsview.cpp b/src/ui/graphicsview.cpp
index 68479e98..1297102e 100644
--- a/src/ui/graphicsview.cpp
+++ b/src/ui/graphicsview.cpp
@@ -79,3 +79,12 @@ Overlay * MapView::getOverlay(int layer) {
}
return overlay;
}
+
+void ConnectionsView::keyPressEvent(QKeyEvent *event) {
+ if (event->key() == Qt::Key_Delete || event->key() == Qt::Key_Backspace) {
+ emit pressedDelete();
+ event->accept();
+ } else {
+ QGraphicsView::keyPressEvent(event);
+ }
+}