QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
ToolStripHoverButton.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7Button {
8 id: control
9 width: contentLayoutItem.contentWidth + (contentMargins * 2)
10 height: width
11 hoverEnabled: !ScreenTools.isMobile
12 enabled: toolStripAction.enabled
13 visible: toolStripAction.visible
14 imageSource: toolStripAction.showAlternateIcon ? modelData.alternateIconSource : modelData.iconSource
15 text: toolStripAction.text
16 checked: toolStripAction.checked
17 checkable: toolStripAction.dropPanelComponent || modelData.checkable
18
19 property var toolStripAction: undefined
20 property var dropPanel: undefined
21 property alias radius: buttonBkRect.radius
22 property alias fontPointSize: innerText.font.pointSize
23 property alias imageSource: innerImage.source
24 property alias contentWidth: innerText.contentWidth
25
26 property bool forceImageScale11: false
27 property real imageScale: forceImageScale11 && (text == "") ? 0.8 : 0.6
28 property real contentMargins: innerText.height * 0.1
29
30 property color _currentContentColor: (checked || pressed) ? qgcPal.buttonHighlightText : qgcPal.windowTransparentText
31 property color _currentContentColorSecondary: (checked || pressed) ? qgcPal.windowTransparentText : qgcPal.buttonHighlight
32
33 signal dropped(int index)
34
35 onCheckedChanged: toolStripAction.checked = checked
36
37 onClicked: {
38 if (mainWindow.allowViewSwitch()) {
39 dropPanel.hide()
40 if (!toolStripAction.dropPanelComponent) {
41 toolStripAction.triggered(this)
42 } else if (checked) {
43 var panelEdgeTopPoint = mapToItem(_root, width, 0)
44 dropPanel.show(panelEdgeTopPoint, toolStripAction.dropPanelComponent, this)
45 checked = true
46 control.dropped(index)
47 }
48 } else if (checkable) {
49 checked = !checked
50 }
51 }
52
53 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
54
55 contentItem: Item {
56 id: contentLayoutItem
57 anchors.fill: parent
58 anchors.margins: contentMargins
59
60 Column {
61 anchors.centerIn: parent
62 spacing: 0
63
64 Image {
65 id: innerImageColorful
66 height: contentLayoutItem.height * imageScale
67 width: contentLayoutItem.width * imageScale
68 smooth: true
69 mipmap: true
70 fillMode: Image.PreserveAspectFit
71 antialiasing: true
72 sourceSize.height: height
73 sourceSize.width: width
74 anchors.horizontalCenter: parent.horizontalCenter
75 source: control.imageSource
76 visible: source != "" && modelData.fullColorIcon
77 }
78
79 QGCColoredImage {
80 id: innerImage
81 height: contentLayoutItem.height * imageScale
82 width: contentLayoutItem.width * imageScale
83 smooth: true
84 mipmap: true
85 color: _currentContentColor
86 fillMode: Image.PreserveAspectFit
87 antialiasing: true
88 sourceSize.height: height
89 sourceSize.width: width
90 anchors.horizontalCenter: parent.horizontalCenter
91 visible: source != "" && !modelData.fullColorIcon
92
93 QGCColoredImage {
94 id: innerImageSecondColor
95 source: modelData.alternateIconSource
96 height: contentLayoutItem.height * imageScale
97 width: contentLayoutItem.width * imageScale
98 smooth: true
99 mipmap: true
100 color: _currentContentColorSecondary
101 fillMode: Image.PreserveAspectFit
102 antialiasing: true
103 sourceSize.height: height
104 sourceSize.width: width
105 anchors.horizontalCenter: parent.horizontalCenter
106 visible: source != "" && modelData.biColorIcon
107 }
108 }
109
110 QGCLabel {
111 id: innerText
112 text: control.text
113 color: _currentContentColor
114 anchors.horizontalCenter: parent.horizontalCenter
115 font.bold: !innerImage.visible && !innerImageColorful.visible
116 opacity: !innerImage.visible ? 0.8 : 1.0
117 }
118 }
119 }
120
121 background: Rectangle {
122 id: buttonBkRect
123 color: (control.checked || control.pressed) ?
124 qgcPal.buttonHighlight :
125 ((control.enabled && control.hovered) ? qgcPal.toolStripHoverColor : "transparent")
126 }
127}