Debian Codegraph @

plugins/ja/qml5/keys/ModifierKey.qml

raw
1 /*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18 import QtMultimedia 5.0
19 import Lomiri.Components 1.3
20 import Lomiri.Components.Popups 1.3
21
22 import "modifier.js" as Modifier
23 import keys 1.0
24
25 FlickCharKey {
26 label: (isPreedit && layoutState == "kana") ? " ゛ ゜" : "␣"
27 leaves: isPreedit ? preeditLeaves : ["␣", "□"]
28 annotation: isPreedit ? "大⇔小" : ""
29 fontSize: isPreedit ? units.gu( UI.fontSize ) * 0.8 : units.gu( UI.fontSize )
30
31 overridePressArea: true
32
33 property string layoutState: "kana"
34 property string preedit: maliit_input_method.preedit
35 property int cursorPosition: maliit_input_method.cursorPosition
36 property bool isPreedit: preedit != ""
37 property string lastChar: ""
38 property var preeditLeaves: Modifier.map[lastChar] ? Modifier.map[lastChar] : [lastChar]
39
40 onReleased: {
41 if (isPreedit) {
42 if (layoutState == "alnum") {
43 if (index != 0) {
44 event_handler.onKeyReleased("", "space");
45 } else {
46 var pos = cursorPosition
47 var newChar = lastChar.charCodeAt(0) < 91 ? lastChar.toLowerCase() : lastChar.toUpperCase()
48 maliit_input_method.preedit = preedit.substr(0, cursorPosition-1) + newChar + preedit.substr(cursorPosition)
49 maliit_input_method.cursorPosition = pos
50 }
51 } else if (preeditLeaves[index] && preeditLeaves[index] != "") {
52 var pos = cursorPosition
53 maliit_input_method.preedit = preedit.substr(0, cursorPosition-1) + preeditLeaves[index] + preedit.substr(cursorPosition)
54 maliit_input_method.cursorPosition = pos
55 }
56 } else {
57 if (index == 0) {
58 event_handler.onKeyReleased("", "space");
59 } else {
60 event_handler.onKeyReleased(" ", "");
61 }
62 }
63 }
64
65 onPressed: {
66 if (maliit_input_method.useAudioFeedback)
67 audioFeedback.play();
68
69 if (maliit_input_method.useHapticFeedback)
70 pressEffect.start();
71
72 if (isPreedit) {
73 lastChar = preedit.charAt(cursorPosition-1)
74 if (!Modifier.map[lastChar] && Modifier.normalize[lastChar]) {
75 lastChar = Modifier.normalize[lastChar]
76 }
77 }
78 }
79 }