QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCDelayButton.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3import QtQuick.Layouts
4
5import QGroundControl
6import QGroundControl.Controls
7
8DelayButton {
9 id: control
10 hoverEnabled: !ScreenTools.isMobile
11 topPadding: _verticalPadding
12 bottomPadding: alwaysShowHelp ? Math.max(_verticalPadding, helpText.implicitHeight) : _verticalPadding
13 leftPadding: _horizontalPadding
14 rightPadding: _horizontalPadding
15 focusPolicy: Qt.ClickFocus
16 font.family: ScreenTools.normalFontFamily
17 delay: defaultDelay
18
19 property bool primary: false
20 property bool showBorder: true
21 property real backRadius: ScreenTools.defaultBorderRadius
22 property real heightFactor: 0.3
23 property real fontWeight: Font.Normal // default for qml Text
24 property real pointSize: ScreenTools.defaultFontPointSize
25 property int defaultDelay: 500
26 property bool alwaysShowHelp: false
27
28 property alias wrapMode: text.wrapMode
29 property alias horizontalAlignment: text.horizontalAlignment
30 property alias backgroundColor: backRect.color
31 property alias textColor: text.color
32
33 property bool _showHighlight: enabled && pressed
34 property int _horizontalPadding: ScreenTools.defaultFontPixelWidth * 2
35 property int _verticalPadding: Math.round(ScreenTools.defaultFontPixelHeight * heightFactor)
36 property bool _showHelp: false
37 property bool _activated: false
38
39 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
40
41 TextMetrics {
42 id: holdToConfirmMetrics
43 font.pointSize: control.pointSize
44 font.family: control.font.family
45 font.weight: control.fontWeight
46 text: qsTr("Hold to Confirm")
47 }
48
49 TextMetrics {
50 id: buttonTextMetrics
51 font: holdToConfirmMetrics.font
52 text: control.text
53 }
54
55 Timer {
56 id: helpTimeout
57 interval: 3000
58 repeat: false
59 onTriggered: control._showHelp = false
60 }
61
62 onActivated: {
63 _activated = true
64 _showHelp = false
65 }
66 onPressed: {
67 _activated = false
68 }
69 onReleased: {
70 _showHelp = !_activated
71 _activated = false
72 if (_showHelp) {
73 helpTimeout.start()
74 } else {
75 helpTimeout.stop()
76 }
77 }
78
79 background: Rectangle {
80 id: backRect
81 radius: backRadius
82 // Wide enough for both the button text and the early-release prompt so the button never resizes when it swaps
83 implicitWidth: Math.max(Math.ceil(Math.max(holdToConfirmMetrics.advanceWidth, buttonTextMetrics.advanceWidth)) + control.leftPadding + control.rightPadding,
84 ScreenTools.implicitButtonWidth)
85 implicitHeight: ScreenTools.implicitButtonHeight
86 border.width: showBorder ? 1 : 0
87 border.color: control.primary || control._showHighlight || (control.enabled && control.hovered) ? qgcPal.accent : qgcPal.borderSubtle
88 color: control.primary ? qgcPal.accent : (control._showHighlight ? qgcPal.accentSubtle : qgcPal.windowCard)
89
90 Rectangle {
91 anchors.fill: parent
92 radius: parent.radius
93 color: qgcPal.accentText
94 visible: control.primary
95 opacity: control._showHighlight ? 0.25 : (control.enabled && control.hovered ? 0.12 : 0)
96 }
97
98 QGCColoredImage {
99 anchors.topMargin: _sliderIndicatorMargin
100 anchors.bottomMargin: _sliderIndicatorMargin
101 anchors.leftMargin: control.pressed ? (parent.width - width) * control.progress : 0
102 anchors.left: parent.left
103 anchors.top: parent.top
104 anchors.bottom: parent.bottom
105 width: height
106 source: "qrc:/res/chevron-double-right.svg"
107 sourceSize.height: parent.height
108 fillMode: Image.PreserveAspectFit
109 color: control.primary ? qgcPal.accentText : (control._showHighlight ? qgcPal.accent : qgcPal.textPrimary)
110 opacity: control._showHighlight ? 1 : (control.primary ? 0.4 : 0.2)
111
112 property real _sliderIndicatorMargin: ScreenTools.defaultFontPixelWidth * 0.5
113 }
114
115 QGCLabel {
116 id: helpText
117 text: qsTr("Hold to Confirm")
118 anchors.bottom: parent.bottom
119 anchors.horizontalCenter: parent.horizontalCenter
120 font.pointSize: ScreenTools.smallFontPointSize
121 color: control.textColor
122 visible: control.alwaysShowHelp
123 }
124 }
125
126 contentItem: QGCLabel {
127 id: text
128 horizontalAlignment: Text.AlignHCenter
129 text: control._showHelp && !control.alwaysShowHelp ? qsTr("Hold to Confirm") : control.text
130 font.pointSize: control.pointSize
131 font.family: control.font.family
132 font.weight: control.fontWeight
133 color: control.primary ? qgcPal.accentText : qgcPal.textPrimary
134 }
135}