Kstars

DevicePanel.qml
1// SPDX-FileCopyrightText: 2016 Artem Fedoskin <afedoskin3@gmail.com>
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4import QtQuick 2.8
5import QtQuick.Window 2.2
6import "../modules"
7import "../constants" 1.0
8import QtQuick.Layouts 1.2
9import QtQuick.Controls 2.0
10
11KSPage {
12 id: devicesPage
13 title: devicesPage.deviceName + " - " + tabBar.currentItem.text
14
15 property string deviceName
16 property ImagePreview imagePreview: null
17
18 ColumnLayout {
19 anchors.fill: parent
20
21 Item {
22 anchors {
23 left: parent.left
24 right: parent.right
25 }
26 height: tabBar.height
27
28 KSTabBarArrow {
29 imgSource: "../images/left-arrow.png"
30 tabBar: tabBar
31 state: {
32 if(!tabBar.contentItem.atXBeginning) {
33 return "Visible"
34 } else {
35 return "Invisible"
36 }
37 }
38 anchors {
39 left: parent.left
40 top: parent.top
41 bottom: parent.bottom
42 }
43 }
44
45 KSTabBarArrow {
46 imgSource: "../images/right-arrow.png"
47 tabBar: tabBar
48 state: {
49 if(!tabBar.contentItem.atXEnd) {
50 return "Visible"
51 } else {
52 return "Invisible"
53 }
54 }
55 anchors {
56 right: parent.right
57 top: parent.top
58 bottom: parent.bottom
59 }
60 flickSpeed: -1000
61 }
62
63 TabBar {
64 id: tabBar
65 Layout.fillHeight: true
66 anchors {
67 left: parent.left
68 right: parent.right
69 }
70 clip: true
71 spacing: 20
72 Component.onCompleted: {
73 contentItem.flickDeceleration = 1000
74 }
75
76 background: Rectangle {
77 color: Num.sysPalette.base
78 }
79 }
80 }
81
82 SwipeView {
83 id: deviceSwipeView
84 Layout.fillHeight: true
85 Layout.fillWidth: true
86 currentIndex: tabBar.currentIndex
87 clip: true
88
89 property var groups: []
90 property var properties: []
91 property var tabs: []
92
93 onCurrentIndexChanged: {
94 tabBar.currentIndex = currentIndex
95 }
96
97 Connections {
98 target: ClientManagerLite
99 onNewINDIProperty: {
100 if(devicesPage.deviceName === deviceName) {
101 if(deviceSwipeView.groups.indexOf(groupName) == -1) {
102 deviceSwipeView.groups.push(groupName)
103 var newTabComp = Qt.createComponent("../modules/KSTab.qml");
104 var newTab = newTabComp.createObject(deviceSwipeView)
105 newTab.title = groupName
106
107 var columnForTab = Qt.createQmlObject('import QtQuick 2.7
108 import QtQuick.Layouts 1.3
109 Column {
110 spacing: 5
111 }', newTab.contentItem)
112
113 newTab.rootItem = columnForTab
114 var tabButton = Qt.createQmlObject('import QtQuick 2.7;
115 import QtQuick.Controls 2.0
116 import "../modules"
117 KSTabButton {}',
118 tabBar);
119 tabButton.text = groupName
120 if(tabBar.count == 1) {
121 //Without notifying about adding first item to tabBar title of devicesPage won't be updated
122 tabBar.currentItemChanged()
123 }
124
125 deviceSwipeView.tabs.push(newTab)
126 if(groupName == "Motion Control") {
127 var component = Qt.createComponent("modules/MotionControl.qml");
128 var motionControl = component.createObject(newTab)
129 motionControl.deviceName = deviceName
130 }
131 }
132
133 if(groupName != "Motion Control") {
134 for(var i = 0; i < deviceSwipeView.tabs.length; ++i) {
135 var tab = deviceSwipeView.tabs[i]
136 if(tab.title === groupName) {
137 var propComp = Qt.createComponent("modules/Property.qml");
138 var property = propComp.createObject(tab.rootItem)
139 property.propName = propName
140 property.label = label
141 property.deviceName = deviceName
142 property.parentTab = tab
143 if(propName == "CCD_EXPOSURE" && devicesPage.imagePreview == null) {
144 var imgPreviewComp = Qt.createComponent("ImagePreview.qml");
145 devicesPage.imagePreview = imgPreviewComp.createObject(window)
146 devicesPage.imagePreview.deviceName = devicesPage.deviceName
147 }
148 }
149 }
150 }
151 }
152 }
153
154 onRemoveINDIProperty: {
155 for(var i = 0; i < deviceSwipeView.tabs.length; ++i) {
156 var tab = deviceSwipeView.tabs[i]
157 if(tab.title === groupName && groupName != "Motion Control") {
158 var contentItem = deviceSwipeView.tabs[i].rootItem
159 for(var c = 0; c < contentItem.children.length; ++c) {
160 if(contentItem.children[c].propName === propName) {
161 contentItem.children[c].destroy()
162 }
163 }
164 if(contentItem.children.length == 0) {
165 var groups = deviceSwipeView.groups
166 groups.splice(groups.indexOf(groupName), 1)
167 tab.destroy()
168 }
169 /*if(propName == "CCD_EXPOSURE" && devicesPage.imagePreview != null) {
170 imgPreview.destroy()
171 }*/
172 }
173 }
174 }
175 }
176 }
177 }
178}
KGuiItem properties()
QString label(StandardShortcut id)
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:16:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.