TreeDelegate.qml 3.13 KB
Newer Older
1
/*
2
 *   Copyright 2012 Marco Martin <mart@kde.org>
3
4
 *
 *   This program is free software; you can redistribute it and/or modify
5
6
7
 *   it under the terms of the GNU General Public License as
 *   published by the Free Software Foundation; either version 2,
 *   or (at your option) any later version.
8
9
10
11
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *   GNU General Public License for more details
13
 *
14
 *   You should have received a copy of the GNU General Public
15
16
17
18
19
 *   License along with this program; if not, write to the
 *   Free Software Foundation, Inc.,
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

Marco Martin's avatar
Marco Martin committed
20
21
22
import QtQuick 2.1
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.core 2.0 as PlasmaCore
23
import org.kde.kquickcontrolsaddons 2.0
24
25
26
27
28

Column {
    id: treeDelegate
    property variant sourceModel
    property int rowIndex: index
29
30
    width: parent.width

31
    property bool matches: display.toLowerCase().indexOf(searchField.text.toLowerCase()) !== -1
Marco Martin's avatar
Marco Martin committed
32
33


Marco Martin's avatar
Marco Martin committed
34
    MouseArea {
Marco Martin's avatar
Marco Martin committed
35
        id: delegateArea
36
        width: parent.width
37
        height: matches ? label.height : 0
Marco Martin's avatar
Marco Martin committed
38
39
40
41
42
43
44
        opacity: matches ? 1 : 0
        Behavior on opacity {
            NumberAnimation {
                duration: 250
            }
        }

45

Marco Martin's avatar
Marco Martin committed
46
        onClicked: {
Marco Martin's avatar
Marco Martin committed
47
            documentItem.currentPage = page-1
Marco Martin's avatar
Marco Martin committed
48
49

            resourceBrowser.open = false
50
        }
51

Marco Martin's avatar
Marco Martin committed
52
53
54
55
56
57
        QIconItem {
            id: icon
            icon: decoration
            width: theme.smallIconSize
            height: width
            anchors.verticalCenter: parent.verticalCenter
58
            x: units.largeSpacing
Marco Martin's avatar
Marco Martin committed
59
        }
60
61
62
63
        PlasmaComponents.Label {
            id: label
            text: display
            verticalAlignment: Text.AlignBottom
Marco Martin's avatar
Marco Martin committed
64
            anchors.left: icon.right
65
        }
66
        //there isn't a sane way to do a dotted line in QML
67
68
        Rectangle {
            color: theme.textColor
69
            opacity: 0.3
70
71
72
73
74
75
76
77
78
            height: 1
            anchors {
                bottom: parent.bottom
                left: label.right
                right: pageNumber.left
            }
        }
        PlasmaComponents.Label {
            id: pageNumber
79
            text: pageLabel ? pageLabel : page
80
81
            anchors.right: parent.right
            verticalAlignment: Text.AlignBottom
82
            anchors.rightMargin: units.largeSpacing
83
        }
84
85
86
87
    }
    Column {
        id: col
        x: 20
88
        width: parent.width - 20
89
90
91
92
93
94
95
96
97
98
99
100
101
        property variant model: childrenModel
        Repeater {
            id: rep
            model: VisualDataModel {
                id: childrenModel
                model: documentItem.tableOfContents
            }
        }
    }
    onParentChanged: {
        if (treeDelegate.parent && treeDelegate.parent.model) {
            sourceModel = treeDelegate.parent.model
        }
102

103
104
105
106
107
108
109
        childrenModel.rootIndex = sourceModel.modelIndex(index)

        if (model.hasModelChildren) {
            childrenModel.delegate = Qt.createComponent("TreeDelegate.qml")
        }
    }
}