QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
LogViewerCursorPopup.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Layouts
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// Shared cursor-position info popup used by LogViewerChart and LogViewerAltChart.
8///
9/// Set required properties and place chart-specific rows as children — they
10/// appear below the shared time label via the default property alias.
11///
12/// Caller is responsible for setting x/y and visible.
13Rectangle {
14 id: control
15
16 // -------------------------------------------------------------------------
17 // Required properties
18 // -------------------------------------------------------------------------
19 required property real cursorXValue ///< seconds from log start
20 required property var logParser ///< for logParser.startTime
21 required property bool xAxisShowLocalTime ///< elapsed vs. local clock
22 required property real zoomMinX
23 required property real zoomMaxX
24 required property real plotAreaWidth ///< drives sub-second decimal count
25
26 // -------------------------------------------------------------------------
27 // Chart-specific content — injected as children of this item
28 // -------------------------------------------------------------------------
29 default property alias extraContent: _extraColumn.data
30
31 // Exposed so callers can align indented rows to the color block
32 readonly property real colorBlockWidth: ScreenTools.defaultFontPixelHeight * 0.8
33
34 // -------------------------------------------------------------------------
35 // Styling
36 // -------------------------------------------------------------------------
37 readonly property real _margin: ScreenTools.defaultFontPixelWidth / 2
38
39 color: qgcPal.windowShade
40 border.color: qgcPal.windowShadeDark
41 radius: ScreenTools.defaultFontPixelWidth * 0.3
42 implicitWidth: _mainColumn.implicitWidth + _margin * 2
43 implicitHeight: _mainColumn.implicitHeight + _margin * 2
44
45 QGCPalette { id: qgcPal }
46
47 // -------------------------------------------------------------------------
48 // Content
49 // -------------------------------------------------------------------------
50 ColumnLayout {
51 id: _mainColumn
52 anchors.fill: parent
53 anchors.margins: control._margin
54 spacing: ScreenTools.defaultFontPixelHeight * 0.2
55
56 // ---- Shared time label ----
57 QGCLabel {
58 font.bold: true
59 text: {
60 const secsPerPixel = control.plotAreaWidth > 0
61 ? (control.zoomMaxX - control.zoomMinX) / control.plotAreaWidth : 1.0
62 const decimals = secsPerPixel < 0.1 ? 2 : secsPerPixel < 1.0 ? 1 : 0
63
64 const wholeSecs = Math.floor(control.cursorXValue)
65 const frac = control.cursorXValue - wholeSecs
66 const hh = Math.floor(wholeSecs / 3600)
67 const mm = Math.floor((wholeSecs % 3600) / 60)
68 const ss = wholeSecs % 60
69 const fracStr = decimals > 0 ? frac.toFixed(decimals).slice(1) : ""
70
71 let elapsed = ""
72 if (hh > 0) {
73 elapsed = hh + ":" + String(mm).padStart(2, "0") + ":" + String(ss).padStart(2, "0") + fracStr
74 } else if (mm > 0) {
75 elapsed = mm + ":" + String(ss).padStart(2, "0") + fracStr
76 } else {
77 elapsed = decimals > 0 ? (ss + frac).toFixed(decimals) + "s" : ss + "s"
78 }
79
80 if (control.xAxisShowLocalTime) {
81 const st = control.logParser.startTime
82 if (st && !isNaN(st.getTime()) && st.getTime() > 0) {
83 const use12h = Qt.locale().timeFormat(Locale.ShortFormat).indexOf("a") >= 0
84 || Qt.locale().timeFormat(Locale.ShortFormat).indexOf("A") >= 0
85 const local = Qt.formatTime(new Date(st.getTime() + control.cursorXValue * 1000),
86 use12h ? "h:mm:ss AP" : "HH:mm:ss")
87 return local + qsTr(" (local) / ") + elapsed + qsTr(" (elapsed)")
88 }
89 }
90 return elapsed + qsTr(" (elapsed)")
91 }
92 }
93
94 // ---- Chart-specific rows (provided by each chart as children) ----
95 ColumnLayout {
96 id: _extraColumn
97 spacing: ScreenTools.defaultFontPixelHeight * 0.2
98 }
99 }
100}