From 1e81b78b6e28cd615a38f9c04a16c76b1a2f58f2 Mon Sep 17 00:00:00 2001 From: Rodney Date: Mar 18 2021 17:59:20 +0000 Subject: Merge pull request #3782 from shun-iwasawa/fix_alt_drag_fx_insertion Fix Alt-drag Fx Node Insertion --- diff --git a/toonz/sources/toonzqt/fxschematicscene.cpp b/toonz/sources/toonzqt/fxschematicscene.cpp index 533b260..2707d59 100644 --- a/toonz/sources/toonzqt/fxschematicscene.cpp +++ b/toonz/sources/toonzqt/fxschematicscene.cpp @@ -490,7 +490,7 @@ void FxSchematicScene::updateEditedGroups( const QMap> &editedGroup) { QMap>::const_iterator it; for (it = editedGroup.begin(); it != editedGroup.end(); it++) { - int zValue = 2; + int zValue = 2; QMap>::const_iterator it2 = editedGroup.begin(); while (it2 != editedGroup.end()) { FxSchematicNode *placedFxNode = @@ -626,7 +626,7 @@ void FxSchematicScene::updatePosition(FxSchematicNode *node, //------------------------------------------------------------------ /*! create node depends on the fx type -*/ + */ FxSchematicNode *FxSchematicScene::createFxSchematicNode(TFx *fx) { if (TLevelColumnFx *lcFx = dynamic_cast(fx)) return new FxSchematicColumnNode(this, lcFx); @@ -644,7 +644,7 @@ FxSchematicNode *FxSchematicScene::createFxSchematicNode(TFx *fx) { //------------------------------------------------------------------ /*! place nodes of which positions are not specified manually -*/ + */ void FxSchematicScene::placeNode(FxSchematicNode *node) { if (!node) return; int step = m_gridDimension == eLarge ? 100 : 50; @@ -872,7 +872,7 @@ void FxSchematicScene::updateLink() { } TZeraryColumnFx *zfx = dynamic_cast(fx); - if (zfx) fx = zfx->getZeraryFx(); + if (zfx) fx = zfx->getZeraryFx(); if (fx) { int j; for (j = 0; j < fx->getInputPortCount(); j++) { @@ -1026,7 +1026,7 @@ QPointF FxSchematicScene::nearestPoint(const QPointF &point) { if (item) return rect.bottomRight(); item = itemAt(rect.topLeft()); if (item) return rect.topLeft(); - item = itemAt(rect.topRight()); + item = itemAt(rect.topRight()); #endif if (item) return rect.topRight(); return QPointF(); @@ -1471,8 +1471,8 @@ void FxSchematicScene::setEnableCache(bool toggle) { for (int i = 0; i < selectedFxs.size(); i++) { TFx *fx = selectedFxs[i].getPointer(); TZeraryColumnFx *zcfx = dynamic_cast(fx); - if (zcfx) fx = zcfx->getZeraryFx(); - TFxAttributes *attr = fx->getAttributes(); + if (zcfx) fx = zcfx->getZeraryFx(); + TFxAttributes *attr = fx->getAttributes(); if (!attr->isGrouped() || attr->isGroupEditing()) { if (toggle) { TPassiveCacheManager::instance()->enableCache(fx); @@ -1490,9 +1490,9 @@ void FxSchematicScene::setEnableCache(bool toggle) { TPassiveCacheManager::instance()->enableCache(fx); } else { TPassiveCacheManager::instance()->disableCache(fx); - } - } - } + } + } + } group->update(); } } @@ -1589,7 +1589,7 @@ void FxSchematicScene::mousePressEvent(QGraphicsSceneMouseEvent *me) { #if QT_VERSION >= 0x050000 QGraphicsItem *item = itemAt(me->scenePos(), QTransform()); #else - QGraphicsItem *item = itemAt(me->scenePos()); + QGraphicsItem *item = itemAt(me->scenePos()); #endif FxSchematicPort *port = dynamic_cast(item); FxSchematicLink *link = dynamic_cast(item); @@ -1646,7 +1646,7 @@ void FxSchematicScene::mouseMoveEvent(QGraphicsSceneMouseEvent *me) { SchematicLink *link = dynamic_cast(itemAt(m_lastPos, QTransform())); #else - SchematicLink *link = dynamic_cast(itemAt(m_lastPos)); + SchematicLink *link = dynamic_cast(itemAt(m_lastPos)); #endif if (link && (link->getEndPort() && link->getStartPort())) { TFxCommand::Link fxLink = m_selection->getBoundingFxs(link); @@ -1710,8 +1710,8 @@ void FxSchematicScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *me) { if (port == outputNode->getInputPort(i)) break; TFxCommand::Link fxLink; - fxLink.m_outputFx = outputNode->getFx(); - fxLink.m_inputFx = inputNode->getFx(); + fxLink.m_outputFx = outputNode->getFx(); + fxLink.m_inputFx = inputNode->getFx(); if (!outputNode->isA(eXSheetFx)) fxLink.m_index = i; TFxCommand::connectFxs(fxLink, m_selection->getFxs().toStdList(), @@ -1880,7 +1880,7 @@ void FxSchematicScene::simulateDisconnectSelection(bool disconnect) { if (selectedFxs.isEmpty()) return; QMap visitedFxs; int i; - for (i = 0; i < selectedFxs.size(); i++) + for (i = 0; i < selectedFxs.size(); i++) visitedFxs[selectedFxs[i].getPointer()] = false; TFx *inputFx = 0, *outputFx = 0; @@ -1935,61 +1935,62 @@ void FxSchematicScene::simulateDisconnectSelection(bool disconnect) { void FxSchematicScene::simulateInsertSelection(SchematicLink *link, bool connect) { - if (!link || !connect) { - m_connectionLinks.showBridgeLinks(); - m_connectionLinks.hideInputLinks(); - m_connectionLinks.hideOutputLinks(); - m_connectionLinks.removeBridgeLinks(); - m_connectionLinks.removeInputLinks(true); - m_connectionLinks.removeOutputLinks(true); - } else { - if (m_disconnectionLinks.isABridgeLink(link) || m_selection->isEmpty()) - return; + // first, remove all connected links + m_connectionLinks.showBridgeLinks(); + m_connectionLinks.hideInputLinks(); + m_connectionLinks.hideOutputLinks(); + m_connectionLinks.removeBridgeLinks(); + m_connectionLinks.removeInputLinks(true); + m_connectionLinks.removeOutputLinks(true); + if (!link || !connect) return; + + if (m_disconnectionLinks.isABridgeLink(link) || m_selection->isEmpty()) + return; - m_connectionLinks.addBridgeLink(link); - m_connectionLinks.hideBridgeLinks(); + m_connectionLinks.addBridgeLink(link); + m_connectionLinks.hideBridgeLinks(); - SchematicPort *inputPort = 0, *outputPort = 0; - if (link) { - if (link->getStartPort()->getType() == eFxInputPort) { - inputPort = link->getStartPort(); - outputPort = link->getEndPort(); - } else { - inputPort = link->getEndPort(); - outputPort = link->getStartPort(); - } + SchematicPort *inputPort = 0, *outputPort = 0; + if (link) { + if (link->getStartPort()->getType() == eFxInputPort) { + inputPort = link->getStartPort(); + outputPort = link->getEndPort(); + } else { + inputPort = link->getEndPort(); + outputPort = link->getStartPort(); } + } - QMap visitedFxs; - QList selectedFxs = m_selection->getFxs(); - if (selectedFxs.isEmpty()) return; - int i; - for (i = 0; i < selectedFxs.size(); i++) - visitedFxs[selectedFxs[i].getPointer()] = false; - - TFx *inputFx = 0, *outputFx = 0; - findBoundariesFxs(inputFx, outputFx, visitedFxs); - FxSchematicNode *inputNode = m_table[inputFx]; - FxSchematicNode *outputNode = m_table[outputFx]; - assert(inputNode && outputNode); - - if (inputNode->getInputPortCount() > 0) { - SchematicPort *inputNodePort = inputNode->getInputPort(0); - if (inputNodePort && outputPort) - m_connectionLinks.addInputLink(inputNodePort->makeLink(outputPort)); - } + QMap visitedFxs; + QList selectedFxs = m_selection->getFxs(); + if (selectedFxs.isEmpty()) return; + int i; + for (i = 0; i < selectedFxs.size(); i++) + visitedFxs[selectedFxs[i].getPointer()] = false; + + TFx *inputFx = 0, *outputFx = 0; + findBoundariesFxs(inputFx, outputFx, visitedFxs); + FxSchematicNode *inputNode = m_table[inputFx]; + FxSchematicNode *outputNode = m_table[outputFx]; + assert(inputNode && outputNode); + + if (inputNode->getInputPortCount() > 0) { + SchematicPort *inputNodePort = inputNode->getInputPort(0); + if (inputNodePort && outputPort) + m_connectionLinks.addInputLink(inputNodePort->makeLink(outputPort)); + } - SchematicPort *outputNodePort = outputNode->getOutputPort(); - if (outputNodePort && inputPort) - m_connectionLinks.addOutputLink(inputPort->makeLink(outputNodePort)); + SchematicPort *outputNodePort = outputNode->getOutputPort(); + if (outputNodePort && inputPort) + m_connectionLinks.addOutputLink(inputPort->makeLink(outputNodePort)); - m_connectionLinks.showInputLinks(); - m_connectionLinks.showOutputLinks(); - } + m_connectionLinks.showInputLinks(); + m_connectionLinks.showOutputLinks(); } + //------------------------------------------------------------ /*! in order to select nods after pasting the copied fx nodes from FxSelection -*/ + */ void FxSchematicScene::selectNodes(QList &fxs) { clearSelection(); for (int i = 0; i < (int)fxs.size(); i++) { @@ -2021,7 +2022,7 @@ void FxSchematicScene::updateNestedGroupEditors(FxSchematicNode *node, #if QT_VERSION >= 0x050000 rect = rect.united(app); #else - rect = rect.unite(app); + rect = rect.unite(app); #endif } } @@ -2035,7 +2036,7 @@ void FxSchematicScene::updateNestedGroupEditors(FxSchematicNode *node, #if QT_VERSION >= 0x050000 rect = rect.united(app); #else - rect = rect.unite(app); + rect = rect.unite(app); #endif } } @@ -2046,7 +2047,7 @@ void FxSchematicScene::updateNestedGroupEditors(FxSchematicNode *node, rect = rect.united(m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect()); #else - rect = rect.unite(m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect()); + rect = rect.unite(m_groupEditorTable[groupIdStack[i]]->sceneBoundingRect()); #endif QRectF app = m_groupEditorTable[groupIdStack[i]]->boundingSceneRect(); if (m_groupEditorTable[groupIdStack[i]]->scenePos() != app.topLeft()) @@ -2059,7 +2060,7 @@ void FxSchematicScene::updateNestedGroupEditors(FxSchematicNode *node, #if QT_VERSION >= 0x050000 rect = rect.united(app); #else - rect = rect.unite(app); + rect = rect.unite(app); #endif app = editor->boundingSceneRect(); if (editor->scenePos() != app.topLeft()) editor->setPos(app.topLeft());