aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/tracing/qml/SelectionRangeDetails.qml
blob: c77c901c16fa8b6210ce649e47ee4ec11cca0348 (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
110
111
112
113
114
115
116
117
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0

import QtQuick
import QtQuick.Controls

import QtCreator.Tracing

Item {
    id: selectionRangeDetails

    signal recenter
    signal close

    property double startTime
    property double endTime
    property double duration
    property double referenceDuration
    property bool showDuration
    property bool hasContents

    width: Math.max(150, col.width + 25)
    height: hasContents ? col.height + 30 : 0

    // keep inside view
    Connections {
        target: selectionRangeDetails.parent
        function onWidthChanged() { fitInView(); }
        function onHeightChanged() { fitInView(); }
    }

    function fitInView() {
        // don't reposition if it does not fit
        if (parent.width < width || parent.height < height)
            return;

        if (x + width > parent.width)
            x = parent.width - width;
        if (x < 0)
            x = 0;
        if (y + height > parent.height)
            y = parent.height - height;
        if (y < 0)
            y = 0;
    }

    // title bar
    Rectangle {
        width: parent.width
        height: 20
        color: Theme.color(Theme.Timeline_PanelHeaderColor)
    }

    //title
    TimelineText {
        id: typeTitle
        text: "  "+qsTr("Selection")
        font.bold: true
        height: 20
        verticalAlignment: Text.AlignVCenter
        width: parent.width
        color: Theme.color(Theme.PanelTextColorLight)
    }

    // Details area
    Rectangle {
        color: Theme.color(Theme.Timeline_PanelBackgroundColor)
        width: parent.width
        height: col.height + 10
        y: 20
        Grid {
            id: col
            x: 10
            y: 5
            spacing: 5
            columns: 2

            Repeater {
                id: details
                property var contents: [
                    qsTr("Start") + ":",
                    TimeFormatter.format(startTime, referenceDuration),
                    (qsTr("End") + ":"),
                    TimeFormatter.format(endTime, referenceDuration),
                    (qsTr("Duration") + ":"),
                    TimeFormatter.format(duration, referenceDuration)
                ]

                model: showDuration ? 6 : 2
                Detail {
                    isLabel: index % 2 === 0
                    text: details.contents[index]
                }
            }
        }
    }

    MouseArea {
        anchors.fill: parent
        drag.target: parent
        drag.minimumX: 0
        drag.maximumX: selectionRangeDetails.parent.width - width
        drag.minimumY: 0
        drag.maximumY: selectionRangeDetails.parent.height - height
        onClicked: selectionRangeDetails.recenter()
    }

    ImageToolButton {
        id: closeIcon
        imageSource: "image://icons/close_window"
        anchors.right: selectionRangeDetails.right
        anchors.top: selectionRangeDetails.top
        implicitHeight: typeTitle.height
        onClicked: selectionRangeDetails.close()
        ToolTip.text: qsTr("Close")
    }
}