5import QGroundControl.Controls
7/// Shared cursor-position info popup used by LogViewerChart and LogViewerAltChart.
9/// Set required properties and place chart-specific rows as children — they
10/// appear below the shared time label via the default property alias.
12/// Caller is responsible for setting x/y and visible.
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
26 // -------------------------------------------------------------------------
27 // Chart-specific content — injected as children of this item
28 // -------------------------------------------------------------------------
29 default property alias extraContent: _extraColumn.data
31 // Exposed so callers can align indented rows to the color block
32 readonly property real colorBlockWidth: ScreenTools.defaultFontPixelHeight * 0.8
34 // -------------------------------------------------------------------------
36 // -------------------------------------------------------------------------
37 readonly property real _margin: ScreenTools.defaultFontPixelWidth / 2
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
45 QGCPalette { id: qgcPal }
47 // -------------------------------------------------------------------------
49 // -------------------------------------------------------------------------
53 anchors.margins: control._margin
54 spacing: ScreenTools.defaultFontPixelHeight * 0.2
56 // ---- Shared time label ----
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
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) : ""
73 elapsed = hh + ":" + String(mm).padStart(2, "0") + ":" + String(ss).padStart(2, "0") + fracStr
75 elapsed = mm + ":" + String(ss).padStart(2, "0") + fracStr
77 elapsed = decimals > 0 ? (ss + frac).toFixed(decimals) + "s" : ss + "s"
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)")
90 return elapsed + qsTr(" (elapsed)")
94 // ---- Chart-specific rows (provided by each chart as children) ----
97 spacing: ScreenTools.defaultFontPixelHeight * 0.2