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