~stefan-schwarzburg/qreator/touch-scanner-automaticscan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
import QtQuick 2.0
import Ubuntu.Components 0.1
import Ubuntu.Components.ListItems 0.1 as ListItems
import Ubuntu.Components.Popups 0.1
import QtGraphicalEffects 1.0
import QtMultimedia 5.0
import "js/jsqrcode-combined.js" as QR

MainView {
    objectName: "mainView"
    applicationName: "qreator-touch"
    id: root

    width: device.naturalOrientation == "portrait" ? units.gu(40) : units.gu(80)
    height: device.naturalOrientation == "portrait" ? units.gu(80) : units.gu(40)

    Tabs {
        id: tabs

        Tab {
            objectName: "TabScanner"
            title: i18n.tr("Scan")

            page: Page {
                    VideoOutput {
                        id: viewFinder
                        source: camera
                        anchors {
                            centerIn: parent
                            //top: parent.top
                            //left: parent.left
                        }
                        //width: parent.width
                        //height: parent.width

                        focus: visible

                        /* This rotation need to be applied since the camera hardware in the
                           Galaxy Nexus phone is mounted at an angle inside the device, so the video
                           feed is rotated too.
                           FIXME: This should come from a system configuration option so that we
                           don't have to have a different codebase for each different device we want
                           to run on */
                        orientation: device.naturalOrientation === "portrait"  ? -90 : 0
			Item {
			    Timer {
				interval: 1500
				running: parent.visible
				repeat: true
				onTriggered: camera.imageCapture.capture()
			    }
			}
                    }
            }

            Canvas {
                id: canvas
                renderStrategy: Canvas.Immediate
                property string imageurl
                width: 200
                height: 200
                visible: false
                onImageLoaded: {
                    console.log("Loaded image: " + imageurl);
                    QR.qrcode.imagedata = canvas.getContext("2d").createImageData(imageurl);
                    QR.qrcode.width = QR.qrcode.imagedata.width;
                    QR.qrcode.height = QR.qrcode.imagedata.height;
                    try {
                        var result = QR.qrcode.process(context);
                        console.log("Result: " + result);
                    }
                    catch(e) {
                        console.log("Could not decode: " + e );
                    }
                }
            }
        }

        Tab {
            objectName: "TabQreator"
            title: i18n.tr("Create")

            page: PageStack {

            id: pageStack
            property real pageSpacing: units.gu(6)

            anchors {
                fill: parent
            }

            Component.onCompleted: push(pageRoot)

            Page {
                id: pageRoot
                title: i18n.tr("QR code type")
                visible: false

                Column {
                    anchors.fill: parent
                    ListItems.Standard {
                        id: itemQrText
                        text: i18n.tr("Text")
                        icon: Qt.resolvedUrl("img/text.png")
                        onClicked: pageStack.push(pageQrText)
                        progression: true
                    }
                    ListItems.Standard {
                        id: itemQrUrl
                        text: i18n.tr("URL")
                        icon: Qt.resolvedUrl("img/url.png")
                        onClicked: pageStack.push(pageQrUrl)
                        progression: true
                    }
                    ListItems.Standard {
                        id: itemQrWifi
                        text: i18n.tr("Wifi")
                        icon: Qt.resolvedUrl("img/wifi.png")
                        onClicked: pageStack.push(pageQrWifi)
                        progression: true
                    }
                }

            }

            Page {
                id: pageQrText
                title: i18n.tr("Text QR code")
                visible: false
                tools: QrCodeToolbar{}

                Column {
                    anchors.centerIn: parent
                    spacing: pageStack.pageSpacing

                    TextArea {
                         id: textQrCodeText
                         placeholderText: i18n.tr("Type the text to encode")
                         autoSize: true
                         maximumLineCount: 5
                         width: units.gu(33)

                         onTextChanged: {qrcanvastext.requestQrCodePaint(text)}
                     }

                    QrCodeCanvas {
                            id: qrcanvastext
                            width: units.gu(33)
                            height: units.gu(33)
                    }
                }

            }

            Page {
                id: pageQrUrl
                title: i18n.tr("URL QR code")
                visible: false
                tools: QrCodeToolbar{}

                Column {
                    anchors.centerIn: parent
                    spacing: pageStack.pageSpacing

                    TextField {
                            id: textQrCodeUrl
                            width: units.gu(33)
                            placeholderText: i18n.tr("Type the URL to encode")
                            hasClearButton: true

                            onTextChanged: {qrcanvasurl.requestQrCodePaint(text)}
                    }

                    QrCodeCanvas {
                            id: qrcanvasurl
                            width: units.gu(33)
                            height: units.gu(33)
                    }
                }
            }

            Page {
                id: pageQrWifi
                title: i18n.tr("Wireless access QR code")
                visible: false
                tools: QrCodeToolbar{}

                ListModel {
                    id: wifiSecurity
                    ListElement {
                        security: "WPA"
                        index: 0
                    }
                    ListElement {
                        security: "WEP"
                        index: 1
                    }
                    ListElement {
                        security: "No security"
                        index: 2
                    }
                }

                Column {
                    anchors.centerIn: parent
                    spacing: units.gu(4)

                    Column {
                        spacing: units.gu(2)

                        TextField {
                             id: textQrCodeSsid
                             placeholderText: i18n.tr("Type the wifi network's identifier")
                             hasClearButton: true
                             width: units.gu(33)

                             onTextChanged: {qrcanvaswifi.requestQrCodePaint(text)}
                        }

                        Button {
                            id: selectorSecurity
                                        //property int currencyIndex: 0
                                        //property  TextField input: inputFrom
                                        //text: currencies.getCurrency(currencyIndex)
                                        // open the popover
                            text: i18n.tr("Select security")
                            width: units.gu(33)
                            onClicked: PopupUtils.open(popoverWifiSecurity, selectorSecurity)
                            onTextChanged: {qrcanvaswifi.requestQrCodePaint(text)}
                        }

                        Row {
                            spacing: units.gu(2)

                            TextField {
                                 id: textQrCodePassword
                                 placeholderText: i18n.tr("Type the wifi network's password")
                                 hasClearButton: true
                                 echoMode: switchPassword.checked ? TextInput.Normal : TextInput.Password
                                 width: units.gu(33) - parent.spacing - switchPassword.width

                                 onTextChanged: {qrcanvaswifi.requestQrCodePaint(text)}
                            }

                            Switch {
                                id: switchPassword
                                checked: false

                                //onClicked:
                            }
                        }
                    }

                    QrCodeCanvas {
                            id: qrcanvaswifi
                            width: units.gu(33)
                            height: units.gu(33)
                    }
                }

            }

            Page {
                id: pageSettings
                visible: false

                Column {

                }
            }

            Page {
                id: pageAbout
                title: i18n.tr("About")
                visible: false

                Column {

                }
            }

            Page {
                id: pageHistory
                title: i18n.tr("History")
                visible: false

                Column {

                }
            }

            }
        }
    }

    DeviceOrientation {
        id: device
    }

    Camera {
        id: camera
        flash.mode: Camera.FlashOff
        captureMode: Camera.CaptureStillImage
        focus.focusMode: Camera.FocusAuto
        exposure.exposureMode: Camera.ExposureAuto

        imageCapture {
            onImageCaptured: {
                // Show the preview in an Image
                console.log("Captured Image: " + preview);
                //photoPreview.source = preview;
                //decoder.decodeImageQML(photoPreview);
                //console.log('[QML] Image URL: ' + photoPreview.source)
                //decoder.decodeImageQML('/home/dpm/Escriptori/Collsacabra.jpg');
                //photoPreview.source = preview  // Show the preview in an Image
                canvas.imageurl = preview;
                canvas.loadImage(preview);
                //canvas.loadImage("/home/dpm/Escriptori/Collsacabra.jpg");

            }

            onImageSaved: {
                //console.log("Picture saved as " + path)
                //decoder.decodeImageQML(path);
            }
        }
    }

    Component {
        id: popoverWifiSecurity
        Popover {
            Column {
                anchors {
                    top: parent.top
                    left: parent.left
                    right: parent.right
                }
                // Make sure the Popover doesn't flow off the screen
                height: units.gu(33) //getHeight()

                //units.gu(33) //wifiSecurity.count * wifiSecurity.get(0).height //units.gu(33)//root.height

                function getHeight () {
                    var firstElement = wifiSecurity.get(0);
                    console.log(firstElement.security);
                    return wifiSecurity.count * firstElement.height;
                }

                // Header displaying title
                ListItems.Header {
                    id: header
                    text: i18n.tr("Select security")
                }

                // List of security modes
                ListView {
                    clip: true
                    width: parent.width
                    height: parent.height - header.height
                    model: wifiSecurity
                    delegate: ListItems.Standard {
                        text: security
                        onClicked: {
                            caller.text = security
                            //caller.input.update()
                            hide()
                        }
                    }
                }
            }
        }
    }
}