QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCCheckBoxSlider.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8AbstractButton {
9 id: control
10 checkable: true
11 padding: 0
12
13 property int _sliderInset: 2
14 property bool _showHighlight: enabled && (pressed || checked)
15 property real _labelSpacing: ScreenTools.defaultFontPixelWidth
16
17 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
18
19 // The label wraps only when the control is narrower than its single-line width
20 contentItem: Item {
21 implicitWidth: (label.visible ? label.implicitWidth + control._labelSpacing : 0) + indicator.width
22 implicitHeight: label.contentHeight
23
24 QGCLabel {
25 id: label
26 objectName: "checkBoxSlider_label"
27 anchors.left: parent.left
28 width: Math.max(0, parent.width - indicator.width - control._labelSpacing)
29 text: visible ? control.text : "X"
30 wrapMode: Text.WordWrap
31 visible: control.text !== ""
32 }
33
34 Rectangle {
35 id: indicator
36 objectName: "checkBoxSlider_indicator"
37 anchors.right: parent.right
38 anchors.verticalCenter: parent.verticalCenter
39 height: ScreenTools.defaultFontPixelHeight
40 width: height * 2
41 radius: height / 2
42 color: checked ? qgcPal.accent : qgcPal.windowInset
43 border.width: 1
44 border.color: checked ? qgcPal.accent : qgcPal.borderSubtle
45
46 Rectangle {
47 anchors.fill: parent
48 color: qgcPal.accent
49 opacity: _showHighlight ? 1 : control.enabled && control.hovered ? .2 : 0
50 radius: parent.radius
51 }
52
53 Rectangle {
54 anchors.verticalCenter: parent.verticalCenter
55 x: checked ? indicator.width - width - _sliderInset : _sliderInset
56 height: parent.height - (_sliderInset * 2)
57 width: height
58 radius: height / 2
59 color: qgcPal.textPrimary
60 }
61 }
62 }
63}