summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.si>2021-09-05 16:23:41 +0200
committerTimotej Lazar <timotej.lazar@araneo.si>2021-09-16 20:33:39 +0200
commit54bb1c1c2be5fdd1b8e1eda7c9cd6fe40337800f (patch)
tree972edd9689c3d6a8e109c93eed00355fd96e3319
parent8d44150598a4e04a751b7df0d8c91ea29099e10e (diff)
Clean up field types
-rw-r--r--Fields/Enum.qml69
-rw-r--r--Fields/Text.qml7
-rw-r--r--Fields/TextArea.qml9
3 files changed, 40 insertions, 45 deletions
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
+
+ Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i))
+
+ ButtonGroup { id: choices }
+ Repeater {
+ id: buttons
+
+ model: control.model.values
+ delegate: Button {
+ required property int index
+ required property var modelData
+ readonly property string name: modelData.name
- ButtonGroup { id: buttons }
+ text: Util.addShortcut(name, modelData.key)
- Repeater {
- model: control.model.values
- delegate: Button {
- ButtonGroup.group: buttons
- checkable: true
- checked: control.index === index
- focusPolicy: Qt.NoFocus
+ ButtonGroup.group: choices
+ checkable: true
+ focusPolicy: Qt.NoFocus
- implicitWidth: implicitContentWidth + leftPadding + rightPadding
- padding: 0
- leftPadding: 5
- rightPadding: leftPadding
+ implicitWidth: implicitContentWidth + leftPadding + rightPadding
+ padding: 0
+ 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
+ }
}
}
}
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()
}