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
0008 import QtQuick.Layouts
0009 import org.kde.coreaddons as KCoreAddons
0010 import org.kde.quickcharts as QuickCharts
0011 import org.kde.quickcharts.controls as QuickChartsControls
0012 import org.kde.plasma.components as PlasmaComponents3
0013 import org.kde.kirigami as Kirigami
0014 
0015 ColumnLayout {
0016     property alias downloadSpeed: download.value
0017     property alias uploadSpeed: upload.value
0018 
0019     spacing: Kirigami.Units.largeSpacing
0020 
0021     Item {
0022         Layout.leftMargin: Kirigami.Units.smallSpacing
0023         Layout.fillWidth: true
0024         implicitHeight: plotter.height + metricsLabel.implicitHeight
0025 
0026         QuickChartsControls.AxisLabels {
0027             id: verticalAxisLabels
0028             anchors {
0029                 left: parent.left
0030                 top: plotter.top
0031                 bottom: plotter.bottom
0032             }
0033             width: metricsLabel.implicitWidth
0034             constrainToBounds: false
0035             direction: QuickChartsControls.AxisLabels.VerticalBottomTop
0036             delegate: PlasmaComponents3.Label {
0037                 text: KCoreAddons.Format.formatByteSize(QuickChartsControls.AxisLabels.label) + i18n("/s")
0038                 font: metricsLabel.font
0039             }
0040             source: QuickCharts.ChartAxisSource {
0041                 chart: plotter
0042                 axis: QuickCharts.ChartAxisSource.YAxis
0043                 itemCount: 5
0044             }
0045         }
0046         QuickChartsControls.GridLines {
0047             anchors.fill: plotter
0048             direction: QuickChartsControls.GridLines.Vertical
0049             minor.visible: false
0050             major.count: 3
0051             major.lineWidth: 1
0052             // Same calculation as Kirigami Separator
0053             major.color: Kirigami.ColorUtils.linearInterpolation(Kirigami.Theme.backgroundColor, Kirigami.Theme.textColor, 0.4)
0054         }
0055         QuickCharts.LineChart {
0056             id: plotter
0057             anchors {
0058                 left: verticalAxisLabels.right
0059                 leftMargin: Kirigami.Units.smallSpacing
0060                 right: parent.right
0061                 top: parent.top
0062                 // Align plotter lines with labels.
0063                 topMargin: Math.round(metricsLabel.implicitHeight / 2) + Kirigami.Units.smallSpacing
0064             }
0065             height: Kirigami.Units.gridUnit * 8
0066             interpolate: true
0067             direction: QuickCharts.XYChart.ZeroAtEnd
0068             yRange {
0069                 minimum: 100 * 1024
0070                 increment: 100 * 1024
0071             }
0072             valueSources: [
0073                 QuickCharts.HistoryProxySource {
0074                     source: QuickCharts.SingleValueSource {
0075                         id: upload
0076                     }
0077                     maximumHistory: 40
0078                     fillMode: QuickCharts.HistoryProxySource.FillFromStart
0079                 },
0080                 QuickCharts.HistoryProxySource {
0081                     source: QuickCharts.SingleValueSource {
0082                         id: download
0083                     }
0084                     maximumHistory: 40
0085                     fillMode: QuickCharts.HistoryProxySource.FillFromStart
0086                 }
0087             ]
0088             nameSource: QuickCharts.ArraySource {
0089                 array: [i18n("Upload"), i18n("Download")]
0090             }
0091             colorSource: QuickCharts.ArraySource {
0092                 // Array.reverse() mutates the array but colors.colors is read-only.
0093                 array: [colors.colors[1], colors.colors[0]]
0094             }
0095             fillColorSource: QuickCharts.ArraySource  {
0096                 array: plotter.colorSource.array.map(color => Qt.lighter(color, 1.5))
0097             }
0098             QuickCharts.ColorGradientSource {
0099                 id: colors
0100                 baseColor:  Kirigami.Theme.highlightColor
0101                 itemCount: 2
0102             }
0103         }
0104         // Note: TextMetrics might be using a different renderType by default,
0105         // so we need a Label instance anyway.
0106         PlasmaComponents3.Label {
0107             id: metricsLabel
0108             visible: false
0109             font: Kirigami.Theme.smallFont
0110             // Measure 888.8 KiB/s
0111             text: KCoreAddons.Format.formatByteSize(910131) + i18n("/s")
0112         }
0113     }
0114     QuickChartsControls.Legend {
0115         chart: plotter
0116         Layout.leftMargin: Kirigami.Units.smallSpacing
0117         Layout.fillWidth: true
0118         spacing: Kirigami.Units.largeSpacing
0119         delegate: RowLayout {
0120             spacing: Kirigami.Units.smallSpacing
0121 
0122             QuickChartsControls.LegendLayout.maximumWidth: implicitWidth
0123 
0124             Rectangle {
0125                 color: model.color
0126                 width: Kirigami.Units.smallSpacing
0127                 height: legendLabel.height
0128             }
0129             PlasmaComponents3.Label {
0130                 id: legendLabel
0131                 font: Kirigami.Theme.smallFont
0132                 text: model.name
0133             }
0134         }
0135     }
0136 }