Add tooltips to plasmoid statistics

This commit is contained in:
Martchus 2019-07-21 22:33:52 +02:00
parent 248af38f8b
commit 62fc662692
5 changed files with 72 additions and 36 deletions

View File

@ -13,10 +13,12 @@ set(PLASMOID_FILES
../package/contents/ui/TopLevelItem.qml
../package/contents/ui/DetailView.qml
../package/contents/ui/DetailItem.qml
../package/contents/ui/ToolTipTrigger.qml
../package/contents/ui/ToolTipView.qml
../package/contents/ui/TinyButton.qml
../package/contents/ui/TinyButtonStyle.qml
../package/contents/ui/ButtonShadow.qml
../package/contents/ui/IconLabel.qml
../package/contents/ui/StatisticsView.qml
../package/contents/ui/main.qml)
list(APPEND QML_SRC_FILES ${PLASMOID_FILES})

View File

@ -439,7 +439,7 @@ ColumnLayout {
Layout.leftMargin: 5
Layout.fillWidth: true
Layout.fillHeight: false
columns: 4
columns: 3
rowSpacing: 1
columnSpacing: 4
@ -451,18 +451,16 @@ ColumnLayout {
StatisticsView {
Layout.leftMargin: 4
statistics: plasmoid.nativeInterface.globalStatistics
context: qsTr("Global")
}
PlasmaCore.IconItem {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
IconLabel {
Layout.leftMargin: 10
source: plasmoid.nativeInterface.loadFontAwesomeIcon(
iconSource: plasmoid.nativeInterface.loadFontAwesomeIcon(
"cloud-download-alt")
opacity: plasmoid.nativeInterface.hasIncomingTraffic ? 1.0 : 0.5
}
PlasmaComponents.Label {
iconOpacity: plasmoid.nativeInterface.hasIncomingTraffic ? 1.0 : 0.5
text: plasmoid.nativeInterface.incomingTraffic
tooltip: qsTr("Global incoming traffic")
}
PlasmaCore.IconItem {
@ -473,18 +471,16 @@ ColumnLayout {
StatisticsView {
Layout.leftMargin: 4
statistics: plasmoid.nativeInterface.localStatistics
context: qsTr("Local")
}
PlasmaCore.IconItem {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
IconLabel {
Layout.leftMargin: 10
source: plasmoid.nativeInterface.loadFontAwesomeIcon(
iconSource: plasmoid.nativeInterface.loadFontAwesomeIcon(
"cloud-upload-alt")
opacity: plasmoid.nativeInterface.hasOutgoingTraffic ? 1.0 : 0.5
}
PlasmaComponents.Label {
iconOpacity: plasmoid.nativeInterface.hasOutgoingTraffic ? 1.0 : 0.5
text: plasmoid.nativeInterface.outgoingTraffic
tooltip: qsTr("Global outgoing traffic")
}
}

View File

@ -0,0 +1,34 @@
import QtQuick 2.0
import QtQuick.Layouts 1.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
Item {
property alias iconSource: iconItem.source
property alias iconOpacity: iconItem.opacity
property alias text: label.text
property alias tooltip: tooltipTrigger.tooltip
width: layout.width
height: layout.height
RowLayout {
id: layout
PlasmaCore.IconItem {
id: iconItem
Layout.preferredWidth: 16
Layout.preferredHeight: 16
opacity: 0.7
}
PlasmaComponents.Label {
id: label
}
}
ToolTipTrigger {
id: tooltipTrigger
anchors.fill: layout
}
}

View File

@ -5,34 +5,24 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
RowLayout {
id: rowLayout
property var statistics
property string context: "?"
PlasmaCore.IconItem {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
source: plasmoid.nativeInterface.loadFontAwesomeIcon("file", false)
opacity: 0.7
}
PlasmaComponents.Label {
IconLabel {
iconSource: plasmoid.nativeInterface.loadFontAwesomeIcon("file", false)
text: statistics.files !== undefined ? statistics.files : "?"
tooltip: context + qsTr(" files")
}
PlasmaCore.IconItem {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
source: plasmoid.nativeInterface.loadFontAwesomeIcon("folder", false)
opacity: 0.7
}
PlasmaComponents.Label {
IconLabel {
iconSource: plasmoid.nativeInterface.loadFontAwesomeIcon("folder", false)
text: statistics.dirs !== undefined ? statistics.dirs : "?"
tooltip: context + qsTr(" directories")
}
PlasmaCore.IconItem {
Layout.preferredWidth: 16
Layout.preferredHeight: 16
source: plasmoid.nativeInterface.loadFontAwesomeIcon("hdd", false)
opacity: 0.7
}
PlasmaComponents.Label {
IconLabel {
iconSource: plasmoid.nativeInterface.loadFontAwesomeIcon("hdd", false)
text: statistics.bytes !== undefined ? plasmoid.nativeInterface.formatFileSize(
statistics.bytes) : "?"
tooltip: context + qsTr(" size")
}
}

View File

@ -0,0 +1,14 @@
import QtQuick 2.0
import QtQuick.Controls.Private 1.0 as ControlsPrivate // Why is such a basic thing as a tooltip private?! Let's be evil and just use it.
MouseArea {
property alias interval: timer.interval
property string tooltip: ""
hoverEnabled: true
Timer {
id: timer
interval: 1000
running: parent.containsMouse && parent.tooltip.length !== 0
onTriggered: ControlsPrivate.Tooltip.showText(parent, Qt.point(parent.mouseX, parent.mouseY), parent.tooltip)
}
}