Debian Codegraph @

src/qml/Osd.qml

raw
1 /*
2 * SPDX-FileCopyrightText: 2020 George Florea Bănuș <[email protected]>
3 *
4 * SPDX-License-Identifier: GPL-3.0-or-later
5 */
6
7 import QtQuick
8 import QtQuick.Controls
9
10 import org.kde.kirigami as Kirigami
11 import org.kde.haruna
12 import org.kde.haruna.settings
13
14 Item {
15 id: root
16
17 required property int maxWidth
18
19 property bool active: false
20
21 Label {
22 id: label
23
24 property int textWidth: Math.ceil(textMetrics.advanceWidth) + padding * 2
25
26 x: Kirigami.Units.largeSpacing
27 y: Kirigami.Units.largeSpacing
28 width: textWidth > root.maxWidth ? root.maxWidth : undefined
29 visible: false
30 background: Rectangle {
31 color: Kirigami.Theme.backgroundColor
32 }
33 padding: Kirigami.Units.largeSpacing
34 font.pointSize: parseInt(GeneralSettings.osdFontSize)
35 maximumLineCount: 5
36 wrapMode: Text.WrapAnywhere
37
38 TextMetrics {
39 id: textMetrics
40
41 font: label.font
42 text: label.text
43 }
44 }
45
46 Timer {
47 id: timer
48 running: false
49 repeat: false
50 interval: 3000
51
52 onTriggered: {
53 label.visible = false
54 }
55 }
56
57 function message(text: string) : void {
58 if (!root.active) {
59 return
60 }
61
62 if (text === "" || text === null || text === undefined) {
63 return
64 }
65
66 const osdFontSize = parseInt(GeneralSettings.osdFontSize)
67 if (osdFontSize === 0) {
68 return;
69 }
70
71 timer.restart()
72 label.text = text
73 label.visible = true
74 }
75
76 }