1 | // Copyright (C) 2016 The Qt Company Ltd. |
---|---|
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
3 | |
4 | #include "hangulinputmethod_p.h" |
5 | #include "hangul_p.h" |
6 | #include <QtVirtualKeyboard/qvirtualkeyboardinputcontext.h> |
7 | |
8 | QT_BEGIN_NAMESPACE |
9 | namespace QtVirtualKeyboard { |
10 | |
11 | /*! |
12 | \class QtVirtualKeyboard::HangulInputMethod |
13 | \internal |
14 | */ |
15 | |
16 | HangulInputMethod::HangulInputMethod(QObject *parent) : |
17 | QVirtualKeyboardAbstractInputMethod(parent) |
18 | { |
19 | } |
20 | |
21 | HangulInputMethod::~HangulInputMethod() |
22 | { |
23 | } |
24 | |
25 | QList<QVirtualKeyboardInputEngine::InputMode> HangulInputMethod::inputModes(const QString &locale) |
26 | { |
27 | Q_UNUSED(locale); |
28 | return QList<QVirtualKeyboardInputEngine::InputMode>() << QVirtualKeyboardInputEngine::InputMode::Hangul; |
29 | } |
30 | |
31 | bool HangulInputMethod::setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode) |
32 | { |
33 | Q_UNUSED(locale); |
34 | Q_UNUSED(inputMode); |
35 | return true; |
36 | } |
37 | |
38 | bool HangulInputMethod::setTextCase(QVirtualKeyboardInputEngine::TextCase textCase) |
39 | { |
40 | Q_UNUSED(textCase); |
41 | return true; |
42 | } |
43 | |
44 | bool HangulInputMethod::keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers) |
45 | { |
46 | Q_UNUSED(modifiers); |
47 | QVirtualKeyboardInputContext *ic = inputContext(); |
48 | bool accept = false; |
49 | int cursorPosition = ic->cursorPosition(); |
50 | if (ic->cursorPosition() > 0) { |
51 | if (key == Qt::Key_Backspace) { |
52 | int contextLength = cursorPosition > 1 ? 2 : 1; |
53 | QString hangul = Hangul::decompose(source: ic->surroundingText().mid(position: cursorPosition - contextLength, n: contextLength)); |
54 | int length = hangul.size(); |
55 | if (hangul.size() > 1) { |
56 | ic->commit(text: Hangul::compose(source: hangul.left(n: length - 1)), replaceFrom: -contextLength, replaceLength: contextLength); |
57 | accept = true; |
58 | } |
59 | } else if (!text.isEmpty() && Hangul::isJamo(unicode: text.at(i: 0).unicode())) { |
60 | QString hangul = Hangul::compose(source: ic->surroundingText().mid(position: cursorPosition - 1, n: 1) + text); |
61 | ic->commit(text: hangul, replaceFrom: -1, replaceLength: 1); |
62 | accept = true; |
63 | } |
64 | } |
65 | return accept; |
66 | } |
67 | |
68 | void HangulInputMethod::reset() |
69 | { |
70 | } |
71 | |
72 | void HangulInputMethod::update() |
73 | { |
74 | } |
75 | |
76 | } // namespace QtVirtualKeyboard |
77 | QT_END_NAMESPACE |
78 |