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.ArraySource { | ||||
45 | id: colorSource | ||||
46 | array: root.controller.highPrioritySensorColors | ||||
47 | } | ||||
48 | Charts.ColorGradientSource { | ||||
49 | baseColor: Kirigami.Theme.highlightColor | ||||
50 | itemCount: root.controller.highPrioritySensorIds.length | ||||
51 | | ||||
52 | onItemCountChanged: generate() | ||||
53 | Component.onCompleted: generate() | ||||
54 | | ||||
55 | function generate() { | ||||
56 | var colors = colorSource.colors; | ||||
57 | var savedColors = root.controller.highPrioritySensorColors; | ||||
58 | for (var i = 0; i < root.controller.highPrioritySensorIds.length; ++i) { | ||||
59 | if (savedColors.length <= i) { | ||||
60 | savedColors.push(colors[i]); | ||||
61 | } else { | ||||
62 | // Use the darker trick to make Qt validate the scring as a valid color; | ||||
63 | var currentColor = Qt.darker(savedColors[i], 1); | ||||
64 | if (!currentColor) { | ||||
65 | savedColors[i] = (colors[i]); | ||||
66 | } | ||||
67 | } | ||||
68 | } | ||||
69 | root.controller.highPrioritySensorColors = savedColors; | ||||
70 | } | ||||
71 | } | ||||
72 | } |