Clean up field types

This commit is contained in:
Timotej Lazar 2021-09-05 16:23:41 +02:00
parent 8d44150598
commit 54bb1c1c2b
No known key found for this signature in database
GPG key ID: B6F38793D143456F
3 changed files with 40 additions and 45 deletions

View file

@ -5,45 +5,43 @@ import QtQuick.Controls 2.13
import '../util.js' as Util import '../util.js' as Util
Column { Flow {
id: control id: control
property var model property var model
property int index: -1 readonly property string value:
readonly property string value: index >= 0 ? model.values[index].name : '' choices.checkedButton && choices.checkState !== Qt.Unchecked ?
choices.checkedButton.name : ''
function set(val) { function set(val) {
for (var i = 0; i < model.values.length; i++) { choices.checkState = Qt.Unchecked
if (model.values[i].name === val) { for (var i = 0; i < buttons.count; i++) {
index = i if (buttons.itemAt(i).name === val) {
return true buttons.itemAt(i).checked = 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
break break
} }
} }
return value === val
} }
Flow {
spacing: 5 spacing: 5
width: parent.width
ButtonGroup { id: buttons } Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i))
ButtonGroup { id: choices }
Repeater { Repeater {
id: buttons
model: control.model.values model: control.model.values
delegate: Button { delegate: Button {
ButtonGroup.group: buttons required property int index
required property var modelData
readonly property string name: modelData.name
text: Util.addShortcut(name, modelData.key)
ButtonGroup.group: choices
checkable: true checkable: true
checked: control.index === index
focusPolicy: Qt.NoFocus focusPolicy: Qt.NoFocus
implicitWidth: implicitContentWidth + leftPadding + rightPadding implicitWidth: implicitContentWidth + leftPadding + rightPadding
@ -51,8 +49,11 @@ Column {
leftPadding: 5 leftPadding: 5
rightPadding: leftPadding rightPadding: leftPadding
onClicked: control.index = (control.index === index ? -1 : index) Keys.onPressed: {
text: Util.addShortcut(modelData.name, modelData.key) if (modelData.key === event.text) {
checked = !checked
event.accepted = true
}
} }
} }
} }

View file

@ -24,7 +24,6 @@ Label {
id: popup id: popup
width: parent.width width: parent.width
height: parent.height
padding: 0 padding: 0
onOpened: { onOpened: {
@ -35,11 +34,9 @@ Label {
TextInput { TextInput {
id: input id: input
anchors { fill: parent; leftMargin: 2; rightMargin: 2 }
padding: 0
clip: true clip: true
padding: 2
topPadding: 0
bottomPadding: 0
width: parent.width
onAccepted: { onAccepted: {
value = input.text.trim() value = input.text.trim()

View file

@ -24,7 +24,6 @@ Label {
id: popup id: popup
width: parent.width width: parent.width
height: input.height
padding: 0 padding: 0
onOpened: { onOpened: {
@ -35,15 +34,13 @@ Label {
TextArea { TextArea {
id: input id: input
anchors.fill: parent
padding: 2 padding: 2
topPadding: 0
bottomPadding: 0
width: parent.width
wrapMode: TextEdit.Wrap wrapMode: TextEdit.Wrap
Keys.onPressed: { 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() value = input.text.trim()
popup.close() popup.close()
} }