Newer
Older
/****************************************************************************
*
* (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0
color: qgcPal.globalTheme === QGCPalette.Light ? QGroundControl.corePlugin.options.toolbarBackgroundLight : QGroundControl.corePlugin.options.toolbarBackgroundDark
width: _idealWidth < repeater.contentWidth ? repeater.contentWidth : _idealWidth
height: Math.min(maxHeight, toolStripColumn.height + (flickable.anchors.margins * 2))
radius: ScreenTools.defaultFontPixelWidth / 2
property alias model: repeater.model
property real maxHeight ///< Maximum height for control, determines whether text is hidden to make control shorter
property AbstractButton lastClickedButton: null
if (!toolStripColumn.children[buttonIndex].checked) {
toolStripColumn.children[buttonIndex].checked = true
toolStripColumn.children[buttonIndex].clicked()
}
// Ensure we don't get narrower than content
property real _idealWidth: (ScreenTools.isMobile ? ScreenTools.minTouchPixels : ScreenTools.defaultFontPixelWidth * 8) + toolStripColumn.anchors.margins * 2
signal clicked(int index, bool checked)
function setChecked(idx, check) {
repeater.itemAt(idx).checked = check
}
function getChecked(idx) {
return repeater.itemAt(idx).checked
}
}
anchors.margins: ScreenTools.defaultFontPixelWidth * 0.4
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: parent.height
contentHeight: toolStripColumn.height
flickableDirection: Flickable.VerticalFlick
Column {
id: toolStripColumn
anchors.left: parent.left
anchors.right: parent.right
spacing: ScreenTools.defaultFontPixelWidth * 0.25
QGCLabel {
id: titleLabel
anchors.left: parent.left
anchors.right: parent.right
horizontalAlignment: Text.AlignHCenter
font.pointSize: ScreenTools.smallFontPointSize
visible: title != ""
}
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Repeater {
id: repeater
QGCHoverButton {
id: buttonTemplate
anchors.left: toolStripColumn.left
anchors.right: toolStripColumn.right
height: width
radius: ScreenTools.defaultFontPixelWidth / 2
fontPointSize: ScreenTools.smallFontPointSize
autoExclusive: true
enabled: modelData.buttonEnabled
visible: modelData.buttonVisible
imageSource: modelData.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource
text: modelData.name
checked: modelData.checked !== undefined ? modelData.checked : checked
ButtonGroup.group: buttonGroup
// Only drop panel and toggleable are checkable
checkable: modelData.dropPanelComponent !== undefined || (modelData.toggle !== undefined && modelData.toggle)
onClicked: {
dropPanel.hide() // DropPanel will call hide on "lastClickedButton"
if (modelData.dropPanelComponent === undefined) {
_root.clicked(index, checked)
} else if (checked) {
var panelEdgeTopPoint = mapToItem(_root, width, 0)
dropPanel.show(panelEdgeTopPoint, height, modelData.dropPanelComponent)
_root.dropped(index)
}
if(_root && buttonTemplate)
_root.lastClickedButton = buttonTemplate