ccce16959b1c340ace4533dbb61bd4ab1662d70d
[apps/onscreenapp.git] / sample / app / main.qml
1 import QtQuick 2.7
2 import QtQuick.Window 2.2
3 import QtQuick.Controls 2.0
4 import QtQuick.Layouts 1.0
5 import QtQuick.VirtualKeyboard 2.1
6
7
8 ApplicationWindow {
9     id: root
10     visible: true
11     width: 1080
12     height: 1487
13
14     property string onsId: qsTr("onscreenapp")
15     property string pri_path: qsTr("/home/0/app-data/OnScreen/qml/")
16     property string filepath: pri_path + qsTr("vics.qml")
17     property string msgdata: ""
18     property string postmsg: ""
19
20     Text {
21         id: title
22         width: parent.width
23         height: 40
24         text: "OnScreen Test App"
25         font.pixelSize: 40
26     }
27
28     ColumnLayout {
29         spacing: 20
30         anchors.top: title.bottom
31         anchors.topMargin: 40
32         anchors.horizontalCenter: title.horizontalCenter
33
34         // show received reply information area
35         Flickable {
36              id: flickable
37              width: 800
38              height: 160
39              Layout.alignment: Qt.AlignCenter
40
41              TextArea.flickable: TextArea {
42                  id: output
43                  text: "show received reply information area\n...\n...\n...\n...\n"
44                  font.pixelSize: 20
45                  wrapMode: TextArea.Wrap
46              }
47
48              ScrollBar.vertical: ScrollBar { }
49          }
50
51         // select onscreen type area
52         GroupBox {
53             title: "Please select send OnScreen Type"
54             font.pixelSize: 30
55             font.bold: true
56             width: 800
57             height: 100
58             Layout.alignment: Qt.AlignLeft
59
60             RowLayout {
61                 anchors.fill: parent
62                 RadioButton {
63                     text: qsTr("VICS")
64                     font.pixelSize: 20
65                     checked: true
66                     onClicked: {
67                         selectVICS();
68                         console.log("clicked:", "VICS")
69                     }
70                 }
71                 RadioButton {
72                     text: qsTr("SYS")
73                     font.pixelSize: 20
74                     onClicked: {
75                         selectSYS();
76                         console.log("clicked:", "SYS")
77                     }
78                 }
79                 RadioButton {
80                     text: qsTr("TEL")
81                     font.pixelSize: 20
82                     onClicked: {
83                         selectTEL();
84                         console.log("clicked:", "TEL")
85                     }
86                 }
87                 RadioButton {
88                     text: qsTr("MSG")
89                     font.pixelSize: 20
90                     onClicked: {
91                         selectMSG();
92                         console.log("clicked:", "MSG")
93                     }
94                 }
95             }
96         }
97
98         // edit post message area
99         GroupBox {
100             id : editarea
101             title: "Please input parameter to onscreen"
102             font.pixelSize: 30
103             font.bold: true
104             width: 800
105             height: 400
106             Layout.alignment: Qt.AlignLeft
107
108             ColumnLayout {
109                 spacing:  20
110                 RowLayout {
111                     id: line1
112                     height: 80
113                     Label {
114                         id: guitype
115                         anchors.left: parent.left
116                         anchors.leftMargin: 10
117                         text: 'gui_type'
118                         font.pixelSize: 20
119                         color: '#00ADDC'
120                     }
121
122                     Label {
123                         text: qsTr("application")
124                         font.pixelSize: 20
125                         color: '#00ADDC'
126                         anchors.left: guitype.right
127                         anchors.leftMargin: 20
128                     }
129                 }
130                 RowLayout {
131                     id: line2
132                     spacing:  20
133                     Label {
134                         id: qmlpath
135                         anchors.left: parent.left
136                         anchors.leftMargin: 30
137                         text: qsTr("file")
138                         font.pixelSize: 20
139                         font.italic: true
140                         color: '#00ADDC'
141                     }
142
143                     TextInput {
144                         id: fpath
145                         text: filepath
146                         font.pixelSize: 20
147                         font.italic: true
148                         anchors.left: qmlpath.right
149                         anchors.leftMargin: 20
150                         color: '#00ADDC'
151                         cursorVisible: true
152                         inputMethodHints: Qt.ImhNone
153                         onFocusChanged: {
154                             console.log("filepath")
155                             if(fpath.focus)
156                                 vkb.visible = true
157                         }
158                     }
159                 }
160                 RowLayout {
161                     id: line3
162                     spacing: 20
163                     Label {
164                         id: dataname1
165                         anchors.left: parent.left
166                         anchors.leftMargin: 30
167                         text: qsTr("info")
168                         font.pixelSize: 20
169                         font.italic: true
170                         color: '#00ADDC'
171                     }
172
173                     TextInput {
174                         id: data1
175                         text: qsTr("tokyo vics information!")
176                         font.pixelSize: 20
177                         font.italic: true
178                         anchors.left: dataname1.right
179                         anchors.leftMargin: 20
180                         color: '#00ADDC'
181                         cursorVisible: true
182                         inputMethodHints: Qt.ImhNone
183                         onFocusChanged: {
184                             console.log("OnScreenData1")
185                             if(data1.focus)
186                                 vkb.visible = true
187                         }
188                     }
189                 }
190                 RowLayout {
191                     id: line4
192                     visible: false
193                     spacing: 20
194                     Label {
195                         id: dataname2
196                         anchors.left: parent.left
197                         anchors.leftMargin: 30
198                         text: qsTr("")
199                         font.pixelSize: 20
200                         font.italic: true
201                         color: '#00ADDC'
202                     }
203
204                     TextInput {
205                         id: data2
206                         text: qsTr("")
207                         font.pixelSize: 20
208                         font.italic: true
209                         anchors.left: dataname2.right
210                         anchors.leftMargin: 20
211                         color: '#00ADDC'
212                         cursorVisible: true
213                         inputMethodHints: Qt.ImhNone
214                         onFocusChanged: {
215                             console.log("OnScreenData2")
216                             if(data2.focus)
217                                 vkb.visible = true
218                         }
219                     }
220                 }
221                 RowLayout {
222                     id: line5
223                     visible: false
224                     spacing: 20
225                     Label {
226                         id: dataname3
227                         anchors.left: parent.left
228                         anchors.leftMargin: 30
229                         text: qsTr("")
230                         font.pixelSize: 20
231                         font.italic: true
232                         color: '#00ADDC'
233                     }
234
235                     TextInput {
236                         id: data3
237                         text: qsTr("")
238                         font.pixelSize: 20
239                         font.italic: true
240                         anchors.left: dataname3.right
241                         anchors.leftMargin: 20
242                         color: '#00ADDC'
243                         cursorVisible: true
244                         inputMethodHints: Qt.ImhNone
245                         onFocusChanged: {
246                             console.log("OnScreenData3")
247                             if(data3.focus)
248                                 vkb.visible = true
249                         }
250                     }
251                 }
252             }
253         }
254
255         // post button
256         Button {
257             id: poster
258             text: "Post"
259             Layout.alignment: Qt.AlignCenter
260             onClicked: {
261                 console.log("poster pressed")
262                 if (onsId != "")
263                     postMessage();
264             }
265         }
266     }
267
268     InputPanel {
269         id: vkb
270         visible: false
271         anchors.right: parent.right
272         anchors.left: parent.left
273         anchors.bottom: parent.bottom
274         onActiveChanged: {
275             if(!active) { visible = false; }
276         }
277     }
278
279     function selectVICS() {
280         filepath = pri_path + "vics.qml";
281         dataname1.text = "info"
282         data1.text = "tokyo vics information!"
283         dataname2.text = ""
284         data2.text = ""
285         dataname3.text = ""
286         data3.text = ""
287         line3.visible = true
288         line4.visible = false
289         line5.visible = false
290     }
291
292     function selectSYS() {
293         filepath = pri_path + "system.qml";
294         dataname1.text = "type"
295         data1.text = "system error"
296         dataname2.text = "text"
297         data2.text = "System Error Occured!"
298         dataname3.text = ""
299         data3.text = ""
300         line3.visible = true
301         line4.visible = true
302         line5.visible = false
303     }
304
305     function selectTEL() {
306         filepath = pri_path + "phone.qml";
307         dataname1.text = "status"
308         data1.text = "Call Answered"
309         dataname2.text = ""
310         data2.text = ""
311         dataname3.text = ""
312         data3.text = ""
313         line3.visible = true
314         line4.visible = false
315         line5.visible = false
316     }
317
318     function selectMSG() {
319         filepath = pri_path + "msg.qml";
320         dataname1.text = "data1"
321         data1.text = "from testApp data1"
322         dataname2.text = "data2"
323         data2.text = "from testApp data2"
324         dataname3.text = "data3"
325         data3.text = "from testApp data3"
326         line3.visible = true
327         line4.visible = true
328         line5.visible = true
329     }
330
331     function postMessage() {
332         postmsg = "{\"gui\": \"application\", \"file\": \"" + filepath + "\"";
333         if (data1.text != "") {
334             msgdata = "\"" + dataname1.text + "\":\"" + data1.text + "\"";
335         }
336         if (data2.text !="") {
337             if (msgdata != "")
338                 msgdata += ",";
339             msgdata += "\"" + dataname2.text + "\":\"" + data2.text + "\"";
340         }
341         if (data3.text !="") {
342             if (msgdata != "")
343                 msgdata += ",";
344             msgdata += "\"" + dataname3.text + "\":\"" + data3.text + "\"";
345         }
346         if(msgdata != "")
347             postmsg += ",\"data\":{" + msgdata + "}}"
348         else
349             postmsg += "}"
350
351         eventHandler.showWindow(onsId, postmsg);
352     }
353
354     function qmlOnReplyShowWindow(text) {
355         console.log("onstestapp received:",text);
356         output.text = text;
357     }
358 }