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