diff options
Diffstat (limited to 'src/plugins/pinyin/plugin')
-rw-r--r-- | src/plugins/pinyin/plugin/.prev_CMakeLists.txt | 78 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/CMakeLists.txt | 79 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyin.json | 6 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyindecoderservice.cpp | 236 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyindecoderservice_p.h | 86 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyininputmethod.cpp | 501 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyininputmethod_p.h | 82 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyinplugin.cpp | 44 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/pinyinplugin.h | 49 | ||||
-rw-r--r-- | src/plugins/pinyin/plugin/plugin.pro | 59 |
10 files changed, 0 insertions, 1220 deletions
diff --git a/src/plugins/pinyin/plugin/.prev_CMakeLists.txt b/src/plugins/pinyin/plugin/.prev_CMakeLists.txt deleted file mode 100644 index 6fe4fe4f..00000000 --- a/src/plugins/pinyin/plugin/.prev_CMakeLists.txt +++ /dev/null @@ -1,78 +0,0 @@ -# Generated from plugin.pro. - -##################################################################### -## QtVirtualKeyboardPinyinPlugin Plugin: -##################################################################### - -qt_internal_add_plugin(QtVirtualKeyboardPinyinPlugin - OUTPUT_NAME qtvirtualkeyboard_pinyin - TYPE virtualkeyboard - SOURCES - pinyindecoderservice.cpp pinyindecoderservice_p.h - pinyininputmethod.cpp pinyininputmethod_p.h - pinyinplugin.cpp pinyinplugin.h - DEFINES - QT_ASCII_CAST_WARNINGS - QT_NO_CAST_FROM_ASCII - QT_NO_CAST_FROM_BYTEARRAY - QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES - Qt::Core - Qt::Gui - Qt::Qml - Qt::VirtualKeyboard - pinyin -) - -# Resources: -set(qmake_virtualkeyboard_pinyin_layouts_resource_files - "virtualkeyboard/content/layouts/zh_CN/dialpad.fallback" - "virtualkeyboard/content/layouts/zh_CN/digits.fallback" - "virtualkeyboard/content/layouts/zh_CN/main.qml" - "virtualkeyboard/content/layouts/zh_CN/numbers.fallback" - "virtualkeyboard/content/layouts/zh_CN/symbols.qml" -) - -qt_add_resource(QtVirtualKeyboardPinyinPlugin "qmake_virtualkeyboard_pinyin_layouts" - PREFIX - "$$LAYOUTS_PREFIX" - BASE - "$$LAYOUTS_BASE" - FILES - ${qmake_virtualkeyboard_pinyin_layouts_resource_files} -) - - -#### Keys ignored in scope 1:.:.:plugin.pro:<TRUE>: -# OTHER_FILES = "pinyin.json" "$$LAYOUT_FILES" - -## Scopes: -##################################################################### - -if(NOT no-bundle-pinyin) - # Resources: - set(qmake_pinyin_resource_files - "../3rdparty/pinyin/data/dict_pinyin.dat" - ) - - qt_add_resource(QtVirtualKeyboardPinyinPlugin "qmake_pinyin" - PREFIX - "/QtQuick/VirtualKeyboard" - BASE - "$$PWD/.." - FILES - ${qmake_pinyin_resource_files} - ) -endif() - -#### Keys ignored in scope 3:.:.:plugin.pro:else: -# INSTALLS = "pinyin_data" -# pinyin_data.files = "$$PWD/../3rdparty/pinyin/data/dict_pinyin.dat" -# pinyin_data.path = "$$DATAPATH/pinyin" - -#### Keys ignored in scope 4:.:.:plugin.pro:NOT prefix_build: -# COPIES = "pinyin_data" - -#### Keys ignored in scope 5:.:.:plugin.pro:WIN32: -# QMAKE_TARGET_DESCRIPTION = "Virtual Keyboard Extension for Qt." -# QMAKE_TARGET_PRODUCT = "Qt Virtual Keyboard Pinyin (Qt $$QT_VERSION)" diff --git a/src/plugins/pinyin/plugin/CMakeLists.txt b/src/plugins/pinyin/plugin/CMakeLists.txt deleted file mode 100644 index 41835575..00000000 --- a/src/plugins/pinyin/plugin/CMakeLists.txt +++ /dev/null @@ -1,79 +0,0 @@ -# Generated from plugin.pro. - -##################################################################### -## QtVirtualKeyboardPinyinPlugin Plugin: -##################################################################### - -qt_internal_add_plugin(QtVirtualKeyboardPinyinPlugin - OUTPUT_NAME qtvirtualkeyboard_pinyin - TYPE virtualkeyboard - SOURCES - pinyindecoderservice.cpp pinyindecoderservice_p.h - pinyininputmethod.cpp pinyininputmethod_p.h - pinyinplugin.cpp pinyinplugin.h - DEFINES - QT_ASCII_CAST_WARNINGS - QT_NO_CAST_FROM_ASCII - QT_NO_CAST_FROM_BYTEARRAY - QT_NO_CAST_TO_ASCII - PUBLIC_LIBRARIES - Qt::Core - Qt::Gui - Qt::Qml - Qt::VirtualKeyboard - LIBRARIES # special case - BundledPinyin # special case -) - -# Resources: -set(qmake_virtualkeyboard_pinyin_layouts_resource_files - "virtualkeyboard/content/layouts/zh_CN/dialpad.fallback" - "virtualkeyboard/content/layouts/zh_CN/digits.fallback" - "virtualkeyboard/content/layouts/zh_CN/main.qml" - "virtualkeyboard/content/layouts/zh_CN/numbers.fallback" - "virtualkeyboard/content/layouts/zh_CN/symbols.qml" -) - -qt_add_resource(QtVirtualKeyboardPinyinPlugin "qmake_virtualkeyboard_pinyin_layouts" - PREFIX - "${VKB_LAYOUTS_PREFIX}" #special case - BASE - "${VKB_LAYOUTS_BASE}" #special case - FILES - ${qmake_virtualkeyboard_pinyin_layouts_resource_files} -) - - -#### Keys ignored in scope 1:.:.:plugin.pro:<TRUE>: -# OTHER_FILES = "pinyin.json" "$$LAYOUT_FILES" - -## Scopes: -##################################################################### - -if(NOT no-bundle-pinyin) - # Resources: - set(qmake_pinyin_resource_files - "../3rdparty/pinyin/data/dict_pinyin.dat" - ) - - qt_add_resource(QtVirtualKeyboardPinyinPlugin "qmake_pinyin" - PREFIX - "/QtQuick/VirtualKeyboard" - BASE - "${CMAKE_CURRENT_SOURCE_DIR}" #special case - FILES - ${qmake_pinyin_resource_files} - ) -endif() - -#### Keys ignored in scope 3:.:.:plugin.pro:else: -# INSTALLS = "pinyin_data" -# pinyin_data.files = "$$PWD/../3rdparty/pinyin/data/dict_pinyin.dat" -# pinyin_data.path = "$$DATAPATH/pinyin" - -#### Keys ignored in scope 4:.:.:plugin.pro:NOT prefix_build: -# COPIES = "pinyin_data" - -#### Keys ignored in scope 5:.:.:plugin.pro:WIN32: -# QMAKE_TARGET_DESCRIPTION = "Virtual Keyboard Extension for Qt." -# QMAKE_TARGET_PRODUCT = "Qt Virtual Keyboard Pinyin (Qt $$QT_VERSION)" diff --git a/src/plugins/pinyin/plugin/pinyin.json b/src/plugins/pinyin/plugin/pinyin.json deleted file mode 100644 index 6bb19d11..00000000 --- a/src/plugins/pinyin/plugin/pinyin.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "Name": "pinyin", - "Provider": "Qt Pinyin Extension", - "InputMethod": "PinyinInputMethod", - "Version": 100 -} diff --git a/src/plugins/pinyin/plugin/pinyindecoderservice.cpp b/src/plugins/pinyin/plugin/pinyindecoderservice.cpp deleted file mode 100644 index 856c67d9..00000000 --- a/src/plugins/pinyin/plugin/pinyindecoderservice.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "pinyindecoderservice_p.h" -#include "pinyinime.h" -#include "dictdef.h" -#include <QStandardPaths> -#include <QFileInfo> -#include <QDir> -#include <QtCore/QLibraryInfo> -#include <QLoggingCategory> - -QT_BEGIN_NAMESPACE -namespace QtVirtualKeyboard { - -Q_DECLARE_LOGGING_CATEGORY(lcPinyin) - -using namespace ime_pinyin; - -QScopedPointer<PinyinDecoderService> PinyinDecoderService::_instance; - -/*! - \class QtVirtualKeyboard::PinyinDecoderService - \internal -*/ - -PinyinDecoderService::PinyinDecoderService(QObject *parent) : - QObject(parent), - initDone(false) -{ -} - -PinyinDecoderService::~PinyinDecoderService() -{ - if (initDone) { - im_close_decoder(); - initDone = false; - } -} - -PinyinDecoderService *PinyinDecoderService::getInstance() -{ - if (!_instance) - _instance.reset(new PinyinDecoderService()); - if (!_instance->init()) - return nullptr; - return _instance.data(); -} - -bool PinyinDecoderService::init() -{ - if (initDone) - return true; - - QString sysDict(qEnvironmentVariable("QT_VIRTUALKEYBOARD_PINYIN_DICTIONARY")); - if (!QFileInfo::exists(sysDict)) { - sysDict = QLatin1String(":///QtQuick/VirtualKeyboard/3rdparty/pinyin/data/dict_pinyin.dat"); - if (!QFileInfo::exists(sysDict)) - sysDict = QLibraryInfo::location(QLibraryInfo::DataPath) + QLatin1String("/qtvirtualkeyboard/pinyin/dict_pinyin.dat"); - } - - QString usrDictPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); - QFileInfo usrDictInfo(usrDictPath + QLatin1String("/qtvirtualkeyboard/pinyin/usr_dict.dat")); - if (!usrDictInfo.exists()) { - qCWarning(lcPinyin) << "PinyinDecoderService::init(): creating directory for user dictionary" << usrDictInfo.absolutePath(); - QDir().mkpath(usrDictInfo.absolutePath()); - } - - initDone = im_open_decoder(sysDict.toUtf8().constData(), usrDictInfo.absoluteFilePath().toUtf8().constData()); - if (!initDone) - qCWarning(lcPinyin) << "Could not initialize pinyin engine. sys_dict:" << sysDict << "usr_dict:" << usrDictInfo.absoluteFilePath(); - - return initDone; -} - -void PinyinDecoderService::setUserDictionary(bool enabled) -{ - if (enabled == im_is_user_dictionary_enabled()) - return; - if (enabled) { - QString usrDictPath = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation); - QFileInfo usrDictInfo(usrDictPath + QLatin1String("/qtvirtualkeyboard/pinyin/usr_dict.dat")); - im_init_user_dictionary(usrDictInfo.absoluteFilePath().toUtf8().constData()); - } else { - im_init_user_dictionary(nullptr); - } -} - -bool PinyinDecoderService::isUserDictionaryEnabled() const -{ - return im_is_user_dictionary_enabled(); -} - -void PinyinDecoderService::setLimits(int maxSpsLen, int maxHzsLen) -{ - if (maxSpsLen <= 0) - maxSpsLen = kMaxSearchSteps - 1; - if (maxHzsLen <= 0) - maxHzsLen = kMaxSearchSteps; - im_set_max_lens(size_t(maxSpsLen), size_t(maxHzsLen)); -} - -int PinyinDecoderService::search(const QString &spelling) -{ - QByteArray spellingBuf = spelling.toLatin1(); - return int(im_search(spellingBuf.constData(), spellingBuf.length())); -} - -int PinyinDecoderService::deleteSearch(int pos, bool isPosInSpellingId, bool clearFixedInThisStep) -{ - if (pos <= 0) - pos = 0; - return int(im_delsearch(size_t(pos), isPosInSpellingId, clearFixedInThisStep)); -} - -void PinyinDecoderService::resetSearch() -{ - im_reset_search(); -} - -QString PinyinDecoderService::pinyinString(bool decoded) -{ - size_t py_len; - const char *py = im_get_sps_str(&py_len); - if (!decoded) - py_len = strlen(py); - - return QString(QLatin1String(py, (int)py_len)); -} - -int PinyinDecoderService::pinyinStringLength(bool decoded) -{ - size_t py_len; - const char *py = im_get_sps_str(&py_len); - if (!decoded) - py_len = strlen(py); - return (int)py_len; -} - -QList<int> PinyinDecoderService::spellingStartPositions() -{ - const unsigned short *spl_start; - int len; - // There will be len + 1 elements in the buffer when len > 0. - len = (int)im_get_spl_start_pos(spl_start); - - QList<int> arr; - arr.resize(len + 2); - arr[0] = len; // element 0 is used to store the length of buffer. - for (int i = 0; i <= len; i++) - arr[i + 1] = spl_start[i]; - return arr; -} - -QString PinyinDecoderService::candidateAt(int index) -{ - Q_ASSERT(index >= 0); - QList<QChar> candidateBuf; - candidateBuf.resize(kMaxSearchSteps + 1); - if (!im_get_candidate(size_t(index), (char16 *)candidateBuf.data(), candidateBuf.length() - 1)) - return QString(); - candidateBuf.last() = u'\0'; - return QString(candidateBuf.data()); -} - -QList<QString> PinyinDecoderService::fetchCandidates(int index, int count, int sentFixedLen) -{ - QList<QString> candidatesList; - for (int i = index; i < index + count; i++) { - QString retStr = candidateAt(i); - if (0 == i) - retStr.remove(0, sentFixedLen); - candidatesList.append(retStr); - } - return candidatesList; -} - -int PinyinDecoderService::chooceCandidate(int index) -{ - return int(im_choose(index)); -} - -int PinyinDecoderService::cancelLastChoice() -{ - return int(im_cancel_last_choice()); -} - -int PinyinDecoderService::fixedLength() -{ - return (int)im_get_fixed_len(); -} - -void PinyinDecoderService::flushCache() -{ - im_flush_cache(); -} - -QList<QString> PinyinDecoderService::predictionList(const QString &history) -{ - QList<QString> predictList; - char16 (*predictItems)[kMaxPredictSize + 1] = nullptr; - int predictNum = int(im_get_predicts(history.utf16(), predictItems)); - predictList.reserve(predictNum); - for (int i = 0; i < predictNum; i++) - predictList.append(QString((QChar *)predictItems[i])); - return predictList; -} - -} // namespace QtVirtualKeyboard -QT_END_NAMESPACE diff --git a/src/plugins/pinyin/plugin/pinyindecoderservice_p.h b/src/plugins/pinyin/plugin/pinyindecoderservice_p.h deleted file mode 100644 index 4c5884dd..00000000 --- a/src/plugins/pinyin/plugin/pinyindecoderservice_p.h +++ /dev/null @@ -1,86 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PINYINDECODERSERVICE_P_H -#define PINYINDECODERSERVICE_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QObject> - -QT_BEGIN_NAMESPACE -namespace QtVirtualKeyboard { - -class PinyinDecoderService : public QObject -{ - Q_OBJECT - Q_DISABLE_COPY(PinyinDecoderService) - explicit PinyinDecoderService(QObject *parent = nullptr); - -public: - ~PinyinDecoderService(); - - static PinyinDecoderService *getInstance(); - - bool init(); - void setUserDictionary(bool enabled); - bool isUserDictionaryEnabled() const; - void setLimits(int maxSpelling, int maxHzsLen); - int search(const QString &spelling); - int deleteSearch(int pos, bool isPosInSpellingId, bool clearFixedInThisStep); - void resetSearch(); - QString pinyinString(bool decoded); - int pinyinStringLength(bool decoded); - QList<int> spellingStartPositions(); - QString candidateAt(int index); - QList<QString> fetchCandidates(int index, int count, int sentFixedLen); - int chooceCandidate(int index); - int cancelLastChoice(); - int fixedLength(); - void flushCache(); - QList<QString> predictionList(const QString &history); - -private: - static QScopedPointer<PinyinDecoderService> _instance; - bool initDone; -}; - -} // namespace QtVirtualKeyboard -QT_END_NAMESPACE - -#endif // PINYINDECODERSERVICE_P_H diff --git a/src/plugins/pinyin/plugin/pinyininputmethod.cpp b/src/plugins/pinyin/plugin/pinyininputmethod.cpp deleted file mode 100644 index c70e31b5..00000000 --- a/src/plugins/pinyin/plugin/pinyininputmethod.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "pinyininputmethod_p.h" -#include "pinyindecoderservice_p.h" -#include <QtVirtualKeyboard/qvirtualkeyboardinputcontext.h> -#include <QLoggingCategory> - -QT_BEGIN_NAMESPACE -namespace QtVirtualKeyboard { - -Q_LOGGING_CATEGORY(lcPinyin, "qt.virtualkeyboard.pinyin") - -class PinyinInputMethodPrivate -{ - Q_DECLARE_PUBLIC(PinyinInputMethod) - -public: - enum State - { - Idle, - Input, - Predict - }; - - PinyinInputMethodPrivate(PinyinInputMethod *q_ptr) : - q_ptr(q_ptr), - inputMode(QVirtualKeyboardInputEngine::InputMode::Pinyin), - pinyinDecoderService(PinyinDecoderService::getInstance()), - state(Idle), - surface(), - totalChoicesNum(0), - candidatesList(), - fixedLen(0), - composingStr(), - activeCmpsLen(0), - finishSelection(true), - posDelSpl(-1), - isPosInSpl(false) - { - } - - void resetToIdleState() - { - Q_Q(PinyinInputMethod); - - QVirtualKeyboardInputContext *inputContext = q->inputContext(); - - // Disable the user dictionary when entering sensitive data - if (inputContext) { - bool userDictionaryEnabled = !inputContext->inputMethodHints().testFlag(Qt::ImhSensitiveData); - if (userDictionaryEnabled != pinyinDecoderService->isUserDictionaryEnabled()) - pinyinDecoderService->setUserDictionary(userDictionaryEnabled); - } - - if (state == Idle) - return; - - state = Idle; - surface.clear(); - fixedLen = 0; - finishSelection = true; - composingStr.clear(); - if (inputContext) - inputContext->setPreeditText(QString()); - activeCmpsLen = 0; - posDelSpl = -1; - isPosInSpl = false; - - resetCandidates(); - } - - bool addSpellingChar(QChar ch, bool reset) - { - if (reset) { - surface.clear(); - pinyinDecoderService->resetSearch(); - } - if (ch == u'\'') { - if (surface.isEmpty()) - return false; - if (surface.endsWith(ch)) - return true; - } - surface.append(ch); - return true; - } - - bool removeSpellingChar() - { - if (surface.isEmpty()) - return false; - QList<int> splStart = pinyinDecoderService->spellingStartPositions(); - isPosInSpl = (surface.length() <= splStart[fixedLen + 1]); - posDelSpl = isPosInSpl ? fixedLen - 1 : surface.length() - 1; - return true; - } - - void chooseAndUpdate(int candId) - { - Q_Q(PinyinInputMethod); - - if (state == Predict) - choosePredictChoice(candId); - else - chooseDecodingCandidate(candId); - - if (composingStr.length() > 0) { - if ((candId >= 0 || finishSelection) && composingStr.length() == fixedLen) { - QString resultStr = getComposingStrActivePart(); - tryPredict(); - q->inputContext()->commit(resultStr); - } else if (state == Idle) { - state = Input; - } - } else { - tryPredict(); - } - } - - bool chooseAndFinish() - { - if (state == Predict || !totalChoicesNum) - return false; - - chooseAndUpdate(0); - if (state != Predict && totalChoicesNum > 0) - chooseAndUpdate(0); - - return true; - } - - int candidatesCount() - { - return totalChoicesNum; - } - - QString candidateAt(int index) - { - if (index < 0 || index >= totalChoicesNum) - return QString(); - if (index >= candidatesList.size()) { - int fetchMore = qMin(index + 20, totalChoicesNum - candidatesList.size()); - candidatesList.append(pinyinDecoderService->fetchCandidates(candidatesList.size(), fetchMore, fixedLen)); - if (index == 0 && totalChoicesNum == 1) { - int surfaceDecodedLen = pinyinDecoderService->pinyinStringLength(true); - if (surfaceDecodedLen < surface.length()) - candidatesList[0] = candidatesList[0] + surface.mid(surfaceDecodedLen).toLower(); - } - } - return index < candidatesList.size() ? candidatesList[index] : QString(); - } - - void chooseDecodingCandidate(int candId) - { - Q_Q(PinyinInputMethod); - Q_ASSERT(state != Predict); - - int result = 0; - if (candId < 0) { - if (surface.length() > 0) { - if (posDelSpl < 0) { - result = pinyinDecoderService->search(surface); - } else { - result = pinyinDecoderService->deleteSearch(posDelSpl, isPosInSpl, false); - posDelSpl = -1; - } - } - } else { - if (totalChoicesNum > 1) { - result = pinyinDecoderService->chooceCandidate(candId); - } else { - QString resultStr; - if (totalChoicesNum == 1) { - QString undecodedStr = candId < candidatesList.length() ? candidatesList.at(candId) : QString(); - resultStr = pinyinDecoderService->candidateAt(0).mid(0, fixedLen) + undecodedStr; - } - resetToIdleState(); - if (!resultStr.isEmpty()) - q->inputContext()->commit(resultStr); - return; - } - } - - resetCandidates(); - totalChoicesNum = result; - - surface = pinyinDecoderService->pinyinString(false); - QList<int> splStart = pinyinDecoderService->spellingStartPositions(); - QString fullSent = pinyinDecoderService->candidateAt(0); - fixedLen = pinyinDecoderService->fixedLength(); - composingStr = fullSent.mid(0, fixedLen) + surface.mid(splStart[fixedLen + 1]); - activeCmpsLen = composingStr.length(); - - // Prepare the display string. - QString composingStrDisplay; - int surfaceDecodedLen = pinyinDecoderService->pinyinStringLength(true); - if (!surfaceDecodedLen) { - composingStrDisplay = composingStr.toLower(); - if (!totalChoicesNum) - totalChoicesNum = 1; - } else { - activeCmpsLen = activeCmpsLen - (surface.length() - surfaceDecodedLen); - composingStrDisplay = fullSent.mid(0, fixedLen); - for (int pos = fixedLen + 1; pos < splStart.size() - 1; pos++) { - composingStrDisplay += surface.mid(splStart[pos], splStart[pos + 1] - splStart[pos]).toUpper(); - if (splStart[pos + 1] < surfaceDecodedLen) - composingStrDisplay += QLatin1String(" "); - } - if (surfaceDecodedLen < surface.length()) - composingStrDisplay += surface.mid(surfaceDecodedLen).toLower(); - } - q->inputContext()->setPreeditText(composingStrDisplay); - - finishSelection = splStart.size() == (fixedLen + 2); - if (!finishSelection) - candidateAt(0); - } - - void choosePredictChoice(int choiceId) - { - Q_ASSERT(state == Predict); - - if (choiceId < 0 || choiceId >= totalChoicesNum) - return; - - QString tmp = candidatesList.at(choiceId); - - resetCandidates(); - - candidatesList.append(tmp); - totalChoicesNum = 1; - - surface.clear(); - fixedLen = tmp.length(); - composingStr = tmp; - activeCmpsLen = fixedLen; - - finishSelection = true; - } - - QString getComposingStrActivePart() - { - return composingStr.mid(0, activeCmpsLen); - } - - void resetCandidates() - { - candidatesList.clear(); - if (totalChoicesNum) { - totalChoicesNum = 0; - } - } - - void updateCandidateList() - { - Q_Q(PinyinInputMethod); - emit q->selectionListChanged(QVirtualKeyboardSelectionListModel::Type::WordCandidateList); - emit q->selectionListActiveItemChanged(QVirtualKeyboardSelectionListModel::Type::WordCandidateList, - totalChoicesNum > 0 && state == PinyinInputMethodPrivate::Input ? 0 : -1); - } - - bool canDoPrediction() - { - Q_Q(PinyinInputMethod); - QVirtualKeyboardInputContext *inputContext = q->inputContext(); - return inputMode == QVirtualKeyboardInputEngine::InputMode::Pinyin && - composingStr.length() == fixedLen && - inputContext && - !inputContext->inputMethodHints().testFlag(Qt::ImhNoPredictiveText); - } - - void tryPredict() - { - // Try to get the prediction list. - if (canDoPrediction()) { - Q_Q(PinyinInputMethod); - if (state != Predict) - resetToIdleState(); - QVirtualKeyboardInputContext *inputContext = q->inputContext(); - int cursorPosition = inputContext->cursorPosition(); - int historyStart = qMax(0, cursorPosition - 3); - QString history = inputContext->surroundingText().mid(historyStart, cursorPosition - historyStart); - candidatesList = pinyinDecoderService->predictionList(history); - totalChoicesNum = candidatesList.size(); - finishSelection = false; - state = Predict; - } else { - resetCandidates(); - } - - if (!candidatesCount()) - resetToIdleState(); - } - - PinyinInputMethod *q_ptr; - QVirtualKeyboardInputEngine::InputMode inputMode; - QPointer<PinyinDecoderService> pinyinDecoderService; - State state; - QString surface; - int totalChoicesNum; - QList<QString> candidatesList; - int fixedLen; - QString composingStr; - int activeCmpsLen; - bool finishSelection; - int posDelSpl; - bool isPosInSpl; -}; - -class ScopedCandidateListUpdate -{ - Q_DISABLE_COPY(ScopedCandidateListUpdate) -public: - inline explicit ScopedCandidateListUpdate(PinyinInputMethodPrivate *d) : - d(d), - candidatesList(d->candidatesList), - totalChoicesNum(d->totalChoicesNum), - state(d->state) - { - } - - inline ~ScopedCandidateListUpdate() - { - if (totalChoicesNum != d->totalChoicesNum || state != d->state || candidatesList != d->candidatesList) - d->updateCandidateList(); - } - -private: - PinyinInputMethodPrivate *d; - QList<QString> candidatesList; - int totalChoicesNum; - PinyinInputMethodPrivate::State state; -}; - -/*! - \class QtVirtualKeyboard::PinyinInputMethod - \internal -*/ - -PinyinInputMethod::PinyinInputMethod(QObject *parent) : - QVirtualKeyboardAbstractInputMethod(parent), - d_ptr(new PinyinInputMethodPrivate(this)) -{ -} - -PinyinInputMethod::~PinyinInputMethod() -{ -} - -QList<QVirtualKeyboardInputEngine::InputMode> PinyinInputMethod::inputModes(const QString &locale) -{ - Q_UNUSED(locale); - Q_D(PinyinInputMethod); - QList<QVirtualKeyboardInputEngine::InputMode> result; - if (d->pinyinDecoderService) - result << QVirtualKeyboardInputEngine::InputMode::Pinyin; - result << QVirtualKeyboardInputEngine::InputMode::Latin; - return result; -} - -bool PinyinInputMethod::setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode) -{ - Q_UNUSED(locale); - Q_D(PinyinInputMethod); - reset(); - if (inputMode == QVirtualKeyboardInputEngine::InputMode::Pinyin && !d->pinyinDecoderService) - return false; - d->inputMode = inputMode; - return true; -} - -bool PinyinInputMethod::setTextCase(QVirtualKeyboardInputEngine::TextCase textCase) -{ - Q_UNUSED(textCase); - return true; -} - -bool PinyinInputMethod::keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers) -{ - Q_UNUSED(modifiers); - Q_D(PinyinInputMethod); - if (d->inputMode == QVirtualKeyboardInputEngine::InputMode::Pinyin) { - ScopedCandidateListUpdate scopedCandidateListUpdate(d); - Q_UNUSED(scopedCandidateListUpdate); - if ((key >= Qt::Key_A && key <= Qt::Key_Z) || (key == Qt::Key_Apostrophe)) { - if (d->state == PinyinInputMethodPrivate::Predict) - d->resetToIdleState(); - if (d->addSpellingChar(text.at(0), d->state == PinyinInputMethodPrivate::Idle)) { - d->chooseAndUpdate(-1); - return true; - } - } else if (key == Qt::Key_Space) { - if (d->state != PinyinInputMethodPrivate::Predict && d->candidatesCount() > 0) { - d->chooseAndUpdate(0); - return true; - } - } else if (key == Qt::Key_Return) { - if (d->state != PinyinInputMethodPrivate::Predict && d->candidatesCount() > 0) { - QString surface = d->surface; - d->resetToIdleState(); - inputContext()->commit(surface); - return true; - } - } else if (key == Qt::Key_Backspace) { - if (d->removeSpellingChar()) { - d->chooseAndUpdate(-1); - return true; - } - } else if (!text.isEmpty()) { - d->chooseAndFinish(); - } - } - return false; -} - -QList<QVirtualKeyboardSelectionListModel::Type> PinyinInputMethod::selectionLists() -{ - return QList<QVirtualKeyboardSelectionListModel::Type>() << QVirtualKeyboardSelectionListModel::Type::WordCandidateList; -} - -int PinyinInputMethod::selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type) -{ - Q_UNUSED(type); - Q_D(PinyinInputMethod); - return d->candidatesCount(); -} - -QVariant PinyinInputMethod::selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, QVirtualKeyboardSelectionListModel::Role role) -{ - QVariant result; - Q_UNUSED(type); - Q_D(PinyinInputMethod); - switch (role) { - case QVirtualKeyboardSelectionListModel::Role::Display: - result = QVariant(d->candidateAt(index)); - break; - case QVirtualKeyboardSelectionListModel::Role::WordCompletionLength: - result.setValue(0); - break; - default: - result = QVirtualKeyboardAbstractInputMethod::selectionListData(type, index, role); - break; - } - return result; -} - -void PinyinInputMethod::selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index) -{ - Q_UNUSED(type); - Q_D(PinyinInputMethod); - ScopedCandidateListUpdate scopedCandidateListUpdate(d); - Q_UNUSED(scopedCandidateListUpdate); - d->chooseAndUpdate(index); -} - -void PinyinInputMethod::reset() -{ - Q_D(PinyinInputMethod); - ScopedCandidateListUpdate scopedCandidateListUpdate(d); - Q_UNUSED(scopedCandidateListUpdate); - d->resetToIdleState(); -} - -void PinyinInputMethod::update() -{ - Q_D(PinyinInputMethod); - ScopedCandidateListUpdate scopedCandidateListUpdate(d); - Q_UNUSED(scopedCandidateListUpdate); - d->chooseAndFinish(); - d->tryPredict(); -} - -} // namespace QtVirtualKeyboard -QT_END_NAMESPACE diff --git a/src/plugins/pinyin/plugin/pinyininputmethod_p.h b/src/plugins/pinyin/plugin/pinyininputmethod_p.h deleted file mode 100644 index 14df2e55..00000000 --- a/src/plugins/pinyin/plugin/pinyininputmethod_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PINYININPUTMETHOD_P_H -#define PINYININPUTMETHOD_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the Qt API. It exists purely as an -// implementation detail. This header file may change from version to -// version without notice, or even be removed. -// -// We mean it. -// - -#include <QtVirtualKeyboard/qvirtualkeyboardabstractinputmethod.h> - -QT_BEGIN_NAMESPACE -namespace QtVirtualKeyboard { - -class PinyinInputMethodPrivate; - -class PinyinInputMethod : public QVirtualKeyboardAbstractInputMethod -{ - Q_OBJECT - Q_DECLARE_PRIVATE(PinyinInputMethod) - -public: - explicit PinyinInputMethod(QObject *parent = nullptr); - ~PinyinInputMethod(); - - QList<QVirtualKeyboardInputEngine::InputMode> inputModes(const QString &locale) override; - bool setInputMode(const QString &locale, QVirtualKeyboardInputEngine::InputMode inputMode) override; - bool setTextCase(QVirtualKeyboardInputEngine::TextCase textCase) override; - - bool keyEvent(Qt::Key key, const QString &text, Qt::KeyboardModifiers modifiers) override; - - QList<QVirtualKeyboardSelectionListModel::Type> selectionLists() override; - int selectionListItemCount(QVirtualKeyboardSelectionListModel::Type type) override; - QVariant selectionListData(QVirtualKeyboardSelectionListModel::Type type, int index, - QVirtualKeyboardSelectionListModel::Role role) override; - void selectionListItemSelected(QVirtualKeyboardSelectionListModel::Type type, int index) override; - - void reset() override; - void update() override; - -private: - QScopedPointer<PinyinInputMethodPrivate> d_ptr; -}; - -} // namespace QtVirtualKeyboard -QT_END_NAMESPACE - -#endif // PINYININPUTMETHOD_P_H diff --git a/src/plugins/pinyin/plugin/pinyinplugin.cpp b/src/plugins/pinyin/plugin/pinyinplugin.cpp deleted file mode 100644 index 6edef332..00000000 --- a/src/plugins/pinyin/plugin/pinyinplugin.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "pinyinplugin.h" -#include "pinyininputmethod_p.h" -#include <QtQml> - -QT_BEGIN_NAMESPACE - -using namespace QtVirtualKeyboard; - -void QtVirtualKeyboardPinyinPlugin::registerTypes(const char *uri) const -{ - qmlRegisterType<PinyinInputMethod>(uri, 1, 1, "PinyinInputMethod"); - qmlRegisterType<PinyinInputMethod>(uri, 2, 0, "PinyinInputMethod"); -} - -QT_END_NAMESPACE diff --git a/src/plugins/pinyin/plugin/pinyinplugin.h b/src/plugins/pinyin/plugin/pinyinplugin.h deleted file mode 100644 index c642919c..00000000 --- a/src/plugins/pinyin/plugin/pinyinplugin.h +++ /dev/null @@ -1,49 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2018 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the Qt Virtual Keyboard module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 or (at your option) any later version -** approved by the KDE Free Qt Foundation. The licenses are as published by -** the Free Software Foundation and appearing in the file LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef PINYINPLUGIN_H -#define PINYINPLUGIN_H - -#include <QVirtualKeyboardExtensionPlugin> - -QT_BEGIN_NAMESPACE - -class QtVirtualKeyboardPinyinPlugin : public QVirtualKeyboardExtensionPlugin -{ - Q_OBJECT - Q_INTERFACES(QVirtualKeyboardExtensionPlugin) - Q_PLUGIN_METADATA(IID QVirtualKeyboardExtensionPluginFactoryInterface_iid - FILE "pinyin.json") -public: - void registerTypes(const char *uri) const override; -}; - -QT_END_NAMESPACE - -#endif diff --git a/src/plugins/pinyin/plugin/plugin.pro b/src/plugins/pinyin/plugin/plugin.pro deleted file mode 100644 index 5b11fe8c..00000000 --- a/src/plugins/pinyin/plugin/plugin.pro +++ /dev/null @@ -1,59 +0,0 @@ -TARGET = qtvirtualkeyboard_pinyin -QT += qml virtualkeyboard - -include(../../../shared.pri) - -HEADERS += \ - pinyindecoderservice_p.h \ - pinyininputmethod_p.h \ - pinyinplugin.h -SOURCES += \ - pinyindecoderservice.cpp \ - pinyininputmethod.cpp \ - pinyinplugin.cpp -OTHER_FILES += \ - pinyin.json - -DEFINES += \ - QT_NO_CAST_TO_ASCII \ - QT_ASCII_CAST_WARNINGS \ - QT_NO_CAST_FROM_ASCII \ - QT_NO_CAST_FROM_BYTEARRAY - -LAYOUT_FILES += \ - $$LAYOUTS_BASE/content/layouts/zh_CN/dialpad.fallback \ - $$LAYOUTS_BASE/content/layouts/zh_CN/digits.fallback \ - $$LAYOUTS_BASE/content/layouts/zh_CN/main.qml \ - $$LAYOUTS_BASE/content/layouts/zh_CN/numbers.fallback \ - $$LAYOUTS_BASE/content/layouts/zh_CN/symbols.qml - -OTHER_FILES += \ - $$LAYOUT_FILES - -virtualkeyboard_pinyin_layouts.files = $$LAYOUT_FILES -virtualkeyboard_pinyin_layouts.base = $$LAYOUTS_BASE -virtualkeyboard_pinyin_layouts.prefix = $$LAYOUTS_PREFIX -RESOURCES += virtualkeyboard_pinyin_layouts - -QMAKE_USE += pinyin -!no-bundle-pinyin { - PINYIN_FILES += ../3rdparty/pinyin/data/dict_pinyin.dat - pinyin.files = $$PINYIN_FILES - pinyin.base = $$PWD/.. - pinyin.prefix = /QtQuick/VirtualKeyboard - RESOURCES += pinyin -} else { - pinyin_data.files = $$PWD/../3rdparty/pinyin/data/dict_pinyin.dat - pinyin_data.path = $$DATAPATH/pinyin - INSTALLS += pinyin_data - !prefix_build: COPIES += pinyin_data -} - -win32 { - QMAKE_TARGET_PRODUCT = "Qt Virtual Keyboard Pinyin (Qt $$QT_VERSION)" - QMAKE_TARGET_DESCRIPTION = "Virtual Keyboard Extension for Qt." -} - -PLUGIN_TYPE = virtualkeyboard -PLUGIN_CLASS_NAME = QtVirtualKeyboardPinyinPlugin -load(qt_plugin) |