QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMarqueeLabel.qml
Go to the documentation of this file.
1import QtQuick
2import QtQuick.Controls
3
4import QGroundControl
5import QGroundControl.Controls
6
7Item {
8 property color color: qgcPal.text
9 property alias contentHeight: _measureText.contentHeight
10 property font font
11 property string text: ""
12 property real maxWidth: _measureText.implicitWidth
13
14 id: _root
15 clip: true
16 implicitWidth: Math.min(_measureText.implicitWidth, maxWidth)
17 implicitHeight: _measureText.implicitHeight
18 font.pointSize: ScreenTools.defaultFontPointSize
19 font.family: ScreenTools.normalFontFamily
20
21 property bool _scrollMarquee: _measureText.implicitWidth > maxWidth
22 property real _scrollWidth: _measureText.implicitWidth + _measureBlanks.implicitWidth
23 property int _scrollDuration: _root.text.length * 500
24 property real _innerText1StartX: 0
25 property real _innerText2StartX: _scrollWidth
26 property bool _componentCompleted: false
27
28 Component.onCompleted: {
29 _componentCompleted = true
30 if (_scrollMarquee) {
31 _innerText1Animation.start()
32 _innerText2Animation.start()
33 }
34 }
35
36 on_ScrollWidthChanged: _recalcTimer.restart() // Wait for update storm to settle out before recalcing
37
38 Timer {
39 id: _recalcTimer
40 interval: 100
41
42 onTriggered: {
43 if (!_componentCompleted) {
44 return
45 }
46 _innerText1Animation.stop()
47 _innerText2Animation.stop()
48 _innerText1.startX = _innerText1StartX
49 _innerText2.startX = _innerText2StartX
50 _innerText1.x = _innerText1.startX
51 _innerText2.x = _innerText2.startX
52 if (_measureText.implicitWidth > maxWidth) {
53 _innerText1Animation.start()
54 _innerText2Animation.start()
55 }
56 }
57 }
58
59 QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
60
61 Text {
62 id: _innerText1
63 anchors.verticalCenter: parent.verticalCenter
64 font: _root.font
65 color: _root.color
66 antialiasing: true
67 text: _root.text
68
69 property real startX: _innerText1StartX
70
71 NumberAnimation on x {
72 id: _innerText1Animation
73 from: _innerText1.startX
74 to: _innerText1.startX -_scrollWidth
75 duration: _scrollDuration
76
77 onFinished: {
78 _innerText2Animation.stop()
79 var text1StartX = _innerText1.startX
80 var text2StartX = _innerText2.startX
81 _innerText1.startX = text2StartX
82 _innerText2.startX = text1StartX
83 start()
84 _innerText2Animation.start()
85 }
86 }
87 }
88
89 Text {
90 id: _innerText2
91 anchors.verticalCenter: parent.verticalCenter
92 font: _root.font
93 color: _root.color
94 antialiasing: true
95 text: _root.text
96 visible: _scrollMarquee
97
98 property real startX: _innerText2StartX
99
100 NumberAnimation on x {
101 id: _innerText2Animation
102 from: _innerText2.startX
103 to: _innerText2.startX -_scrollWidth
104 duration: _scrollDuration
105 }
106 }
107
108 Text {
109 id: _measureText
110 font: _root.font
111 antialiasing: true
112 text: _root.text
113 visible: false
114 }
115
116 Text {
117 id: _measureBlanks
118 font: _root.font
119 antialiasing: true
120 text: " "
121 visible: false
122 }
123}