on master help sign in
Add QML syntax test
3729aefR1tschY
tests/syntax-tests/highlighted/QML/BatSyntaxTest.qmlnew file+219
@@ -0,0 +1,219 @@
1+import QtQuick 2.0
2+import "../components"
3+
4+Page {
5+ id: page
6+
7+ // properties
8+
9+ property bool startup: true
10+ readonly property var var1: null
11+ readonly property QtObject var2: null
12+
13+ allowedOrientations: Orientation.All
14+
15+ /* components */
16+
17+ DBusServiceWatcher {
18+ id: dbusService
19+ service: "org.bat.service"
20+
21+ onRegisteredChanged: {
22+ if (dbusService.registered) {
23+ announcedNameField.text = daemon.announcedName()
24+ }
25+ }
26+ }
27+
28+ Component.onCompleted: {
29+ console.debug("completed")
30+ }
31+
32+ Flickable {
33+ anchors.fill: parent
34+ contentHeight: column.height
35+ visible: dbusService.registered
36+
37+ ViewPlaceholder {
38+ enabled: !startup
39+ && trustedDevices.count == 0
40+ && nearDevices.count == 0
41+ text: qsTr("Install Bat.")
42+ }
43+
44+ Column {
45+ id: column
46+
47+ width: page.width
48+ spacing: Theme.paddingLarge
49+
50+ PageHeader {
51+ title: qsTr("Syntax Test")
52+ }
53+
54+ TextField {
55+ id: announcedNameField
56+ width: parent.width
57+ label: qsTr("Device Name")
58+ text: dbusService.registered ? daemon.announcedName() : ""
59+
60+ onActiveFocusChanged: {
61+ if (activeFocus)
62+ return
63+
64+ if (text.length === 0) {
65+ text = daemon.announcedName()
66+ } else {
67+ daemon.setAnnouncedName(text)
68+ placeholderText = text
69+ }
70+ }
71+
72+ EnterKey.onClicked: announcedNameField.focus = false
73+ EnterKey.iconSource: "image://theme/icon-m-enter-close"
74+ }
75+
76+
77+ Component {
78+ id: deviceDelegate
79+
80+ ListItem {
81+ id: listItem
82+
83+ property bool showStatus: deviceStatusLabel.text.length
84+
85+ width: page.width
86+ height: Theme.itemSizeMedium
87+
88+ Image {
89+ id: icon
90+ source: iconUrl
91+
92+ x: Theme.horizontalPageMargin
93+ anchors.verticalCenter: parent.verticalCenter
94+ sourceSize.width: Theme.iconSizeMedium
95+ sourceSize.height: Theme.iconSizeMedium
96+ }
97+
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)
108+
109+ text: name
110+ color: listItem.highlighted
111+ ? Theme.highlightColor
112+ : Theme.primaryColor
113+ truncationMode: TruncationMode.Fade
114+ textFormat: Text.PlainText
115+
116+ Behavior on y { NumberAnimation {} }
117+ }
118+
119+ Label {
120+ id: deviceStatusLabel
121+ anchors {
122+ left: deviceNameLabel.left
123+ top: deviceNameLabel.bottom
124+ right: parent.right
125+ rightMargin: Theme.horizontalPageMargin
126+ }
127+
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
140+
141+ Behavior on opacity { FadeAnimation {} }
142+ }
143+
144+ onClicked: {
145+ pageStack.push(
146+ Qt.resolvedUrl("DevicePage.qml"),
147+ { deviceId: id })
148+ }
149+ }
150+ }
151+
152+ DeviceListModel {
153+ id: devicelistModel
154+ }
155+
156+ ColumnView {
157+ id: devicesView
158+ width: page.width
159+ itemHeight: Theme.itemSizeMedium
160+
161+
162+ model: trustedDevicesModel
163+ delegate: deviceDelegate
164+ visible: devicesView.count > 0
165+ }
166+ }
167+
168+ PullDownMenu {
169+// MenuItem {
170+// text: qsTr("About ...")
171+// onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
172+// }
173+
174+ MenuItem {
175+ text: qsTr("Settings ...")
176+ onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
177+ }
178+ }
179+
180+ VerticalScrollDecorator {}
181+ }
182+
183+ /*
184+ Connections {
185+ target: ui
186+ onOpeningDevicePage: openDevicePage(deviceId)
187+ }*/
188+
189+ Timer {
190+ interval: 1000
191+ running: true
192+ repeat: false
193+ onTriggered: startup = false
194+ }
195+
196+ function openDevicePage(deviceId) {
197+ if (typeof pageStack === "undefined")
198+ return;
199+
200+ console.log("opening device " + deviceId)
201+
202+ window.activate()
203+
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+ }
212+
213+ pageStack.pop(page, PageStackAction.Immediate)
214+ pageStack.push(
215+ Qt.resolvedUrl("DevicePage.qml"),
216+ { deviceId: deviceId },
217+ PageStackAction.Immediate)
218+ }
219+}
tests/syntax-tests/source/QML/BatSyntaxTest.qmlnew file+219
@@ -0,0 +1,219 @@
1+import QtQuick 2.0
2+import "../components"
3+
4+Page {
5+ id: page
6+
7+ // properties
8+
9+ property bool startup: true
10+ readonly property var var1: null
11+ readonly property QtObject var2: null
12+
13+ allowedOrientations: Orientation.All
14+
15+ /* components */
16+
17+ DBusServiceWatcher {
18+ id: dbusService
19+ service: "org.bat.service"
20+
21+ onRegisteredChanged: {
22+ if (dbusService.registered) {
23+ announcedNameField.text = daemon.announcedName()
24+ }
25+ }
26+ }
27+
28+ Component.onCompleted: {
29+ console.debug("completed")
30+ }
31+
32+ Flickable {
33+ anchors.fill: parent
34+ contentHeight: column.height
35+ visible: dbusService.registered
36+
37+ ViewPlaceholder {
38+ enabled: !startup
39+ && trustedDevices.count == 0
40+ && nearDevices.count == 0
41+ text: qsTr("Install Bat.")
42+ }
43+
44+ Column {
45+ id: column
46+
47+ width: page.width
48+ spacing: Theme.paddingLarge
49+
50+ PageHeader {
51+ title: qsTr("Syntax Test")
52+ }
53+
54+ TextField {
55+ id: announcedNameField
56+ width: parent.width
57+ label: qsTr("Device Name")
58+ text: dbusService.registered ? daemon.announcedName() : ""
59+
60+ onActiveFocusChanged: {
61+ if (activeFocus)
62+ return
63+
64+ if (text.length === 0) {
65+ text = daemon.announcedName()
66+ } else {
67+ daemon.setAnnouncedName(text)
68+ placeholderText = text
69+ }
70+ }
71+
72+ EnterKey.onClicked: announcedNameField.focus = false
73+ EnterKey.iconSource: "image://theme/icon-m-enter-close"
74+ }
75+
76+
77+ Component {
78+ id: deviceDelegate
79+
80+ ListItem {
81+ id: listItem
82+
83+ property bool showStatus: deviceStatusLabel.text.length
84+
85+ width: page.width
86+ height: Theme.itemSizeMedium
87+
88+ Image {
89+ id: icon
90+ source: iconUrl
91+
92+ x: Theme.horizontalPageMargin
93+ anchors.verticalCenter: parent.verticalCenter
94+ sourceSize.width: Theme.iconSizeMedium
95+ sourceSize.height: Theme.iconSizeMedium
96+ }
97+
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)
108+
109+ text: name
110+ color: listItem.highlighted
111+ ? Theme.highlightColor
112+ : Theme.primaryColor
113+ truncationMode: TruncationMode.Fade
114+ textFormat: Text.PlainText
115+
116+ Behavior on y { NumberAnimation {} }
117+ }
118+
119+ Label {
120+ id: deviceStatusLabel
121+ anchors {
122+ left: deviceNameLabel.left
123+ top: deviceNameLabel.bottom
124+ right: parent.right
125+ rightMargin: Theme.horizontalPageMargin
126+ }
127+
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
140+
141+ Behavior on opacity { FadeAnimation {} }
142+ }
143+
144+ onClicked: {
145+ pageStack.push(
146+ Qt.resolvedUrl("DevicePage.qml"),
147+ { deviceId: id })
148+ }
149+ }
150+ }
151+
152+ DeviceListModel {
153+ id: devicelistModel
154+ }
155+
156+ ColumnView {
157+ id: devicesView
158+ width: page.width
159+ itemHeight: Theme.itemSizeMedium
160+
161+
162+ model: trustedDevicesModel
163+ delegate: deviceDelegate
164+ visible: devicesView.count > 0
165+ }
166+ }
167+
168+ PullDownMenu {
169+// MenuItem {
170+// text: qsTr("About ...")
171+// onClicked: pageStack.push(Qt.resolvedUrl("AboutPage.qml"))
172+// }
173+
174+ MenuItem {
175+ text: qsTr("Settings ...")
176+ onClicked: pageStack.push(Qt.resolvedUrl("SettingsPage.qml"))
177+ }
178+ }
179+
180+ VerticalScrollDecorator {}
181+ }
182+
183+ /*
184+ Connections {
185+ target: ui
186+ onOpeningDevicePage: openDevicePage(deviceId)
187+ }*/
188+
189+ Timer {
190+ interval: 1000
191+ running: true
192+ repeat: false
193+ onTriggered: startup = false
194+ }
195+
196+ function openDevicePage(deviceId) {
197+ if (typeof pageStack === "undefined")
198+ return;
199+
200+ console.log("opening device " + deviceId)
201+
202+ window.activate()
203+
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+ }
212+
213+ pageStack.pop(page, PageStackAction.Immediate)
214+ pageStack.push(
215+ Qt.resolvedUrl("DevicePage.qml"),
216+ { deviceId: deviceId },
217+ PageStackAction.Immediate)
218+ }
219+}