Skip to content

Commit

Permalink
qmlui: fix RGBMatrix color reset
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Dec 30, 2024
1 parent a53cc94 commit 4d99a82
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
40 changes: 27 additions & 13 deletions qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -362,11 +362,14 @@ Rectangle
width: UISettings.listItemHeight
height: width
imgSource: "qrc:/cancel.svg"
tooltip: qsTr("Reset color 2")
visible: rgbMatrixEditor.algoColors > 1 ? true : false
onClicked: rgbMatrixEditor.hasColor2 = false
onClicked:
{
color2Button.color = "transparent"
rgbMatrixEditor.resetColorAtIndex(1)
}
}
// filler
//Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" }
}

// row 7
Expand Down Expand Up @@ -400,7 +403,7 @@ Rectangle
radius: 5
border.color: color3MouseArea.containsMouse ? "white" : UISettings.bgLight
border.width: 2
color: rgbMatrixEditor.colorAtIndex(2)
color: rgbMatrixEditor.hasColorAtIndex(2) ? rgbMatrixEditor.colorAtIndex(2) : "transparent"
visible: rgbMatrixEditor.algoColors > 2 ? true : false

MouseArea
Expand All @@ -422,8 +425,13 @@ Rectangle
width: UISettings.listItemHeight
height: width
imgSource: "qrc:/cancel.svg"
tooltip: qsTr("Reset color 3")
visible: rgbMatrixEditor.algoColors > 2 ? true : false
onClicked: rgbMatrixEditor.hasColor3 = false
onClicked:
{
color3Button.color = "transparent"
rgbMatrixEditor.resetColorAtIndex(2)
}
}

Rectangle
Expand All @@ -434,7 +442,7 @@ Rectangle
radius: 5
border.color: color4MouseArea.containsMouse ? "white" : UISettings.bgLight
border.width: 2
color: rgbMatrixEditor.colorAtIndex(3)
color: rgbMatrixEditor.hasColorAtIndex(3) ? rgbMatrixEditor.colorAtIndex(3) : "transparent"
visible: rgbMatrixEditor.algoColors > 3 ? true : false

MouseArea
Expand All @@ -456,11 +464,14 @@ Rectangle
width: UISettings.listItemHeight
height: width
imgSource: "qrc:/cancel.svg"
tooltip: qsTr("Reset color 4")
visible: rgbMatrixEditor.algoColors > 3 ? true : false
onClicked: rgbMatrixEditor.hasColor4 = false
onClicked:
{
color4Button.color = "transparent"
rgbMatrixEditor.resetColorAtIndex(3)
}
}
// filler
//Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" }
}

// row 8
Expand Down Expand Up @@ -493,7 +504,7 @@ Rectangle
radius: 5
border.color: color5MouseArea.containsMouse ? "white" : UISettings.bgLight
border.width: 2
color: rgbMatrixEditor.colorAtIndex(4)
color: rgbMatrixEditor.hasColorAtIndex(4) ? rgbMatrixEditor.colorAtIndex(4) : "transparent"
visible: rgbMatrixEditor.algoColors > 4 ? true : false

MouseArea
Expand All @@ -515,11 +526,14 @@ Rectangle
width: UISettings.listItemHeight
height: width
imgSource: "qrc:/cancel.svg"
tooltip: qsTr("Reset color 5")
visible: rgbMatrixEditor.algoColors > 4 ? true : false
onClicked: rgbMatrixEditor.hasColor5 = false
onClicked:
{
color5Button.color = "transparent"
rgbMatrixEditor.resetColorAtIndex(4)
}
}
// filler
//Rectangle { Layout.fillWidth: true; height: parent.height; color: "transparent" }
}

SectionBox
Expand Down
14 changes: 13 additions & 1 deletion qmlui/rgbmatrixeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ void RGBMatrixEditor::setAlgorithmIndex(int algoIndex)
/** if we're setting the same algorithm, then there's nothing to do */
if (m_matrix->algorithm() != nullptr && m_matrix->algorithm()->name() == algo->name())
return;

Q_ASSERT(5 == RGBAlgorithmColorDisplayCount);
QVector<QColor> colors = {
m_matrix->getColor(0),
Expand Down Expand Up @@ -177,7 +178,18 @@ void RGBMatrixEditor::setColorAtIndex(int index, QColor color)

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());
if (index < 2)
m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm());
}

void RGBMatrixEditor::resetColorAtIndex(int index)
{
if (m_matrix == nullptr || m_matrix->getColor(index).isValid() == false)
return;

m_matrix->setColor(index, QColor());
if (index < 2)
m_previewStepHandler->calculateColorDelta(m_matrix->getColor(0), m_matrix->getColor(1), m_matrix->algorithm());
}

bool RGBMatrixEditor::hasColorAtIndex(int index)
Expand Down
1 change: 1 addition & 0 deletions qmlui/rgbmatrixeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class RGBMatrixEditor : public FunctionEditor

Q_INVOKABLE QColor colorAtIndex(int index);
Q_INVOKABLE void setColorAtIndex(int index, QColor color);
Q_INVOKABLE void resetColorAtIndex(int index);
Q_INVOKABLE bool hasColorAtIndex(int index);

QString algoText() const;
Expand Down

0 comments on commit 4d99a82

Please sign in to comment.