diff --git a/Fields/Enum.qml b/Fields/Enum.qml index cb49b3b..b594b88 100644 --- a/Fields/Enum.qml +++ b/Fields/Enum.qml @@ -5,54 +5,55 @@ import QtQuick.Controls 2.13 import '../util.js' as Util -Column { +Flow { id: control property var model - property int index: -1 - readonly property string value: index >= 0 ? model.values[index].name : '' + readonly property string value: + choices.checkedButton && choices.checkState !== Qt.Unchecked ? + choices.checkedButton.name : '' function set(val) { - for (var i = 0; i < model.values.length; i++) { - if (model.values[i].name === val) { - index = i - return true - } - } - index = -1 - } - - Keys.onPressed: { - for (var i = 0; i < model.values.length; i++) { - if (model.values[i].key === event.text) { - index = (index === i ? -1 : i) - event.accepted = true + choices.checkState = Qt.Unchecked + for (var i = 0; i < buttons.count; i++) { + if (buttons.itemAt(i).name === val) { + buttons.itemAt(i).checked = true break } } + return value === val } - Flow { - spacing: 5 - width: parent.width + spacing: 5 - ButtonGroup { id: buttons } + Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i)) - Repeater { - model: control.model.values - delegate: Button { - ButtonGroup.group: buttons - checkable: true - checked: control.index === index - focusPolicy: Qt.NoFocus + ButtonGroup { id: choices } + Repeater { + id: buttons - implicitWidth: implicitContentWidth + leftPadding + rightPadding - padding: 0 - leftPadding: 5 - rightPadding: leftPadding + model: control.model.values + delegate: Button { + required property int index + required property var modelData + readonly property string name: modelData.name - onClicked: control.index = (control.index === index ? -1 : index) - text: Util.addShortcut(modelData.name, modelData.key) + text: Util.addShortcut(name, modelData.key) + + ButtonGroup.group: choices + checkable: true + focusPolicy: Qt.NoFocus + + implicitWidth: implicitContentWidth + leftPadding + rightPadding + padding: 0 + leftPadding: 5 + rightPadding: leftPadding + + Keys.onPressed: { + if (modelData.key === event.text) { + checked = !checked + event.accepted = true + } } } } diff --git a/Fields/Text.qml b/Fields/Text.qml index b4e4dbf..55542e9 100644 --- a/Fields/Text.qml +++ b/Fields/Text.qml @@ -24,7 +24,6 @@ Label { id: popup width: parent.width - height: parent.height padding: 0 onOpened: { @@ -35,11 +34,9 @@ Label { TextInput { id: input + anchors { fill: parent; leftMargin: 2; rightMargin: 2 } + padding: 0 clip: true - padding: 2 - topPadding: 0 - bottomPadding: 0 - width: parent.width onAccepted: { value = input.text.trim() diff --git a/Fields/TextArea.qml b/Fields/TextArea.qml index 7be3564..9b44c35 100644 --- a/Fields/TextArea.qml +++ b/Fields/TextArea.qml @@ -24,7 +24,6 @@ Label { id: popup width: parent.width - height: input.height padding: 0 onOpened: { @@ -35,15 +34,13 @@ Label { TextArea { id: input + anchors.fill: parent padding: 2 - topPadding: 0 - bottomPadding: 0 - width: parent.width wrapMode: TextEdit.Wrap Keys.onPressed: { - if (event.modifiers === Qt.NoModifier) { - if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { + if (event.key === Qt.Key_Return || event.key === Qt.Key_Enter) { + if (event.modifiers === Qt.NoModifier) { value = input.text.trim() popup.close() }