Clean up field types
This commit is contained in:
parent
8d44150598
commit
54bb1c1c2b
3 changed files with 40 additions and 45 deletions
|
@ -5,54 +5,55 @@ 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))
|
||||||
|
|
||||||
Repeater {
|
ButtonGroup { id: choices }
|
||||||
model: control.model.values
|
Repeater {
|
||||||
delegate: Button {
|
id: buttons
|
||||||
ButtonGroup.group: buttons
|
|
||||||
checkable: true
|
|
||||||
checked: control.index === index
|
|
||||||
focusPolicy: Qt.NoFocus
|
|
||||||
|
|
||||||
implicitWidth: implicitContentWidth + leftPadding + rightPadding
|
model: control.model.values
|
||||||
padding: 0
|
delegate: Button {
|
||||||
leftPadding: 5
|
required property int index
|
||||||
rightPadding: leftPadding
|
required property var modelData
|
||||||
|
readonly property string name: modelData.name
|
||||||
|
|
||||||
onClicked: control.index = (control.index === index ? -1 : index)
|
text: Util.addShortcut(name, modelData.key)
|
||||||
text: Util.addShortcut(modelData.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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
|
@ -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()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue