QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCOptionsComboBox.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8ComboBox {
9 id: control
10 padding: ScreenTools.comboBoxPadding
11
12 property string labelText: qsTr("Options")
13
14 signal itemClicked(int index)
15
16 property var _controlQGCPal: QGCPalette { colorGroupEnabled: enabled }
17 property bool _flashChecked
18 property string _flashText
19 property bool _showFlash: false
20
21 Component.onCompleted: indicator.color = Qt.binding(function() { return _controlQGCPal.text })
22
23 background: Rectangle {
24 implicitWidth: ScreenTools.implicitComboBoxWidth
25 implicitHeight: ScreenTools.implicitComboBoxHeight
26 color: _controlQGCPal.window
27 border.width: enabled ? 1 : 0
28 border.color: "#999"
29 }
30
31 /*! Adding the Combobox list item to the theme. */
32
33 delegate: ItemDelegate {
34 implicitHeight: modelData.visible ?
35 (Math.max(background ? background.implicitHeight : 0, Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)) :
36 0
37 width: control.width
38 checkable: true
39 enabled: modelData.enabled
40 text: modelData.text
41
42 property var _checkedValue: 1
43 property var _uncheckedValue: 0
44 property var _itemQGCPal: QGCPalette { colorGroupEnabled: enabled }
45 property var _control: control
46
47 Binding on checked { value: modelData.fact ?
48 (modelData.fact.typeIsBool ? (modelData.fact.value === false ? Qt.Unchecked : Qt.Checked) : (modelData.fact.value === 0 ? Qt.Unchecked : Qt.Checked)) :
49 modelData.checked }
50
51 contentItem: RowLayout {
52 spacing: ScreenTools.defaultFontPixelWidth
53
54 Rectangle {
55 height: ScreenTools.defaultFontPixelHeight
56 width: height
57 border.color: _itemQGCPal.buttonText
58 border.width: 1
59 color: _itemQGCPal.button
60
61 QGCColoredImage {
62 anchors.centerIn: parent
63 width: parent.width * 0.75
64 height: width
65 source: "/qmlimages/checkbox-check.svg"
66 color: _itemQGCPal.buttonText
67 mipmap: true
68 fillMode: Image.PreserveAspectFit
69 sourceSize.height: height
70 visible: checked
71 }
72 }
73
74 Text {
75 text: modelData.text
76 color: _itemQGCPal.buttonText
77 }
78
79 }
80
81 background: Rectangle {
82 color: _controlQGCPal.button
83 }
84
85 onClicked: {
86 if (modelData.fact) {
87 modelData.fact.value = (checked ? _checkedValue : _uncheckedValue)
88 } else {
89 itemClicked(index)
90 }
91 _control._flashChecked = checked
92 _control._flashText = text
93 _control._showFlash = true
94 _control.popup.close()
95 }
96 }
97
98 /*! This defines the label of the button. */
99 contentItem: Item {
100 implicitWidth: _showFlash ? flash.implicitWidth : text.implicitWidth
101 implicitHeight: _showFlash ? flash.implicitHeight : text.implicitHeight
102
103 QGCLabel {
104 id: text
105 anchors.verticalCenter: parent.verticalCenter
106 text: labelText
107 color: _controlQGCPal.text
108 visible: !_showFlash
109 }
110
111 RowLayout {
112 id: flash
113 anchors.verticalCenter: parent.verticalCenter
114 spacing: ScreenTools.defaultFontPixelWidth
115 visible: _showFlash
116
117 onVisibleChanged: {
118 if (visible) {
119 flashTimer.restart()
120 }
121 }
122
123 Timer {
124 id: flashTimer
125 interval: 1500
126 repeat: false
127 running: false
128 onTriggered: _showFlash = false
129 }
130
131 Rectangle {
132 height: ScreenTools.defaultFontPixelHeight
133 width: height
134 border.color: _controlQGCPal.buttonText
135 border.width: 1
136 color: _controlQGCPal.window
137
138 QGCColoredImage {
139 anchors.centerIn: parent
140 width: parent.width * 0.75
141 height: width
142 source: "/qmlimages/checkbox-check.svg"
143 color: _controlQGCPal.text
144 mipmap: true
145 fillMode: Image.PreserveAspectFit
146 sourceSize.height: height
147 visible: _flashChecked
148 }
149 }
150
151 Text {
152 text: _flashText
153 color: _controlQGCPal.buttonText
154 }
155
156 }
157 }
158}