Warning, /plasma/plasma-nm/applet/contents/ui/TrafficMonitor.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2013-2017 Jan Grulich <jgrulich@redhat.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 import QtQuick 2.4
0008 import QtQuick.Layouts 1.4
0009 import org.kde.kcoreaddons 1.0 as KCoreAddons
0010 import org.kde.quickcharts 1.0 as QuickCharts
0011 import org.kde.quickcharts.controls 1.0 as QuickChartControls
0012 import org.kde.kirigami 2.15 as Kirigami
0013 import org.kde.plasma.components 3.0 as PlasmaComponents3
0014 import org.kde.plasma.core 2.0 as PlasmaCore
0015 
0016 ColumnLayout {
0017     property alias downloadSpeed: download.value
0018     property alias uploadSpeed: upload.value
0019 
0020     spacing: PlasmaCore.Units.largeSpacing
0021 
0022     Item {
0023         Layout.fillWidth: true
0024         implicitHeight: plotter.height + speedMetrics.height
0025 
0026         QuickCharts.AxisLabels {
0027             anchors {
0028                 right: plotter.left
0029                 rightMargin: PlasmaCore.Units.smallSpacing
0030                 top: plotter.top
0031                 bottom: plotter.bottom
0032             }
0033             constrainToBounds: false
0034             direction: QuickCharts.AxisLabels.VerticalBottomTop
0035             delegate:  PlasmaComponents3.Label {
0036                 text: KCoreAddons.Format.formatByteSize(QuickCharts.AxisLabels.label) + i18n("/s")
0037                 font: PlasmaCore.Theme.smallestFont
0038             }
0039             source: QuickCharts.ChartAxisSource {
0040                 chart: plotter
0041                 axis: QuickCharts.ChartAxisSource.YAxis
0042                 itemCount: 5
0043             }
0044         }
0045         QuickCharts.GridLines {
0046             anchors.fill: plotter
0047             direction: QuickCharts.GridLines.Vertical
0048             minor.visible: false
0049             major.count: 3
0050             major.lineWidth: 1
0051             // Same calculation as Kirigami Separator
0052             major.color: Kirigami.ColorUtils.linearInterpolation(PlasmaCore.Theme.backgroundColor, PlasmaCore.Theme.textColor, 0.4)
0053         }
0054         QuickCharts.LineChart {
0055             id: plotter
0056             anchors {
0057                 left: parent.left
0058                 leftMargin: speedMetrics.width + PlasmaCore.Units.smallSpacing
0059                 right: parent.right
0060                 top: parent.top
0061                 // Align plotter lines with labels.
0062                 topMargin: speedMetrics.height / 2 + PlasmaCore.Units.smallSpacing
0063             }
0064             height: PlasmaCore.Units.gridUnit * 8
0065             smooth: true
0066             direction: QuickCharts.XYChart.ZeroAtEnd
0067             yRange {
0068                 minimum: 100 * 1024
0069                 increment: 100 * 1024
0070             }
0071             valueSources: [
0072                 QuickCharts.HistoryProxySource {
0073                     source: QuickCharts.SingleValueSource {
0074                         id: upload
0075                     }
0076                     maximumHistory: 40
0077                     fillMode: QuickCharts.HistoryProxySource.FillFromStart
0078                 },
0079                 QuickCharts.HistoryProxySource {
0080                     source: QuickCharts.SingleValueSource {
0081                         id: download
0082                     }
0083                     maximumHistory: 40
0084                     fillMode: QuickCharts.HistoryProxySource.FillFromStart
0085                 }
0086             ]
0087             nameSource: QuickCharts.ArraySource {
0088                 array: [i18n("Upload"), i18n("Download")]
0089             }
0090             colorSource: QuickCharts.ArraySource {
0091                 array: colors.colors.reverse()
0092             }
0093             fillColorSource: QuickCharts.ArraySource  {
0094                 array: colors.colors.reverse().map(color => Qt.lighter(color, 1.5))
0095             }
0096             QuickCharts.ColorGradientSource {
0097                 id: colors
0098                 baseColor:  PlasmaCore.Theme.highlightColor
0099                 itemCount: 2
0100             }
0101         }
0102         TextMetrics {
0103             id: speedMetrics
0104             font: PlasmaCore.Theme.smallestFont
0105             // Measure 888.8 KiB/s
0106             text: KCoreAddons.Format.formatByteSize(910131) + i18n("/s")
0107         }
0108     }
0109     QuickChartControls.Legend {
0110         chart: plotter
0111         Layout.leftMargin: PlasmaCore.Units.smallSpacing
0112         spacing: PlasmaCore.Units.largeSpacing
0113         delegate: RowLayout {
0114             spacing: PlasmaCore.Units.smallSpacing
0115             Rectangle {
0116                 color: model.color
0117                 width: PlasmaCore.Units.smallSpacing
0118                 height: legendLabel.height
0119             }
0120             PlasmaComponents3.Label {
0121                 id: legendLabel
0122                 font: PlasmaCore.Theme.smallestFont
0123                 text: model.name
0124             }
0125         }
0126     }
0127 }