Only allow moving connections on connection tab

This commit is contained in:
GriffinR 2023-01-15 23:18:19 -05:00
parent ca0c667135
commit 0556afaf98
4 changed files with 42 additions and 27 deletions

View file

@ -146,7 +146,6 @@ public:
QUndoGroup editGroup; // Manages the undo history for each map QUndoGroup editGroup; // Manages the undo history for each map
bool selectingEvent = false; bool selectingEvent = false;
bool editingConnections = false;
void shouldReselectEvents(); void shouldReselectEvents();
void scaleMapView(int); void scaleMapView(int);
@ -166,7 +165,7 @@ private:
void setBorderItemsVisible(bool, qreal = 1); void setBorderItemsVisible(bool, qreal = 1);
void setConnectionEditControlValues(MapConnection*); void setConnectionEditControlValues(MapConnection*);
void setConnectionEditControlsEnabled(bool); void setConnectionEditControlsEnabled(bool);
void setConnectionHighlights(bool); void setConnectionsEditable(bool);
void createConnectionItem(MapConnection* connection, bool hide); void createConnectionItem(MapConnection* connection, bool hide);
void populateConnectionMapPickers(); void populateConnectionMapPickers();
void setDiveEmergeControls(); void setDiveEmergeControls();

View file

@ -29,6 +29,9 @@ public:
void render(qreal opacity = 1); void render(qreal opacity = 1);
int getMinOffset(); int getMinOffset();
int getMaxOffset(); int getMaxOffset();
void setEditable(bool editable);
bool getEditable();
void updateHighlight(bool selected);
protected: protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value); QVariant itemChange(GraphicsItemChange change, const QVariant &value);

View file

@ -95,8 +95,7 @@ void Editor::setEditingMap() {
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionHighlights(false); setConnectionsEditable(false);
this->editingConnections = false;
this->cursorMapTileRect->stopSingleTileMode(); this->cursorMapTileRect->stopSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -119,8 +118,7 @@ void Editor::setEditingCollision() {
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionHighlights(false); setConnectionsEditable(false);
this->editingConnections = false;
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(true); this->cursorMapTileRect->setActive(true);
@ -143,8 +141,7 @@ void Editor::setEditingObjects() {
} }
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked()); setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
setConnectionHighlights(false); setConnectionsEditable(false);
this->editingConnections = false;
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
@ -192,8 +189,7 @@ void Editor::setEditingConnections() {
} }
setBorderItemsVisible(true, 0.4); setBorderItemsVisible(true, 0.4);
setConnectionItemsVisible(true); setConnectionItemsVisible(true);
setConnectionHighlights(true); setConnectionsEditable(true);
this->editingConnections = true;
this->cursorMapTileRect->setSingleTileMode(); this->cursorMapTileRect->setSingleTileMode();
this->cursorMapTileRect->setActive(false); this->cursorMapTileRect->setActive(false);
} }
@ -860,30 +856,20 @@ void Editor::setConnectionEditControlsEnabled(bool enabled) {
} }
} }
void Editor::setConnectionHighlights(bool enabled) { void Editor::setConnectionsEditable(bool editable) {
for (ConnectionPixmapItem* item : connection_items) { for (ConnectionPixmapItem* item : connection_items) {
bool isSelectedItem = item == selected_connection_item; item->setEditable(editable);
int zValue = (isSelectedItem || !enabled) ? 0 : -1; item->updateHighlight(item == selected_connection_item);
qreal opacity = (isSelectedItem || !enabled) ? 1 : 0.75;
item->setZValue(zValue);
item->render(opacity);
if (enabled && isSelectedItem) {
QPixmap pixmap = item->pixmap();
QPainter painter(&pixmap);
painter.setPen(QColor(255, 0, 255));
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
painter.end();
item->setPixmap(pixmap);
}
} }
} }
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) { void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
selected_connection_item = connectionItem; if (!connectionItem)
if (!selected_connection_item || !this->editingConnections)
return; return;
setConnectionHighlights(true); selected_connection_item = connectionItem;
for (ConnectionPixmapItem* item : connection_items)
item->updateHighlight(item == selected_connection_item);
setConnectionEditControlsEnabled(true); setConnectionEditControlsEnabled(true);
setConnectionEditControlValues(selected_connection_item->connection); setConnectionEditControlValues(selected_connection_item->connection);
ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset()); ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());

View file

@ -65,7 +65,34 @@ QVariant ConnectionPixmapItem::itemChange(GraphicsItemChange change, const QVari
} }
} }
void ConnectionPixmapItem::setEditable(bool editable) {
setFlag(ItemIsMovable, editable);
setFlag(ItemSendsGeometryChanges, editable);
}
bool ConnectionPixmapItem::getEditable() {
return (this->flags() & ItemIsMovable) != 0;
}
void ConnectionPixmapItem::updateHighlight(bool selected) {
bool editable = this->getEditable();
int zValue = (selected || !editable) ? 0 : -1;
qreal opacity = (selected || !editable) ? 1 : 0.75;
this->setZValue(zValue);
this->render(opacity);
if (editable && selected) {
QPixmap pixmap = this->pixmap();
QPainter painter(&pixmap);
painter.setPen(QColor(255, 0, 255));
painter.drawRect(0, 0, pixmap.width() - 1, pixmap.height() - 1);
painter.end();
this->setPixmap(pixmap);
}
}
void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) { void ConnectionPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *) {
if (!this->getEditable())
return;
emit connectionItemSelected(this); emit connectionItemSelected(this);
} }