QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
SelectableControl.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7import QGroundControl.FactControls
8
9/// Controt that allows the user to select from a list of controls to display.
10/// Selection is is shown on right-click for desktop and long press for mobile.
11Control {
12 id: control
13 topInset: 0
14 bottomInset: 0
15 leftInset: 0
16 rightInset: 0
17 topPadding: _showSelectionUI ? selectionUILayout.height : 0
18 bottomPadding: 0
19 leftPadding: 0
20 rightPadding: 0
21
22 property Fact selectedControl ///< Fact which has enumStrings/Values where values are the qml file for the control
23 property bool selectionUIRightAnchor: false
24 property var innerControl: loader.item
25
26 property bool _showSelectionUI: false
27
28 background: Item {
29 RowLayout {
30 id: selectionUILayout
31 anchors.right: control.selectionUIRightAnchor ? parent.right : undefined
32 spacing: ScreenTools.defaultFontPixelWidth
33 visible: _showSelectionUI
34
35 QGCButton {
36 onClicked: _showSelectionUI = false
37 iconSource: "qrc:/InstrumentValueIcons/lock-open.svg"
38 }
39
40 FactComboBox {
41 fact: selectedControl
42 indexModel: false
43 sizeToContents: true
44 }
45 }
46 }
47
48 contentItem: Item {
49 implicitWidth: loader.item.width
50 implicitHeight: loader.item.height
51
52 Loader {
53 id: loader
54 source: selectedControl ? selectedControl.rawValue : ""
55 }
56
57 QGCMouseArea {
58 anchors.fill: parent
59 acceptedButtons: Qt.LeftButton | Qt.RightButton
60
61 onClicked: (mouse) => {
62 if (!ScreenTools.isMobile && mouse.button === Qt.RightButton) {
63 _showSelectionUI = true
64 }
65 }
66
67 onPressAndHold: _showSelectionUI = true
68 }
69 }
70}