summaryrefstree
path: root/usr/bin/qml/com/neusoft/auto/widgets/HMIHandWriteBoard.qml
blob: b0a523793f399c01a60967a1cb4e01db4f7ee0a1 (plain)
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
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
import QtQuick 2.0
import Label 2.0
Item
{
    id:handWriteID
    width: 610
    height: 216
    property bool isInput           : false
    property string stInput           : ""
    property bool isDel           : false
    property bool isSearch           : false
    signal searchStarth()
    signal keyborad(int itype)

    onVisibleChanged: {

        if(mycanvas.isClear)
        {
        mycanvas.clear()
        systemCtrl.handWriteRecognize();
        }
    }

    Connections
    {
        target: systemCtrl
        onHandWriteAlternateListChanged:
        {

            listView.model = systemCtrl.handWriteAlternateList
        }
        onHandWritePredictListChanged:{

            gridViewID.model = systemCtrl.handWritePredictList
        }
        onInputTempHanziChanged:{

            stInput=inputTemp
            isInput=true
        }
    }
    Image {
        id: image_list_bg
        x: 219
        y: -107
        width: 391
        height: 60
        opacity: (listView.count>0&&isInput)?1:0
        enabled: (listView.count>0&&isInput)?1:0
        //source: "../images/Search/Input_Space_Btn_C_P.png"
        MouseArea{
            x: -200
            y: -30
            width: 800
            height: 120
            onClicked: {

            }
        }

        HMIButton{
            id:keyList_l
            x: 11
            y: 14
            enabled: (listView.count<6||listView.currentIndex==0)?false:true
            //btnImg: keyList_l.enabled?(keyList_l.pressed?"../images/Search/Search_Title_L_Btn_P.png":"../images/Search/Search_Title_L_Btn_N.png"):"../images/Search/Search_Title_L_Btn_D.png"
            onClicked: {
                listView.currentIndex--
            }
            onPressAndHold: {
                keyList_l_t.restart()
            }
            onCanceled: {
                keyList_l_t.stop()
            }
            onReleased: {
                keyList_l_t.stop()
            }
            Timer{
                id: keyList_l_t
                interval:150
                repeat:true
                onTriggered: {
                    if (listView.currentIndex > 0){
                        listView.currentIndex--
                    }
                }
            }
        }
        HMIButton{
            id:keyList_r
            x: 352
            y: 14
            enabled: (listView.count<6||listView.currentIndex==listView.count-1)?false:true
            //btnImg: keyList_r.enabled?(keyList_r.pressed?"../images/Search/Search_Title_R_Btn_P.png":"../images/Search/Search_Title_R_Btn_N.png"):"../images/Search/Search_Title_R_Btn_D.png"
            onClicked: {
                listView.currentIndex++//listView.contentX+=61
            }
            onPressAndHold: {
                keyList_r_t.restart()
            }
            onCanceled: {
                keyList_r_t.stop()
            }
            onReleased: {
                keyList_r_t.stop()
            }
            Timer{
                id: keyList_r_t
                interval:150
                repeat:true
                onTriggered: {
                    if (listView.currentIndex < listView.count-1){
                        listView.currentIndex++
                    }
                }
            }
        }

    }
    Component{
        id: recipeDelegate
        Item{
            //Rectangle{
            id: delegateImgMain
            width: _testLabelbg.width
            height: _testLabelbg.height

            Row{
                id: _testLabelbg

                Image {
                    width: _testLabel.contentWidth+16
                    height: 40
                    //source: "../images/Search/Search_keyboardBtn_N.png"
                }

            }

            HMILabel{
                id: _testLabel
                width: _testLabelbg.width
                height: _testLabelbg.height
                text: col0
                color:m_area.pressed?"#FF8400":"white"
                HMIMouseArea{
                    id: m_area
                    anchors.fill: parent
                    onPressed: {
                        //listView.currentIndex = index
                    }
                    onClicked: {
                        isInput=false
                        mycanvas.clear()
                        systemCtrl.setSelectedHandWriteHanzi(col0)
                        stInput=""

                    }
                }
            }
        }
    }
    ListView{
        id:listView
        x: 260
        y: -107
        width: 305
        height: 60
        opacity: (listView.count>0&&isInput)?1:0
        enabled: (listView.count>0&&isInput)?1:0
        flickableDirection:Flickable.HorizontalFlick
        clip: true
        snapMode:ListView.SnapToItem
        orientation:ListView.Horizontal
        model:systemCtrl.handWriteAlternateList
        highlightFollowsCurrentItem:true
        highlightRangeMode: ListView.StrictlyEnforceRange
        cacheBuffer: listView.width*4
        delegate: recipeDelegate
    }


    Component{
        id:gridDelegate
        HMIButton
        {
            labelText: col0
            labelColor: "white"
            width: 47
            height: 77
           // btnImg: pressed?"../images/Search/Search_Hand_CandidateBack_C_Pushed.png":""
            onClicked:
            {
                if(isInput==true)
                {
                    isInput=false
                    mycanvas.clear()
                    systemCtrl.setSelectedHandWriteHanzi(col0,stInput)
                    stInput=""
                }
                else
                {
                    mycanvas.clear()
                    systemCtrl.setSelectedHandWriteHanzi(col0)
                }
            }
        }
    }
    Component{
        id:repeater
        HMIKeyBtn
        {
            id:handkey
            labelText: name
            labelColor: handkey.enabled?"white":"grey"
            enabled: {
                if(0 == index)
                {
                    true
                }
                else if(1 == index)
                {
                    true
                }
                else if(2 == index)
                {
                    isDel
                }
                else if(3 == index)
                {
                    isSearch
                }
            }

            onClicked:
            {
                if(0 == index)
                {
                    keyborad()
                }
                else if(1 == index)
                {
                    mycanvas.clear()
                }
                else if(2 == index)
                {
                    systemCtrl.setKeyPress("delete")
                }
                else if(3 == index)
                {
                    searchStarth()
                }
            }
        }
    }
    Row{
        x:195
        Image {
            id: imagel

            width: 6
            height: 214
            //source: "../images/Search/Search_Hand_Background_L.png"
        }

        Image {
                id: imagec
                width: 303
                height: 214
                //source: "../images/Search/Search_Hand_Background_C.png"
        }

        Image {
            id: imager
            width: 6
            height: 214
            //source: "../images/Search/Search_Hand_Background_R.png"
        }
    }
    Rectangle{
        id:mainID
        width: 610
        height: 216
        color: "#00000000"
        anchors.bottom: parent.bottom
    Row{
        Rectangle{
            width: 47*4
            height: 77*2
            color: "#20202000"
            Image {
                id: bline
                x:0
                y:76
                opacity: gridViewID.count>0?1:0
                //source: "../images/Search/Search_Hand_CandidateDivisionLine.png"
            }
            GridView
            {
                id:gridViewID
                width: 47*4
                height: 77*2

                anchors.fill:parent
                cellHeight : 77
                cellWidth: 47
                snapMode:GridView.SnapToRow
                model:systemCtrl.handWritePredictList
                delegate:gridDelegate
                clip:true
            }
        }

        Canvas {

            id: mycanvas
            width: 325
            height: 216

            property var clickX :[];
            property var clickY  :[];
            property var clickDrag  :[];
            property bool isPressed: false;
            property bool isClear: false;

            onPaint: {
                drawLine()
            }

            MouseArea {
                id: mousearea1
                width: 325
                height: 216
                anchors.fill: parent
                onPressed:  {
                    mycanvas.isPressed = true;
                    mycanvas.isClear = true;
                    mycanvas.addClick(mouse.x, mouse.y, false);
                    mycanvas.requestPaint();
                }
                onPositionChanged: {
                    if (mycanvas.isPressed &&mouse.x>=0 && mouse.y>=0)
                    {
                        mycanvas.isClear = true;
                        mycanvas.addClick(mouse.x, mouse.y, true);
                        mycanvas.requestPaint();
                    }
                }
                onReleased: {
                    mycanvas.isPressed = false;
                    mycanvas.isClear = true;
                    systemCtrl.handWriteRecognize();
                }
            }
            function clear()
            {
                mycanvas.isClear = false;
                systemCtrl.clearHandWritePoint();
                var context = mycanvas.getContext('2d');
                context.clearRect(0,0,mycanvas.width,mycanvas.height);
                clickX = [];
                clickY = [];
                clickDrag = [];
                mycanvas.requestPaint();
            }
            function addClick(m, n, dragging)
            {
                clickX.push(m);
                clickY.push(n);
                clickDrag.push(dragging);
                systemCtrl.addHandWritePoint(m, n, dragging);
            }
            function drawLine(){
                if(isPressed){
                   var context = mycanvas.getContext('2d');
                   context.strokeStyle = "blue";
                   context.lineJoin = "round";
                   context.lineWidth = 5;
                   if(clickX.length > 3){
                       if(clickX.length <= 16)
                       {
                           for(var i=0; i < clickX.length - 3; i=i+3)
                           {
                               if(clickDrag[i] && clickDrag[i+1] && clickDrag[i+2] && clickDrag[i+3]){
                                   context.beginPath();
                                   context.moveTo(clickX[i], clickY[i]);
                                   context.bezierCurveTo(clickX[i+1],clickY[i+1],clickX[i+2],clickY[i+2],clickX[i+3],clickY[i+3]);
                                   context.closePath();
                                   context.stroke();
                               }
                           }
                       }
                       else
                       {
                           for(var k = clickX.length - clickX.length%3 - 16; k < clickX.length - 3; k = k+3)
                           {
                               if(clickDrag[k] && clickDrag[k+1] && clickDrag[k+2] && clickDrag[k+3]){
                                   context.beginPath();
                                   context.moveTo(clickX[k], clickY[k]);
                                   context.bezierCurveTo(clickX[k+1],clickY[k+1],clickX[k+2],clickY[k+2],clickX[k+3],clickY[k+3]);
                                   context.closePath();
                                   context.stroke();
                               }
                           }
                       }
                   }
                   else{
                       for(var j=0; j < clickX.length; j++)
                       {
                           context.beginPath();
                           if(clickDrag[j] && j){
                               context.moveTo(clickX[j-1], clickY[j-1]);
                           }else{
                               context.moveTo(clickX[j]-1, clickY[j]);
                           }
                           context.lineTo(clickX[j], clickY[j]);
                           context.closePath();
                           context.stroke();
                       }
                   }
                }
                else
                {
                   clickX = [];
                   clickY = [];
                   clickDrag = [];
                }
           }
        }
        Column{
//            spacing: 0
//            Repeater
//            {
//                model:settingControl.iLanguage == true?menuModel_en:menuModel_cn
//                delegate: repeater
//            }
            HMIButton{
                id:hddel
                //btnImg: pressed?"../images/Search/Search_Handwriting_Btn_C_P.png":"../images/Search/Search_Handwriting_Btn_C.png"
                //btnIcon:hddel.enabled?"../images/Search/Input_Delete.png":"../images/Search/Input_Delete_C_Disable.png"
                onClicked: {
                    if(listView.count<1&&mycanvas.isClear == true)
                    {
                        mycanvas.clear()
                        systemCtrl.handWriteRecognize();
                    }
                    else
                    {
                        systemCtrl.setKeyPress("delete")
                        isInput=false
                        mycanvas.clear()
                        systemCtrl.handWriteRecognize();
                    }
                }
            }
            HMIButton{
                id:hddelmask
                opacity: 0
                //btnImg: pressed?"../images/Search/Search_Handwriting_Btn_C_P.png":"../images/Search/Search_Handwriting_Btn_C.png"
                //btnIcon:hddel.enabled?"../images/Search/Input_Delete.png":"../images/Search/Input_Delete_C_Disable.png"
            }
            HMIButton{
                id:hdsearcd
                enabled: isSearch?true:false
                btnImg: pressed?"../images/Search/Search_Handwriting_Search_Btn_P.png":"../images/Search/Search_Handwriting_Search_Btn_N.png"
                Image {
                    id: iicon
                    x:10
                    y:17
                    //source:"../images/Search/Search_Handwriting_Search_Icon.png"
                }
                HMILabel{
                    id:txt
                    x:0
                    y:106/2
                    width:81
                    height: 106/2
                    color:isSearch?"white":"#4D4D4D"
                    //DEL F0028 2016/10/12 liduo begin
		    //text:"检索"
		    //DEL F0028 2016/10/12 liduo end
		    //ADD F0028 2016/10/12 liduo begin
                    text:"搜索"
		    //ADD F0028 2016/10/12 liduo end
                    font.pixelSize:28
                    
		 }
                onClicked: {
                    searchStarth()
                    isInput=false
                }


            }
        }
    }
    }
    HMIButton{
        id:hd123
        x:-50
        y:160
        //btnImg: pressed?"../images/Search/Search_Handwriting_Btn_C_P.png":"../images/Search/Search_Handwriting_Btn_C.png"
        labelText: "123"
        onClicked: {
            keyborad(3)
            isInput = false
        }
    }
    HMIButton{
        id:hdqiehuan
        x:hd123.x+hd123.width
        y:160
        //btnImg: pressed?"../images/Search/Search_Handwriting_Btn_C_P.png":"../images/Search/Search_Handwriting_Btn_C.png"
        //labelText: settingControl.iLanguage == true ? qsTr("HW"):qsTr("手写")
        labelText: "手写"
        onClicked: {
            keyborad(1)
            isInput = false
        }
    }
    HMIButton{
        id:hdkongge
        x:hdqiehuan.x+hdqiehuan.width
        y:160
        //btnImg: pressed?"../images/Search/Search_Handwriting_Btn_C_P.png":"../images/Search/Search_Handwriting_Btn_C.png"
        //btnIcon:"../images/Search/Search_SpaceBar.png"
        labelText: " "
        onClicked: {
            systemCtrl.setKeyPress(" ")
        }
    }
}