Advertisement
manticore010

22.04-OsdItem.qml

Mar 30th, 2024 (edited)
168
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 3.69 KB | Software | 0 0
  1. import QtQuick 2.14
  2. import QtQuick.Layouts 1.1
  3. import org.kde.plasma.core 2.0 as PlasmaCore
  4. import org.kde.plasma.components 3.0 as PlasmaComponents3
  5. import org.kde.plasma.extras 2.0 as PlasmaExtra
  6. import QtQuick.Window 2.2
  7.  
  8. RowLayout {
  9.     // OSD Timeout in msecs - how long it will stay on the screen
  10.     property int timeout: 1800
  11.     // This is either a text or a number, if showingProgress is set to true,
  12.     // the number will be used as a value for the progress bar
  13.     property var osdValue
  14.     // Maximum percent value
  15.     property int osdMaxValue: 100
  16.     // Icon name to display
  17.     property string icon
  18.     // Set to true if the value is meant for progress bar,
  19.     // false for displaying the value as normal text
  20.     property bool showingProgress: false
  21.  
  22.     spacing: PlasmaCore.Units.smallSpacing
  23.  
  24.     Layout.minimumWidth: Math.max(Math.min(Screen.desktopAvailableWidth / 2, implicitWidth), PlasmaCore.Units.gridUnit * 15)
  25.     Layout.minimumHeight: PlasmaCore.Units.iconSizes.medium
  26.     Layout.maximumWidth: Layout.minimumWidth
  27.     Layout.maximumHeight: Layout.minimumHeight
  28.  
  29.     PlasmaCore.IconItem {
  30.         Layout.leftMargin: PlasmaCore.Units.smallSpacing
  31.         Layout.preferredWidth: PlasmaCore.Units.iconSizes.medium
  32.         Layout.preferredHeight: PlasmaCore.Units.iconSizes.medium
  33.         Layout.alignment: Qt.AlignVCenter
  34.         source: icon
  35.         visible: valid
  36.     }
  37.  
  38.     PlasmaComponents3.ProgressBar {
  39.         id: progressBar
  40.         Layout.fillWidth: true
  41.         Layout.alignment: Qt.AlignVCenter
  42.         // So it never exceeds the minimum popup size
  43.         Layout.minimumWidth: 0
  44.         Layout.rightMargin: PlasmaCore.Units.smallSpacing
  45.         visible: showingProgress
  46.         from: 0
  47.         to: osdMaxValue
  48.         value: Number(osdValue)
  49.     }
  50.  
  51.     // Get the width of a three-digit number so we can size the label
  52.     // to the maximum width to avoid the progress bad resizing itself
  53.     TextMetrics {
  54.         id: widestLabelSize
  55.         text: i18n("100%")
  56.         font: percentageLabel.font
  57.     }
  58.  
  59.     // Numerical display of progress bar value
  60.     PlasmaExtra.Heading {
  61.         id: percentageLabel
  62.         Layout.fillHeight: true
  63.         Layout.preferredWidth: widestLabelSize.width
  64.         Layout.rightMargin: PlasmaCore.Units.smallSpacing
  65.         Layout.alignment: Qt.AlignVCenter
  66.         level: 3
  67.         horizontalAlignment: Text.AlignHCenter
  68.         verticalAlignment: Text.AlignVCenter
  69.         text: i18nc("Percentage value", "%1%", progressBar.value)
  70.         visible: showingProgress
  71.         // Display a subtle visual indication that the volume might be
  72.         // dangerously high
  73.         // ------------------------------------------------
  74.         // Keep this in sync with the copies in plasma-pa:ListItemBase.qml
  75.         // and plasma-pa:VolumeSlider.qml
  76.         color: {
  77.             if (progressBar.value <= 100) {
  78.                 return PlasmaCore.Theme.textColor
  79.             } else if (progressBar.value > 100 && progressBar.value <= 125) {
  80.                 return PlasmaCore.Theme.neutralTextColor
  81.             } else {
  82.                 return PlasmaCore.Theme.negativeTextColor
  83.             }
  84.         }
  85.     }
  86.  
  87.     PlasmaExtra.Heading {
  88.         id: label
  89.         Layout.fillWidth: true
  90.         Layout.fillHeight: true
  91.         Layout.rightMargin: PlasmaCore.Units.smallSpacing
  92.         Layout.alignment: Qt.AlignVCenter
  93.         level: 3
  94.         horizontalAlignment: Text.AlignHCenter
  95.         verticalAlignment: Text.AlignVCenter
  96.         textFormat: Text.PlainText
  97.         wrapMode: Text.NoWrap
  98.         elide: Text.ElideRight
  99.         text: !showingProgress && osdValue ? osdValue : ""
  100.         visible: !showingProgress
  101.     }
  102. }
  103.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement