Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/TrafficMonitor.qml
Show All 12 Lines | 1 | /* | |||
---|---|---|---|---|---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | 15 | Lesser General Public License for more details. | ||
16 | 16 | | |||
17 | You should have received a copy of the GNU Lesser General Public | 17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | import QtQuick 2.2 | 21 | import QtQuick 2.4 | ||
22 | import org.kde.kcoreaddons 1.0 as KCoreAddons | 22 | import org.kde.kcoreaddons 1.0 as KCoreAddons | ||
23 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | 23 | import org.kde.kquickcontrolsaddons 2.0 as KQuickControlsAddons | ||
24 | import org.kde.plasma.components 2.0 as PlasmaComponents | 24 | import org.kde.plasma.components 2.0 as PlasmaComponents | ||
25 | 25 | | |||
26 | Item { | 26 | Item { | ||
27 | property real rxBytes: 0 | 27 | property real rxBytes: 0 | ||
28 | property real txBytes: 0 | 28 | property real txBytes: 0 | ||
29 | property alias interval: timer.interval | 29 | property alias interval: timer.interval | ||
Show All 23 Lines | |||||
53 | KQuickControlsAddons.Plotter { | 53 | KQuickControlsAddons.Plotter { | ||
54 | id: plotter | 54 | id: plotter | ||
55 | property variant downloadColor: theme.highlightColor | 55 | property variant downloadColor: theme.highlightColor | ||
56 | property variant uploadColor: Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | 56 | property variant uploadColor: Qt.hsva((downloadColor.hsvHue + 0.5) % 1, downloadColor.hsvSaturation, downloadColor.hsvValue, downloadColor.a) | ||
57 | // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately | 57 | // Joining two QList<foo> in QML/javascript doesn't seem to work so I'm getting maximum from both list separately | ||
58 | readonly property int maxValue: Math.max(Math.max.apply(null, downloadPlotData.values), Math.max.apply(null, uploadPlotData.values)) | 58 | readonly property int maxValue: Math.max(Math.max.apply(null, downloadPlotData.values), Math.max.apply(null, uploadPlotData.values)) | ||
59 | anchors { | 59 | anchors { | ||
60 | left: parent.left | 60 | left: parent.left | ||
61 | leftMargin: units.gridUnit * 3 | 61 | leftMargin: speedMetrics.width + units.smallSpacing * 2 | ||
62 | right: parent.right | 62 | right: parent.right | ||
63 | top: parent.top | 63 | top: parent.top | ||
64 | // Align plotter lines with labels. | 64 | // Align plotter lines with labels. | ||
65 | topMargin: Math.round(labels.labelHeight / 2) | 65 | topMargin: Math.round(labels.labelHeight / 2) | ||
66 | } | 66 | } | ||
67 | width: units.gridUnit * 20 | | |||
68 | height: units.gridUnit * 8 | 67 | height: units.gridUnit * 8 | ||
69 | horizontalGridLineCount: 5 | 68 | horizontalGridLineCount: 5 | ||
70 | 69 | | |||
71 | dataSets: [ | 70 | dataSets: [ | ||
72 | KQuickControlsAddons.PlotData { | 71 | KQuickControlsAddons.PlotData { | ||
73 | id: downloadPlotData | 72 | id: downloadPlotData | ||
74 | label: i18n("Download") | 73 | label: i18n("Download") | ||
75 | color: plotter.downloadColor | 74 | color: plotter.downloadColor | ||
Show All 19 Lines | 93 | onTriggered: { | |||
95 | var rxSpeed = (rxBytes - prevRxBytes) * 1000 / interval | 94 | var rxSpeed = (rxBytes - prevRxBytes) * 1000 / interval | ||
96 | var txSpeed = (txBytes - prevTxBytes) * 1000 / interval | 95 | var txSpeed = (txBytes - prevTxBytes) * 1000 / interval | ||
97 | prevRxBytes = rxBytes | 96 | prevRxBytes = rxBytes | ||
98 | prevTxBytes = txBytes | 97 | prevTxBytes = txBytes | ||
99 | plotter.addSample([rxSpeed, txSpeed]); | 98 | plotter.addSample([rxSpeed, txSpeed]); | ||
100 | } | 99 | } | ||
101 | } | 100 | } | ||
102 | } | 101 | } | ||
102 | | ||||
103 | TextMetrics { | ||||
104 | id: speedMetrics | ||||
105 | font.pointSize: theme.smallestFont.pointSize | ||||
106 | // Measure 888.8 KiB/s | ||||
107 | text: KCoreAddons.Format.formatByteSize(910131) + i18n("/s") | ||||
davidedmundson: what is this number about? | |||||
gvgeo: Biggest number it can display? | |||||
108 | } | ||||
103 | } | 109 | } |
what is this number about?