OsdItem.qml 3.78 KB
Newer Older
1
/*
2
3
4
5
6
    SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
    SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>

    SPDX-License-Identifier: GPL-2.0-or-later
*/
7

8
import QtQuick 2.14
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
9
import QtQuick.Layouts 1.1
10
import org.kde.plasma.core 2.0 as PlasmaCore
11
import org.kde.plasma.components 3.0 as PlasmaComponents3
12
import org.kde.plasma.extras 2.0 as PlasmaExtra
Martin Klapetek's avatar
Martin Klapetek committed
13
import QtQuick.Window 2.2
14

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
15
RowLayout {
16
17
18
19
20
21
22
23
24
25
26
27
    // OSD Timeout in msecs - how long it will stay on the screen
    property int timeout: 1800
    // This is either a text or a number, if showingProgress is set to true,
    // the number will be used as a value for the progress bar
    property var osdValue
    // Maximum percent value
    property int osdMaxValue: 100
    // Icon name to display
    property string icon
    // Set to true if the value is meant for progress bar,
    // false for displaying the value as normal text
    property bool showingProgress: false
28

Nate Graham's avatar
Nate Graham committed
29
    spacing: PlasmaCore.Units.smallSpacing
30

Marco Martin's avatar
Marco Martin committed
31
32
33
34
    Layout.minimumWidth: Math.max(Math.min(Screen.desktopAvailableWidth / 2, implicitWidth), PlasmaCore.Units.gridUnit * 15)
    Layout.minimumHeight: PlasmaCore.Units.iconSizes.medium
    Layout.maximumWidth: Layout.minimumWidth
    Layout.maximumHeight: Layout.minimumHeight
35

Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
36
    PlasmaCore.IconItem {
Nate Graham's avatar
Nate Graham committed
37
38
39
        Layout.leftMargin: PlasmaCore.Units.smallSpacing
        Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
        Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
40
        Layout.alignment: Qt.AlignVCenter
41
        source: icon
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
42
        visible: valid
43
44
    }

45
    PlasmaComponents3.ProgressBar {
46
        id: progressBar
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
47
        Layout.fillWidth: true
48
        Layout.alignment: Qt.AlignVCenter
49
        // So it never exceeds the minimum popup size
50
        Layout.minimumWidth: 0
Nate Graham's avatar
Nate Graham committed
51
        Layout.rightMargin: PlasmaCore.Units.smallSpacing
52
        visible: showingProgress
53
        from: 0
54
55
        to: osdMaxValue
        value: Number(osdValue)
56
    }
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
57

58
59
60
61
62
63
64
65
66
67
68
69
70
    // Get the width of a three-digit number so we can size the label
    // to the maximum width to avoid the progress bad resizing itself
    TextMetrics {
        id: widestLabelSize
        text: i18n("100%")
        font: percentageLabel.font
    }

    // Numerical display of progress bar value
    PlasmaExtra.Heading {
        id: percentageLabel
        Layout.fillHeight: true
        Layout.preferredWidth: widestLabelSize.width
Nate Graham's avatar
Nate Graham committed
71
        Layout.rightMargin: PlasmaCore.Units.smallSpacing
72
        Layout.alignment: Qt.AlignVCenter
73
74
75
76
        level: 3
        horizontalAlignment: Text.AlignHCenter
        verticalAlignment: Text.AlignVCenter
        text: i18nc("Percentage value", "%1%", progressBar.value)
77
        visible: showingProgress
78
79
80
81
82
83
84
        // Display a subtle visual indication that the volume might be
        // dangerously high
        // ------------------------------------------------
        // Keep this in sync with the copies in plasma-pa:ListItemBase.qml
        // and plasma-pa:VolumeSlider.qml
        color: {
            if (progressBar.value <= 100) {
Nate Graham's avatar
Nate Graham committed
85
                return PlasmaCore.Theme.textColor
86
            } else if (progressBar.value > 100 && progressBar.value <= 125) {
Nate Graham's avatar
Nate Graham committed
87
                return PlasmaCore.Theme.neutralTextColor
88
            } else {
Nate Graham's avatar
Nate Graham committed
89
                return PlasmaCore.Theme.negativeTextColor
90
91
            }
        }
92
93
    }

94
    PlasmaExtra.Heading {
95
        id: label
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
96
97
        Layout.fillWidth: true
        Layout.fillHeight: true
Nate Graham's avatar
Nate Graham committed
98
        Layout.rightMargin: PlasmaCore.Units.smallSpacing
99
        Layout.alignment: Qt.AlignVCenter
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
100
        level: 3
101
        horizontalAlignment: Text.AlignHCenter
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
102
        verticalAlignment: Text.AlignVCenter
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
103
        textFormat: Text.PlainText
Kai Uwe Broulik's avatar
Kai Uwe Broulik committed
104
105
        wrapMode: Text.NoWrap
        elide: Text.ElideRight
106
107
        text: !showingProgress && osdValue ? osdValue : ""
        visible: !showingProgress
108
109
    }
}