6import QGroundControl.Controls
7import QGroundControl.FactControls
10 Layout.fillWidth: true
11 heading: qsTr("Connection")
12 visible: _ntrip.userVisible
14 QGCPalette { id: qgcPal }
16 property var _ntrip: QGroundControl.settingsManager.ntripSettings
17 property Fact _enabled: _ntrip.ntripServerConnectEnabled
18 property var _ntripMgr: QGroundControl.ntripManager
19 property bool _isConnected: _ntripMgr.connectionStatus === NTRIPManager.Connected
20 property bool _isConnecting: _ntripMgr.connectionStatus === NTRIPManager.Connecting
21 property bool _isReconnecting: _ntripMgr.connectionStatus === NTRIPManager.Reconnecting
22 property bool _isError: _ntripMgr.connectionStatus === NTRIPManager.Error
23 property bool _isActive: _enabled.rawValue
24 property bool _hasHost: _ntrip.ntripServerHostAddress.rawValue !== ""
27 Layout.fillWidth: true
28 spacing: ScreenTools.defaultFontPixelWidth
31 width: ScreenTools.defaultFontPixelHeight * 0.75
35 switch (_ntripMgr.connectionStatus) {
36 case NTRIPManager.Connected: return qgcPal.colorGreen
37 case NTRIPManager.Connecting:
38 case NTRIPManager.Reconnecting: return qgcPal.colorOrange
39 case NTRIPManager.Error: return qgcPal.colorRed
40 default: return qgcPal.colorGrey
43 Layout.alignment: Qt.AlignVCenter
47 Layout.fillWidth: true
48 text: _ntripMgr.statusMessage || qsTr("Disconnected")
49 wrapMode: Text.WordWrap
54 if (_isConnecting) return qsTr("Connecting…")
55 if (_isReconnecting) return qsTr("Reconnecting…")
56 if (_isConnected) return qsTr("Disconnect")
57 return qsTr("Connect")
59 enabled: !_isConnecting && (_isActive || _hasHost)
60 onClicked: _enabled.rawValue = !_enabled.rawValue
65 Layout.fillWidth: true
66 visible: _isConnected && _ntripMgr.messagesReceived > 0
68 var parts = [qsTr("%1 messages").arg(_ntripMgr.messagesReceived),
69 formatBytes(_ntripMgr.bytesReceived)]
70 if (_ntripMgr.dataRateBytesPerSec > 0)
71 parts.push(formatRate(_ntripMgr.dataRateBytesPerSec))
72 if (_ntripMgr.ggaSource)
73 parts.push(qsTr("GGA: %1").arg(_ntripMgr.ggaSource))
74 return parts.join(" · ")
76 font.pointSize: ScreenTools.smallFontPointSize
77 color: qgcPal.colorGrey
79 function formatBytes(bytes) {
80 if (bytes < 1024) return bytes + " B"
81 if (bytes < 1048576) return (bytes / 1024).toFixed(1) + " KB"
82 return (bytes / 1048576).toFixed(1) + " MB"
85 function formatRate(bytesPerSec) {
86 if (bytesPerSec < 1024) return bytesPerSec.toFixed(0) + " B/s"
87 return (bytesPerSec / 1024).toFixed(1) + " KB/s"
92 Layout.fillWidth: true
93 visible: _isError && _ntripMgr.statusMessage !== ""
94 text: _ntripMgr.statusMessage
95 wrapMode: Text.WordWrap
96 color: qgcPal.colorRed
97 font.pointSize: ScreenTools.smallFontPointSize