5import QGroundControl.Controls
12 property real radius: ScreenTools.isMobile ? ScreenTools.defaultFontPixelHeight * 1.75 : ScreenTools.defaultFontPixelHeight * 1.25
13 property real viewportMargins: 0
14 property var toolStrip
16 // Should be an enum but that get's into the whole problem of creating a singleton which isn't worth the effort
17 readonly property int dropLeft: 1
18 readonly property int dropRight: 2
19 readonly property int dropUp: 3
20 readonly property int dropDown: 4
22 readonly property real _arrowBaseHeight: radius // Height of vertical side of arrow
23 readonly property real _arrowPointWidth: radius * 0.666 // Distance from vertical side to point
24 readonly property real _dropMargin: ScreenTools.defaultFontPixelWidth
26 property var _dropEdgeTopPoint
27 property alias _dropDownComponent: panelLoader.sourceComponent
28 property real _viewportMaxTop: 0
29 property real _viewportMaxBottom: parent.parent.height - parent.y
30 property real _viewportMaxHeight: _viewportMaxBottom - _viewportMaxTop
31 property var _dropPanelCancel
32 property var _parentButton
34 function show(panelEdgeTopPoint, panelComponent, parentButton) {
35 _parentButton = parentButton
36 _dropEdgeTopPoint = panelEdgeTopPoint
37 _dropDownComponent = panelComponent
40 _dropPanelCancel = dropPanelCancelComponent.createObject(toolStrip.parent)
44 if (_dropPanelCancel) {
45 _dropPanelCancel.destroy()
46 _parentButton.checked = false
48 _dropDownComponent = undefined
52 function _calcPositions() {
53 var panelComponentWidth = panelLoader.item.width
54 var panelComponentHeight = panelLoader.item.height
56 dropDownItem.width = panelComponentWidth + (_dropMargin * 2) + _arrowPointWidth
57 dropDownItem.height = panelComponentHeight + (_dropMargin * 2)
59 dropDownItem.x = _dropEdgeTopPoint.x + _dropMargin
60 dropDownItem.y = _dropEdgeTopPoint.y -(dropDownItem.height / 2) + radius
62 // Validate that dropdown is within viewport
63 dropDownItem.y = Math.min(dropDownItem.y + dropDownItem.height, _viewportMaxBottom) - dropDownItem.height
64 dropDownItem.y = Math.max(dropDownItem.y, _viewportMaxTop)
66 // Adjust height to not exceed viewport bounds
67 dropDownItem.height = Math.min(dropDownItem.height, _viewportMaxHeight - dropDownItem.y)
70 arrowCanvas.arrowPoint.y = (_dropEdgeTopPoint.y + radius) - dropDownItem.y
71 arrowCanvas.arrowPoint.x = 0
72 arrowCanvas.arrowBase1.x = _arrowPointWidth
73 arrowCanvas.arrowBase1.y = arrowCanvas.arrowPoint.y - (_arrowBaseHeight / 2)
74 arrowCanvas.arrowBase2.x = arrowCanvas.arrowBase1.x
75 arrowCanvas.arrowBase2.y = arrowCanvas.arrowBase1.y + _arrowBaseHeight
76 arrowCanvas.requestPaint()
77 } // function - _calcPositions
79 QGCPalette { id: qgcPal }
82 // Overlay which is used to cancel the panel when the user clicks away
83 id: dropPanelCancelComponent
88 onClicked: dropPanel.hide()
92 // This item is sized to hold the entirety of the drop panel including the arrow point
104 property point arrowPoint: Qt.point(0, 0)
105 property point arrowBase1: Qt.point(0, 0)
106 property point arrowBase2: Qt.point(0, 0)
109 var panelX = _arrowPointWidth
111 var panelWidth = parent.width - _arrowPointWidth
112 var panelHeight = parent.height
114 var context = getContext("2d")
118 context.moveTo(panelX, panelY) // top left
119 context.lineTo(panelX + panelWidth, panelY) // top right
120 context.lineTo(panelX + panelWidth, panelX + panelHeight) // bottom right
121 context.lineTo(panelX, panelY + panelHeight) // bottom left
122 context.lineTo(arrowBase2.x, arrowBase2.y)
123 context.lineTo(arrowPoint.x, arrowPoint.y)
124 context.lineTo(arrowBase1.x, arrowBase1.y)
125 context.lineTo(panelX, panelY) // top left
128 context.fillStyle = qgcPal.windowShade
131 } // Canvas - arrowCanvas
134 id: panelItemFlickable
135 anchors.margins: _dropMargin
136 anchors.leftMargin: _dropMargin + _arrowPointWidth
138 flickableDirection: Flickable.VerticalFlick
139 contentWidth: panelLoader.width
140 contentHeight: panelLoader.height
145 onHeightChanged: _calcPositions()
146 onWidthChanged: _calcPositions()
148 property var dropPanel: _root
151 } // Item - dropDownItem