Debian Codegraph @

src/qml/CPUFreqForm.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 CPU_CPUFREQ {
11 id: cpuFreq
12 objectName: "CPU_CPUFREQ"
13
14 width: contents.width
15 height: contents.height
16
17 onScalingGovernorsChanged: governors => {
18 scalingGovernorListModel.clear()
19
20 for (var i = 0; i < governors.length; i+=2) {
21 var element = scalingGovernorListElement.createObject()
22 element.governor= governors[i]
23 element.text = governors[i + 1]
24 scalingGovernorListModel.append(element)
25 }
26
27 cbScalingGovernor.updateWidth()
28 }
29
30 onScalingGovernorChanged: governor => {
31 for (var i = 0; i < scalingGovernorListModel.count; ++i) {
32 if (scalingGovernorListModel.get(i).governor === governor) {
33 cbScalingGovernor.lastIndex = i
34 cbScalingGovernor.currentIndex = i
35 break;
36 }
37 }
38 }
39
40 onEppHintsChanged: hints => {
41 eppHintListModel.clear()
42
43 for (var i = 0; i < hints.length; i+=2) {
44 var element = eppHintListElement.createObject()
45 element.hint = hints[i]
46 element.text = hints[i + 1]
47 eppHintListModel.append(element)
48 }
49
50 cbEppHint.updateWidth()
51 }
52
53 onEppHintChanged: hint => {
54 for (var i = 0; i < eppHintListModel.count; ++i) {
55 if (eppHintListModel.get(i).hint === hint) {
56 cbEppHint.lastIndex = i
57 cbEppHint.currentIndex = i
58 break;
59 }
60 }
61 }
62
63 onToggleEppHint: enable => {
64 lbEppHint.visible = enable
65 cbEppHint.visible = enable
66 }
67
68 ListModel { id: scalingGovernorListModel }
69 Component {
70 id: scalingGovernorListElement
71
72 ListElement {
73 property string text
74 property string governor
75 }
76 }
77
78 ListModel { id: eppHintListModel }
79 Component {
80 id: eppHintListElement
81
82 ListElement {
83 property string text
84 property string hint
85 }
86 }
87
88 CPane {
89 id: contents
90
91 GridLayout {
92 columns: 2
93 columnSpacing: 10
94
95 Label {
96 text: qsTr("Frequency governor")
97 Layout.alignment: Qt.AlignRight
98 }
99
100 CComboBox {
101 id: cbScalingGovernor
102 model: scalingGovernorListModel
103 Layout.alignment: Qt.AlignLeft
104 Layout.fillWidth: true
105
106 property int lastIndex: 0
107
108 onActivated: {
109 if (lastIndex !== currentIndex) {
110 lastIndex = currentIndex
111
112 var governor = model.get(currentIndex).governor
113 cpuFreq.changeScalingGovernor(governor)
114 }
115 }
116 }
117
118 Label {
119 id: lbEppHint
120 text: qsTr("Energy Performance Preference")
121 Layout.alignment: Qt.AlignRight
122 visible: false
123 }
124
125 CComboBox {
126 id: cbEppHint
127 model: eppHintListModel
128 Layout.alignment: Qt.AlignLeft
129 Layout.fillWidth: true
130 visible: false
131
132 property int lastIndex: 0
133
134 onActivated: {
135 if (lastIndex !== currentIndex) {
136 lastIndex = currentIndex
137
138 var hint = model.get(currentIndex).hint
139 cpuFreq.changeEPPHint(hint)
140 }
141 }
142 }
143 }
144 }
145 }