Only allow moving connections on connection tab
This commit is contained in:
parent
ca0c667135
commit
0556afaf98
4 changed files with 42 additions and 27 deletions
|
@ -146,7 +146,6 @@ public:
|
|||
QUndoGroup editGroup; // Manages the undo history for each map
|
||||
|
||||
bool selectingEvent = false;
|
||||
bool editingConnections = false;
|
||||
|
||||
void shouldReselectEvents();
|
||||
void scaleMapView(int);
|
||||
|
@ -166,7 +165,7 @@ private:
|
|||
void setBorderItemsVisible(bool, qreal = 1);
|
||||
void setConnectionEditControlValues(MapConnection*);
|
||||
void setConnectionEditControlsEnabled(bool);
|
||||
void setConnectionHighlights(bool);
|
||||
void setConnectionsEditable(bool);
|
||||
void createConnectionItem(MapConnection* connection, bool hide);
|
||||
void populateConnectionMapPickers();
|
||||
void setDiveEmergeControls();
|
||||
|
|
|
@ -29,6 +29,9 @@ public:
|
|||
void render(qreal opacity = 1);
|
||||
int getMinOffset();
|
||||
int getMaxOffset();
|
||||
void setEditable(bool editable);
|
||||
bool getEditable();
|
||||
void updateHighlight(bool selected);
|
||||
|
||||
protected:
|
||||
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
|
||||
|
|
|
@ -95,8 +95,7 @@ void Editor::setEditingMap() {
|
|||
}
|
||||
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionHighlights(false);
|
||||
this->editingConnections = false;
|
||||
setConnectionsEditable(false);
|
||||
this->cursorMapTileRect->stopSingleTileMode();
|
||||
this->cursorMapTileRect->setActive(true);
|
||||
|
||||
|
@ -119,8 +118,7 @@ void Editor::setEditingCollision() {
|
|||
}
|
||||
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionHighlights(false);
|
||||
this->editingConnections = false;
|
||||
setConnectionsEditable(false);
|
||||
this->cursorMapTileRect->setSingleTileMode();
|
||||
this->cursorMapTileRect->setActive(true);
|
||||
|
||||
|
@ -143,8 +141,7 @@ void Editor::setEditingObjects() {
|
|||
}
|
||||
setBorderItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionItemsVisible(ui->checkBox_ToggleBorder->isChecked());
|
||||
setConnectionHighlights(false);
|
||||
this->editingConnections = false;
|
||||
setConnectionsEditable(false);
|
||||
this->cursorMapTileRect->setSingleTileMode();
|
||||
this->cursorMapTileRect->setActive(false);
|
||||
|
||||
|
@ -192,8 +189,7 @@ void Editor::setEditingConnections() {
|
|||
}
|
||||
setBorderItemsVisible(true, 0.4);
|
||||
setConnectionItemsVisible(true);
|
||||
setConnectionHighlights(true);
|
||||
this->editingConnections = true;
|
||||
setConnectionsEditable(true);
|
||||
this->cursorMapTileRect->setSingleTileMode();
|
||||
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) {
|
||||
bool isSelectedItem = item == selected_connection_item;
|
||||
int zValue = (isSelectedItem || !enabled) ? 0 : -1;
|
||||
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);
|
||||
}
|
||||
item->setEditable(editable);
|
||||
item->updateHighlight(item == selected_connection_item);
|
||||
}
|
||||
}
|
||||
|
||||
void Editor::onConnectionItemSelected(ConnectionPixmapItem* connectionItem) {
|
||||
selected_connection_item = connectionItem;
|
||||
if (!selected_connection_item || !this->editingConnections)
|
||||
if (!connectionItem)
|
||||
return;
|
||||
|
||||
setConnectionHighlights(true);
|
||||
selected_connection_item = connectionItem;
|
||||
for (ConnectionPixmapItem* item : connection_items)
|
||||
item->updateHighlight(item == selected_connection_item);
|
||||
setConnectionEditControlsEnabled(true);
|
||||
setConnectionEditControlValues(selected_connection_item->connection);
|
||||
ui->spinBox_ConnectionOffset->setMaximum(selected_connection_item->getMaxOffset());
|
||||
|
|
|
@ -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 *) {
|
||||
if (!this->getEditable())
|
||||
return;
|
||||
emit connectionItemSelected(this);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue