60 lines
1.5 KiB
QML
60 lines
1.5 KiB
QML
|
// SPDX-License-Identifier: Unlicense
|
||
|
|
||
|
import QtQuick 2.12
|
||
|
import QtQuick.Controls 2.13
|
||
|
|
||
|
import '../util.js' as Util
|
||
|
|
||
|
Column {
|
||
|
id: control
|
||
|
|
||
|
property var definition
|
||
|
property int index: -1
|
||
|
readonly property string value: index >= 0 ? definition.values.get(index).name : ''
|
||
|
|
||
|
function set(val) {
|
||
|
for (var i = 0; i < definition.values.count; i++) {
|
||
|
if (definition.values.get(i).name === val) {
|
||
|
index = i
|
||
|
return true
|
||
|
}
|
||
|
}
|
||
|
index = -1
|
||
|
}
|
||
|
|
||
|
Keys.onPressed: {
|
||
|
for (var i = 0; i < definition.values.count; i++) {
|
||
|
if (definition.values.get(i).key === event.text) {
|
||
|
index = (index === i ? -1 : i)
|
||
|
event.accepted = true
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
Flow {
|
||
|
spacing: 5
|
||
|
width: parent.width
|
||
|
|
||
|
ButtonGroup { id: buttons }
|
||
|
|
||
|
Repeater {
|
||
|
model: definition.values
|
||
|
delegate: Button {
|
||
|
ButtonGroup.group: buttons
|
||
|
checkable: true
|
||
|
checked: control.index === index
|
||
|
focusPolicy: Qt.NoFocus
|
||
|
|
||
|
implicitWidth: implicitContentWidth + leftPadding + rightPadding
|
||
|
padding: 0
|
||
|
leftPadding: 5
|
||
|
rightPadding: leftPadding
|
||
|
|
||
|
onClicked: control.index = (control.index === index ? -1 : index)
|
||
|
text: Util.addShortcut(name, key)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|