forked from johanhelsing/wayland-log-reader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.qml
161 lines (148 loc) · 5.26 KB
/
Main.qml
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import QtQuick 2.10
import QtQuick.Controls 2.3
import QtQuick.Window 2.3
import "./lodash.js" as Lodash
import "./wayland-debug-tools.js" as WaylandDebugTools
ApplicationWindow {
id: window
visible: true
title: "wayland-log-reader"
width: 1024
height: 1024
background: Rectangle { color: "white" }
property int highlightObject: 0
property string log: waylandLog
function handleObjectSelected(object) {
highlightObject = object.uniqueId;
}
ScrollView {
id: objectsView
anchors.top: parent.top
anchors.bottom: parent.bottom
anchors.right: parent.right
width: parent.width / 2
Column {
spacing: 3
width: objectsView.width
Label { text: "All objects"; font.weight: Font.Bold; font.pixelSize: 16 }
Repeater {
model: objects
ObjectLabel { object: objects.get(index); onClicked: handleObjectSelected(object) }
}
Item { height: 5; width: 1 }
Label { text: "Globals"; font.weight: Font.Bold; font.pixelSize: 16 }
Repeater {
model: globals
Label { text: number + ": " + interfaceName + " v" + version }
}
}
}
ScrollView {
id: messagesView
anchors.top: parent.top
anchors.bottom: parent.bottom
width: parent.width / 2
clip: true
Column {
width: messagesView.width
CheckBox {
id: showComments
text: "Show comments"
checked: true
}
Repeater {
model: parsedLines
Item {
id: lineItem
property var line: parsedLines[index]
width: parent.width
implicitWidth: childrenRect.width
implicitHeight: childrenRect.height
Repeater {
model: type === "comment" && showComments.checked
Label {
height: 25
text: rawText; color: "gray"
}
}
Repeater {
model: type === "event"
Row {
// anchors.right: parent.right
height: 25
spacing: 5
ObjectLabel { object: parts.object; onClicked: handleObjectSelected(object) }
Label { text: parts.fn }
Label { text: "(" }
Repeater {
model: parts.args
ArgumentItem {
arg: parts.args[index];
function onObjectSelected(object) {
handleObjectSelected(object)
}
}
}
Label { text: ")" }
}
}
Repeater {
model: type === "request"
Row {
height: 25
spacing: 5
Label { text: " → " }
ObjectLabel { object: parts.object; onClicked: window.highlightObject = object.uniqueId }
Label { text: parts.fn }
Label { text: "(" }
Repeater {
model: parts.args
ArgumentItem {
arg: parts.args[index];
function onObjectSelected(object) {
handleObjectSelected(object)
}
}
}
Label { text: ")" }
}
}
}
}
}
}
property var state: ({})
ListModel { id: parsedLines }
ListModel { id: objects }
ListModel { id: globals }
function hash(str) {
var hash = 0;
if (this.length === 0)
return hash;
for (var i = 0; i < str.length; ++i) {
const chr = str.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash |= 0; // Convert to 32bit integer
}
return hash;
}
function colorHash(value) {
const hue = 0.5 + hash(Qt.md5(value)) / Math.pow(2, 32);
return Qt.hsla(hue, 1, 0.4, 1);
}
Component.onCompleted: {
state = WaylandDebugTools.parseLog(log);
// add the lines to a model Qt understands
state.parsedLines.forEach(function(line) {
parsedLines.append(line);
});
// and the objets
Lodash._.forEach(state.objects, function(object) {
objects.append(object);
});
// and the globals
Lodash._.forEach(state.globals, function(global) {
globals.append(global);
});
}
}