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 /Event.qml | |
First commit
There was history before but now there is no more.
Diffstat (limited to 'Event.qml')
| -rw-r--r-- | Event.qml | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/Event.qml b/Event.qml new file mode 100644 index 0000000..38d3eeb --- /dev/null +++ b/Event.qml @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: Unlicense + +import QtQuick 2.12 +import QtQuick.Controls 2.13 +import QtQuick.Layouts 1.6 + +import 'util.js' as Util + +// This is the delegate for event list items. +Pane { + id: control + + property int time + property alias tag: tag.text + property alias fields: inputs.model + property bool editing: false + + signal remove + + clip: true + height: visible ? stuff.height + 2*padding : 0 // TODO fix filtering and remove this + padding: 2 + + // set to current value or default + function reset() { + for (var i = 0; i < fields.count; i++) { + const child = inputs.itemAt(i) + if (child && child.item) + child.item.set(fields.get(i).value) + } + } + + function store() { + for (var i = 0; i < fields.count; i++) + fields.setProperty(i, 'value', inputs.itemAt(i).item.value) + } + + // Pass keys to each field input in order. + Keys.forwardTo: Array.from({ length: inputs.count }, (_, i) => inputs.itemAt(i).item) + + Behavior on height { NumberAnimation { duration: 50 } } + + ColumnLayout { + id: stuff + anchors { left: parent.left; right: parent.right; margins: 5 } + + RowLayout { + Label { + text: new Date(time).toISOString().substr(12, 9) + font.pixelSize: 10 + Layout.alignment: Qt.AlignBaseline + } + Label { + id: tag + font.weight: Font.DemiBold + Layout.alignment: Qt.AlignBaseline + } + Label { + text: { + var str = '' + for (var i = 0; i < fields.count; i++) { + const field = fields.get(i) + if (field.value && field.type !== 'TextArea') + str += (field.type === 'Bool' ? field.name : field.value) + ' ' + } + return str + } + elide: Text.ElideRight + textFormat: Text.PlainText + Layout.fillWidth: true + Layout.alignment: Qt.AlignBaseline + } + } + + // Event‐specific inputs. + GridLayout { + id: fieldset + + flow: GridLayout.TopToBottom + rows: inputs.count + + columnSpacing: 10 + visible: editing + + // Labels. + Repeater { + model: inputs.model + delegate: Label { + text: Util.addShortcut(model.name, model.key) + Layout.alignment: Qt.AlignRight + } + } + + // Inputs. + Repeater { + id: inputs + delegate: Loader { + source: 'qrc:/Fields/' + model.type + '.qml' + Layout.fillHeight: true + Layout.fillWidth: true + Binding { + target: item; property: 'definition' + value: model + } + } + } + } + } +} |
