Skip to content

Commit

Permalink
qmlui: improve RGBMatrix editor code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Dec 30, 2024
1 parent 0cc5540 commit a53cc94
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 290 deletions.
167 changes: 83 additions & 84 deletions qmlui/qml/fixturesfunctions/RGBMatrixEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -273,35 +307,31 @@ 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
{
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
Expand All @@ -310,29 +340,21 @@ 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
{
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
Expand All @@ -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)
Expand All @@ -377,29 +400,21 @@ 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
{
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
Expand All @@ -419,29 +434,21 @@ 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
{
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
Expand All @@ -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:
Expand All @@ -486,29 +493,21 @@ 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
{
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
Expand Down
Loading

0 comments on commit a53cc94

Please sign in to comment.