4import QtQuick.Templates as T
7import QGroundControl.Controls
10 property bool sizeToContents: false
11 property string alternateText: ""
14 padding: ScreenTools.comboBoxPadding
15 spacing: ScreenTools.defaultFontPixelWidth
16 font.pointSize: ScreenTools.defaultFontPointSize
17 font.family: ScreenTools.normalFontFamily
18 implicitWidth: Math.max(background.implicitWidth,
19 (control.sizeToContents ? _largestTextWidth : contentItem.implicitWidth) + leftPadding + rightPadding + padding)
20 implicitHeight: Math.max(background.implicitHeight,
21 Math.max(contentItem.implicitHeight, indicator ? indicator.implicitHeight : 0) + topPadding + bottomPadding)
22 baselineOffset: contentItem.y + text.baselineOffset
23 leftPadding: padding + (!control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width + spacing)
24 rightPadding: padding + (control.mirrored || !indicator || !indicator.visible ? 0 : indicator.width)
26 property real _popupWidth: width
27 property real _largestTextWidth: 0
28 property bool _onCompleted: false
29 property bool _showBorder: qgcPal.globalTheme === QGCPalette.Light
30 property bool _showHighlight: enabled && pressed
32 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
36 font.family: control.font.family
37 font.pointSize: control.font.pointSize
41 id: itemDelegateMetrics
43 font.family: control.font.family
44 font.pointSize: control.font.pointSize
47 function _calcPopupWidth() {
48 if (_onCompleted && sizeToContents && control.count > 0) {
50 for (let i = 0; i < control.count; i++) {
51 textMetrics.text = control.textAt(i)
52 _largestTextWidth = Math.max(textMetrics.width, _largestTextWidth)
54 _popupWidth = _largestTextWidth + itemDelegateMetrics.leftPadding + itemDelegateMetrics.rightPadding
58 onModelChanged: _calcPopupWidth()
59 onCountChanged: _calcPopupWidth()
61 Component.onCompleted: {
66 // The items in the popup
67 delegate: ItemDelegate {
69 height: Math.round(popupItemMetrics.height * 1.75)
71 property string _text: control.textRole ?
72 (model.hasOwnProperty(control.textRole) ? model[control.textRole] : modelData[control.textRole]) :
84 color: control.currentIndex === index ? qgcPal.buttonHighlightText : qgcPal.buttonText
85 verticalAlignment: Text.AlignVCenter
88 background: Rectangle {
89 color: control.currentIndex === index ? qgcPal.buttonHighlight : qgcPal.button
92 highlighted: control.highlightedIndex === index
95 indicator: QGCColoredImage {
96 anchors.rightMargin: control.padding
97 anchors.right: parent.right
98 anchors.verticalCenter: parent.verticalCenter
99 height: ScreenTools.defaultFontPixelWidth
101 source: "/qmlimages/arrow-down.png"
102 color: qgcPal.buttonText
105 // The label of the button
106 contentItem: QGCLabel {
108 text: control.alternateText === "" ? control.currentText : control.alternateText
110 color: qgcPal.buttonText
111 elide: Text.ElideRight
114 background: Rectangle {
116 border.color: qgcPal.buttonBorder
117 border.width: _showBorder ? 1 : 0
118 radius: ScreenTools.defaultBorderRadius
122 color: qgcPal.buttonHighlight
123 opacity: _showHighlight ? 1 : control.enabled && control.hovered ? .2 : 0
124 radius: parent.radius
129 x: Math.max(-_controlPos.x, Math.min(control.width - _popupWidth, control.Window.width - _controlPos.x - _popupWidth))
130 y: _openAbove ? -height : control.height
132 height: Math.min(contentItem.implicitHeight, _openAbove ? _spaceAbove : _spaceBelow)
136 readonly property point _controlPos: control.mapToItem(null, 0, 0)
137 readonly property real _spaceBelow: Math.max(0, control.Window.height - _controlPos.y - control.height - bottomMargin)
138 readonly property real _spaceAbove: Math.max(0, _controlPos.y - topMargin)
139 readonly property bool _openAbove: contentItem.implicitHeight > _spaceBelow && _spaceAbove > _spaceBelow
141 contentItem: ListView {
143 implicitHeight: contentHeight
144 model: control.delegateModel
145 currentIndex: control.highlightedIndex
146 highlightMoveDuration: 0
151 height: parent.height
153 border.color: qgcPal.text
156 T.ScrollIndicator.vertical: ScrollIndicator { }
159 background: Rectangle {