MainView.qml 15.8 KB
Newer Older
Kai Koehne's avatar
Kai Koehne committed
1
2
3
4
5
6
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
**
Tobias Hunger's avatar
Tobias Hunger committed
7
** Contact: Nokia Corporation (info@qt.nokia.com)
Kai Koehne's avatar
Kai Koehne committed
8
9
10
11
**
**
** GNU Lesser General Public License Usage
**
Thomas Murach's avatar
Thomas Murach committed
12
13
14
15
16
17
** 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
18
19
**
** In addition, as a special exception, Nokia gives you certain additional
Thomas Murach's avatar
Thomas Murach committed
20
** rights. These rights are described in the Nokia Qt LGPL Exception
Kai Koehne's avatar
Kai Koehne committed
21
22
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
Thomas Murach's avatar
Thomas Murach committed
23
24
25
26
27
** 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.
**
Kai Koehne's avatar
Kai Koehne committed
28
** If you have questions regarding the use of this file, please contact
Tobias Hunger's avatar
Tobias Hunger committed
29
** Nokia at info@qt.nokia.com.
Kai Koehne's avatar
Kai Koehne committed
30
31
32
**
**************************************************************************/

33
import QtQuick 1.0
Christiaan Janssen's avatar
Christiaan Janssen committed
34
35
36
37
38
39
import Monitor 1.0
import "MainView.js" as Plotter

Rectangle {
    id: root

40
    property bool dataAvailable: true;
41
42
    property int eventCount: 0;
    property real progress: 0;
Christiaan Janssen's avatar
Christiaan Janssen committed
43

44
45
    property bool mouseOverSelection : true

Christiaan Janssen's avatar
Christiaan Janssen committed
46
47
48
49
50
51
52
53
54
55
    // 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();
    }

56
    function clearData() {
57
58
        Plotter.reset();
        view.clearData();
59
        root.dataAvailable = false;
60
        root.eventCount = 0;
61
62
        rangeMover.x = 2
        rangeMover.opacity = 0
63
        hideRangeDetails();
64
65
    }

66
    function clearDisplay() {
67
68
69
70
        clearData();
        selectedEventIndex = -1;
        canvas.requestPaint();
        view.visible = false;
71
72
73
74
    }

    function clearAll() {
        clearDisplay();
75
76
77
78
79
80
81
        root.elapsedTime = 0;
        root.updateTimer();
    }

    property int selectedEventIndex : -1;
    property bool mouseTracking: false;

82
    onSelectedEventIndexChanged: {
83
84
        if ((!mouseTracking) && eventCount > 0
                && selectedEventIndex > -1 && selectedEventIndex < eventCount) {
85
86
            // re-center flickable if necessary
            var xs = Plotter.xScale(canvas);
87
88
89
90
            var startTime = qmlEventList.firstTimeMark();
            var eventStartTime = qmlEventList.getStartTime(selectedEventIndex);
            var eventDuration = qmlEventList.getDuration(selectedEventIndex);
            if (rangeMover.value + startTime > eventStartTime) {
91
                rangeMover.x = Math.max(0,
92
93
94
                    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);
95
96
            }
        }
97
98
99
100

        if (selectedEventIndex == -1) {
            selectionHighlight.visible = false;
        }
101
102
103
    }

    function nextEvent() {
104
        if (eventCount > 0) {
105
            ++selectedEventIndex;
106
            if (selectedEventIndex >= eventCount)
107
108
109
110
111
                selectedEventIndex = 0;
        }
    }

    function prevEvent() {
112
        if (eventCount > 0) {
113
114
            --selectedEventIndex;
            if (selectedEventIndex < 0)
115
                selectedEventIndex = eventCount - 1;
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
    function zoomIn() {
        // 10%
        var newZoom = rangeMover.zoomWidth / 1.1;

        // 0.1 ms minimum zoom
        if (newZoom * Plotter.xScale(canvas) > 100000) {
            rangeMover.zoomWidth =  newZoom
            rangeMover.updateZoomControls();
        }
    }

    function zoomOut() {
        // 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();
    }

Christiaan Janssen's avatar
Christiaan Janssen committed
141
    Connections {
142
143
144
145
146
147
148
149
150
151
        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;
Christiaan Janssen's avatar
Christiaan Janssen committed
152
153
        }

154
155
        onParsingStatusChanged: {
            root.dataAvailable = false;
Christiaan Janssen's avatar
Christiaan Janssen committed
156
157
        }

158
159
160
161
162
        onDataReady: {
            if (eventCount > 0) {
                view.clearData();
                view.rebuildCache();
            }
163
        }
Christiaan Janssen's avatar
Christiaan Janssen committed
164
165
    }

Christiaan Janssen's avatar
Christiaan Janssen committed
166
167
168
169
    // Elapsed
    property real elapsedTime;
    signal updateTimer;
    Timer {
170
        id: elapsedTimer
Christiaan Janssen's avatar
Christiaan Janssen committed
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
        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();
        }
    }

Christiaan Janssen's avatar
Christiaan Janssen committed
189
190
191
192
193
    // time markers
    TimeDisplay {
        height: flick.height + labels.y
        anchors.left: flick.left
        anchors.right: flick.right
194
195
        startTime: rangeMover.x * Plotter.xScale(canvas) + qmlEventList.firstTimeMark();
        endTime: (rangeMover.x + rangeMover.zoomWidth) * Plotter.xScale(canvas) + qmlEventList.firstTimeMark();
Christiaan Janssen's avatar
Christiaan Janssen committed
196
197
    }

198
199
200
201
202
203
204
    function hideRangeDetails() {
        rangeDetails.visible = false
        rangeDetails.duration = ""
        rangeDetails.label = ""
        rangeDetails.type = ""
        rangeDetails.file = ""
        rangeDetails.line = -1
205
206
207

        root.mouseOverSelection = true;
        selectionHighlight.visible = false;
208
209
    }

Christiaan Janssen's avatar
Christiaan Janssen committed
210
211
212
213
    //our main interaction view
    Flickable {
        id: flick
        anchors.top: parent.top
Christiaan Janssen's avatar
Christiaan Janssen committed
214
        anchors.topMargin: labels.y
Christiaan Janssen's avatar
Christiaan Janssen committed
215
216
217
218
        anchors.right: parent.right
        anchors.left: labels.right
        anchors.bottom: canvas.top
        contentWidth: view.totalWidth
219
        contentHeight: height
220
        flickableDirection: Flickable.HorizontalFlick
Christiaan Janssen's avatar
Christiaan Janssen committed
221

222
223
        clip:true

Christiaan Janssen's avatar
Christiaan Janssen committed
224
225
226
        TimelineView {
            id: view

227
228
229
            eventList: qmlEventList;
            onEventListChanged: Plotter.qmlEventList = qmlEventList;

230
            width: flick.width;
231
            height: flick.contentHeight;
Christiaan Janssen's avatar
Christiaan Janssen committed
232
233
234
235
236
237
238
239
240
241

            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
242
            endTime: startTime + (rangeMover.zoomWidth*Plotter.xScale(canvas))
243
244
245
246
247
248
249
250
251
252
253
254
            onEndTimeChanged: {
                updateTimeline();
            }

            property real timeSpan: endTime - startTime
            onTimeSpanChanged: {
                if (selectedEventIndex != -1 && selectionHighlight.visible) {
                    var spacing = flick.width / timeSpan;
                    selectionHighlight.x = (qmlEventList.getStartTime(selectedEventIndex) - qmlEventList.firstTimeMark()) * spacing;
                    selectionHighlight.width = qmlEventList.getDuration(selectedEventIndex) * spacing;
               }
            }
Christiaan Janssen's avatar
Christiaan Janssen committed
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
            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
                }
            }

Christiaan Janssen's avatar
Christiaan Janssen committed
270
271
            delegate: Rectangle {
                id: obj
272
                property color myColor: Plotter.colors[type]
Christiaan Janssen's avatar
Christiaan Janssen committed
273
274
275
276
277
278

                function conditionalHide() {
                    if (!mouseArea.containsMouse)
                        mouseArea.exited()
                }

279
280
281
282
                property int baseY: type * view.height / labels.rowCount;
                property int baseHeight: view.height / labels.rowCount
                y: baseY + (nestingLevel-1)*(baseHeight / nestingDepth);
                height: baseHeight / nestingDepth;
Christiaan Janssen's avatar
Christiaan Janssen committed
283
284
285
286
287
288
                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
289
290

                property bool componentIsCompleted: false
291
292
293
294
                Component.onCompleted: {
                    componentIsCompleted = true;
                    updateDetails();
                }
295
296

                property bool isSelected: root.selectedEventIndex == index;
297
298
                onIsSelectedChanged: updateDetails();
                function updateDetails() {
299
300
301
302
303
304
305
306
                    if (!root.mouseTracking && componentIsCompleted) {
                        if (isSelected) {
                            enableSelected(0, 0);
                        }
                    }
                }

                function enableSelected(x,y) {
307
308
309
310
                    rangeDetails.duration = qmlEventList.getDuration(index)/1000.0;
                    rangeDetails.label = qmlEventList.getDetails(index);
                    rangeDetails.file = qmlEventList.getFilename(index);
                    rangeDetails.line = qmlEventList.getLine(index);
311
312
313
314
                    rangeDetails.type = Plotter.names[type]

                    rangeDetails.visible = true

315
316
317
318
319
                    selectionHighlight.x = obj.x;
                    selectionHighlight.y = obj.y;
                    selectionHighlight.width = width;
                    selectionHighlight.height = height;
                    selectionHighlight.visible = true;
320
321
                }

Christiaan Janssen's avatar
Christiaan Janssen committed
322
323
324
325
326
                MouseArea {
                    id: mouseArea
                    anchors.fill: parent
                    hoverEnabled: true
                    onEntered: {
327
328
329
330
331
332
333
334
335
                        if (root.mouseOverSelection) {
                            root.mouseTracking = true;
                            root.selectedEventIndex = index;
                            enableSelected(mouseX, y);
                            root.mouseTracking = false;
                        }
                    }

                    onPressed: {
336
337
338
339
340
                        root.mouseTracking = true;
                        root.selectedEventIndex = index;
                        enableSelected(mouseX, y);
                        root.mouseTracking = false;

341
342
343
                        root.mouseOverSelection = false;
                        root.gotoSourceLocation(rangeDetails.file, rangeDetails.line);
                    }
Christiaan Janssen's avatar
Christiaan Janssen committed
344
345
                }
            }
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362

            Rectangle {
                id: selectionHighlight
                color:"transparent"
                border.width: 2
                border.color: "blue"
                radius: 2
                visible: false
                z:1
            }

            MouseArea {
                width: parent.width
                height: parent.height
                x: flick.contentX
                onClicked: root.hideRangeDetails();
            }
Christiaan Janssen's avatar
Christiaan Janssen committed
363
364
365
366
367
368
369
370
371
372
373
        }
    }
    //popup showing the details for the hovered range
    RangeDetails {
        id: rangeDetails
    }

    Rectangle {
        id: labels
        width: 150
        color: "#dcdcdc"
374
        y: 24
Christiaan Janssen's avatar
Christiaan Janssen committed
375
        height: flick.height
Christiaan Janssen's avatar
Christiaan Janssen committed
376

377
378
        property int rowCount: 5

Christiaan Janssen's avatar
Christiaan Janssen committed
379
        Column {
380
            id: col
Christiaan Janssen's avatar
Christiaan Janssen committed
381
            //### change to use Repeater + Plotter.names?
382
383
384
385
386
            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 }
Christiaan Janssen's avatar
Christiaan Janssen committed
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
        }

        //right border divider
        Rectangle {
            width: 1
            height: parent.height
            anchors.right: parent.right
            color: "#cccccc"
        }
    }

    //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
Christiaan Janssen's avatar
Christiaan Janssen committed
424
        canvasWindow.height: height
Christiaan Janssen's avatar
Christiaan Janssen committed
425
426

        onDrawRegion: {
427
             if (root.dataAvailable)
Christiaan Janssen's avatar
Christiaan Janssen committed
428
429
430
431
432
433
434
435
436
437
                 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
438
        onPressed: rangeMover.x = mouse.x - rangeMover.zoomWidth/2
Christiaan Janssen's avatar
Christiaan Janssen committed
439
440
441
442
443
444
445
    }

    RangeMover {
        id: rangeMover
        opacity: 0
        anchors.top: canvas.top
    }
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

    // 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
    }
502
503
504
505

    StatusDisplay {
        anchors.centerIn: flick
    }
Christiaan Janssen's avatar
Christiaan Janssen committed
506
}