diff options
| author | Timotej Lazar <timotej.lazar@araneo.si> | 2021-06-14 19:09:53 +0200 |
|---|---|---|
| committer | Timotej Lazar <timotej.lazar@araneo.si> | 2021-06-14 19:13:14 +0200 |
| commit | 8d57bfb1aef3b71557bc408154ee028751fd688e (patch) | |
| tree | 22ee6eaa22a3cfc7dfd4f938be16a6e28d7eaf1f /Fields | |
First commit
There was history before but now there is no more.
Diffstat (limited to 'Fields')
| -rw-r--r-- | Fields/Bool.qml | 27 | ||||
| -rw-r--r-- | Fields/Enum.qml | 59 | ||||
| -rw-r--r-- | Fields/Text.qml | 50 | ||||
| -rw-r--r-- | Fields/TextArea.qml | 54 |
4 files changed, 190 insertions, 0 deletions
diff --git a/Fields/Bool.qml b/Fields/Bool.qml new file mode 100644 index 0000000..ccb0758 --- /dev/null +++ b/Fields/Bool.qml @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: Unlicense + +import QtQuick 2.12 +import QtQuick.Controls 2.13 + +Row { + id: control + width: parent.width + + property var definition + property alias value: input.checked + + Keys.onPressed: { + if (event.text === definition.key) { + value = !value + event.accepted = true + } + } + function set(val) { value = val || false } + + CheckBox { + id: input + focusPolicy: Qt.NoFocus + padding: 0 + font.capitalization: Font.SmallCaps + } +} diff --git a/Fields/Enum.qml b/Fields/Enum.qml new file mode 100644 index 0000000..30712b6 --- /dev/null +++ b/Fields/Enum.qml @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: Unlicense + +import QtQuick 2.12 +import QtQuick.Controls 2.13 + +import '../util.js' as Util + +Column { + id: control + + property var definition + property int index: -1 + readonly property string value: index >= 0 ? definition.values.get(index).name : '' + + function set(val) { + for (var i = 0; i < definition.values.count; i++) { + if (definition.values.get(i).name === val) { + index = i + return true + } + } + index = -1 + } + + Keys.onPressed: { + for (var i = 0; i < definition.values.count; i++) { + if (definition.values.get(i).key === event.text) { + index = (index === i ? -1 : i) + event.accepted = true + break + } + } + } + + Flow { + spacing: 5 + width: parent.width + + ButtonGroup { id: buttons } + + Repeater { + model: definition.values + delegate: Button { + ButtonGroup.group: buttons + checkable: true + checked: control.index === index + focusPolicy: Qt.NoFocus + + implicitWidth: implicitContentWidth + leftPadding + rightPadding + padding: 0 + leftPadding: 5 + rightPadding: leftPadding + + onClicked: control.index = (control.index === index ? -1 : index) + text: Util.addShortcut(name, key) + } + } + } +} diff --git a/Fields/Text.qml b/Fields/Text.qml new file mode 100644 index 0000000..49d7ad2 --- /dev/null +++ b/Fields/Text.qml @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: Unlicense + +import QtQuick 2.12 +import QtQuick.Controls 2.13 + +Label { + id: control + + property var definition + property alias value: control.text + + Keys.onPressed: { + if (event.text === definition.key) { + popup.open() + event.accepted = true + } + } + + function set(val) { value = val || '' } + + elide: Text.ElideRight + + Popup { + id: popup + + width: control.width + height: control.height + padding: 0 + + onOpened: { + input.text = value + input.forceActiveFocus() + } + + TextInput { + id: input + + clip: true + padding: 2 + topPadding: 0 + bottomPadding: 0 + width: parent.width + + onAccepted: { + value = input.text.trim() + popup.close() + } + } + } +} diff --git a/Fields/TextArea.qml b/Fields/TextArea.qml new file mode 100644 index 0000000..20cfeff --- /dev/null +++ b/Fields/TextArea.qml @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Unlicense + +import QtQuick 2.12 +import QtQuick.Controls 2.13 + +Label { + id: control + + property var definition + property alias value: control.text + + Keys.onPressed: { + if (event.text === definition.key) { + popup.open() + event.accepted = true + } + } + + function set(val) { value = (val || '').trim() } + + wrapMode: Text.Wrap + + Popup { + id: popup + + width: control.width + height: input.height + padding: 0 + + onOpened: { + input.text = value + input.forceActiveFocus() + } + + TextArea { + id: input + + 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) { + value = input.text.trim() + popup.close() + } + } + } + } + } +} |
