summaryrefslogtreecommitdiff
path: root/src/libs/tracing/qml/TimelineRulers.qml
blob: 3c93c884686263f2c42d273884b744a8bbd9eac5 (plain)
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
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

import QtQuick
import QtCreator.Tracing

Item {
    id: rulersParent
    property int scaleHeight
    property double viewTimePerPixel: 1
    property double contentX
    property double windowStart
    clip: true

    ListModel {
        id: rulersModel
    }

    MouseArea {
        anchors.top: parent.top
        anchors.left: parent.left
        anchors.right: parent.right
        height: rulersParent.scaleHeight

        onClicked: (mouse) => {
            rulersModel.append({
                timestamp: (mouse.x + contentX) * viewTimePerPixel + windowStart
            });
        }
    }

    Item {
        id: dragDummy
        property int index: -1
        onXChanged: {
            if (index >= 0) {
                rulersModel.setProperty(
                        index, "timestamp",
                        (x + rulersParent.contentX) * rulersParent.viewTimePerPixel
                            + rulersParent.windowStart);
            }
        }
    }

    Repeater {
        model: rulersModel

        Item {
            id: ruler
            x: (timestamp - rulersParent.windowStart) / rulersParent.viewTimePerPixel
                    - 1 - rulersParent.contentX
            y: 0
            width: 2
            height: rulersParent.height
            Rectangle {
                id: arrow
                height: rulersParent.scaleHeight
                width: rulersParent.scaleHeight
                rotation: 45
                anchors.verticalCenter: parent.top
                anchors.horizontalCenter: parent.horizontalCenter
                color: Theme.color(Theme.Timeline_HandleColor)
                MouseArea {
                    cursorShape: pressed ? Qt.DragMoveCursor : Qt.OpenHandCursor
                    anchors.fill: parent
                    drag.target: dragDummy
                    drag.axis: Drag.XAxis
                    drag.smoothed: false
                    onPressedChanged: {
                        if (!pressed) {
                            dragDummy.index = -1
                        } else {
                            dragDummy.x = ruler.x + 1
                            dragDummy.index = index
                        }
                    }
                }
            }

            Rectangle {
                anchors.left: parent.left
                anchors.top: arrow.bottom
                anchors.bottom: parent.bottom
                width: 2
                color: Theme.color(Theme.Timeline_HandleColor)
            }

            Rectangle {
                anchors.top: arrow.bottom
                anchors.horizontalCenter: ruler.horizontalCenter
                width: rulersParent.scaleHeight / 4
                height: width
                color: Theme.color(Theme.Timeline_PanelBackgroundColor)

                Rectangle {
                    anchors.centerIn: parent
                    width: parent.width - 2
                    height: 1
                    color: Theme.color(Theme.Timeline_TextColor)
                }

                MouseArea {
                    anchors.fill: parent
                    onClicked: rulersModel.remove(index, 1)
                }
            }
        }
    }
}