Index: sources/gui/qml/components/GridSelection.qml =================================================================== diff -u -reefe8acbe5b10deb379c5e4ceabeaa95d429410e -r73091a6f5717c0fc88e236c06c618ad361f30a3c --- sources/gui/qml/components/GridSelection.qml (.../GridSelection.qml) (revision eefe8acbe5b10deb379c5e4ceabeaa95d429410e) +++ sources/gui/qml/components/GridSelection.qml (.../GridSelection.qml) (revision 73091a6f5717c0fc88e236c06c618ad361f30a3c) @@ -35,73 +35,45 @@ property int numCols : 2 property int buttonHeight : Variables.gridSelectionButtonHeight property int buttonWidth : Variables.gridSelectionButtonWidth - property var buttonNames : ["Button 1", "Button 2", "Button 3"] + property var buttonNames : [] property alias name : _text.text - property int selectedIndex : unselectedIndex - property int unselectedIndex : 9999 - height: numRows * buttonHeight - width: numCols * buttonWidth - signal buttonClicked() + property int selectedIndex : -1 + height : numRows * buttonHeight + width : numCols * buttonWidth - function setValid(valid) { - if (valid) { - _text.color = Colors.textMain - } else { - _text.color = Colors.textInvalid - } - } + signal buttonClicked(int vIndex) - function setActive(active) { - if (!active) { - for (let i = 0; i < _repeater.count; i++) { - _repeater.itemAt(i).setSelected(false) - } - selectedIndex = unselectedIndex - } - } - - Text { - id: _text - text: "Title" + Text { id: _text + text : "Title" + color : Colors.textMain; font.pixelSize: Fonts.fontPixelFluidText - color: Colors.textMain; } - Grid { - id: _grid - anchors.top: _text.bottom - anchors.topMargin: Variables.sliderTextMargin - rows: parent.numRows - columns: parent.numCols - + Grid { id: _grid + spacing: 5 + anchors { + top : _text.bottom + topMargin : Variables.sliderTextMargin + } + rows : parent.numRows + columns : parent.numCols Repeater { id: _repeater model: buttonNames - TouchRect { - id: _touchRect - objectName: _root.objectName + index - text.text: modelData; - selectable: true - height: _root.buttonHeight - width: _root.buttonWidth - radius: 0 - borderColor: Colors.borderButtonUnselected + TouchRect { id : _touchRect + objectName : _root.objectName + index + text.text : modelData + selectable : true + height : _root.buttonHeight + width : _root.buttonWidth + radius : 5 + Binding on selected { + when : _root.selectedIndex > -1 + value : index === _root.selectedIndex + } onClicked: { - _text.color = Colors.textMain - if (selectedIndex === index) { - _repeater.itemAt(index).setSelected(false) - selectedIndex = unselectedIndex - } else { - _repeater.itemAt(index).setSelected(true) - selectedIndex = index - } - - for (let j = 0; j < _repeater.count; j += 1) { - if (index !== j) { - _repeater.itemAt(j).setSelected(false) - } - } - buttonClicked() + _root.selectedIndex = index + buttonClicked(index) } } }