QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCRadioButtonBar.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7/// Mutually exclusive buttons joined into a single bar. Selecting a button emits activated; the owner updates
8/// currentIndex in response, so a binding on currentIndex is never replaced.
9Rectangle {
10 id: control
11 implicitWidth: buttonRow.implicitWidth + border.width * 2
12 implicitHeight: buttonRow.implicitHeight + border.width * 2
13 color: "transparent"
14 border.color: qgcPal.borderSubtle
15 radius: ScreenTools.defaultBorderRadius * 2
16
17 property var model: [] ///< Button labels
18 property int currentIndex: 0
19
20 /// Emitted only when the user selects a different button
21 signal activated(int index)
22
23 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
24
25 Row {
26 id: buttonRow
27 x: control.border.width
28 y: control.border.width
29
30 Repeater {
31 id: buttonRepeater
32 model: control.model
33
34 AbstractButton {
35 id: button
36 text: modelData
37 checked: index === control.currentIndex
38 hoverEnabled: true
39 leftPadding: ScreenTools.defaultFontPixelWidth * 1.5
40 rightPadding: leftPadding
41 topPadding: ScreenTools.defaultFontPixelHeight * 0.3
42 bottomPadding: topPadding
43
44 required property int index
45 required property string modelData
46
47 readonly property real _outerRadius: Math.max(control.radius - control.border.width, 0)
48
49 background: Rectangle {
50 color: button.checked ? qgcPal.borderSubtle : (button.hovered ? qgcPal.windowCard : "transparent")
51 topLeftRadius: button.index === 0 ? button._outerRadius : 0
52 bottomLeftRadius: topLeftRadius
53 topRightRadius: button.index === buttonRepeater.count - 1 ? button._outerRadius : 0
54 bottomRightRadius: topRightRadius
55 }
56
57 contentItem: QGCLabel {
58 text: button.text
59 font.bold: true
60 color: button.checked ? qgcPal.textPrimary : qgcPal.textSecondary
61 horizontalAlignment: Text.AlignHCenter
62 verticalAlignment: Text.AlignVCenter
63 }
64
65 onClicked: {
66 if (index !== control.currentIndex) {
67 control.activated(index)
68 }
69 }
70 }
71 }
72 }
73}