Changeset View
Changeset View
Standalone View
Standalone View
applet/contents/ui/TrafficMonitor.qml
Show All 22 Lines | |||||
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 | ||
30 | 30 | | |||
31 | height: visible ? plotter.height + units.gridUnit : 0 | 31 | height: visible ? plotter.height + plotter.anchors.topMargin + units.smallSpacing : 0 | ||
32 | 32 | | |||
33 | Repeater { | 33 | Repeater { | ||
34 | model: 5 | 34 | id: labels | ||
35 | model: 6 | ||||
36 | readonly property int labelHeight: theme.mSize(theme.smallestFont).height | ||||
35 | 37 | | |||
36 | PlasmaComponents.Label { | 38 | PlasmaComponents.Label { | ||
37 | anchors { | 39 | anchors { | ||
38 | left: parent.left | 40 | right: plotter.left | ||
39 | top: parent.top | 41 | top: parent.top | ||
40 | topMargin: Math.round(units.gridUnit / 3) + (index * plotter.height / 5) | 42 | rightMargin: units.smallSpacing | ||
43 | topMargin: Math.round(index * plotter.height / 5) | ||||
broulik: Always `Math.round` when you doing random fractions of sizes | |||||
41 | } | 44 | } | ||
42 | height: paintedHeight | 45 | // Workaround to get paintedHeight. (Undefined or paintedheight does not work.) | ||
46 | height: labels.labelHeight | ||||
broulik: You can set it to `undefiend` to reset the height | |||||
43 | font.pointSize: theme.smallestFont.pointSize | 47 | font.pointSize: theme.smallestFont.pointSize | ||
44 | lineHeight: 1.75 | 48 | lineHeight: 1.75 | ||
45 | text: KCoreAddons.Format.formatByteSize(plotter.maxValue * (1 - index / 5)) + i18n("/s") | 49 | text: KCoreAddons.Format.formatByteSize(plotter.maxValue * (1 - index / 5)) + i18n("/s") | ||
46 | } | 50 | } | ||
47 | } | 51 | } | ||
48 | 52 | | |||
49 | KQuickControlsAddons.Plotter { | 53 | KQuickControlsAddons.Plotter { | ||
50 | id: plotter | 54 | id: plotter | ||
51 | property variant downloadColor: theme.highlightColor | 55 | property variant downloadColor: theme.highlightColor | ||
52 | 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) | ||
53 | // 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 | ||
54 | 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)) | ||
55 | anchors { | 59 | anchors { | ||
56 | left: parent.left | 60 | left: parent.left | ||
57 | leftMargin: units.gridUnit * 3 | 61 | leftMargin: units.gridUnit * 3 | ||
58 | right: parent.right | 62 | right: parent.right | ||
59 | top: parent.top | 63 | top: parent.top | ||
60 | topMargin: units.gridUnit | 64 | topMargin: Math.round(labels.labelHeight / 2) | ||
broulik: Ideally we didn't randomly divide random sizes | |||||
We could probably just use a smaller predefined unit, like largeSpacing, instead of coming up with a semi-random-looking value derived from the label height ngraham: We could probably just use a smaller predefined unit, like `largeSpacing`, instead of coming up… | |||||
61 | } | 65 | } | ||
62 | width: units.gridUnit * 20 | 66 | width: units.gridUnit * 20 | ||
63 | height: units.gridUnit * 8 | 67 | height: units.gridUnit * 8 | ||
64 | horizontalGridLineCount: 5 | 68 | horizontalGridLineCount: 5 | ||
65 | 69 | | |||
66 | dataSets: [ | 70 | dataSets: [ | ||
67 | KQuickControlsAddons.PlotData { | 71 | KQuickControlsAddons.PlotData { | ||
68 | id: downloadPlotData | 72 | id: downloadPlotData | ||
Show All 30 Lines |
Always Math.round when you doing random fractions of sizes