diff --git a/components/mobileshell/qml/components/MarqueeLabel.qml b/components/mobileshell/qml/components/MarqueeLabel.qml new file mode 100644 index 00000000..f2562451 --- /dev/null +++ b/components/mobileshell/qml/components/MarqueeLabel.qml @@ -0,0 +1,67 @@ +/* + * SPDX-FileCopyrightText: 2022 Yari Polla + * + * SPDX-License-Identifier: LGPL-2.0-or-later + */ + +import QtQuick 2.15 + +import org.kde.plasma.core 2.0 as PlasmaCore +import org.kde.plasma.components 3.0 as PlasmaComponents + +/** + * This is a simple marquee (flowing) label based on PlasmaComponents Label.Array() + * + * + */ +PlasmaComponents.Label { + id: root + + required property string inputText + required property real rightPadding + + property int interval: PlasmaCore.Units.veryLongDuration + + readonly property int charactersOverflow: Math.ceil((txtMeter.width - parent.width + 2*rightPadding) / font.pointSize) + readonly property string displayedText: inputText.substring(step, step + inputText.length - charactersOverflow) + property int step: 0 + + TextMetrics { + id: txtMeter + font.pointSize: root.font.pointSize + text: inputText + } + + Timer { + property bool paused: false + + interval: root.interval + running: visible && charactersOverflow > 0 + repeat: true + onTriggered: { + if (paused) { + if (step != 0) { + step = 0; + } else { + interval /= 3; + paused = false; + } + } else { + step = (step + 1) % inputText.length; + + if (step === charactersOverflow) { + interval *= 3; + paused = true; + } + } + } + + onRunningChanged: { + if (!running) { + step = 0; + } + } + } + + text: displayedText +} diff --git a/components/mobileshell/resources.qrc b/components/mobileshell/resources.qrc index 23a9f1e8..4135c7c3 100644 --- a/components/mobileshell/resources.qrc +++ b/components/mobileshell/resources.qrc @@ -21,6 +21,7 @@ qml/actiondrawer/PortraitContentContainer.qml qml/components/BaseItem.qml + qml/components/MarqueeLabel.qml qml/components/StartupFeedback.qml qml/components/util.js qml/components/VelocityCalculator.qml