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

import QtQuick 2.12
import QtQuick.Controls 2.13

import 'util.js' as Util

// Tag list.
Flow {
    id: control

    property alias model: buttons.model

    signal clicked(string tag)

    // Try passing key to each field input in order.
    Keys.enabled: enabled
    Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i))

    spacing: 5

    Repeater {
        id: buttons
        delegate: Button {
            text: Util.addShortcut(modelData.tag, modelData.key)
            focusPolicy: Qt.NoFocus
            implicitWidth: implicitContentWidth + 2*padding
            onClicked: control.clicked(modelData.tag)
            Keys.onPressed: {
                if (event.text === modelData.key) {
                    clicked()
                    event.accepted = true
                }
            }
        }
    }
}