summaryrefslogtreecommitdiff
path: root/Tags.qml
blob: 7d3f0ce7f7c601681d7385120348c1fbeeb72382 (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
// SPDX-License-Identifier: Unlicense

import QtQuick 2.12
import QtQuick.Controls 2.13
import QtQuick.Layouts 1.6

import 'util.js' as Util

// Tag list.
Page {
    id: control

    property alias model: tags.model

    signal clicked(string tag, var fields)

    Keys.enabled: enabled
    Keys.onPressed: {
        for (var i = 0; i < model.length; i++) {
            const tag = model[i]
            if (tag.key === event.text) {
                clicked(tag.tag, tag.fields)
                return
            }
        }
        event.accepted = false
    }

    RowLayout {
        width: parent.width

        Flow {
            spacing: 5
            Layout.fillWidth: true

            Repeater {
                id: tags
                delegate: Button {
                    text: Util.addShortcut(modelData.tag, modelData.key)
                    onClicked: control.clicked(modelData.tag, modelData.fields)
                    focusPolicy: Qt.NoFocus
                    implicitWidth: implicitContentWidth + 2*padding
                }
            }
        }
    }
}