diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..6d751cc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,24 @@ +cmake_minimum_required(VERSION 3.16) +project(cutekeyboardplugin VERSION 1.0 LANGUAGES C CXX) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +set(CMAKE_AUTORCC ON) + +find_package(QT NAMES Qt5 Qt6 REQUIRED COMPONENTS Core) +find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Gui Qml Quick) + +set(BUILD_EXAMPLES OFF) + +if(QT_KNOWN_POLICY_QTP0001) + qt_policy(SET QTP0001 NEW) +endif() + +qt_standard_project_setup() + +add_subdirectory(src) + +if(BUILD_EXAMPLES) + add_subdirectory(example) +endif() diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt new file mode 100644 index 0000000..295402b --- /dev/null +++ b/example/CMakeLists.txt @@ -0,0 +1,35 @@ +qt_add_executable(example WIN32 MACOSX_BUNDLE + main.cpp +) +target_compile_definitions(example PRIVATE + QT_DEPRECATED_WARNINGS +) + +target_link_libraries(example PRIVATE + Qt::Core + Qt::Gui + Qt::Quick +) + +set(qml_resource_files + "main.qml" +) + +qt_add_resources(example "qml" + PREFIX + "/" + FILES + ${qml_resource_files} +) + +install(TARGETS example + BUNDLE DESTINATION . + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) + +qt_generate_deploy_app_script( + TARGET example + FILENAME_VARIABLE deploy_script + NO_UNSUPPORTED_PLATFORM_ERROR +) +install(SCRIPT ${deploy_script}) diff --git a/example/main.cpp b/example/main.cpp index 79b0a9e..d312bdc 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -9,6 +9,7 @@ int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; + engine.addImportPath(":/"); const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect( &engine, &QQmlApplicationEngine::objectCreated, &app, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..9e3d9a3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,100 @@ +set(HEADERS + "EnterKeyAction.hpp" + "EnterKeyActionAttachedType.hpp" + "InputPanelIface.hpp" + "VirtualKeyboardInputContextPlugin.h" + "VirtualKeyboardInputContext.h" + "DeclarativeInputEngine.h" +) + +set(SOURCES + "EnterKeyAction.cpp" + "EnterKeyActionAttachedType.cpp" + "InputPanelIface.cpp" + "VirtualKeyboardInputContextPlugin.cpp" + "VirtualKeyboardInputContext.cpp" + "DeclarativeInputEngine.cpp" +) + +set(QML_FILES + "qml/AlternativeKeysPopup.qml" + "qml/BackspaceKey.qml" + "qml/CsLayout.qml" + "qml/DeLayout.qml" + "qml/DigitsLayout.qml" + "qml/ElLayout.qml" + "qml/EnLayout.qml" + "qml/EnterKey.qml" + "qml/EsLayout.qml" + "qml/FrLayout.qml" + "qml/HideKey.qml" + "qml/InputPanel.qml" + "qml/ItLayout.qml" + "qml/KeyModel.qml" + "qml/KeyPopup.qml" + "qml/Key.qml" + "qml/NlLayout.qml" + "qml/PlLayout.qml" + "qml/PtLayout.qml" + "qml/QwertyLayout.qml" + "qml/ShiftKey.qml" + "qml/SpaceKey.qml" + "qml/SymbolKey.qml" + "qml/SymbolLayout.qml" +) + +foreach(_file IN_LISTS QML_FILES) + cmake_path(GET _file FILENAME _fileName) + set_source_files_properties(${_file} PROPERTIES + QT_RESOURCE_ALIAS ${_fileName} + ) +endforeach() + +qt_add_qml_module(${PROJECT_NAME} + URI + "QtQuick.CuteKeyboard" + VERSION + 1.0 + PLUGIN_TARGET + ${PROJECT_NAME} + OUTPUT_DIRECTORY + "QtQuick/CuteKeyboard" + RESOURCE_PREFIX + "/" + CLASS_NAME + "VirtualKeyboardInputContextPlugin" + SOURCES + ${HEADERS} + ${SOURCES} + QML_FILES + ${QML_FILES} + NO_GENERATE_PLUGIN_SOURCE +) + +qt_add_resources(${PROJECT_NAME} "icons" + PREFIX "/" + FILES + "resources.qrc" +) + +target_link_libraries(${PROJECT_NAME} PRIVATE + Qt::Core + Qt::Gui + Qt::GuiPrivate + Qt::Qml + Qt::Quick + Qt::QuickPrivate +) + +if(${PROJECT_NAME} STREQUAL ${CMAKE_PROJECT_NAME}) + set(INSTALL_DIR ${QT_DIR}/../../../plugins/platforminputcontexts) +else() + set(INSTALL_DIR ${CMAKE_INSTALL_BINDIR}/platforminputcontexts) + set_target_properties(${PROJECT_NAME} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY "$/platforminputcontexts" + ) +endif() + +install(TARGETS ${PROJECT_NAME} + LIBRARY DESTINATION ${INSTALL_DIR} +) diff --git a/src/qml/EnterKey.qml b/src/qml/EnterKey.qml index 79d712d..84a8c2a 100644 --- a/src/qml/EnterKey.qml +++ b/src/qml/EnterKey.qml @@ -9,6 +9,6 @@ Key { btnText: "\n" btnDisplayedText: InputPanel.enterIcon === "" ? "Enter" : "" btnIcon: InputPanel.enterIcon === "" ? "" : InputPanel.enterIcon - enabled: InputContext.focusItemHasEnterKeyAction(InputContext.inputItem) ? InputContext.inputItem.EnterKeyAction.enabled : true + enabled: InputContext.inputItem?.EnterKeyAction.enabled ?? true opacity: enabled ? 1 : 0.5 } diff --git a/src/qml/InputPanel.qml b/src/qml/InputPanel.qml index 5883ecf..7712631 100644 --- a/src/qml/InputPanel.qml +++ b/src/qml/InputPanel.qml @@ -127,8 +127,12 @@ Item { } target: InputEngine - onInputModeChanged: refreshLayouts() - onIsSymbolModeChanged: refreshLayouts() + function onInputModeChanged() { + refreshLayouts() + } + function onIsSymbolModeChanged() { + refreshLayouts() + } } }