Warning, /plasma/plasma-workspace/lookandfeel/org.kde.breeze/contents/osd/OsdItem.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2014 Martin Klapetek <mklapetek@kde.org>
0003     SPDX-FileCopyrightText: 2019 Kai Uwe Broulik <kde@broulik.de>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 import QtQuick
0009 import QtQuick.Layouts
0010 
0011 import org.kde.plasma.components as PlasmaComponents3
0012 import org.kde.plasma.extras as PlasmaExtras
0013 import org.kde.kirigami as Kirigami
0014 
0015 RowLayout {
0016     id: root
0017 
0018     // OSD Timeout in msecs - how long it will stay on the screen
0019     property int timeout: 1800
0020     // This is either a text or a number, if showingProgress is set to true,
0021     // the number will be used as a value for the progress bar
0022     property var osdValue
0023     // Maximum percent value
0024     property int osdMaxValue: 100
0025     // Icon name to display
0026     property string icon
0027     // Set to true if the value is meant for progress bar,
0028     // false for displaying the value as normal text
0029     property bool showingProgress: false
0030 
0031     function formatPercent(number) {
0032         return i18ndc("plasma_lookandfeel_org.kde.lookandfeel", "Percentage value", "%1%", number);
0033     }
0034 
0035     spacing: Kirigami.Units.largeSpacing
0036 
0037     Layout.preferredWidth: Math.max(Math.min(Screen.desktopAvailableWidth / 2, implicitWidth), Kirigami.Units.gridUnit * 15)
0038     Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0039     Layout.minimumWidth: Layout.preferredWidth
0040     Layout.minimumHeight: Layout.preferredHeight
0041     Layout.maximumWidth: Layout.preferredWidth
0042     Layout.maximumHeight: Layout.preferredHeight
0043     width: Layout.preferredWidth
0044     height: Layout.preferredHeight
0045 
0046     Kirigami.Icon {
0047         id: iconItem
0048         Layout.leftMargin: Kirigami.Units.smallSpacing // Left end spacing
0049         Layout.preferredWidth: Kirigami.Units.iconSizes.medium
0050         Layout.preferredHeight: Kirigami.Units.iconSizes.medium
0051         Layout.alignment: Qt.AlignVCenter
0052         source: root.icon
0053         visible: valid
0054     }
0055 
0056     PlasmaComponents3.ProgressBar {
0057         id: progressBar
0058         Layout.leftMargin: iconItem.valid ? 0 : Kirigami.Units.smallSpacing // Left end spacing
0059         Layout.fillWidth: true
0060         Layout.alignment: Qt.AlignVCenter
0061         // So it never exceeds the minimum popup size
0062         Layout.minimumWidth: 0
0063         Layout.rightMargin: Kirigami.Units.smallSpacing
0064         visible: root.showingProgress
0065         from: 0
0066         to: root.osdMaxValue
0067         value: Number(root.osdValue)
0068     }
0069 
0070     // Get the width of a three-digit number so we can size the label
0071     // to the maximum width to avoid the progress bad resizing itself
0072     TextMetrics {
0073         id: widestLabelSize
0074         text: formatPercent(root.osdMaxValue)
0075         font: percentageLabel.font
0076     }
0077 
0078     // Numerical display of progress bar value
0079     PlasmaExtras.Heading {
0080         id: percentageLabel
0081         Layout.rightMargin: Kirigami.Units.smallSpacing // Right end spacing
0082         Layout.fillHeight: true
0083         Layout.preferredWidth: Math.ceil(widestLabelSize.advanceWidth)
0084         Layout.alignment: Qt.AlignVCenter
0085         level: 3
0086         horizontalAlignment: Text.AlignHCenter
0087         verticalAlignment: Text.AlignVCenter
0088         text: formatPercent(progressBar.value)
0089         textFormat: Text.PlainText
0090         wrapMode: Text.NoWrap
0091         visible: root.showingProgress
0092         // Display a subtle visual indication that the volume might be
0093         // dangerously high
0094         // ------------------------------------------------
0095         // Keep this in sync with the copies in plasma-pa:ListItemBase.qml
0096         // and plasma-pa:VolumeSlider.qml
0097         color: {
0098             if (progressBar.value <= 100) {
0099                 return Kirigami.Theme.textColor
0100             } else if (progressBar.value > 100 && progressBar.value <= 125) {
0101                 return Kirigami.Theme.neutralTextColor
0102             } else {
0103                 return Kirigami.Theme.negativeTextColor
0104             }
0105         }
0106     }
0107 
0108     PlasmaExtras.Heading {
0109         Layout.fillWidth: true
0110         Layout.fillHeight: true
0111         Layout.leftMargin: iconItem.valid ? 0 : Kirigami.Units.smallSpacing
0112         Layout.rightMargin: Kirigami.Units.smallSpacing
0113         Layout.alignment: Qt.AlignVCenter
0114         level: 3
0115         horizontalAlignment: Text.AlignHCenter
0116         verticalAlignment: Text.AlignVCenter
0117         textFormat: Text.PlainText
0118         wrapMode: Text.NoWrap
0119         elide: Text.ElideRight
0120         text: !root.showingProgress && root.osdValue ? root.osdValue : ""
0121         visible: !root.showingProgress
0122     }
0123 }