Skip to content

Instantly share code, notes, and snippets.

@Zren Zren/Osd.qml
Created Oct 19, 2018

Embed
What would you like to do?
/*
* Copyright 2014 Martin Klapetek <mklapetek@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.0
import QtQuick.Window 2.2
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtra
PlasmaCore.Dialog {
id: root
location: PlasmaCore.Types.Floating
type: PlasmaCore.Dialog.OnScreenDisplay
outputOnly: true
// We need X11BypassWindowManagerHint otherwise KWin will
// center the OSD the second time it appears.
flags: Qt.X11BypassWindowManagerHint | Qt.FramelessWindowHint
property int xPos: (Screen.desktopAvailableWidth - width) / 2
property int yPos: Screen.desktopAvailableHeight*0.9 - height
x: xPos
y: yPos
// 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
// 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
property bool animateOpacity: false
Behavior on opacity {
SequentialAnimation {
// prevent press and hold from flickering
PauseAnimation { duration: 100 }
NumberAnimation {
duration: root.timeout
easing.type: Easing.InQuad
}
}
enabled: root.animateOpacity
}
mainItem: OsdItem {
rootItem: root
}
}
/*
* Copyright 2014 Martin Klapetek <mklapetek@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.7
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
import org.kde.plasma.extras 2.0 as PlasmaExtra
import QtQuick.Window 2.2
Row {
property QtObject rootItem
property int iconWidth: units.iconSizes.medium
readonly property int percentageWidth: percentageLabelMetrics.boundingRect.width
property int progressBarWidth: Screen.desktopAvailableWidth / 5
width: iconWidth + progressBarWidth + percentageWidth
height: iconWidth
TextMetrics {
id: percentageLabelMetrics
font: percentageLabel.font
text: "100"
}
PlasmaCore.IconItem {
id: icon
width: iconWidth
height: parent.height
source: rootItem.icon
}
PlasmaComponents.ProgressBar {
id: progressBar
width: progressBarWidth
height: parent.height
visible: rootItem.showingProgress
minimumValue: 0
maximumValue: 100
value: Number(rootItem.osdValue)
}
PlasmaExtra.Heading {
id: percentageLabel
width: percentageWidth
height: parent.height
visible: rootItem.showingProgress
text: (typeof rootItem.osdValue !== "undefined" ? rootItem.osdValue : "")
horizontalAlignment: Text.AlignHCenter
maximumLineCount: 1
elide: Text.ElideLeft
minimumPointSize: theme.defaultFont.pointSize
fontSizeMode: Text.VerticalFit
}
PlasmaExtra.Heading {
id: label
width: progressBarWidth
height: parent.height
visible: !rootItem.showingProgress
text: rootItem.showingProgress ? "" : (rootItem.osdValue ? rootItem.osdValue : "")
horizontalAlignment: Text.AlignHCenter
maximumLineCount: 1
elide: Text.ElideLeft
minimumPointSize: theme.defaultFont.pointSize
fontSizeMode: Text.Fit
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.