summaryrefslogtreecommitdiffstats
path: root/examples/positioning/satelliteinfo/SatelliteView.qml
blob: 042dd57c65951bd029ca46d2e6f2424be9156ab5 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

pragma ComponentBehavior: Bound
import QtPositioning
import QtQuick
import QtQuick.Controls.Basic as QC
import QtQuick.Layouts
import SatelliteInformation

Rectangle {
    id: root

    required property SortFilterModel sortFilterModel
    required property color inViewColor
    required property color inUseColor

    readonly property int iconItemWidth: 50

    color: Theme.darkBackgroundColor

    property var satelliteSystemModel: [
        {"name": "GPS", "id": GeoSatelliteInfo.GPS},
        {"name": "GLONASS", "id": GeoSatelliteInfo.GLONASS},
        {"name": "GALILEO", "id": GeoSatelliteInfo.GALILEO},
        {"name": "BEIDOU", "id": GeoSatelliteInfo.BEIDOU},
        {"name": "QZSS", "id": GeoSatelliteInfo.QZSS}
    ]

    component RssiElement : Rectangle {
        id: rssiRoot

        required property int rssi

        implicitHeight: rssiVal.implicitHeight
        implicitWidth: rssiVal.implicitWidth + dbm.implicitWidth + rssiLayout.spacing
        color: "transparent"

        RowLayout {
            id: rssiLayout
            anchors.fill: parent
            spacing: 2
            Text {
                id: rssiVal
                text: rssiRoot.rssi >= 0 ? rssiRoot.rssi : qsTr("N/A")
                color: Theme.textSecondaryColor
                font.pixelSize: Theme.smallFontSize
                font.weight: Theme.fontDefaultWeight
            }
            Text{
                id: dbm
                visible: rssiRoot.rssi >= 0
                text: qsTr("dBm")
                color: Theme.textGrayColor
                font.pixelSize: Theme.smallFontSize
                font.weight: Theme.fontDefaultWeight
            }
        }
    }

    component StatusElement : Rectangle {
        id: statusRoot

        required property bool inUse

        implicitHeight: statusText.implicitHeight
        implicitWidth: statusText.implicitWidth + statusIcon.implicitWidth + statusLayout.spacing
        color: "transparent"

        RowLayout {
            id: statusLayout
            anchors.fill: parent
            spacing: Theme.defaultSpacing
            Rectangle {
                id: statusIcon
                implicitHeight: statusText.font.pixelSize
                implicitWidth: implicitHeight
                radius: height / 2
                color: statusRoot.inUse ? root.inUseColor : root.inViewColor
            }
            Text {
                id: statusText
                text: statusRoot.inUse ? qsTr("In Use") : qsTr("In View")
                color: Theme.textSecondaryColor
                font.pixelSize: Theme.smallFontSize
                font.weight: Theme.fontLightWeight
            }
        }
    }

    RssiElement {
        id: hiddenRssiElement
        rssi: 999
        visible: false
    }
    StatusElement {
        id: hiddenStatusElement
        inUse: false
        visible: false
    }

    component ListHeader : Rectangle {
        implicitHeight: identifierHdr.height
        color: root.color

        RowLayout {
            anchors {
                fill: parent
                leftMargin: Theme.defaultSpacing * 2
                rightMargin: Theme.defaultSpacing * 2
            }
            spacing: Theme.defaultSpacing * 2
            Item {
                id: blank
                implicitWidth: root.iconItemWidth
            }
            Text {
                id: identifierHdr
                text: qsTr("Identifier")
                color: Theme.textSecondaryColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.fillWidth: true
            }
            Text {
                id: rssiHdr
                text: qsTr("RSSI")
                color: Theme.textSecondaryColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.preferredWidth: hiddenRssiElement.width
            }
            Text {
                id: statusHdr
                text: qsTr("Status")
                color: Theme.textSecondaryColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.preferredWidth: hiddenStatusElement.width
            }
        }
        Rectangle {
            anchors.bottom: parent.bottom
            height: 1
            width: parent.width
            color: Theme.tableSeparatorColor
        }
    }

    component ListItem : Rectangle {
        id: listItem

        required property int index
        required property var modelData

        color: "transparent"

        RowLayout {
            anchors {
                fill: parent
                leftMargin: Theme.defaultSpacing * 2
                rightMargin: Theme.defaultSpacing * 2
            }
            spacing: Theme.defaultSpacing * 2
            Rectangle {
                implicitWidth: root.iconItemWidth
                color: "transparent"
                Image {
                    anchors.centerIn: parent
                    source: listItem.index % 2 === 0 ? "icons/satellite1.png"
                                                     : "icons/satellite2.png"
                }
            }
            Text {
                text: listItem.modelData.system + "-" + listItem.modelData.id
                color: Theme.textMainColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.fillWidth: true
            }
            RssiElement {
                rssi: listItem.modelData.rssi
                Layout.preferredWidth: hiddenRssiElement.width
            }
            StatusElement {
                inUse: listItem.modelData.inUse
                Layout.preferredWidth: hiddenStatusElement.width
            }
        }
        Rectangle {
            anchors.bottom: parent.bottom
            height: 1
            width: parent.width
            color: Theme.tableSeparatorColor
        }
    }

    component SearchInput : QC.TextField {
        id: searchInput
        palette {
            placeholderText: Theme.grayColor
            text: Theme.textMainColor
        }
        rightPadding: padding + searchIcon.width + searchIcon.anchors.rightMargin
        font.pixelSize: Theme.smallFontSize
        font.weight: Theme.fontLightWeight
        background: Rectangle {
            border {
                width: 1
                color:Theme.searchBorderColor
            }
            color: "transparent"
            radius: 3
            Image {
                id: searchIcon
                anchors {
                    right: parent.right
                    rightMargin: Theme.defaultSpacing
                    verticalCenter: parent.verticalCenter
                }
                source: "icons/search.svg"
                sourceSize.height: searchInput.implicitHeight - searchInput.padding * 2
                fillMode: Image.PreserveAspectFit
            }
        }
    }

    component IconButton : QC.ToolButton {
        id: iconButton
        property bool selected: false
        icon.width: 0
        icon.height: 0
        icon.color: selected ? Theme.greenColor : Theme.grayColor
        background: Rectangle {
            border {
                width: 1
                color: iconButton.selected ? Theme.greenColor : Theme.searchBorderColor
            }
            color: "transparent"
            radius: 3
        }
    }

    component MenuPopup : QC.Popup {
        modal: true
        background: Rectangle {
            radius: 8
            color: Theme.backgroundColor
            border {
                width: 1
                color: Theme.separatorColor
            }
        }
    }

    component CheckElement : QC.ItemDelegate {
        id: checkElement

        readonly property int iconSize: font.pixelSize * 2

        checked: true
        padding: 0

        display: QC.AbstractButton.TextBesideIcon

        font.pixelSize: Theme.smallFontSize
        font.weight: Theme.fontLightWeight
        palette.text: checked ? Theme.greenColor : Theme.textSecondaryColor

        icon.source: checked ? "icons/checkbox.svg" : "icons/checkbox_blank.svg"
        icon.height: iconSize
        icon.width: iconSize
        icon.color: checked ? Theme.greenColor : Theme.textSecondaryColor

        LayoutMirroring.enabled: true
        LayoutMirroring.childrenInherit: true

        background: Rectangle {
            anchors.fill: parent
            color: "transparent"
        }

        onClicked: {
            checked = !checked
        }
    }

    Rectangle {
        id: sortAndFilter
        width: root.width
        height: searchField.implicitHeight + sortAndFilterLayout.anchors.margins * 2
        color: Theme.backgroundColor
        RowLayout {
            id: sortAndFilterLayout
            anchors {
                fill: parent
                margins: Theme.defaultSpacing * 2
            }
            spacing: Theme.defaultSpacing * 2
            SearchInput {
                id: searchField
                placeholderText: qsTr("Search")
                Layout.fillWidth: true
                onTextChanged: root.sortFilterModel.updateFilterString(text);
            }
            IconButton {
                selected: sortMenu.visible
                icon.source: "icons/sort.svg"
                rotation: 90
                Layout.preferredHeight: searchField.implicitHeight
                Layout.preferredWidth: Layout.preferredHeight
                onClicked: sortMenu.open()
            }
            IconButton {
                selected: filterMenu.visible
                icon.source: "icons/filter.svg"
                Layout.preferredHeight: searchField.implicitHeight
                Layout.preferredWidth: Layout.preferredHeight
                onClicked: filterMenu.open()
            }
        }
    }

    Rectangle {
        id: separator
        anchors.top: sortAndFilter.bottom
        color: Theme.separatorColor
        height: 1
        width: root.width
    }

    ListView {
        id: satellitesView
        anchors {
            top: separator.bottom
            bottom: root.bottom
        }
        width: root.width
        clip: true
        model: root.sortFilterModel
        header: ListHeader {
            height: 30
            width: root.width
            z: 2 // to show on top of the items
        }
        headerPositioning: ListView.OverlayHeader
        delegate: ListItem {
            height: 50
            width: root.width
        }
    }

    MenuPopup {
        id: sortMenu
        x: root.width - sortMenu.width - Theme.defaultSpacing
        y: satellitesView.y - Theme.defaultSpacing
        ColumnLayout {
            anchors.fill: parent
            spacing: Theme.defaultSpacing
            CheckElement {
                checked: false
                text: qsTr("By Identifier")
                Layout.alignment: Qt.AlignRight
                onCheckedChanged: {
                    root.sortFilterModel.updateSortRoles(Roles.SystemRole, checked)
                }
            }
            CheckElement {
                checked: false
                text: qsTr("By Status")
                Layout.alignment: Qt.AlignRight
                onCheckedChanged: {
                    root.sortFilterModel.updateSortRoles(Roles.InUseRole, checked)
                }
            }
        }
    }

    MenuPopup {
        id: filterMenu
        x: root.width - filterMenu.width - Theme.defaultSpacing
        y: satellitesView.y - Theme.defaultSpacing
        ColumnLayout {
            id: filterLayout
            anchors.fill: parent
            spacing: Theme.defaultSpacing
            Text {
                text: qsTr("Satellite Identifier")
                color: Theme.textMainColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.alignment: Qt.AlignRight
            }
            //! [0]
            Repeater {
                model: root.satelliteSystemModel
                delegate: CheckElement {
                    required property var modelData
                    text: modelData.name
                    Layout.alignment: Qt.AlignRight
                    onCheckedChanged: {
                        root.sortFilterModel.updateSelectedSystems(modelData.id, checked)
                    }
                }
            }
            //! [0]
            Text {
                text: qsTr("Satellite Status")
                color: Theme.textMainColor
                font.pixelSize: Theme.mediumFontSize
                font.weight: Theme.fontDefaultWeight
                Layout.alignment: Qt.AlignRight
            }
            //! [1]
            CheckElement {
                text: qsTr("In View")
                Layout.alignment: Qt.AlignRight
                onCheckedChanged: root.sortFilterModel.updateShowInView(checked)
            }
            CheckElement {
                text: qsTr("In Use")
                Layout.alignment: Qt.AlignRight
                onCheckedChanged: root.sortFilterModel.updateShowInUse(checked)
            }
            //! [1]
        }
    }
}