FirstCellDelegate.qml 2.99 KB
Newer Older
1
2
3
4
5
6
/*
 * SPDX-FileCopyrightText: 2020 Arjen Hiemstra <ahiemstra@heimr.nl>
 *
 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
 */

7
8
9
10
11
12
13
14
15
16
17
18
import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Layouts 1.12
import QtQml.Models 2.12

import org.kde.kirigami 2.2 as Kirigami

Control {
    id: delegate

    property string iconName
    property string text: model.display != undefined ? model.display : ""
David Edmundson's avatar
David Edmundson committed
19
    property alias truncated: label.truncated
Marco Martin's avatar
Marco Martin committed
20
    property real iconSize: Kirigami.Units.iconSizes.small
21
    property bool treeDecorationVisible: false
22
23

    Kirigami.Theme.colorSet: background.selected ? Kirigami.Theme.Selection : Kirigami.Theme.View
David Redondo's avatar
David Redondo committed
24
    Kirigami.Theme.inherit: false
25

David Redondo's avatar
David Redondo committed
26
27
28
29
30
    topPadding: 0
    bottomPadding: 0
    rightPadding: 0
    leftPadding: Kirigami.Units.largeSpacing

31
32
33
    background: CellBackground { view: delegate.TableView.view; row: model.row; column: model.column }

    contentItem: RowLayout {
34
35
        id: row
        property Item treeDecoration
36
        Kirigami.Icon {
Marco Martin's avatar
Marco Martin committed
37
            id:blah
38
39
40
41
42
43
44
45
46
47
48
            Layout.preferredWidth: delegate.iconName != "" ? delegate.iconSize : 0
            Layout.preferredHeight: Layout.preferredWidth
            source: delegate.iconName
            fallback: ""
        }
        Label {
            id: label

            padding: Kirigami.Units.smallSpacing

            Layout.fillWidth: true
Marco Martin's avatar
Marco Martin committed
49
            Layout.fillHeight: true
50
51
52
53
54
55
56
            text: delegate.text
            horizontalAlignment: Text.AlignLeft
            elide: Text.ElideRight
        }
    }

    hoverEnabled: true
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

    onTreeDecorationVisibleChanged: {
        if (treeDecorationVisible) {
            var component = Qt.createComponent("TreeDecoration.qml")
            if (component.status == Component.Ready) {
                var incubator = component.incubateObject(null, {
                    hasSiblings: Qt.binding(() => model.kDescendantHasSiblings),
                    level: Qt.binding(() => model.kDescendantLevel),
                    expandable: Qt.binding(() => model.kDescendantExpandable),
                    expanded: Qt.binding(() => model.kDescendantExpanded)
                })
                var finishCreation = () => {
                    row.treeDecoration = incubator.object
                    row.treeDecoration.clicked.connect(() => descendantsModel.toggleChildren(index))
                    var children = Array.from(row.children)
                    children.unshift(row.treeDecoration)
                    row.children = children
                }
                if (incubator.status == Component.Ready) {
                    finishCreation()
                } else {
                    incubator.onStatusChanged = (status) => {
                        if (status == Component.Ready) {
                            finishCreation()
                        }
                    }
                }
            }
        } else {
            if (row.treeDecoration) {
                row.treeDecoration.destroy()
            }
        }
    }
91
}