Changeset View
Changeset View
Standalone View
Standalone View
faces/import/SensorFace.qml
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2019 Marco Martin <mart@kde.org> | ||||
3 | * Copyright 2019 David Edmundson <davidedmundson@kde.org> | ||||
4 | * Copyright 2019 Arjen Hiemstra <ahiemstra@heimr.nl> | ||||
5 | * Copyright 2019 Kai Uwe Broulik <kde@broulik.de> | ||||
6 | * | ||||
7 | * This program is free software; you can redistribute it and/or modify | ||||
8 | * it under the terms of the GNU Library General Public License as | ||||
9 | * published by the Free Software Foundation; either version 2, or | ||||
10 | * (at your option) any later version. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU Library General Public | ||||
18 | * License along with this program; if not, write to the | ||||
19 | * Free Software Foundation, Inc., | ||||
20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
21 | */ | ||||
22 | | ||||
23 | import QtQuick 2.9 | ||||
24 | import QtQuick.Layouts 1.4 | ||||
25 | | ||||
26 | import org.kde.kirigami 2.8 as Kirigami | ||||
27 | import org.kde.quickcharts 1.0 as Charts | ||||
28 | import org.kde.ksysguard.sensors 1.0 as Sensors | ||||
29 | import org.kde.ksysguard.faces 1.0 as Faces | ||||
30 | | ||||
31 | Faces.AbstractSensorFace { | ||||
32 | id: root | ||||
33 | implicitWidth: contentItem.implicitWidth | ||||
34 | implicitHeight: contentItem.implicitHeight | ||||
35 | Layout.minimumWidth: contentItem.Layout.minimumWidth | ||||
36 | Layout.minimumHeight: contentItem.Layout.minimumHeight | ||||
37 | Layout.preferredWidth: contentItem.Layout.preferredWidth | ||||
38 | Layout.preferredHeight: contentItem.Layout.preferredHeight | ||||
39 | Layout.maximumWidth: contentItem.Layout.maximumWidth | ||||
40 | Layout.maximumHeight: contentItem.Layout.maximumHeight | ||||
41 | | ||||
42 | property alias colorSource: colorSource | ||||
43 | | ||||
44 | Charts.MapProxySource { | ||||
45 | id: colorSource | ||||
46 | source: Charts.ArraySource { | ||||
47 | array: root.controller.highPrioritySensorIds | ||||
48 | } | ||||
49 | map: root.controller.sensorColors | ||||
50 | } | ||||
51 | Charts.ColorGradientSource { | ||||
52 | baseColor: Kirigami.Theme.highlightColor | ||||
53 | itemCount: root.controller.highPrioritySensorIds.length | ||||
54 | | ||||
55 | onItemCountChanged: generate() | ||||
56 | Component.onCompleted: generate() | ||||
57 | | ||||
58 | function generate() { | ||||
59 | //var colors = colorSource.colors; | ||||
60 | var savedColors = root.controller.sensorColors; | ||||
61 | for (var i = 0; i < root.controller.highPrioritySensorIds.length; ++i) { | ||||
62 | if (savedColors.length <= i) { | ||||
63 | savedColors[root.controller.highPrioritySensorIds[i]] = colors[i]; | ||||
64 | } else { | ||||
65 | // Use the darker trick to make Qt validate the scring as a valid color; | ||||
66 | var currentColor = Qt.darker(savedColors[i], 1); | ||||
67 | if (!currentColor) { | ||||
68 | savedColors[root.controller.highPrioritySensorIds[i]] = colors[i]; | ||||
69 | } else { | ||||
70 | savedColors[root.controller.highPrioritySensorIds[i]] = currentColor; | ||||
71 | } | ||||
72 | } | ||||
73 | } | ||||
74 | root.controller.sensorColors = savedColors; | ||||
75 | } | ||||
76 | } | ||||
77 | } |