5a70102b330a6d5ae7e16fecfa8bef357441cde6
[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/onstestapp/")
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: line3
112                     spacing: 20
113                     Label {
114                         id: dataname1
115                         anchors.left: parent.left
116                         anchors.leftMargin: 30
117                         text: qsTr("info")
118                         font.pixelSize: 20
119                         font.italic: true
120                         color: '#00ADDC'
121                     }
122
123                     TextInput {
124                         id: data1
125                         text: qsTr("tokyo vics information!")
126                         font.pixelSize: 20
127                         font.italic: true
128                         anchors.left: dataname1.right
129                         anchors.leftMargin: 20
130                         color: '#00ADDC'
131                         cursorVisible: true
132                         inputMethodHints: Qt.ImhNone
133                         onFocusChanged: {
134                             console.log("OnScreenData1")
135                             if(data1.focus)
136                                 vkb.visible = true
137                         }
138                     }
139                 }
140                 RowLayout {
141                     id: line4
142                     visible: false
143                     spacing: 20
144                     Label {
145                         id: dataname2
146                         anchors.left: parent.left
147                         anchors.leftMargin: 30
148                         text: qsTr("")
149                         font.pixelSize: 20
150                         font.italic: true
151                         color: '#00ADDC'
152                     }
153
154                     TextInput {
155                         id: data2
156                         text: qsTr("")
157                         font.pixelSize: 20
158                         font.italic: true
159                         anchors.left: dataname2.right
160                         anchors.leftMargin: 20
161                         color: '#00ADDC'
162                         cursorVisible: true
163                         inputMethodHints: Qt.ImhNone
164                         onFocusChanged: {
165                             console.log("OnScreenData2")
166                             if(data2.focus)
167                                 vkb.visible = true
168                         }
169                     }
170                 }
171                 RowLayout {
172                     id: line5
173                     visible: false
174                     spacing: 20
175                     Label {
176                         id: dataname3
177                         anchors.left: parent.left
178                         anchors.leftMargin: 30
179                         text: qsTr("")
180                         font.pixelSize: 20
181                         font.italic: true
182                         color: '#00ADDC'
183                     }
184
185                     TextInput {
186                         id: data3
187                         text: qsTr("")
188                         font.pixelSize: 20
189                         font.italic: true
190                         anchors.left: dataname3.right
191                         anchors.leftMargin: 20
192                         color: '#00ADDC'
193                         cursorVisible: true
194                         inputMethodHints: Qt.ImhNone
195                         onFocusChanged: {
196                             console.log("OnScreenData3")
197                             if(data3.focus)
198                                 vkb.visible = true
199                         }
200                     }
201                 }
202             }
203         }
204
205         // post button
206         Button {
207             id: poster
208             text: "Post"
209             Layout.alignment: Qt.AlignCenter
210             onClicked: {
211                 console.log("poster pressed")
212                 if (onsId != "")
213                     postMessage();
214             }
215         }
216     }
217
218     InputPanel {
219         id: vkb
220         visible: false
221         anchors.right: parent.right
222         anchors.left: parent.left
223         anchors.bottom: parent.bottom
224         onActiveChanged: {
225             if(!active) { visible = false; }
226         }
227     }
228
229     function selectVICS() {
230         filepath = pri_path + "vics.qml";
231         dataname1.text = "info"
232         data1.text = "tokyo vics information!"
233         dataname2.text = ""
234         data2.text = ""
235         dataname3.text = ""
236         data3.text = ""
237         line3.visible = true
238         line4.visible = false
239         line5.visible = false
240     }
241
242     function selectSYS() {
243         filepath = pri_path + "system.qml";
244         dataname1.text = "type"
245         data1.text = "system error"
246         dataname2.text = "text"
247         data2.text = "System Error Occured!"
248         dataname3.text = ""
249         data3.text = ""
250         line3.visible = true
251         line4.visible = true
252         line5.visible = false
253     }
254
255     function selectTEL() {
256         filepath = pri_path + "phone.qml";
257         dataname1.text = "status"
258         data1.text = "Call Answered"
259         dataname2.text = ""
260         data2.text = ""
261         dataname3.text = ""
262         data3.text = ""
263         line3.visible = true
264         line4.visible = false
265         line5.visible = false
266     }
267
268     function selectMSG() {
269         filepath = pri_path + "msg.qml";
270         dataname1.text = "data1"
271         data1.text = "from testApp data1"
272         dataname2.text = "data2"
273         data2.text = "from testApp data2"
274         dataname3.text = "data3"
275         data3.text = "from testApp data3"
276         line3.visible = true
277         line4.visible = true
278         line5.visible = true
279     }
280
281     function postMessage() {
282         postmsg = "{\"file\": \"" + filepath + "\"";
283         if (data1.text != "") {
284             msgdata = "\"" + dataname1.text + "\":\"" + data1.text + "\"";
285         }
286         if (data2.text !="") {
287             if (msgdata != "")
288                 msgdata += ",";
289             msgdata += "\"" + dataname2.text + "\":\"" + data2.text + "\"";
290         }
291         if (data3.text !="") {
292             if (msgdata != "")
293                 msgdata += ",";
294             msgdata += "\"" + dataname3.text + "\":\"" + data3.text + "\"";
295         }
296         if(msgdata != "")
297             postmsg += ",\"data\":{" + msgdata + "}}"
298         else
299             postmsg += "}"
300
301         eventHandler.showWindow(onsId, postmsg);
302     }
303
304     function qmlOnReplyShowWindow(text) {
305         console.log("onstestapp received:",text);
306         output.text = text;
307         eventHandler.hideWindow(onsId);
308     }
309 }