Debian Codegraph @

src/qml/AMDPMPowerProfileForm.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_PM_POWER_PROFILE {
11 id: pmPowerProfile
12 objectName: "AMD_PM_POWER_PROFILE"
13
14 width: contents.width
15 height: contents.height
16
17 onModeChanged: mode => {
18 for (var i = 0; i < listModel.count; ++i) {
19 if (listModel.get(i).mode === mode) {
20 cbMode.lastIndex = i
21 cbMode.currentIndex = i
22 break;
23 }
24 }
25 }
26
27 onModesChanged: modes => {
28 listModel.clear()
29
30 for (var i = 0; i < modes.length; i+=2) {
31 var element = listElement.createObject()
32 element.mode = modes[i]
33 element.text = modes[i + 1]
34 listModel.append(element)
35 }
36
37 cbMode.updateWidth()
38 }
39
40 ListModel { id: listModel }
41 Component {
42 id: listElement
43
44 ListElement {
45 property string text
46 property string mode
47 }
48 }
49
50 CPane {
51 id: contents
52
53 RowLayout {
54 Label {
55 text: qsTr("Power profile")
56 rightPadding: 6
57 }
58
59 CComboBox {
60 id: cbMode
61 model: listModel
62
63 property int lastIndex: 0
64
65 onActivated: {
66 if (lastIndex !== currentIndex) {
67 lastIndex = currentIndex
68
69 var mode = model.get(currentIndex).mode
70 pmPowerProfile.changeMode(mode)
71 }
72 }
73 }
74 }
75 }
76 }