|
31 | 31 | #include "UndoCommands/DeleteComponentCommand.h"
|
32 | 32 | #include "UndoCommands/MoveComponentCommand.h"
|
33 | 33 | #include "UndoCommands/SelectComponentCommand.h"
|
| 34 | +#include "UndoCommands/LinkPinCommand.h" |
| 35 | +#include "UndoCommands/UnlinkPinCommand.h" |
34 | 36 | #include "AudioSettings.h"
|
35 | 37 |
|
36 | 38 | // JSON keys
|
@@ -69,13 +71,56 @@ NodeItem* NodalScene::createComponent(QString _componentName, qreal _width)
|
69 | 71 | {
|
70 | 72 | m_creationPosition = m_contextPosition;
|
71 | 73 | }
|
72 |
| - qDebug() << "Create Component"; |
| 74 | + qDebug() << "Create Component: " << _componentName; |
73 | 75 | NodeItem* item = createNode(_componentName, _width);
|
74 | 76 | m_creationPosition += QPoint(20, 20);
|
75 | 77 | setDirty();
|
76 | 78 | return item;
|
77 | 79 | }
|
78 | 80 |
|
| 81 | +NodeItem* NodalScene::createPassThrough(LinkItem* _link) |
| 82 | +{ |
| 83 | + Q_ASSERT(_link->firstPin() != nullptr && _link->secondPin() != nullptr); |
| 84 | + |
| 85 | + PinInputItem* pinIn = nullptr; |
| 86 | + PinOutputItem* pinOut = nullptr; |
| 87 | + if (qgraphicsitem_cast<PinInputItem*>(_link->firstPin()) != nullptr) |
| 88 | + { |
| 89 | + pinIn = qgraphicsitem_cast<PinInputItem*>(_link->firstPin()); |
| 90 | + pinOut = qgraphicsitem_cast<PinOutputItem*>(_link->secondPin()); |
| 91 | + } |
| 92 | + else |
| 93 | + { |
| 94 | + pinIn = qgraphicsitem_cast<PinInputItem*>(_link->secondPin()); |
| 95 | + pinOut = qgraphicsitem_cast<PinOutputItem*>(_link->firstPin()); |
| 96 | + } |
| 97 | + |
| 98 | + Q_ASSERT(pinIn != nullptr && pinOut != nullptr); |
| 99 | + |
| 100 | + QPointF tmp = m_creationPosition; |
| 101 | + if(m_isContextMenu) |
| 102 | + { |
| 103 | + m_creationPosition = m_contextPosition; |
| 104 | + } |
| 105 | + else |
| 106 | + { |
| 107 | + m_creationPosition = 0.5 * (pinIn->pos() + pinOut->pos()); |
| 108 | + } |
| 109 | + |
| 110 | + qDebug() << "Create PassThrough"; |
| 111 | + |
| 112 | + m_undoStack->beginMacro("Create PassThrough"); |
| 113 | + NodeItem* item = createNode("PassThrough", 20); |
| 114 | + m_undoStack->push(new UnlinkPinCommand(this, pinOut, pinIn)); |
| 115 | + m_undoStack->push(new LinkPinCommand(this, pinOut, item->getInput(0))); |
| 116 | + m_undoStack->push(new LinkPinCommand(this, item->getOutput(), pinIn)); |
| 117 | + m_undoStack->endMacro(); |
| 118 | + setDirty(); |
| 119 | + |
| 120 | + m_creationPosition = tmp; |
| 121 | + return item; |
| 122 | +} |
| 123 | + |
79 | 124 | void NodalScene::addNodeItem(NodeItem *_item)
|
80 | 125 | {
|
81 | 126 | addItem(_item);
|
@@ -234,7 +279,6 @@ void NodalScene::reset()
|
234 | 279 | m_nodeList[0]->setSelected(false);
|
235 | 280 | }
|
236 | 281 |
|
237 |
| - |
238 | 282 | int NodalScene::deleteSelection()
|
239 | 283 | {
|
240 | 284 | int nbRemoved = 0;
|
@@ -387,7 +431,6 @@ void NodalScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
387 | 431 | }
|
388 | 432 | }
|
389 | 433 |
|
390 |
| - |
391 | 434 | void NodalScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
|
392 | 435 | {
|
393 | 436 | QGraphicsScene::mouseReleaseEvent(event);
|
|
0 commit comments