Debian Codegraph @

src/qml/AMDOdFanCurveForm.qml

raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright 2019 Juan Palacios <[email protected]>
3
4 import QtQuick 2.15
5 import QtQuick.Controls 2.15
6 import QtQuick.Layouts 1.15
7 import CoreCtrl.UIComponents 1.0
8 import "Style.js" as Style
9
10 AMD_OD_FAN_CURVE {
11 id: fanCurve
12 objectName: "AMD_OD_FAN_CURVE"
13
14 width: contents.width
15 height: contents.height
16
17 onCurveChanged: curve => {
18 curveControl.removeCurve("curve")
19 curveControl.addCurve("curve", Style.Theme.accent, curve)
20 }
21
22 onCurveRangeChanged: (tempMin, tempMax, speedMin, speedMax) => {
23 curveControl.configureAxes(qsTr("Temperature"), "\u00B0C", tempMin, tempMax,
24 qsTr("Speed"), "%", speedMin, speedMax)
25 }
26
27 onStopAvailable: { p.showFanStopControl() }
28 onStopTempAvailable: { p.showFanStopTempControl() }
29
30 onStopChanged: enabled => {
31 if (p.fanStopTempAvailable) {
32 if (enabled)
33 p.showStopCurve()
34 else
35 p.hideStopCurve()
36 }
37
38 swStop.checked = enabled
39 }
40
41 onStopTempChanged: value => {
42 if (p.fanStopTempAvailable && fanCurve.stop) {
43 p.hideStopCurve()
44 p.showStopCurve()
45 }
46
47 iStopTemp.value = value
48 }
49
50 QtObject { // private stuff
51 id: p
52
53 property bool fanStopAvailable: false
54 property bool fanStopTempAvailable: false
55
56 function showFanStopControl() {
57 fanStopAvailable = true
58 rlStop.visible = fanStopAvailable
59 // The stop temperature input field is a child of rlStop and
60 // it will be set to visible automatically when rsStop is set
61 // to visible.
62 // Make sure that iStopTemp visible state is in sync with
63 // fanStopTempAvailable state.
64 iStopTemp.visible = fanStopTempAvailable
65 }
66
67 function showFanStopTempControl() {
68 fanStopTempAvailable = true
69 iStopTemp.visible = fanStopTempAvailable
70 }
71
72 function hideStopCurve() {
73 curveControl.removeCurve("stop")
74 }
75
76 function showStopCurve() {
77 var points = []
78 points.push(Qt.point(fanCurve.stopTemp,
79 fanCurve.minTemp +
80 (fanCurve.maxTemp - fanCurve.minTemp) * .15))
81 curveControl.addCurve("stop",
82 Style.CurveControl.curve_amd_start_color,
83 points, true)
84 }
85 }
86
87 TextMetrics {
88 id: tFMetrics
89 text: "100"
90 }
91
92 CPane {
93 id: contents
94
95 ColumnLayout {
96 spacing: 8
97
98 CurveControl {
99 id: curveControl
100 minXDistance: 5
101 clampPointsYCoordinate: true
102 width: 480
103 height: 240
104
105 onCurveChanged: (name, oldPoint, newPoint) => {
106 if (name === "curve")
107 fanCurve.updateCurvePoint(oldPoint, newPoint)
108 else if (name === "stop")
109 fanCurve.stopTemp = parseInt(Math.round(newPoint.x))
110 }
111 }
112
113 RowLayout {
114 id: rlStop
115 visible: false
116 spacing: 8
117
118 Item {
119 Layout.fillWidth: true
120 }
121
122 Item {
123 implicitWidth: swStop.width / (1 + Style.g_tweakScale)
124
125 Switch {
126 id: swStop
127
128 scale: Style.g_tweakScale
129 anchors.centerIn: parent
130
131 onToggled: fanCurve.stop = checked
132 }
133 }
134
135 Label {
136 text: qsTr("Fan stop") + (p.fanStopTempAvailable ? " (\u00B0C)" : "")
137 enabled: swStop.checked
138 }
139
140 CIntInput {
141 id: iStopTemp
142
143 minValue: 0
144 maxValue: 100
145
146 enabled: swStop.checked
147 Layout.preferredWidth: tFMetrics.width + padding * 2
148
149 onValueChanged: fanCurve.stopTemp = value
150 }
151 }
152 }
153 }
154 }