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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
|
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (info@qt.nokia.com)
**
**
** GNU Lesser General Public License Usage
**
** 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.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** Other Usage
**
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
** If you have questions regarding the use of this file, please contact
** Nokia at info@qt.nokia.com.
**
**************************************************************************/
import QtQuick 1.0
import Monitor 1.0
import "MainView.js" as Plotter
Rectangle {
id: root
property bool dataAvailable: true;
property int eventCount: 0;
property real progress: 0;
// move the cursor in the editor
signal updateCursorPosition
property string fileName: ""
property int lineNumber: -1
function gotoSourceLocation(file,line) {
root.fileName = file;
root.lineNumber = line;
root.updateCursorPosition();
}
function clearData() {
Plotter.reset();
view.clearData();
root.dataAvailable = false;
root.eventCount = 0;
rangeMover.x = 2
rangeMover.opacity = 0
}
function clearAll() {
clearData();
selectedEventIndex = -1;
canvas.requestPaint();
view.visible = false;
root.elapsedTime = 0;
root.updateTimer();
}
property int selectedEventIndex : -1;
property bool mouseTracking: false;
onSelectedEventIndexChanged: {
if ((!mouseTracking) && eventCount > 0
&& selectedEventIndex > -1 && selectedEventIndex < eventCount) {
// re-center flickable if necessary
var xs = Plotter.xScale(canvas);
var startTime = qmlEventList.firstTimeMark();
var eventStartTime = qmlEventList.getStartTime(selectedEventIndex);
var eventDuration = qmlEventList.getDuration(selectedEventIndex);
if (rangeMover.value + startTime > eventStartTime) {
rangeMover.x = Math.max(0,
Math.floor((eventStartTime - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2) );
} else if (rangeMover.value + startTime + rangeMover.zoomWidth * xs < eventStartTime + eventDuration) {
rangeMover.x = Math.floor((eventStartTime + eventDuration - startTime) / xs - canvas.canvasWindow.x - rangeMover.zoomWidth/2);
}
}
}
function nextEvent() {
if (eventCount > 0) {
++selectedEventIndex;
if (selectedEventIndex >= eventCount)
selectedEventIndex = 0;
}
}
function prevEvent() {
if (eventCount > 0) {
--selectedEventIndex;
if (selectedEventIndex < 0)
selectedEventIndex = eventCount - 1;
}
}
function zoomIn() {
// 10%
var newZoom = rangeMover.zoomWidth / 1.1;
// 0.1 ms minimum zoom
if (newZoom * Plotter.xScale(canvas) > 100000) {
hideRangeDetails();
rangeMover.zoomWidth = newZoom
rangeMover.updateZoomControls();
}
}
function zoomOut() {
hideRangeDetails();
// 10%
var newZoom = rangeMover.zoomWidth * 1.1;
if (newZoom > canvas.width)
newZoom = canvas.width;
if (newZoom + rangeMover.x > canvas.width)
rangeMover.x = canvas.width - newZoom;
rangeMover.zoomWidth = newZoom;
rangeMover.updateZoomControls();
}
Connections {
target: qmlEventList
onCountChanged: {
eventCount = qmlEventList.count();
if (eventCount == 0)
root.clearAll();
if (eventCount > 1) {
root.progress = Math.min(1.0,
(qmlEventList.lastTimeMark() - qmlEventList.firstTimeMark()) / root.elapsedTime * 1e-9 ) * 0.5;
} else
root.progress = 0;
}
onParsingStatusChanged: {
root.dataAvailable = false;
}
onDataReady: {
if (eventCount > 0) {
view.clearData();
view.rebuildCache();
}
}
}
// Elapsed
property real elapsedTime;
signal updateTimer;
Timer {
id: elapsedTimer
property date startDate
property bool reset: true
running: connection.recording
repeat: true
onRunningChanged: if (running) reset = true
interval: 100
triggeredOnStart: true
onTriggered: {
if (reset) {
startDate = new Date()
reset = false
}
var time = (new Date() - startDate)/1000
root.elapsedTime = time.toFixed(1);
root.updateTimer();
}
}
// time markers
TimeDisplay {
height: flick.height + labels.y
anchors.left: flick.left
anchors.right: flick.right
startTime: rangeMover.x * Plotter.xScale(canvas) + qmlEventList.firstTimeMark();
endTime: (rangeMover.x + rangeMover.zoomWidth) * Plotter.xScale(canvas) + qmlEventList.firstTimeMark();
}
function hideRangeDetails() {
rangeDetails.visible = false
rangeDetails.duration = ""
rangeDetails.label = ""
rangeDetails.type = ""
rangeDetails.file = ""
rangeDetails.line = -1
}
//our main interaction view
Flickable {
id: flick
anchors.top: parent.top
anchors.topMargin: labels.y
anchors.right: parent.right
anchors.left: labels.right
anchors.bottom: canvas.top
contentWidth: view.totalWidth
contentHeight: height
flickableDirection: Flickable.HorizontalFlick
clip:true
MouseArea {
width: flick.width
height: flick.contentHeight
x: flick.contentX
onClicked: {
root.hideRangeDetails();
}
hoverEnabled: true
onExited: {
root.hideRangeDetails();
}
}
TimelineView {
id: view
eventList: qmlEventList;
onEventListChanged: Plotter.qmlEventList = qmlEventList;
width: flick.width;
height: flick.contentHeight;
startX: flick.contentX
onStartXChanged: {
var newX = startTime / Plotter.xScale(canvas) - canvas.canvasWindow.x;
if (Math.abs(rangeMover.x - newX) > .01)
rangeMover.x = newX
if (Math.abs(startX - flick.contentX) > .01)
flick.contentX = startX
}
startTime: rangeMover.value
endTime: startTime + (rangeMover.zoomWidth*Plotter.xScale(canvas))
onEndTimeChanged: updateTimeline()
onCachedProgressChanged: root.progress = 0.5 + cachedProgress * 0.5;
onCacheReady: {
root.progress = 1.0;
root.dataAvailable = true;
if (root.eventCount > 0) {
view.visible = true;
view.updateTimeline();
canvas.requestPaint();
rangeMover.x = 1 //### hack to get view to display things immediately
rangeMover.x = 0
rangeMover.opacity = 1
}
}
delegate: Rectangle {
id: obj
property color baseColor: Plotter.colors[type]
property color myColor: baseColor
function conditionalHide() {
if (!mouseArea.containsMouse)
mouseArea.exited()
}
property int baseY: type * view.height / labels.rowCount;
property int baseHeight: view.height / labels.rowCount
y: baseY + (nestingLevel-1)*(baseHeight / nestingDepth);
height: baseHeight / nestingDepth;
gradient: Gradient {
GradientStop { position: 0.0; color: myColor }
GradientStop { position: 0.5; color: Qt.darker(myColor, 1.1) }
GradientStop { position: 1.0; color: myColor }
}
smooth: true
property bool componentIsCompleted: false
Component.onCompleted: {
componentIsCompleted = true;
updateDetails();
}
property bool isSelected: root.selectedEventIndex == index;
onIsSelectedChanged: updateDetails();
function updateDetails() {
if (!root.mouseTracking && componentIsCompleted) {
if (isSelected) {
enableSelected(0, 0);
}
else
disableSelected();
}
}
function enableSelected(x,y) {
myColor = Qt.darker(baseColor, 1.2)
rangeDetails.duration = qmlEventList.getDuration(index)/1000.0;
rangeDetails.label = qmlEventList.getDetails(index);
rangeDetails.file = qmlEventList.getFilename(index);
rangeDetails.line = qmlEventList.getLine(index);
rangeDetails.type = Plotter.names[type]
var margin = 10;
var pos = mapToItem(rangeDetails.parent , x, y)
var preferredX = pos.x + margin;
// if over the right side of the window, render it left to the given pos
if (preferredX + rangeDetails.width + margin > rangeDetails.parent.width)
preferredX = pos.x - rangeDetails.width - margin;
// if window too narrow, put it at least in "margin" pixels
if (preferredX < margin)
preferredX = margin;
rangeDetails.x = preferredX
// center on current item
var preferredY = pos.y + height/2 - rangeDetails.height/2;
// if too low, put it over the bottom of the window
if (preferredY + rangeDetails.height - margin > root.height)
preferredY = root.height - rangeDetails.height - margin;
// but never above the top of the window
if (preferredY < margin)
preferredY = margin;
rangeDetails.y = preferredY;
rangeDetails.visible = true
}
function disableSelected() {
myColor = baseColor
}
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onEntered: {
root.mouseTracking = true;
root.selectedEventIndex = index;
enableSelected(mouseX, y);
root.mouseTracking = false;
}
onExited: {
disableSelected();
}
onClicked: root.gotoSourceLocation(rangeDetails.file, rangeDetails.line);
}
}
}
}
//popup showing the details for the hovered range
RangeDetails {
id: rangeDetails
// follow the flickable
property int flickableX: flick.contentX;
property int lastFlickableX;
onXChanged: lastFlickableX = flickableX;
onFlickableXChanged: {
x = x - flickableX + lastFlickableX;
if (visible && (x + width <= 0 || x > root.width)) {
root.hideRangeDetails();
visible = false;
}
}
}
Rectangle {
id: labels
width: 150
color: "#dcdcdc"
y: 24
height: flick.height
property int rowCount: 5
Column {
id: col
//### change to use Repeater + Plotter.names?
Label { text: qsTr("Painting"); height: labels.height/labels.rowCount}
Label { text: qsTr("Compiling"); height: labels.height/labels.rowCount }
Label { text: qsTr("Creating"); height: labels.height/labels.rowCount }
Label { text: qsTr("Binding"); height: labels.height/labels.rowCount }
Label { text: qsTr("Signal Handler"); height: labels.height/labels.rowCount }
}
//right border divider
Rectangle {
width: 1
height: parent.height
anchors.right: parent.right
color: "#cccccc"
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: root.hideRangeDetails();
}
}
//bottom border divider
Rectangle {
height: 1
width: parent.width
anchors.bottom: canvas.top
color: "#cccccc"
}
//"overview" graph at the bottom
TiledCanvas {
id: canvas
anchors.bottom: parent.bottom
width: parent.width; height: 50
property int canvasWidth: width
canvasSize {
width: canvasWidth
height: canvas.height
}
tileSize.width: width
tileSize.height: height
canvasWindow.width: width
canvasWindow.height: height
onDrawRegion: {
if (root.dataAvailable)
Plotter.plot(canvas, ctxt, region);
else
Plotter.drawGraph(canvas, ctxt, region) //just draw the background
}
}
//moves the range mover to the position of a click
MouseArea {
anchors.fill: canvas
//### ideally we could press to position then immediately drag
onPressed: rangeMover.x = mouse.x - rangeMover.zoomWidth/2
}
RangeMover {
id: rangeMover
opacity: 0
anchors.top: canvas.top
}
// the next elements are here because I want them rendered on top of the other
Rectangle {
id: timeDisplayLabel
color: "lightsteelblue"
border.color: Qt.darker(color)
border.width: 1
radius: 2
height: Math.max(labels.y-2, timeDisplayText.height);
y: timeDisplayEnd.visible ? flick.height - 1 : 1
width: timeDisplayText.width + 10 + ( timeDisplayEnd.visible ? timeDisplayCloseControl.width + 10 : 0 )
visible: false
function hideAll() {
timeDisplayBegin.visible = false;
timeDisplayEnd.visible = false;
timeDisplayLabel.visible = false;
}
Text {
id: timeDisplayText
x: 5
y: parent.height/2 - height/2 + 1
font.pointSize: 8
}
Text {
id: timeDisplayCloseControl
text:"X"
anchors.right: parent.right
anchors.rightMargin: 3
y: parent.height/2 - height/2 + 1
visible: timeDisplayEnd.visible
MouseArea {
anchors.fill: parent
onClicked: {
timeDisplayLabel.hideAll();
}
}
}
}
Rectangle {
id: timeDisplayBegin
width: 1
color: Qt.rgba(0,0,64,0.7);
height: flick.height + labels.y
visible: false
}
Rectangle {
id: timeDisplayEnd
width: 1
color: Qt.rgba(0,0,64,0.7);
height: flick.height + labels.y
visible: false
}
StatusDisplay {
anchors.centerIn: flick
}
}
|