Commit 740289bd authored by Miklos Mate's avatar Miklos Mate Committed by Nate Graham

Systemmonitor: use different label format when the applet is on a vertical panel

Summary:
When the applet is on a vertical panel, its horizontal size is limited, and the speedLabel clashes with the name label. I fixed that by moving the speed values below the sensor name in this case.

I also added some cleanups unintentionally (the first three hunks), as I couldn't find a way to change the diff after it's submitted. They remove an unneeded import, and fix some uninitialized variable warnings. Feel free to ignore them.

Reviewers: #plasma, mart

Reviewed By: #plasma, mart

Subscribers: ngraham, mart, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D12857
parent 033ad5ca
......@@ -24,7 +24,6 @@ import org.kde.plasma.plasmoid 2.0
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 PlasmaExtras
import org.kde.kquickcontrolsaddons 2.0 as KQuickAddons
Item {
id: rootItem
......@@ -83,7 +82,7 @@ Item {
engine: "systemmonitor"
interval: plasmoid.configuration.updateInterval
onSourceAdded: {
if (plasmoid.configuration.sources.length > 0 &&
if (plasmoid.configuration.sources && plasmoid.configuration.sources.length > 0 &&
plasmoid.configuration.sources.indexOf(encodeURIComponent(source)) === -1) {
return;
}
......
......@@ -32,6 +32,7 @@ Item {
property var cfg_sources: []
onCfg_sourcesChanged: {
if (! cfg_sources) { cfg_sources = [] }
if (cfg_sources.length == 0) {
for (var i in mainColumn.children) {
var child = mainColumn.children[i];
......
......@@ -32,11 +32,6 @@ KQuickAddons.Plotter {
Layout.fillHeight: true
horizontalGridLineCount: 0
function formatLabel(data1, data2) {
return i18nc("%1 and %3 are data values, %2 and %4 are unit datatypes", "%1 %2 | %3 %4", data1.value, data1.units,
data2.value, data2.units);
}
function cycle(color, degrees) {
var min = Math.min(color.r, Math.min(color.g, color.b));
var max = Math.max(color.r, Math.max(color.g, color.b));
......@@ -69,16 +64,17 @@ KQuickAddons.Plotter {
]
PlasmaComponents.Label {
id: nameLabel
anchors {
left: parent.left
top: parent.top
}
text: plotter.sensorName
}
PlasmaComponents.Label {
id: speedLabel
wrapMode: Text.WordWrap
visible: plasmoid.formFactor != PlasmaCore.Types.Vertical
anchors {
right: parent.right
}
......@@ -101,7 +97,13 @@ KQuickAddons.Plotter {
plotter.addSample([data1.value, data2.value]);
speedLabel.text = formatLabel(data1, data2);
if (plasmoid.formFactor != PlasmaCore.Types.Vertical) {
nameLabel.text = plotter.sensorName
speedLabel.text = formatData(data1) + " | " + formatData(data2)
} else {
nameLabel.text = plotter.sensorName+ "\n" + formatData(data1) + "\n" + formatData(data2)
speedLabel.text = ""
}
}
}
}
......@@ -35,10 +35,6 @@ KQuickAddons.Plotter {
Layout.preferredHeight: parent.height
horizontalGridLineCount: 0
function formatLabel(data) {
return i18nc("%1 is data value, %2 is unit datatype", "%1 %2", data.value, data.units);
}
dataSets: [
KQuickAddons.PlotData {
color: theme.highlightColor
......@@ -46,16 +42,17 @@ KQuickAddons.Plotter {
]
PlasmaComponents.Label {
id: nameLabel
anchors {
left: parent.left
top: parent.top
}
text: plotter.sensorName
}
PlasmaComponents.Label {
id: speedLabel
wrapMode: Text.WordWrap
visible: plasmoid.formFactor != PlasmaCore.Types.Vertical
anchors {
right: parent.right
}
......@@ -76,7 +73,13 @@ KQuickAddons.Plotter {
plotter.addSample([data1.value]);
speedLabel.text = formatLabel(data1);
if (plasmoid.formFactor != PlasmaCore.Types.Vertical) {
nameLabel.text = plotter.sensorName
speedLabel.text = formatData(data1)
} else {
nameLabel.text = plotter.sensorName+ "\n" + formatData(data1)
speedLabel.text = ""
}
}
}
}
......
......@@ -39,7 +39,7 @@ Applet {
autoRange: false
rangeMin: 0
rangeMax: 100
function formatLabel(data) {
function formatData(data) {
//i18nc("CPU usage: %1 is the value, %2 the unit datatype", "%1 %2")
//return i18n("%1 %2", Math.round(data.value), data.units);
return i18nc("CPU usage: %1 is the value, %2 the unit datatype", "%1 %2", Math.round(data.value), data.units);
......
......@@ -37,9 +37,8 @@ Applet {
}
delegate: DoublePlotter {
function formatLabel(data1, data2) {
return i18nc("%1 and %2 are values of the same datatype", "%1/s | %2/s", KCoreAddons.Format.formatByteSize(data1.value * 1024),
KCoreAddons.Format.formatByteSize(data2.value * 1024));
function formatData(data) {
return i18nc("%1 is value of data per seconds", "%1/s", KCoreAddons.Format.formatByteSize(data.value * 1024))
}
}
}
......@@ -40,9 +40,9 @@ Applet {
autoRange: false
rangeMin: 0
rangeMax: 0
function formatLabel(data) {
function formatData(data) {
rangeMax = data.max;
return KCoreAddons.Format.formatByteSize(data.value * 1024)
}
}
}
\ No newline at end of file
}
......@@ -39,23 +39,19 @@ Applet {
}
}
function formatBitSpeed(value) {
if (value > (1024 * 1024)) {
return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1));
}
if (value > 1024) {
return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024));
}
if (value > 0) {
return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value);
}
return value;
}
delegate: DoublePlotter {
function formatLabel(data1, data2) {
return i18nc("%1 and %2 are values of the same datatype", "%1 | %2", formatBitSpeed(data1.value * 1024 * 8),
formatBitSpeed(data2.value * 1024 * 8));
function formatData(data) {
var value = data.value * 1024 * 8
if (value > (1024 * 1024)) {
return i18nc("%1 is the displayed data transfer speed in megabits per second", "%1 Mbps", (value / (1024 * 1024)).toFixed(1));
}
if (value > 1024) {
return i18nc("%1 is the displayed data transfer speed in kilobits per second", "%1 Kbps", (value / 1024));
}
if (value > 0) {
return i18nc("%1 is the displayed data transfer speed in bits per second", "%1 bps", value);
}
return value;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment