| @@ -22,6 +22,7 @@ struct CableWidget : widget::OpaqueWidget { | |||||
| CableWidget(); | CableWidget(); | ||||
| ~CableWidget(); | ~CableWidget(); | ||||
| void setNextCableColor(); | |||||
| bool isComplete(); | bool isComplete(); | ||||
| /** Based on the input/output ports, re-creates the cable and removes/adds it to the Engine. */ | /** Based on the input/output ports, re-creates the cable and removes/adds it to the Engine. */ | ||||
| void updateCable(); | void updateCable(); | ||||
| @@ -14,6 +14,13 @@ namespace app { | |||||
| CableWidget::CableWidget() { | CableWidget::CableWidget() { | ||||
| color = color::BLACK_TRANSPARENT; | color = color::BLACK_TRANSPARENT; | ||||
| } | |||||
| CableWidget::~CableWidget() { | |||||
| setCable(NULL); | |||||
| } | |||||
| void CableWidget::setNextCableColor() { | |||||
| if (!settings::cableColors.empty()) { | if (!settings::cableColors.empty()) { | ||||
| int id = APP->scene->rack->nextCableColorId++; | int id = APP->scene->rack->nextCableColorId++; | ||||
| APP->scene->rack->nextCableColorId %= settings::cableColors.size(); | APP->scene->rack->nextCableColorId %= settings::cableColors.size(); | ||||
| @@ -21,10 +28,6 @@ CableWidget::CableWidget() { | |||||
| } | } | ||||
| } | } | ||||
| CableWidget::~CableWidget() { | |||||
| setCable(NULL); | |||||
| } | |||||
| bool CableWidget::isComplete() { | bool CableWidget::isComplete() { | ||||
| return outputPort && inputPort; | return outputPort && inputPort; | ||||
| } | } | ||||
| @@ -193,6 +193,7 @@ void PortWidget::onDragStart(const event::DragStart& e) { | |||||
| CableWidget* topCw = APP->scene->rack->getTopCable(this); | CableWidget* topCw = APP->scene->rack->getTopCable(this); | ||||
| if (topCw) { | if (topCw) { | ||||
| cw = new CableWidget; | cw = new CableWidget; | ||||
| cw->color = topCw->color; | |||||
| cw->outputPort = topCw->outputPort; | cw->outputPort = topCw->outputPort; | ||||
| cw->updateCable(); | cw->updateCable(); | ||||
| } | } | ||||
| @@ -221,6 +222,7 @@ void PortWidget::onDragStart(const event::DragStart& e) { | |||||
| if (!cw) { | if (!cw) { | ||||
| // Create a new cable | // Create a new cable | ||||
| cw = new CableWidget; | cw = new CableWidget; | ||||
| cw->setNextCableColor(); | |||||
| if (type == engine::Port::OUTPUT) | if (type == engine::Port::OUTPUT) | ||||
| cw->outputPort = this; | cw->outputPort = this; | ||||
| else | else | ||||
| @@ -279,6 +279,8 @@ void RackWidget::fromJson(json_t* rootJ) { | |||||
| continue; | continue; | ||||
| CableWidget* cw = new CableWidget; | CableWidget* cw = new CableWidget; | ||||
| // Legacy: Before v1, cable colors were not serialized. So we need to initialize the color here. | |||||
| cw->setNextCableColor(); | |||||
| cw->setCable(cable); | cw->setCable(cable); | ||||
| cw->fromJson(cableJ); | cw->fromJson(cableJ); | ||||
| addCable(cw); | addCable(cw); | ||||