From 9ea49664bb44b8f6755d3317fffa421fa40feef7 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 1 Apr 2020 14:24:12 -0400 Subject: [PATCH] Copy cable color when cloning cables with Ctrl+click. --- include/app/CableWidget.hpp | 1 + src/app/CableWidget.cpp | 11 +++++++---- src/app/PortWidget.cpp | 2 ++ src/app/RackWidget.cpp | 2 ++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/include/app/CableWidget.hpp b/include/app/CableWidget.hpp index 1d8490de..3267eb55 100644 --- a/include/app/CableWidget.hpp +++ b/include/app/CableWidget.hpp @@ -22,6 +22,7 @@ struct CableWidget : widget::OpaqueWidget { CableWidget(); ~CableWidget(); + void setNextCableColor(); bool isComplete(); /** Based on the input/output ports, re-creates the cable and removes/adds it to the Engine. */ void updateCable(); diff --git a/src/app/CableWidget.cpp b/src/app/CableWidget.cpp index 3f506166..588a393f 100644 --- a/src/app/CableWidget.cpp +++ b/src/app/CableWidget.cpp @@ -14,6 +14,13 @@ namespace app { CableWidget::CableWidget() { color = color::BLACK_TRANSPARENT; +} + +CableWidget::~CableWidget() { + setCable(NULL); +} + +void CableWidget::setNextCableColor() { if (!settings::cableColors.empty()) { int id = APP->scene->rack->nextCableColorId++; APP->scene->rack->nextCableColorId %= settings::cableColors.size(); @@ -21,10 +28,6 @@ CableWidget::CableWidget() { } } -CableWidget::~CableWidget() { - setCable(NULL); -} - bool CableWidget::isComplete() { return outputPort && inputPort; } diff --git a/src/app/PortWidget.cpp b/src/app/PortWidget.cpp index 3a8d1fb9..648d8ffa 100644 --- a/src/app/PortWidget.cpp +++ b/src/app/PortWidget.cpp @@ -193,6 +193,7 @@ void PortWidget::onDragStart(const event::DragStart& e) { CableWidget* topCw = APP->scene->rack->getTopCable(this); if (topCw) { cw = new CableWidget; + cw->color = topCw->color; cw->outputPort = topCw->outputPort; cw->updateCable(); } @@ -221,6 +222,7 @@ void PortWidget::onDragStart(const event::DragStart& e) { if (!cw) { // Create a new cable cw = new CableWidget; + cw->setNextCableColor(); if (type == engine::Port::OUTPUT) cw->outputPort = this; else diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index c8b9d28e..44f6741c 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -279,6 +279,8 @@ void RackWidget::fromJson(json_t* rootJ) { continue; 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->fromJson(cableJ); addCable(cw);