Clean up field types
This commit is contained in:
parent
8d44150598
commit
54bb1c1c2b
3 changed files with 40 additions and 45 deletions
|
@ -5,45 +5,43 @@ 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
|
||||
|
||||
ButtonGroup { id: buttons }
|
||||
Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i))
|
||||
|
||||
ButtonGroup { id: choices }
|
||||
Repeater {
|
||||
id: buttons
|
||||
|
||||
model: control.model.values
|
||||
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
|
||||
checked: control.index === index
|
||||
focusPolicy: Qt.NoFocus
|
||||
|
||||
implicitWidth: implicitContentWidth + leftPadding + rightPadding
|
||||
|
@ -51,8 +49,11 @@ Column {
|
|||
leftPadding: 5
|
||||
rightPadding: leftPadding
|
||||
|
||||
onClicked: control.index = (control.index === index ? -1 : index)
|
||||
text: Util.addShortcut(modelData.name, modelData.key)
|
||||
Keys.onPressed: {
|
||||
if (modelData.key === event.text) {
|
||||
checked = !checked
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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.modifiers === Qt.NoModifier) {
|
||||
value = input.text.trim()
|
||||
popup.close()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue