Skip to content

Commit

Permalink
feat: compile with CMake
Browse files Browse the repository at this point in the history
The QML files are loaded along with the plugin now, so there is no need
to place them inside the Qt folder.
The plugin will be installed alongside any executables inside the proper
folder, if this cmake project is inside another one. To load it at
runtime use:

qputenv("QT_IM_MODULE", QByteArray("cutekeyboard"));
QCoreApplication::addLibraryPath(QCoreApplication::applicationDirPath());

So the application will look for any plugins in its root directory.
  • Loading branch information
henrique-jung-isi authored and AndreaRicchi committed Jan 24, 2024
1 parent fe7f347 commit adfa633
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 3 deletions.
24 changes: 24 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
35 changes: 35 additions & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
1 change: 1 addition & 0 deletions example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
100 changes: 100 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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 "$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/platforminputcontexts"
)
endif()

install(TARGETS ${PROJECT_NAME}
LIBRARY DESTINATION ${INSTALL_DIR}
)
2 changes: 1 addition & 1 deletion src/qml/EnterKey.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
8 changes: 6 additions & 2 deletions src/qml/InputPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,12 @@ Item {
}

target: InputEngine
onInputModeChanged: refreshLayouts()
onIsSymbolModeChanged: refreshLayouts()
function onInputModeChanged() {
refreshLayouts()
}
function onIsSymbolModeChanged() {
refreshLayouts()
}
}

}
Expand Down

0 comments on commit adfa633

Please sign in to comment.