on 448bfaf help sign in
bat/tests/syntax-tests/source/QML/BatSyntaxTest.qml
219 lines 6.5 kB history raw
1import QtQuick 2.0
2import "../components"
4Page {
5 id: page
7 // properties
9 property bool startup: true
10 readonly property var var1: null
11 readonly property QtObject var2: null
13 allowedOrientations: Orientation.All
15 /* components */
17 DBusServiceWatcher {
18 id: dbusService
19 service: "org.bat.service"
21 onRegisteredChanged: {
22 if (dbusService.registered) {
23 announcedNameField.text = daemon.announcedName()
24 }
25 }
26 }
28 Component.onCompleted: {
29 console.debug("completed")
30 }
32 Flickable {
33 anchors.fill: parent
34 contentHeight: column.height
35 visible: dbusService.registered
37 ViewPlaceholder {
38 enabled: !startup
39 && trustedDevices.count == 0
40 && nearDevices.count == 0
41 text: qsTr("Install Bat.")
42 }
44 Column {
45 id: column
47 width: page.width
48 spacing: Theme.paddingLarge
50 PageHeader {
51 title: qsTr("Syntax Test")
52 }
54 TextField {
55 id: announcedNameField
56 width: parent.width
57 label: qsTr("Device Name")
58 text: dbusService.registered ? daemon.announcedName() : ""
60 onActiveFocusChanged: {
61 if (activeFocus)
62 return
64 if (text.length === 0) {
65 text = daemon.announcedName()
66 } else {
67 daemon.setAnnouncedName(text)
68 placeholderText = text
69 }
70 }
72 EnterKey.onClicked: announcedNameField.focus = false
73 EnterKey.iconSource: "image://theme/icon-m-enter-close"
74 }
77 Component {
78 id: deviceDelegate
80 ListItem {
81 id: listItem
83 property bool showStatus: deviceStatusLabel.text.length
85 width: page.width
86 height: Theme.itemSizeMedium
88 Image {
89 id: icon
90 source: iconUrl
92 x: Theme.horizontalPageMargin
93 anchors.verticalCenter: parent.verticalCenter
94 sourceSize.width: Theme.iconSizeMedium
95 sourceSize.height: Theme.iconSizeMedium
96 }
98 Label {
99 id: deviceNameLabel
100 anchors {
101 left: icon.right
102 leftMargin: Theme.paddingLarge
103 right: parent.right
104 rightMargin: Theme.horizontalPageMargin
105 }
106 y: listItem.contentHeight / 2 - implicitHeight / 2
107 - showStatus * (deviceStatusLabel.implicitHeight / 2)
109 text: name
110 color: listItem.highlighted
111 ? Theme.highlightColor
112 : Theme.primaryColor
113 truncationMode: TruncationMode.Fade
114 textFormat: Text.PlainText
116 Behavior on y { NumberAnimation {} }
117 }
119 Label {
120 id: deviceStatusLabel
121 anchors {
122 left: deviceNameLabel.left
123 top: deviceNameLabel.bottom
124 right: parent.right
125 rightMargin: Theme.horizontalPageMargin
126 }
128 text: (trusted && reachable)
129 ? qsTr("Connected")
130 : (hasPairingRequests || waitsForPairing
131 ? qsTr("Pending pairing request ...") : "")
132 color: listItem.highlighted
133 ? Theme.secondaryHighlightColor
134 : Theme.secondaryColor
135 truncationMode: TruncationMode.Fade
136 font.pixelSize: Theme.fontSizeExtraSmall
137 opacity: showStatus ? 1.0 : 0.0
138 width: parent.width
139 textFormat: Text.PlainText
141 Behavior on opacity { FadeAnimation {} }
142 }
144 onClicked: {
145 pageStack.push(
146 Qt.resolvedUrl("DevicePage.qml"),
147 { deviceId: id })
148 }
149 }
150 }
152 DeviceListModel {
153 id: devicelistModel
154 }
156 ColumnView {
157 id: devicesView
158 width: page.width
159 itemHeight: Theme.itemSizeMedium
162 model: trustedDevicesModel
163 delegate: deviceDelegate
164 visible: devicesView.count > 0
165 }
166 }
168 PullDownMenu {
169// MenuItem {
170// text: qsTr("About ...")
171// onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
172// }
174 MenuItem {
175 text: qsTr("Settings ...")
176 onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
177 }
178 }
180 VerticalScrollDecorator {}
181 }
183 /*
184 Connections {
185 target: ui
186 onOpeningDevicePage: openDevicePage(deviceId)
187 }*/
189 Timer {
190 interval: 1000
191 running: true
192 repeat: false
193 onTriggered: startup = false
194 }
196 function openDevicePage(deviceId) {
197 if (typeof pageStack === "undefined")
198 return;
200 console.log("opening device " + deviceId)
202 window.activate()
204 var devicePage = pageStack.find(function(page) {
205 return page.objectName === "DevicePage"
206 })
207 if (devicePage !== null && devicePage.deviceId === deviceId) {
208 pageStack.pop(devicePage)
209 ui.showMainWindow()
210 return
211 }
213 pageStack.pop(page, PageStackAction.Immediate)
214 pageStack.push(
215 Qt.resolvedUrl("DevicePage.qml"),
216 { deviceId: deviceId },
217 PageStackAction.Immediate)
218 }