summaryrefslogtreecommitdiff
path: root/Event.qml
blob: 38d3eeb56feffd874815f2bb47586a0e9989b874 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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
                    }
                }
            }
        }
    }
}