diff --git a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml index e39416d31..eb2288dea 100644 --- a/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml +++ b/qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml @@ -58,6 +58,40 @@ Rectangle } } + ColorTool + { + id: colorTool + x: -width - (UISettings.iconSizeDefault * 1.25) + y: UISettings.bigItemHeight + visible: false + closeOnSelect: true + + property int colorIndex: -1 + property Item previewBtn + + function showTool(index, button) + { + colorIndex = index + previewBtn = button + currentRGB = rgbMatrixEditor.colorAtIndex(colorIndex) + visible = true + } + + function hide() + { + visible = false + colorIndex = -1 + previewBtn = null + } + + onColorChanged: + { + previewBtn.color = Qt.rgba(r, g, b, 1.0) + rgbMatrixEditor.setColorAtIndex(colorIndex, previewBtn.color) + } + onClose: visible = false + } + EditorTopBar { id: topBar @@ -273,7 +307,7 @@ Rectangle radius: 5 border.color: color1MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.color1 + color: rgbMatrixEditor.colorAtIndex(0) visible: rgbMatrixEditor.algoColors > 0 ? true : false MouseArea @@ -281,27 +315,23 @@ Rectangle id: color1MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color1Tool.visible = !color1Tool.visible - } - - ColorTool - { - id: color1Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color1 - - onColorChanged: + onClicked: { - color1Button.color = Qt.rgba(r, g, b, 1.0) - rgbMatrixEditor.color1 = color1Button.color + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(0, color1Button) } - onClose: visible = false } } + Rectangle + { + width: UISettings.listItemHeight + height: width + color: "transparent" + visible: rgbMatrixEditor.algoColors > 2 ? true : false + } + Rectangle { id: color2Button @@ -310,7 +340,7 @@ Rectangle radius: 5 border.color: color2MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor2 ? rgbMatrixEditor.color2 : "transparent" + color: rgbMatrixEditor.colorAtIndex(1) visible: rgbMatrixEditor.algoColors > 1 ? true : false MouseArea @@ -318,21 +348,13 @@ Rectangle id: color2MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color2Tool.visible = !color2Tool.visible - } - - ColorTool - { - id: color2Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color2 - - onColorChanged: rgbMatrixEditor.color2 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(1, color2Button) + } } } IconButton @@ -355,13 +377,14 @@ Rectangle spacing: 4 visible: rgbMatrixEditor.algoColors > 4 ? true : false - //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) Rectangle { id: colorRow1 height: editorColumn.itemsHeight + width: editorColumn.firstColumnWidth color: "transparent" visible: rgbMatrixEditor.algoColors > 4 ? true : false + onWidthChanged: { editorColumn.checkLabelWidth(width) @@ -377,7 +400,7 @@ Rectangle radius: 5 border.color: color3MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor3 ? rgbMatrixEditor.color3 : "transparent" + color: rgbMatrixEditor.colorAtIndex(2) visible: rgbMatrixEditor.algoColors > 2 ? true : false MouseArea @@ -385,21 +408,13 @@ Rectangle id: color3MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color3Tool.visible = !color3Tool.visible - } - - ColorTool - { - id: color3Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color3 - - onColorChanged: rgbMatrixEditor.color3 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(2, color3Button) + } } } IconButton @@ -419,7 +434,7 @@ Rectangle radius: 5 border.color: color4MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor4 ? rgbMatrixEditor.color4 : "transparent" + color: rgbMatrixEditor.colorAtIndex(3) visible: rgbMatrixEditor.algoColors > 3 ? true : false MouseArea @@ -427,21 +442,13 @@ Rectangle id: color4MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color4Tool.visible = !color4Tool.visible - } - - ColorTool - { - id: color4Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color4 - - onColorChanged: rgbMatrixEditor.color4 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(3, color4Button) + } } } IconButton @@ -464,11 +471,11 @@ Rectangle spacing: 4 visible: rgbMatrixEditor.algoColors > 4 ? true : false - //leftPadding: Qt.binding(function() { return editorColumn.firstColumnWidth }) Rectangle { id: colorRow2 height: editorColumn.itemsHeight + width: editorColumn.firstColumnWidth color: "transparent" visible: rgbMatrixEditor.algoColors > 4 ? true : false onWidthChanged: @@ -486,7 +493,7 @@ Rectangle radius: 5 border.color: color5MouseArea.containsMouse ? "white" : UISettings.bgLight border.width: 2 - color: rgbMatrixEditor.hasColor5 ? rgbMatrixEditor.color5 : "transparent" + color: rgbMatrixEditor.colorAtIndex(4) visible: rgbMatrixEditor.algoColors > 4 ? true : false MouseArea @@ -494,21 +501,13 @@ Rectangle id: color5MouseArea anchors.fill: parent hoverEnabled: true - onClicked: color5Tool.visible = !color5Tool.visible - } - - ColorTool - { - id: color5Tool - parent: rgbmeContainer - x: -width - (UISettings.iconSizeDefault * 1.25) - y: UISettings.bigItemHeight - visible: false - closeOnSelect: true - currentRGB: rgbMatrixEditor.color5 - - onColorChanged: rgbMatrixEditor.color5 = Qt.rgba(r, g, b, 1.0) - onClose: visible = false + onClicked: + { + if (colorTool.visible) + colorTool.hide() + else + colorTool.showTool(4, color5Button) + } } } IconButton diff --git a/qmlui/rgbmatrixeditor.cpp b/qmlui/rgbmatrixeditor.cpp index 81f555ed6..f115b13cb 100644 --- a/qmlui/rgbmatrixeditor.cpp +++ b/qmlui/rgbmatrixeditor.cpp @@ -162,180 +162,32 @@ int RGBMatrixEditor::algoColors() return m_matrix->algorithm()->acceptColors(); } -QColor RGBMatrixEditor::color1() const +QColor RGBMatrixEditor::colorAtIndex(int index) { - if (m_matrix == nullptr) - return Qt::red; - - return m_matrix->getColor(0); -} - -void RGBMatrixEditor::setColor1(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(0) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(0), algoColor); - m_matrix->setColor(0, algoColor); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - - emit color1Changed(algoColor); -} - -QColor RGBMatrixEditor::color2() const -{ - if (m_matrix == nullptr) + if (m_matrix == nullptr || m_matrix->algorithm() == nullptr) return QColor(); - return m_matrix->getColor(1); + return m_matrix->getColor(index); } -void RGBMatrixEditor::setColor2(QColor algoColor) +void RGBMatrixEditor::setColorAtIndex(int index, QColor color) { - if (m_matrix == nullptr || m_matrix->getColor(1) == algoColor) + if (m_matrix == nullptr || m_matrix->getColor(index) == color) return; - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor2, m_matrix->id(), m_matrix->getColor(1), algoColor); - m_matrix->setColor(1, algoColor); + Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor1, m_matrix->id(), m_matrix->getColor(index), color); + m_matrix->setColor(index, color); m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - - emit color2Changed(algoColor); - if (algoColor.isValid()) - emit hasColor2Changed(true); -} - -QColor RGBMatrixEditor::color3() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(2); -} - -void RGBMatrixEditor::setColor3(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(2) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor3, m_matrix->id(), m_matrix->getColor(2), algoColor); - m_matrix->setColor(2, algoColor); - - emit color3Changed(algoColor); - if (algoColor.isValid()) - emit hasColor3Changed(true); -} - -QColor RGBMatrixEditor::color4() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(3); -} - -void RGBMatrixEditor::setColor4(QColor algoColor) -{ - if (m_matrix == nullptr || m_matrix->getColor(3) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor4, m_matrix->id(), m_matrix->getColor(3), algoColor); - m_matrix->setColor(3, algoColor); - - emit color4Changed(algoColor); - if (algoColor.isValid()) - emit hasColor4Changed(true); -} - -QColor RGBMatrixEditor::color5() const -{ - if (m_matrix == nullptr) - return QColor(); - - return m_matrix->getColor(4); } -void RGBMatrixEditor::setColor5(QColor algoColor) +bool RGBMatrixEditor::hasColorAtIndex(int index) { - if (m_matrix == nullptr || m_matrix->getColor(4) == algoColor) - return; - - Tardis::instance()->enqueueAction(Tardis::RGBMatrixSetColor5, m_matrix->id(), m_matrix->getColor(4), algoColor); - m_matrix->setColor(4, algoColor); - - emit color5Changed(algoColor); - if (algoColor.isValid()) - emit hasColor5Changed(true); -} - -bool RGBMatrixEditor::hasColor2() const -{ - if (m_matrix == nullptr || m_matrix->getColor(1).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor2(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(1, QColor()); - m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm()); - } - emit hasColor2Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor3() const -{ - if (m_matrix == nullptr || m_matrix->getColor(2).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor3(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(2, QColor()); - } - emit hasColor3Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor4() const -{ - if (m_matrix == nullptr || m_matrix->getColor(3).isValid() == false) - return false; - - return true; -} - -void RGBMatrixEditor::setHasColor4(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(3, QColor()); - } - emit hasColor4Changed(hasColor); -} - -bool RGBMatrixEditor::hasColor5() const -{ - if (m_matrix == nullptr || m_matrix->getColor(4).isValid() == false) + if (m_matrix == nullptr || m_matrix->getColor(index).isValid() == false) return false; return true; } -void RGBMatrixEditor::setHasColor5(bool hasColor) -{ - if (m_matrix && hasColor == false) - { - m_matrix->setColor(4, QColor()); - } - emit hasColor5Changed(hasColor); -} - QString RGBMatrixEditor::algoText() const { if (m_matrix != nullptr && m_matrix->algorithm() != nullptr && diff --git a/qmlui/rgbmatrixeditor.h b/qmlui/rgbmatrixeditor.h index 711a5a8d2..22cd6009c 100644 --- a/qmlui/rgbmatrixeditor.h +++ b/qmlui/rgbmatrixeditor.h @@ -39,15 +39,6 @@ class RGBMatrixEditor : public FunctionEditor Q_PROPERTY(QStringList algorithms READ algorithms CONSTANT) Q_PROPERTY(int algorithmIndex READ algorithmIndex WRITE setAlgorithmIndex NOTIFY algorithmIndexChanged) Q_PROPERTY(int algoColors READ algoColors NOTIFY algoColorsChanged) - Q_PROPERTY(QColor color1 READ color1 WRITE setColor1 NOTIFY color1Changed) - Q_PROPERTY(QColor color2 READ color2 WRITE setColor2 NOTIFY color2Changed) - Q_PROPERTY(bool hasColor2 READ hasColor2 WRITE setHasColor2 NOTIFY hasColor2Changed) - Q_PROPERTY(QColor color3 READ color3 WRITE setColor3 NOTIFY color3Changed) - Q_PROPERTY(bool hasColor3 READ hasColor3 WRITE setHasColor3 NOTIFY hasColor3Changed) - Q_PROPERTY(QColor color4 READ color4 WRITE setColor4 NOTIFY color4Changed) - Q_PROPERTY(bool hasColor4 READ hasColor4 WRITE setHasColor4 NOTIFY hasColor4Changed) - Q_PROPERTY(QColor color5 READ color5 WRITE setColor5 NOTIFY color5Changed) - Q_PROPERTY(bool hasColor5 READ hasColor5 WRITE setHasColor5 NOTIFY hasColor5Changed) Q_PROPERTY(int blendMode READ blendMode WRITE setBlendMode NOTIFY blendModeChanged) Q_PROPERTY(int controlMode READ controlMode WRITE setControlMode NOTIFY controlModeChanged) @@ -93,37 +84,9 @@ class RGBMatrixEditor : public FunctionEditor /** Return the accepted colors of the current algorithm */ int algoColors(); - /** Get/set the color 1 of the current algorithm */ - QColor color1() const; - void setColor1(QColor algoColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color2() const; - void setColor2(QColor algoColor); - - bool hasColor2() const; - void setHasColor2(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color3() const; - void setColor3(QColor algoColor); - - bool hasColor3() const; - void setHasColor3(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color4() const; - void setColor4(QColor algoColor); - - bool hasColor4() const; - void setHasColor4(bool hasColor); - - /** Get/set the color 2 of the current algorithm */ - QColor color5() const; - void setColor5(QColor algoColor); - - bool hasColor5() const; - void setHasColor5(bool hasColor); + Q_INVOKABLE QColor colorAtIndex(int index); + Q_INVOKABLE void setColorAtIndex(int index, QColor color); + Q_INVOKABLE bool hasColorAtIndex(int index); QString algoText() const; void setAlgoText(QString text); @@ -157,15 +120,6 @@ class RGBMatrixEditor : public FunctionEditor signals: void algorithmIndexChanged(); void algoColorsChanged(); - void color1Changed(QColor color); - void color2Changed(QColor color); - void hasColor2Changed(bool hasColor); - void color3Changed(QColor color); - void hasColor3Changed(bool hasColor); - void color4Changed(QColor color); - void hasColor4Changed(bool hasColor); - void color5Changed(QColor color); - void hasColor5Changed(bool hasColor); void algoTextChanged(QString text); void algoTextFontChanged(QFont algoTextFont);