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: qgcPal.globalTheme === QGCPalette.Light
14 property real backRadius: ScreenTools.defaultBorderRadius
15 property real heightFactor: 0.5
16 property string iconSource: ""
17 property real fontWeight: Font.Normal // default for qml Text
18 property real pointSize: ScreenTools.defaultFontPointSize
19
20 property alias wrapMode: text.wrapMode
21 property alias horizontalAlignment: text.horizontalAlignment
22 property alias backgroundColor: backRect.color
23 property alias textColor: text.color
24
25 id: control
26 hoverEnabled: !ScreenTools.isMobile
27 topPadding: _verticalPadding
28 bottomPadding: _verticalPadding
29 leftPadding: _horizontalPadding
30 rightPadding: _horizontalPadding
31 focusPolicy: Qt.ClickFocus
32 font.family: ScreenTools.normalFontFamily
33 text: ""
34
35 property bool _showHighlight: enabled && (pressed | checked)
36 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth * 2
37 property int _verticalPadding: Math.round(ScreenTools.defaultFontPixelHeight * heightFactor) - (iconSource === "" ? 0 : (_iconHeight - ScreenTools.defaultFontPixelHeight) / 2)
38 property real _iconHeight: text.height * 1.5
39
40 QGCPalette { id: qgcPal; colorGroupEnabled: control.enabled }
41
42 background: Rectangle {
43 id: backRect
44 radius: backRadius
45 implicitWidth: ScreenTools.implicitButtonWidth
46 implicitHeight: ScreenTools.implicitButtonHeight
47 border.width: showBorder ? 1 : 0
48 border.color: qgcPal.buttonBorder
49 color: primary ? qgcPal.primaryButton : qgcPal.button
50
51 Rectangle {
52 anchors.fill: parent
53 color: qgcPal.buttonHighlight
54 opacity: _showHighlight ? 1 : control.enabled && control.hovered ? .2 : 0
55 radius: parent.radius
56 }
57 }
58
59 contentItem: RowLayout {
60 spacing: ScreenTools.defaultFontPixelWidth
61
62 QGCColoredImage {
63 id: icon
64 Layout.alignment: Qt.AlignHCenter
65 source: control.iconSource
66 height: _iconHeight
67 width: height
68 color: text.color
69 fillMode: Image.PreserveAspectFit
70 sourceSize.height: height
71 visible: control.iconSource !== ""
72 }
73
74 QGCLabel {
75 id: text
76 Layout.alignment: Qt.AlignHCenter
77 text: control.text
78 font.pointSize: control.pointSize
79 font.family: control.font.family
80 font.weight: fontWeight
81 color: _showHighlight ? qgcPal.buttonHighlightText : (primary ? qgcPal.primaryButtonText : qgcPal.buttonText)
82 visible: control.text !== ""
83 }
84 }
85}