Debian Codegraph @

src/qml/SysModelForm.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 SYS_MODEL {
11 id: sysModel
12 objectName: "SYS_MODEL"
13
14 anchors.fill: parent
15
16 Component {
17 id: tabButtonComponent
18
19 CTabButton {
20 id: tabBtn
21
22 property var component: null
23 active: component != null ? component.enabled : true
24 text: component != null ? component.name : ""
25 width: implicitWidth
26
27 contentItem: RowLayout {
28 Text {
29 text: tabBtn.text
30 font: tabBtn.font
31 color: tabBtn.active ? tabBtn.checked ? Style.Theme.accent
32 : Style.Theme.foreground
33 : Style.Theme.accent_alt
34 horizontalAlignment: Text.AlignHCenter
35 verticalAlignment: Text.AlignVCenter
36 elide: Text.ElideRight
37 }
38 Item {
39 implicitWidth: swc.width / 2
40
41 Switch {
42 id: swc
43
44 padding: 0
45 rotation: -90
46 scale: Style.g_tweakScale
47 checked: tabBtn.active
48 anchors.centerIn: parent
49
50 onToggled: {
51 tabBtn.component.enabled = swc.checked
52 tabBtn.component.activate(swc.checked)
53 sysModel.settingsChanged()
54 }
55 }
56 }
57 }
58 }
59 }
60
61 ColumnLayout {
62 spacing: 0
63 anchors.fill: parent
64
65 TabBar {
66 id: tabBar
67 spacing: 1
68 Layout.fillWidth: true
69 }
70
71 StackLayout {
72 id: sysModelplug
73 objectName: "SYS_MODEL_Plug"
74 currentIndex: tabBar.currentIndex
75
76 property var childrenAdded: []
77 function isNewChild(child) {
78 for (var i = 0; i < childrenAdded.length; ++i)
79 if (childrenAdded[i] === child)
80 return false
81
82 return true
83 }
84
85 onChildrenChanged: {
86 for (var i = 0; i < children.length; ++i) {
87
88 var sysComponent = children[i]
89 if (isNewChild(sysComponent)) {
90 childrenAdded.push(sysComponent)
91
92 // create and setup the new component
93 var tab = tabButtonComponent.createObject(tabBar)
94 tab.component = sysComponent
95
96 tabBar.addItem(tab)
97 sysModel.setupChild(sysComponent)
98 }
99 }
100 }
101 }
102 }
103 }