CategoryLabel.qml 5.69 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
36
37
    property bool expanded: trigger(qmlProfilerModelProxy.expanded(modelIndex))
    property int modelIndex: index
    property int bindingTrigger: 1
38
39
40
    property var descriptions: []
    property var extdescriptions: []
    property var eventIds: []
41

42
43
    readonly property int dragHeight: 5

44
45
    function trigger(i) {
        return i * bindingTrigger * bindingTrigger;
46
47
    }

48
49
50
51
    visible: trigger(qmlProfilerModelProxy.rowCount(modelIndex)) > 0

    height: trigger(qmlProfilerModelProxy.height(modelIndex))
    width: 150
52

53
    function getDescriptions() {
54
        bindingTrigger = -bindingTrigger;
55
        backgroundMarks.requestPaint();
Christiaan Janssen's avatar
Christiaan Janssen committed
56
57
58
        if (!visible)
            return;

59
60
61
        var desc=[];
        var ids=[];
        var extdesc=[];
62
        var labelList = qmlProfilerModelProxy.getLabels(modelIndex);
Christiaan Janssen's avatar
Christiaan Janssen committed
63
64
65
66
        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;
67
68
69
70
71
72
        }
        descriptions = desc;
        eventIds = ids;
        extdescriptions = extdesc;
    }

73
    Connections {
Christiaan Janssen's avatar
Christiaan Janssen committed
74
        target: qmlProfilerModelProxy
75
76
77
        onExpandedChanged: getDescriptions();
        onStateChanged: getDescriptions()
        onRowHeightChanged: getDescriptions()
78
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
79
80

    Text {
81
        id: txt
Christiaan Janssen's avatar
Christiaan Janssen committed
82
83
        x: 5
        font.pixelSize: 12
Christiaan Janssen's avatar
Christiaan Janssen committed
84
        text: labelContainer.text
Christiaan Janssen's avatar
Christiaan Janssen committed
85
        color: "#232323"
86
        height: trigger(qmlProfilerModelProxy.rowHeight(modelIndex, 0))
87
88
        width: 140
        verticalAlignment: Text.AlignVCenter
Christiaan Janssen's avatar
Christiaan Janssen committed
89
90
91
92
93
    }

    Rectangle {
        height: 1
        width: parent.width
94
        color: "#999999"
Christiaan Janssen's avatar
Christiaan Janssen committed
95
        anchors.bottom: parent.bottom
96
        z: 2
Christiaan Janssen's avatar
Christiaan Janssen committed
97
    }
98
99

    Column {
100
        anchors.top: txt.bottom
101
102
103
        visible: expanded
        Repeater {
            model: descriptions.length
104
105
            Rectangle {
                width: labelContainer.width
106
                height: trigger(qmlProfilerModelProxy.rowHeight(modelIndex, index + 1))
107
108
109
110
                color: "#eaeaea"
                border.width: 1
                border.color:"#c8c8c8"
                Text {
111
112
113
114
                    anchors.fill: parent
                    anchors.leftMargin: 5
                    anchors.rightMargin: 5

115
                    text: descriptions[index]
116
                    textFormat: Text.PlainText
117
118
119
                    elide: Text.ElideRight
                    verticalAlignment: Text.AlignVCenter
                }
120
                MouseArea {
121
                    property bool resizing: false
122
                    anchors.fill: parent
123
                    hoverEnabled: true
124
125
                    cursorShape: (resizing || height - mouseY < dragHeight) ? Qt.SizeVerCursor :
                                                                              Qt.ArrowCursor;
126
127
                    onEntered: changeToolTip(extdescriptions[index]);
                    onExited: changeToolTip("");
128
129
130
131
                    onPressed: resizing = (height - mouseY < dragHeight);

                    onReleased: resizing = false;

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

                    onMouseYChanged: {
                        if (resizing)
                            qmlProfilerModelProxy.setRowHeight(modelIndex, index + 1, mouseY);
                    }
143
                }
144
145
146
147
148
149
150
            }
        }
    }

    Image {
        source: expanded ? "arrow_down.png" : "arrow_right.png"
        x: parent.width - 12
151
        y: 9
152
        smooth: false
153
154
        MouseArea {
            anchors.fill: parent
155
156
157
158
            anchors.rightMargin: -10
            anchors.leftMargin: -10
            anchors.topMargin: -10
            anchors.bottomMargin: -10
159
            onClicked: {
160
161
                // Don't try to expand empty models.
                if (expanded || qmlProfilerModelProxy.count(modelIndex) > 0)
162
                    qmlProfilerModelProxy.setExpanded(modelIndex, !expanded);
163
164
165
            }
        }
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
166
}