CategoryLabel.qml 5.14 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
Kai Koehne's avatar
Kai Koehne committed
2
**
3
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
Kai Koehne's avatar
Kai Koehne committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
Kai Koehne's avatar
Kai Koehne committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
Kai Koehne's avatar
Kai Koehne committed
15
16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
Kai Koehne's avatar
Kai Koehne committed
23
**
hjk's avatar
hjk committed
24
25
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
Kai Koehne's avatar
Kai Koehne committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
Kai Koehne's avatar
Kai Koehne committed
29

30
import QtQuick 2.1
Christiaan Janssen's avatar
Christiaan Janssen committed
31
32

Item {
33
    id: labelContainer
34
    property string text: qmlProfilerModelProxy.title(modelIndex)
35
    property bool expanded: false
36
    property int modelIndex: index;
Christiaan Janssen's avatar
Christiaan Janssen committed
37

38
39
40
    property var descriptions: []
    property var extdescriptions: []
    property var eventIds: []
41

42
    visible: qmlProfilerModelProxy.rowCount(modelIndex) > 0;
Christiaan Janssen's avatar
Christiaan Janssen committed
43

44
45
46
47
48
49
50
51
    height: root.singleRowHeight
    width: 150

    Component.onCompleted: {
        updateHeight();
    }

    function updateHeight() {
52
        height = root.singleRowHeight * qmlProfilerModelProxy.rowCount(modelIndex);
53
54
    }

55
    function getDescriptions() {
56
57
        expanded = qmlProfilerModelProxy.expanded(modelIndex);
        backgroundMarks.requestPaint();
58
        visible = qmlProfilerModelProxy.rowCount(modelIndex) > 0;
Christiaan Janssen's avatar
Christiaan Janssen committed
59
60
61
        if (!visible)
            return;

62
63
64
        var desc=[];
        var ids=[];
        var extdesc=[];
65
        var labelList = qmlProfilerModelProxy.getLabels(modelIndex);
Christiaan Janssen's avatar
Christiaan Janssen committed
66
67
68
69
        for (var i = 0; i < labelList.length; i++ ) {
            desc[i] = labelList[i].description;
            ids[i] = labelList[i].id;
            extdesc[i] = labelList[i].displayName + ":" + labelList[i].description;
70
71
72
73
74
75
76
        }
        descriptions = desc;
        eventIds = ids;
        extdescriptions = extdesc;
        updateHeight();
    }

77
    Connections {
Christiaan Janssen's avatar
Christiaan Janssen committed
78
79
        target: qmlProfilerModelProxy
        onExpandedChanged: {
80
            getDescriptions();
Christiaan Janssen's avatar
Christiaan Janssen committed
81
82
        }

83
        onStateChanged: {
Christiaan Janssen's avatar
Christiaan Janssen committed
84
            getDescriptions();
85
86
        }
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
87
88

    Text {
89
        id: txt
Christiaan Janssen's avatar
Christiaan Janssen committed
90
91
        x: 5
        font.pixelSize: 12
Christiaan Janssen's avatar
Christiaan Janssen committed
92
        text: labelContainer.text
Christiaan Janssen's avatar
Christiaan Janssen committed
93
        color: "#232323"
94
95
96
        height: root.singleRowHeight
        width: 140
        verticalAlignment: Text.AlignVCenter
Christiaan Janssen's avatar
Christiaan Janssen committed
97
98
99
100
101
    }

    Rectangle {
        height: 1
        width: parent.width
102
        color: "#999999"
Christiaan Janssen's avatar
Christiaan Janssen committed
103
        anchors.bottom: parent.bottom
104
        z: 2
Christiaan Janssen's avatar
Christiaan Janssen committed
105
    }
106
107

    Column {
108
        y: root.singleRowHeight
109
110
111
        visible: expanded
        Repeater {
            model: descriptions.length
112
113
            Rectangle {
                width: labelContainer.width
114
                height: root.singleRowHeight
115
116
117
118
119
120
121
122
                color: "#eaeaea"
                border.width: 1
                border.color:"#c8c8c8"
                Text {
                    height: root.singleRowHeight
                    x: 5
                    width: 140
                    text: descriptions[index]
123
                    textFormat: Text.PlainText
124
125
126
                    elide: Text.ElideRight
                    verticalAlignment: Text.AlignVCenter
                }
127
128
                MouseArea {
                    anchors.fill: parent
129
130
131
                    hoverEnabled: true
                    onEntered: changeToolTip(extdescriptions[index]);
                    onExited: changeToolTip("");
132
133
                    onClicked: {
                        if (mouse.modifiers & Qt.ShiftModifier)
Christiaan Janssen's avatar
Christiaan Janssen committed
134
                            view.selectPrevFromId(modelIndex,eventIds[index]);
135
                        else
Christiaan Janssen's avatar
Christiaan Janssen committed
136
                            view.selectNextFromId(modelIndex,eventIds[index]);
137
138
                    }
                }
139
140
141
142
143
144
145
            }
        }
    }

    Image {
        source: expanded ? "arrow_down.png" : "arrow_right.png"
        x: parent.width - 12
146
        y: Math.floor((root.singleRowHeight - height) / 2)
147
        smooth: false
148
149
        MouseArea {
            anchors.fill: parent
150
151
152
153
            anchors.rightMargin: -10
            anchors.leftMargin: -10
            anchors.topMargin: -10
            anchors.bottomMargin: -10
154
            onClicked: {
155
156
                // Don't try to expand empty models.
                if (expanded || qmlProfilerModelProxy.count(modelIndex) > 0)
157
                    qmlProfilerModelProxy.setExpanded(modelIndex, !expanded);
158
159
160
            }
        }
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
161
}