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