1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "hangulinputmethod_p.h"
31#include "hangul_p.h"
32#include <QtVirtualKeyboard/qvirtualkeyboardinputcontext.h>
33
34QT_BEGIN_NAMESPACE
35namespace QtVirtualKeyboard {
36
37/*!
38 \class QtVirtualKeyboard::HangulInputMethod
39 \internal
40*/
41
42HangulInputMethod::HangulInputMethod(QObject *parent) :
43 QVirtualKeyboardAbstractInputMethod(parent)
44{
45}
46
47HangulInputMethod::~HangulInputMethod()
48{
49}
50
51QList<QVirtualKeyboardInputEngine::InputMode> HangulInputMethod::inputModes(const QString &locale)
52{
53 Q_UNUSED(locale)
54 return QList<QVirtualKeyboardInputEngine::InputMode>() << QVirtualKeyboardInputEngine::InputMode::Hangul;
55}
56
57bool HangulInputMethod::setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode)
58{
59 Q_UNUSED(locale)
60 Q_UNUSED(inputMode)
61 return true;
62}
63
64bool HangulInputMethod::setTextCase(QVirtualKeyboardInputEngine::TextCase textCase)
65{
66 Q_UNUSED(textCase)
67 return true;
68}
69
70bool HangulInputMethod::keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers)
71{
72 Q_UNUSED(modifiers)
73 QVirtualKeyboardInputContext *ic = inputContext();
74 bool accept = false;
75 int cursorPosition = ic->cursorPosition();
76 if (ic->cursorPosition() > 0) {
77 if (key == Qt::Key_Backspace) {
78 int contextLength = cursorPosition > 1 ? 2 : 1;
79 QString hangul = Hangul::decompose(source: ic->surroundingText().mid(position: cursorPosition - contextLength, n: contextLength));
80 int length = hangul.length();
81 if (hangul.length() > 1) {
82 ic->commit(text: Hangul::compose(source: hangul.left(n: length - 1)), replaceFrom: -contextLength, replaceLength: contextLength);
83 accept = true;
84 }
85 } else if (!text.isEmpty() && Hangul::isJamo(unicode: text.at(i: 0).unicode())) {
86 QString hangul = Hangul::compose(source: ic->surroundingText().mid(position: cursorPosition - 1, n: 1) + text);
87 ic->commit(text: hangul, replaceFrom: -1, replaceLength: 1);
88 accept = true;
89 }
90 }
91 return accept;
92}
93
94void HangulInputMethod::reset()
95{
96}
97
98void HangulInputMethod::update()
99{
100}
101
102} // namespace QtVirtualKeyboard
103QT_END_NAMESPACE
104

source code of qtvirtualkeyboard/src/plugins/hangul/hangulinputmethod.cpp