summaryrefslogtreecommitdiff
path: root/src/hmi/qml/Core/NavigationAppKeyboard.qml
blob: 119fe560bb5b661fe622c696477afe313e966432 (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
/**
* @licence app begin@
* SPDX-License-Identifier: MPL-2.0
*
*
* \file Keyboard.qml
*
* \brief This file is part of the navigation hmi.
*
* \author Martin Schaller <martin.schaller@it-schaller.de>
*
* \version 
*
* This Source Code Form is subject to the terms of the
* Mozilla Public License (MPL), v. 2.0.
* If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/.
*
* For further information see http://www.genivi.org/.
*
* List of changes:
* <date>, <name>, <description of change>
*
* @licence end@
*/
import QtQuick 2.1 
import "genivi.js" as Genivi;

Item {
	id: keyboard;
    property real w: (keyboard.width*Genivi.kbdColumnRatio)/(Genivi.kbdColumns*(1+Genivi.kbdColumnRatio)-1);
    property real h: (keyboard.height*Genivi.kbdLineRatio)/(Genivi.kbdLines*(1+Genivi.kbdLineRatio)-1);
    property real wspc: w/Genivi.kbdColumnRatio;
    property real hspc: h/Genivi.kbdLineRatio;
    property Item destination;
	property Item layout;
	property string firstLayout;
	property string secondLayout: null;
	property Item next;
	property Item prev;
	property string activekeys;
	property bool activekeys_enabled;
	property string shiftlevel;
	signal keypress(string what);
    property var buttonList:[];

	function keytext(what)
	{
		if (what == '␣') {
			return ' ';
		}
		if (what == '←') {
			return '\b';
		}
		return what;
	}

	function append(what) {
		what=keytext(what);
		if (what.length > 1) {
			shift(what);
			return;
		}
		if (secondLayout && !destination.text.length) {
			shift(secondLayout);
		}
		keypress(what);
		if (what == '\b') {
			backspace();
		} else {
			destination.text+=what;
		}
	}

	function backspace() {
		if (destination.text.length) {
			destination.text=destination.text.slice(0,-1);
			if (secondLayout && !destination.text.length) {
				shift(firstLayout);
			}
		}
	}

	function set(id,text)
	{
		id.text=text;
		var stext=keytext(text.toLowerCase());
		var disabled=true;
		if (text.length) {
			if (!activekeys_enabled || text.length > 1 || activekeys.indexOf(stext) != -1) 
				disabled=false;
			if (stext == '\b' && !destination.text.length)
				disabled=true;
		}
		id.disabled=disabled;
	}

	function setactivekeys(keys,enabled)
	{
		activekeys=keys.toLowerCase();
		activekeys_enabled=enabled;
		shift(shiftlevel);
	}

    function activateAllKeys()
    {
        var keys;
        keys='\b'+'␣'+"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        if(Genivi.g_language ==="eng"){
        }else{
            if(Genivi.g_language==="fra"){
            }else{
                if(Genivi.g_language==="jpn"){
                    keys+="あかさたなはまやらわいきしちにひみりをうくすつぬふむゆるんえけせてねへめれ”おこそとのほもよろ°";
                }else{
                    if(Genivi.g_language==="deu"){
                    }
                }
            }
        }
        setactivekeys(keys,true);
    }

	function shift(what) {
		shiftlevel=what;
		secondLayout="";
        var l=Genivi.keyboardLayout[what];
        for(var i=0;i<buttonList.length;i++){
            set(buttonList[i],l[i])
        }
	}

	Column {
        id:keyboardFrame
		spacing:keyboard.hspc
        Component.onCompleted: {
            var index=0;
            for(var i=0;i<Genivi.kbdLines;i++){
                var row=Qt.createQmlObject('import QtQuick 2.1 ; Row {}',keyboardFrame,'dynamic');
                row.spacing=keyboard.wspc;
                for(var j=0;j<Genivi.kbdColumns;j++){
                    buttonList[index] =Qt.createQmlObject('import QtQuick 2.1 ; KButton {}',row,'dynamic');
                    index++;
                }
            }
        }
	}

    Component.onCompleted: {
        if (destination.text.length && secondLayout) {
               shift(secondLayout);
        } else {
               shift(firstLayout);
        }
    }
}