mirror of
https://github.com/huderlem/porymap.git
synced 2026-07-01 03:59:54 -05:00
Fix connection pixmaps being sensitive to focus
This commit is contained in:
parent
b1d85d32c1
commit
8b85057ca5
|
|
@ -2589,7 +2589,7 @@
|
|||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QGraphicsView" name="graphicsView_Connections">
|
||||
<widget class="ConnectionsView" name="graphicsView_Connections">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||
<horstretch>0</horstretch>
|
||||
|
|
@ -3310,9 +3310,14 @@
|
|||
</customwidget>
|
||||
<customwidget>
|
||||
<class>MapView</class>
|
||||
<extends>QWidget</extends>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>mapview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>ConnectionsView</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>graphicsview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>MapTree</class>
|
||||
<extends>QTreeView</extends>
|
||||
|
|
@ -3321,7 +3326,7 @@
|
|||
<customwidget>
|
||||
<class>NoScrollGraphicsView</class>
|
||||
<extends>QGraphicsView</extends>
|
||||
<header>mapview.h</header>
|
||||
<header>graphicsview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>MapListToolBar</class>
|
||||
|
|
|
|||
|
|
@ -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 *);
|
||||
|
|
|
|||
|
|
@ -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*);
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ private:
|
|||
|
||||
protected:
|
||||
virtual void mousePressEvent(QMouseEvent*) override;
|
||||
virtual void keyPressEvent(QKeyEvent*) override;
|
||||
virtual bool eventFilter(QObject*, QEvent *event) override;
|
||||
|
||||
signals:
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user