QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCButton.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8/// Standard push button control:
9/// If there is both an icon and text the icon will be to the left of the text
10/// If icon only, icon will be centered
11Button {
12 property bool primary: false
13 property bool showBorder: true
14 property real backRadius: ScreenTools.defaultBorderRadius
15 property real heightFactor: small ? 0.2 : 0.3
16 property string iconSource: ""
17 property real fontWeight: Font.Normal // default for qml Text
18 property real pointSize: small ? ScreenTools.smallFontPointSize : ScreenTools.defaultFontPointSize
19
20 /// Compact variant for secondary actions in dense areas (indicator drop-downs, list headers).
21 /// Only changes the defaults of heightFactor, pointSize and horizontal padding and drops the minimum button height
22 /// (the minimum width still applies); each default can still be overridden explicitly.
23 property bool small: false
24
25 property alias wrapMode: text.wrapMode
26 property alias horizontalAlignment: text.horizontalAlignment
27 property color backgroundColor: primary ? qgcPal.accent : qgcPal.windowCard
28 property alias textColor: text.color
29
30 id: control
31 hoverEnabled: !ScreenTools.isMobile
32 topPadding: _verticalPadding
33 bottomPadding: _verticalPadding
34 leftPadding: _horizontalPadding
35 rightPadding: _horizontalPadding
36 focusPolicy: Qt.ClickFocus
37 font.family: ScreenTools.normalFontFamily
38 text: ""
39
40 property bool _showHighlight: enabled && (pressed || checked)
41 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth * (small ? 1 : 2)
42 property int _textVerticalPadding: Math.round(ScreenTools.defaultFontPixelHeight * heightFactor)
43 property real _textOnlyHeight: Math.max(small ? 0 : ScreenTools.implicitButtonHeight, text.implicitHeight + _textVerticalPadding * 2)
44 property real _iconHeight: Math.round(_textOnlyHeight * 0.75)
45 property int _verticalPadding: iconSource === "" ? _textVerticalPadding : Math.max(0, Math.round((_textOnlyHeight - _iconHeight) / 2))
46 // Solid fills (primary or a caller supplied backgroundColor) keep their color and show state with an overlay instead
47 property bool _solidFill: primary || !Qt.colorEqual(backgroundColor, qgcPal.windowCard)
48
49 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
50
51 background: Rectangle {
52 id: backRect
53 radius: backRadius
54 implicitWidth: ScreenTools.implicitButtonWidth
55 implicitHeight: control.small ? control.implicitContentHeight + control.topPadding + control.bottomPadding : ScreenTools.implicitButtonHeight
56 border.width: showBorder ? 1 : 0
57 border.color: primary || _showHighlight || (control.enabled && control.hovered) ? qgcPal.accent : qgcPal.borderSubtle
58 color: !control._solidFill && control._showHighlight ? qgcPal.accentSubtle : control.backgroundColor
59
60 Rectangle {
61 anchors.fill: parent
62 radius: parent.radius
63 color: qgcPal.accentText
64 visible: control._solidFill
65 opacity: control._showHighlight ? 0.25 : (control.enabled && control.hovered ? 0.12 : 0)
66 }
67 }
68
69 contentItem: RowLayout {
70 spacing: ScreenTools.defaultFontPixelWidth
71
72 QGCColoredImage {
73 id: icon
74 Layout.alignment: Qt.AlignHCenter
75 source: control.iconSource
76 height: _iconHeight
77 width: height
78 color: text.color
79 fillMode: Image.PreserveAspectFit
80 sourceSize.height: height
81 visible: control.iconSource !== ""
82 }
83
84 QGCLabel {
85 id: text
86 Layout.alignment: Qt.AlignHCenter
87 text: control.text
88 font.pointSize: control.pointSize
89 font.family: control.font.family
90 font.weight: fontWeight
91 color: primary ? qgcPal.accentText : qgcPal.textPrimary
92 visible: control.text !== ""
93 }
94 }
95}