| 1 |
/* |
| 2 |
* Copyright 2016 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 |
| 18 |
import keys |
| 19 |
|
| 20 |
import "parser.js" as Parser |
| 21 |
|
| 22 |
ActionKey { |
| 23 |
iconNormal: "erase"; |
| 24 |
iconShifted: "erase"; |
| 25 |
iconCapsLock: "erase"; |
| 26 |
action: "backspace"; |
| 27 |
|
| 28 |
property string preedit: maliit_input_method.preedit |
| 29 |
property string m_preedit: "" |
| 30 |
property string syllable_preedit: "" |
| 31 |
property string last_preedit: "" |
| 32 |
property bool isPreedit: preedit != "" |
| 33 |
|
| 34 |
overridePressArea: true; |
| 35 |
|
| 36 |
onReleased: { |
| 37 |
if (isPreedit) { |
| 38 |
if (preedit.length > 1){ /* at least 2 length */ |
| 39 |
syllable_preedit = preedit.substring(0,preedit.length - 1); |
| 40 |
last_preedit = preedit[preedit.length - 1]; /* last jamo or syllable */ |
| 41 |
|
| 42 |
m_preedit = Parser.erase_jamo(last_preedit); |
| 43 |
if (m_preedit != ""){ /* exsit jamo */ |
| 44 |
maliit_input_method.preedit = syllable_preedit + m_preedit; |
| 45 |
} else { |
| 46 |
maliit_input_method.preedit = syllable_preedit; |
| 47 |
} |
| 48 |
} else { |
| 49 |
if (Parser.is_syllable(preedit)){ /* preedit is one syllable */ |
| 50 |
m_preedit = Parser.erase_jamo(preedit); |
| 51 |
maliit_input_method.preedit = m_preedit; |
| 52 |
} else { /* it is only jamo like "ㄱ" or "ㅏ" */ |
| 53 |
event_handler.onKeyReleased("", action); |
| 54 |
} |
| 55 |
} |
| 56 |
} else { |
| 57 |
event_handler.onKeyReleased("", action); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
onPressed: { |
| 62 |
if (maliit_input_method.useAudioFeedback) |
| 63 |
audioFeedback.play(); |
| 64 |
|
| 65 |
if (maliit_input_method.useHapticFeedback) |
| 66 |
pressEffect.start(); |
| 67 |
|
| 68 |
if (!isPreedit) { |
| 69 |
event_handler.onKeyPressed("", action); |
| 70 |
} else { |
| 71 |
if (preedit.length == 1 && !Parser.is_syllable(preedit)) /* fixed erase action repeat */ |
| 72 |
event_handler.onKeyPressed("", action); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
onPressAndHold: { |
| 77 |
return; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
} |