Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qt6 support #235

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
63 changes: 40 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,48 @@ cmake_minimum_required(VERSION 3.9)

project(maliit-keyboard VERSION 2.3.1)

option(BUILD_WITH_QT6 "Enable build with Qt6" OFF)
cordlandwehr marked this conversation as resolved.
Show resolved Hide resolved
set(MALIIT_SUFFIX "")
if(BUILD_WITH_QT6)
find_package(Qt6 6.0 REQUIRED COMPONENTS Core Core5Compat QuickControls2)
find_package(Qt6DBus)
find_package(Qt6Multimedia)
endif()

if(Qt6_FOUND)
set(QT_VERSION_MAJOR 6)
set(MALIIT_SUFFIX "6")
message(STATUS "Building with Qt6")
else()
find_package(Qt5 5.14 REQUIRED COMPONENTS Core QuickControls2)
find_package(Qt5DBus)
find_package(Qt5Multimedia)
find_package(Qt5Feedback)
set(QT_VERSION_MAJOR 5)
message(STATUS "Building with Qt5")
endif()

option(enable-hunspell "Use hunspell for error correction (maliit-keyboard-plugin only)" ON)
option(enable-tests "Build tests" ON)

# Install paths
include(GNUInstallDirs)

if(NOT DEFINED QT5_QML_INSTALL_DIR)
set(QT5_QML_INSTALL_DIR "${LIB_INSTALL_DIR}/qt5/qml" CACHE PATH
"Installation directory for Qt 5 QML plugins [LIB_INSTALL_DIR/qt5/qml]")
endif()

set(HUNSPELL_DICT_PATH "/usr/share/hunspell" CACHE PATH "Directory containing hunspell dictionary files")
set(MALIIT_KEYBOARD_QML_DIR "${CMAKE_INSTALL_LIBDIR}/maliit/keyboard2/qml" CACHE PATH "Directory containing maliit-keyboard QML files")
set(MALIIT_KEYBOARD_DATA_DIR "${CMAKE_INSTALL_DATADIR}/maliit/keyboard2" CACHE PATH "Directory containing maliit-keyboard data files")
set(MALIIT_KEYBOARD_LANGUAGES_DIR "${CMAKE_INSTALL_LIBDIR}/maliit/keyboard2/languages" CACHE PATH "Directory containing maliit-keyboard data")
set(MALIIT_KEYBOARD_QML_DIR "${CMAKE_INSTALL_LIBDIR}/maliit${MALIIT_SUFFIX}/keyboard2/qml" CACHE PATH "Directory containing maliit-keyboard QML files")
set(MALIIT_KEYBOARD_DATA_DIR "${CMAKE_INSTALL_DATADIR}/maliit${MALIIT_SUFFIX}/keyboard2" CACHE PATH "Directory containing maliit-keyboard data files")
set(MALIIT_KEYBOARD_LANGUAGES_DIR "${CMAKE_INSTALL_LIBDIR}/maliit${MALIIT_SUFFIX}/keyboard2/languages" CACHE PATH "Directory containing maliit-keyboard data")

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
list(PREPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)

find_package(MaliitPlugins 0.99.1 REQUIRED)
find_package(Maliit${MALIIT_SUFFIX}Plugins 0.99.1 REQUIRED)

find_package(GLib2 REQUIRED)
find_package(GIO REQUIRED)

find_package(Qt5DBus)

find_package(Qt5QuickControls2 REQUIRED)
find_package(Qt5Multimedia)
find_package(Qt5Feedback)
find_package(Intl REQUIRED)

find_package(AnthyUnicode)
Expand Down Expand Up @@ -87,7 +98,7 @@ set(WESTERNSUPPORT_SOURCES

# TODO install logic/languageplugininterface.h and logic/abstractplugininterface.h as HEADERS

set(maliit-keyboard-libraries Qt5::Core)
set(maliit-keyboard-libraries Qt${QT_VERSION_MAJOR}::Core)
set(maliit-keyboard-definitions HUNSPELL_DICT_PATH="${HUNSPELL_DICT_PATH}"
MALIIT_GETTEXT_PACKAGE="${PROJECT_NAME}"
MALIIT_LOCALE_DIR="${CMAKE_INSTALL_LOCALEDIR}/locale"
Expand All @@ -105,7 +116,7 @@ if(enable-hunspell)
endif()

add_library(maliit-keyboard-lib STATIC ${MALIIT_KEYBOARD_LIB_SOURCES})
target_link_libraries(maliit-keyboard-lib Qt5::Core Maliit::Plugins)
target_link_libraries(maliit-keyboard-lib Qt${QT_VERSION_MAJOR}::Core Maliit::Plugins)
target_include_directories(maliit-keyboard-lib PUBLIC src/lib)
target_compile_definitions(maliit-keyboard-lib PRIVATE ${maliit-keyboard-definitions})

Expand All @@ -129,7 +140,7 @@ set(QGSETTINGS_SOURCES
src/3rdparty/QGSettings/util.h)

add_library(gsettings-qt STATIC ${QGSETTINGS_SOURCES})
target_link_libraries(gsettings-qt Qt5::Core ${GIO_LIBRARIES})
target_link_libraries(gsettings-qt Qt${QT_VERSION_MAJOR}::Core ${GIO_LIBRARIES})
target_include_directories(gsettings-qt PUBLIC ${GIO_INCLUDE_DIRS} src/3rdparty)
target_compile_definitions(gsettings-qt PRIVATE -DQT_NO_KEYWORDS)

Expand All @@ -153,7 +164,10 @@ set(MALIIT_KEYBOARD_COMMON_SOURCES
src/plugin/device.h)

add_library(maliit-keyboard-common STATIC ${MALIIT_KEYBOARD_COMMON_SOURCES})
target_link_libraries(maliit-keyboard-common Qt5::DBus Qt5::QuickControls2 Maliit::Plugins maliit-keyboard-lib maliit-keyboard-view gsettings-qt Qt5::Multimedia ${Intl_LIBRARIES})
target_link_libraries(maliit-keyboard-common Qt${QT_VERSION_MAJOR}::DBus Qt${QT_VERSION_MAJOR}::QuickControls2 Maliit::Plugins maliit-keyboard-lib maliit-keyboard-view gsettings-qt Qt${QT_VERSION_MAJOR}::Multimedia ${Intl_LIBRARIES})
if (BUILD_WITH_QT6)
target_link_libraries(maliit-keyboard-common Qt6::Core5Compat)
endif()
if (Qt5Feedback_FOUND)
target_link_libraries(maliit-keyboard-common Qt5::Feedback)
target_compile_definitions(maliit-keyboard-common PUBLIC HAVE_QT5_FEEDBACK)
Expand Down Expand Up @@ -183,6 +197,9 @@ target_compile_definitions(maliit-keyboard PRIVATE ${maliit-keyboard-definitions

add_library(westernsupport STATIC ${WESTERNSUPPORT_SOURCES})
target_link_libraries(westernsupport ${maliit-keyboard-libraries} Maliit::Plugins)
if (BUILD_WITH_QT6)
target_link_libraries(westernsupport Qt6::Core5Compat)
endif()
target_include_directories(westernsupport PUBLIC src/lib/logic plugins/westernsupport ${maliit-keyboard-include-dirs})
target_compile_definitions(westernsupport PRIVATE ${maliit-keyboard-definitions})

Expand Down Expand Up @@ -256,7 +273,7 @@ function(abstract_language_plugin _language _full_language)
endforeach()
add_library(${_target}plugin MODULE ${PLUGIN_SOURCES})
set_target_properties(${_target}plugin PROPERTIES OUTPUT_NAME ${_language}plugin)
target_link_libraries(${_target}plugin Qt5::Core Maliit::Plugins maliit-keyboard-common ${abstract_language_plugin_LIBRARIES})
target_link_libraries(${_target}plugin Qt${QT_VERSION_MAJOR}::Core Maliit::Plugins maliit-keyboard-common ${abstract_language_plugin_LIBRARIES})
target_include_directories(${_target}plugin PRIVATE src/lib/logic ${abstract_language_plugin_INCLUDE_DIRS})
target_compile_definitions(${_target}plugin PRIVATE ${abstract_language_plugin_DEFINITIONS})
install(TARGETS ${_target}plugin
Expand Down Expand Up @@ -360,7 +377,7 @@ install(FILES COPYING COPYING.BSD README.md
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/maliit-keyboard)

install(TARGETS maliit-keyboard-plugin maliit-keyboard
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/maliit/plugins
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}/maliit${MALIIT_SUFFIX}/plugins
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

install(DIRECTORY qml/keys qml/languages
Expand All @@ -385,15 +402,15 @@ add_subdirectory(po)
if(enable-tests)
enable_testing()

find_package(Qt5Test)
find_package(Qt${QT_VERSION_MAJOR}Test)

add_library(test-utils STATIC
tests/unittests/common/inputmethodhostprobe.cpp
tests/unittests/common/inputmethodhostprobe.h
tests/unittests/common/utils.cpp
tests/unittests/common/utils.h)

target_link_libraries(test-utils PUBLIC Maliit::Plugins Qt5::Core Qt5::Gui Qt5::Test westernsupport)
target_link_libraries(test-utils PUBLIC Maliit::Plugins Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Gui Qt${QT_VERSION_MAJOR}::Test westernsupport)
target_include_directories(test-utils PUBLIC tests/unittests tests/unittests/common src src/lib)

function(create_test name)
Expand Down
3 changes: 1 addition & 2 deletions plugins/pinyin/src/pinyinadapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
#include <string>
#include <string.h>

#include <QCoreApplication>
#include <QDebug>
#include <QLoggingCategory>
#include <QCoreApplication>
#include <QRegExp>

#define MAX_SUGGESTIONS 100

Expand Down
2 changes: 1 addition & 1 deletion plugins/westernsupport/spellchecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ bool SpellChecker::setLanguage(const QString &language)

d->aff_file = dictPath() + QDir::separator() + affMatches[0];
d->dic_file = dictPath() + QDir::separator() + dicMatches[0];
d->user_dictionary_file = QStandardPaths::writableLocation(QStandardPaths::DataLocation) + QDir::separator() + language + "_userDictionary.dic";
d->user_dictionary_file = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation) + QDir::separator() + language + "_userDictionary.dic";

qDebug() << "spellechecker.cpp in setLanguage() aff_file=" << d->aff_file << "dic_file=" << d->dic_file << "user dictionary=" << d->user_dictionary_file;

Expand Down
2 changes: 1 addition & 1 deletion plugins/westernsupport/spellpredictworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void SpellPredictWorker::setLanguage(QString locale, QString pluginPath)
{
// locale for secondary layouts I.E., dvorak will be formatted as locale@layout, swiss keyboard as "fr-ch"
// in this case we want to drop the layout portion
QStringList tmpLocales = locale.split(QRegExp("(@|\\-)"));
QStringList tmpLocales = locale.split(QRegularExpression("(@|\\-)"));
QString baseLocale;
if (tmpLocales.size() > 1) {
baseLocale = tmpLocales[0];
Expand Down
2 changes: 1 addition & 1 deletion src/lib/models/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Key
QString m_command_sequence;

public:
explicit Key();
Key();

// read-only properties:
bool valid() const;
Expand Down
1 change: 1 addition & 0 deletions src/plugin/keyboardsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "keyboardsettings.h"

#include <QDebug>
#include <QVariant>
#include <QGSettings/QGSettings>

using namespace MaliitKeyboard;
Expand Down
26 changes: 14 additions & 12 deletions src/view/abstracttexteditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "logic/abstractlanguagefeatures.h"

#include <QElapsedTimer>
#include <QRegularExpression>

namespace MaliitKeyboard {

Expand Down Expand Up @@ -392,7 +393,7 @@ void AbstractTextEditor::onKeyReleased(const Key &key)

if (d->preedit_enabled) {
if (!enablePreeditAtInsertion &&
(d->text->surroundingRight().left(1).contains(QRegExp(R"([\w])")) || email_detected)) {
(d->text->surroundingRight().left(1).contains(QRegularExpression(R"([\w])")) || email_detected)) {
// We're editing in the middle of a word or entering an email address, so just insert characters directly
d->text->appendToPreedit(text);
commitPreedit();
Expand Down Expand Up @@ -536,14 +537,14 @@ void AbstractTextEditor::onKeyReleased(const Key &key)
// a separator, and there isn't a separator immediately prior to a ')'
else if (look_for_a_double_space
&& not stopSequence.isEmpty()
&& textOnLeft.count() >= 2
&& textOnLeft.at(textOnLeft.count() - 1).isSpace()
&& !textOnLeft.at(textOnLeft.count() - 2).isSpace()
&& textOnLeftTrimmed.count() > 0
&& !d->word_engine->languageFeature()->isSeparator(textOnLeftTrimmed.at(textOnLeftTrimmed.count() - 1))
&& textOnLeft.size() >= 2
&& textOnLeft.at(textOnLeft.size() - 1).isSpace()
&& !textOnLeft.at(textOnLeft.size() - 2).isSpace()
&& textOnLeftTrimmed.size() > 0
&& !d->word_engine->languageFeature()->isSeparator(textOnLeftTrimmed.at(textOnLeftTrimmed.size() - 1))
&& !(textOnLeftTrimmed.endsWith(QLatin1String(")"))
&& textOnLeftTrimmed.count() > 1
&& d->word_engine->languageFeature()->isSeparator(textOnLeftTrimmed.at(textOnLeftTrimmed.count() - 2)))) {
&& textOnLeftTrimmed.size() > 1
&& d->word_engine->languageFeature()->isSeparator(textOnLeftTrimmed.at(textOnLeftTrimmed.size() - 2)))) {
removeTrailingWhitespaces();
if (!d->word_engine->languageFeature()->commitOnSpace()) {
// Commit when inserting a fullstop if we don't insert on spaces
Expand Down Expand Up @@ -1180,7 +1181,7 @@ void AbstractTextEditor::sendKeySequence(const QString &action, const QKeySequen
const int modifiers = actionSequence[i] & AllModifiers;
QString text("");
if (modifiers == Qt::NoModifier || modifiers == Qt::ShiftModifier) {
text = QString(key);
text = QString::number(key);
}
sendKeyPressAndReleaseEvents(key, static_cast<Qt::KeyboardModifiers>(modifiers), text);
}
Expand Down Expand Up @@ -1240,15 +1241,16 @@ void AbstractTextEditor::checkPreeditReentry(bool uncommittedDelete)
} else {
lastChar = text()->surrounding().at(currentOffset-1);
}
if(!QRegExp(R"(\W+)").exactMatch(lastChar) && !d->word_engine->languageFeature()->isSymbol(lastChar)) {
QStringList leftWords = text()->surroundingLeft().trimmed().split(QRegExp(R"([\s\d]+)"));
if (!QRegularExpression(R"(\W+)").match(lastChar).hasMatch() &&
!d->word_engine->languageFeature()->isSymbol(lastChar)) {
QStringList leftWords = text()->surroundingLeft().trimmed().split(QRegularExpression (R"([\s\d]+)"));
int trimDiff = text()->surroundingLeft().size() - text()->surroundingLeft().trimmed().size();
if(leftWords.last().isEmpty()) {
// If removed char was punctuation trimming will result in an empty entry
leftWords.removeLast();
trimDiff += 1;
}
if(d->text->surroundingRight().left(1).contains(QRegExp(R"([\w])"))) {
if(d->text->surroundingRight().left(1).contains(QRegularExpression (R"([\w])"))) {
// Don't enter pre-edit in the middle of a word
return;
}
Expand Down
8 changes: 5 additions & 3 deletions tests/unittests/common/inputmethodhostprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void InputMethodHostProbe::sendPreeditString(const QString &string,
m_last_cursor_pos = cursor_pos;
}

QKeyEvent InputMethodHostProbe::lastKeyEvent() const
const KeyEvent & InputMethodHostProbe::lastKeyEvent() const
{
return m_last_key_event;
}
Expand All @@ -112,9 +112,11 @@ int InputMethodHostProbe::keyEventCount() const

void InputMethodHostProbe::sendKeyEvent(const QKeyEvent& event, Maliit::EventRequestType)
{
m_last_key_event = event;
m_last_key_event.m_type = event.type();
m_last_key_event.m_key = event.key();
m_last_key_event.m_modifiers = event.modifiers();
++m_key_event_count;
Q_EMIT keyEventSent(m_last_key_event);
Q_EMIT keyEventSent(m_last_key_event.m_type, m_last_key_event.m_key, m_last_key_event.m_modifiers);
}

QList<Maliit::PreeditTextFormat> InputMethodHostProbe::lastPreeditTextFormatList() const
Expand Down
38 changes: 32 additions & 6 deletions tests/unittests/common/inputmethodhostprobe.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@

#include <QKeyEvent>

class KeyEvent {
public:
KeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers)
: m_type(type)
, m_key(key)
, m_modifiers(modifiers)
{
}
const inline QEvent::Type type() const {
return m_type;
}
const inline int key() const {
return m_key;
}
const inline Qt::KeyboardModifiers modifiers() const {
return m_modifiers;
}

private:
QEvent::Type m_type;
int m_key;
Qt::KeyboardModifiers m_modifiers;

friend class InputMethodHostProbe;
};

class InputMethodHostProbe
: public MAbstractInputMethodHost
{
Expand All @@ -45,7 +71,7 @@ class InputMethodHostProbe
private:
QString m_commit_string_history;
QString m_last_preedit_string;
QKeyEvent m_last_key_event;
KeyEvent m_last_key_event;
int m_key_event_count;
QList<Maliit::PreeditTextFormat> m_last_preedit_text_format_list;
int m_last_replace_start;
Expand All @@ -60,7 +86,7 @@ class InputMethodHostProbe
void sendCommitString(const QString &string,
int replace_start,
int replace_length,
int cursor_pos);
int cursor_pos) override;

QString lastPreeditString() const;
int lastReplaceStart() const;
Expand All @@ -71,14 +97,14 @@ class InputMethodHostProbe
const QList<Maliit::PreeditTextFormat> &format,
int replace_start,
int replace_length,
int cursor_pos);
int cursor_pos) override;

QKeyEvent lastKeyEvent() const;
const KeyEvent & lastKeyEvent() const;
int keyEventCount() const;
void sendKeyEvent(const QKeyEvent& event, Maliit::EventRequestType);
void sendKeyEvent(const QKeyEvent& event, Maliit::EventRequestType) override;
QList<Maliit::PreeditTextFormat> lastPreeditTextFormatList() const;

Q_SIGNAL void keyEventSent(QKeyEvent ev);
Q_SIGNAL void keyEventSent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers);

// unused reimpl
int contentType(bool&) override {return 0;}
Expand Down
24 changes: 15 additions & 9 deletions tests/unittests/ut_repeat-backspace/ut_repeat-backspace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,21 @@ class TestRepeatBackspace

QCOMPARE(host->keyEventCount(), 0);

TestUtils::waitForSignal(host.data(), SIGNAL(keyEventSent(QKeyEvent)));
QCOMPARE(host->keyEventCount(), 2);
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyRelease);
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));

TestUtils::waitForSignal(host.data(), SIGNAL(keyEventSent(QKeyEvent)));
QCOMPARE(host->keyEventCount(), 4);
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyRelease);
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
{
QSignalSpy spy(host.data(), &InputMethodHostProbe::keyEventSent);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(host->keyEventCount(), 2);
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyRelease);
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
}

{
QSignalSpy spy(host.data(), &InputMethodHostProbe::keyEventSent);
QTRY_VERIFY(spy.count() > 0);
QCOMPARE(host->keyEventCount(), 4);
QCOMPARE(host->lastKeyEvent().type(), QEvent::KeyRelease);
QCOMPARE(host->lastKeyEvent().key(), int(Qt::Key_Backspace));
}

(editor.data()->*finalize)(backspace);

Expand Down