342 lines
15 KiB
Diff
342 lines
15 KiB
Diff
From 4386f2ae8cb329077b7767d9121abba5ee38ed7b Mon Sep 17 00:00:00 2001
|
|
From: Maxime Roussin-Belanger <maxime.roussinbelanger@gmail.com>
|
|
Date: Sun, 16 Jun 2024 22:52:25 -0400
|
|
Subject: [PATCH] cmake: add Qt6 support
|
|
|
|
Upstream-Status: Pending
|
|
Signed-off-by: Andreas Cord-Landwehr <cordlandwehr@kde.org>
|
|
---
|
|
CMakeLists.txt | 47 ++++++++++++-------
|
|
plugins/pinyin/src/pinyinadapter.cpp | 3 +-
|
|
plugins/westernsupport/spellchecker.cpp | 12 +++--
|
|
.../westernlanguagefeatures.cpp | 2 +-
|
|
src/lib/models/key.h | 2 +-
|
|
src/lib/models/layout.cpp | 4 +-
|
|
src/lib/models/wordribbon.cpp | 4 +-
|
|
src/plugin/keyboardsettings.cpp | 1 +
|
|
src/view/abstracttexteditor.cpp | 26 +++++-----
|
|
9 files changed, 58 insertions(+), 43 deletions(-)
|
|
|
|
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
|
index 36a4e8f6..88bc641e 100644
|
|
--- a/CMakeLists.txt
|
|
+++ b/CMakeLists.txt
|
|
@@ -5,15 +5,11 @@ project(maliit-keyboard VERSION 2.3.1)
|
|
option(enable-presage "Use presage to calculate word candidates (maliit-keyboard-plugin only)" ON)
|
|
option(enable-hunspell "Use hunspell for error correction (maliit-keyboard-plugin only)" ON)
|
|
option(enable-tests "Build tests" ON)
|
|
+option(with-qt6 "Built with Qt 6 instead of Qt 5" OFF)
|
|
|
|
# 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")
|
|
@@ -29,11 +25,23 @@ find_package(MaliitPlugins 0.99.1 REQUIRED)
|
|
find_package(GLib2 REQUIRED)
|
|
find_package(GIO REQUIRED)
|
|
|
|
-find_package(Qt5DBus)
|
|
+if(with-qt6)
|
|
+ find_package(Qt6 6.0 REQUIRED COMPONENTS Core DBus Gui Quick QuickControls2 Core5Compat Multimedia)
|
|
+endif()
|
|
+
|
|
+if(Qt6_FOUND)
|
|
+ set(QT_VERSION_MAJOR 6)
|
|
+else()
|
|
+ find_package(Qt5 REQUIRED COMPONENTS Core DBus Gui Quick Multimedia Feedback)
|
|
+ set(QT_VERSION_MAJOR 5)
|
|
+endif()
|
|
+
|
|
+
|
|
+if(NOT DEFINED QT_QML_INSTALL_DIR)
|
|
+ set(QT_QML_INSTALL_DIR "${LIB_INSTALL_DIR}/qt${QT_VERSION_MAJOR}/qml" CACHE PATH
|
|
+ "Installation directory for Qt ${QT_VERSION_MAJOR} QML plugins [LIB_INSTALL_DIR/qt${QT_VERSION_MAJOR}/qml]")
|
|
+endif()
|
|
|
|
-find_package(Qt5QuickControls2 REQUIRED)
|
|
-find_package(Qt5Multimedia)
|
|
-find_package(Qt5Feedback)
|
|
find_package(Intl REQUIRED)
|
|
|
|
find_package(AnthyUnicode)
|
|
@@ -86,7 +94,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::Core)
|
|
set(maliit-keyboard-definitions HUNSPELL_DICT_PATH="${HUNSPELL_DICT_PATH}"
|
|
MALIIT_GETTEXT_PACKAGE="${PROJECT_NAME}"
|
|
MALIIT_LOCALE_DIR="${CMAKE_INSTALL_LOCALEDIR}/locale"
|
|
@@ -122,7 +130,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::Core Maliit::Plugins)
|
|
target_include_directories(maliit-keyboard-lib PUBLIC src/lib)
|
|
target_compile_definitions(maliit-keyboard-lib PRIVATE ${maliit-keyboard-definitions})
|
|
|
|
@@ -146,7 +154,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::Core ${GIO_LIBRARIES})
|
|
target_include_directories(gsettings-qt PUBLIC ${GIO_INCLUDE_DIRS} src/3rdparty)
|
|
target_compile_definitions(gsettings-qt PRIVATE -DQT_NO_KEYWORDS)
|
|
|
|
@@ -170,9 +178,9 @@ 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::DBus Qt::QuickControls2 Maliit::Plugins maliit-keyboard-lib maliit-keyboard-view gsettings-qt Qt::Multimedia ${Intl_LIBRARIES})
|
|
if (Qt5Feedback_FOUND)
|
|
- target_link_libraries(maliit-keyboard-common Qt5::Feedback)
|
|
+ target_link_libraries(maliit-keyboard-common Qt::Feedback)
|
|
target_compile_definitions(maliit-keyboard-common PUBLIC HAVE_QT5_FEEDBACK)
|
|
endif()
|
|
target_compile_definitions(maliit-keyboard-common PRIVATE ${maliit-keyboard-definitions})
|
|
@@ -285,7 +293,7 @@ function(abstract_language_plugin _language _full_language)
|
|
endif()
|
|
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::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
|
|
@@ -419,8 +427,11 @@ add_subdirectory(po)
|
|
# TODO add all tests
|
|
if(enable-tests)
|
|
enable_testing()
|
|
-
|
|
- find_package(Qt5Test)
|
|
+ if(Qt6_FOUND)
|
|
+ find_package(Qt6 6.0 REQUIRED COMPONENTS Test)
|
|
+ else()
|
|
+ find_package(Qt5 5.14 REQUIRED COMPONENTS Test)
|
|
+ endif()
|
|
|
|
add_library(test-utils STATIC
|
|
tests/unittests/common/inputmethodhostprobe.cpp
|
|
@@ -428,7 +439,7 @@ if(enable-tests)
|
|
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::Core Qt::Gui Qt::Test westernsupport)
|
|
target_include_directories(test-utils PUBLIC tests/unittests tests/unittests/common src src/lib)
|
|
|
|
function(create_test name)
|
|
diff --git a/plugins/pinyin/src/pinyinadapter.cpp b/plugins/pinyin/src/pinyinadapter.cpp
|
|
index f31a00c8..ac81ba0d 100644
|
|
--- a/plugins/pinyin/src/pinyinadapter.cpp
|
|
+++ b/plugins/pinyin/src/pinyinadapter.cpp
|
|
@@ -25,10 +25,9 @@
|
|
#include <string>
|
|
#include <string.h>
|
|
|
|
+#include <QCoreApplication>
|
|
#include <QDebug>
|
|
#include <QLoggingCategory>
|
|
-#include <QCoreApplication>
|
|
-#include <QRegExp>
|
|
|
|
#define MAX_SUGGESTIONS 100
|
|
|
|
diff --git a/plugins/westernsupport/spellchecker.cpp b/plugins/westernsupport/spellchecker.cpp
|
|
index d55eeb35..f7563027 100644
|
|
--- a/plugins/westernsupport/spellchecker.cpp
|
|
+++ b/plugins/westernsupport/spellchecker.cpp
|
|
@@ -52,12 +52,12 @@ private:
|
|
};
|
|
#endif
|
|
|
|
-#include <QFile>
|
|
-#include <QTextStream>
|
|
-#include <QTextCodec>
|
|
-#include <QStringList>
|
|
#include <QDebug>
|
|
#include <QDir>
|
|
+#include <QFile>
|
|
+#include <QStringList>
|
|
+#include <QTextStream>
|
|
+#include <QtCore5Compat/QTextCodec>
|
|
|
|
//! \class SpellChecker
|
|
//! Checks spelling and suggest words. Currently Spellchecker is
|
|
@@ -304,7 +304,9 @@ 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::GenericDataLocation) +
|
|
+ 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;
|
|
|
|
diff --git a/plugins/westernsupport/westernlanguagefeatures.cpp b/plugins/westernsupport/westernlanguagefeatures.cpp
|
|
index 6ed6d0e8..c525678e 100644
|
|
--- a/plugins/westernsupport/westernlanguagefeatures.cpp
|
|
+++ b/plugins/westernsupport/westernlanguagefeatures.cpp
|
|
@@ -58,7 +58,7 @@ bool WesternLanguageFeatures::activateAutoCaps(const QString &preedit) const
|
|
return false;
|
|
}
|
|
|
|
- if (sentenceBreak.contains(preedit.mid(preedit.length() - 2, 1)) && preedit.at(preedit.count() - 1).isSpace()) {
|
|
+ if (sentenceBreak.contains(preedit.mid(preedit.length() - 2, 1)) && preedit.at(preedit.size() - 1).isSpace()) {
|
|
return true;
|
|
}
|
|
|
|
diff --git a/src/lib/models/key.h b/src/lib/models/key.h
|
|
index 5695cc1c..1f4380ba 100644
|
|
--- a/src/lib/models/key.h
|
|
+++ b/src/lib/models/key.h
|
|
@@ -94,7 +94,7 @@ private:
|
|
QString m_command_sequence;
|
|
|
|
public:
|
|
- explicit Key();
|
|
+ Key();
|
|
|
|
// read-only properties:
|
|
bool valid() const;
|
|
diff --git a/src/lib/models/layout.cpp b/src/lib/models/layout.cpp
|
|
index 304064e5..375cf840 100644
|
|
--- a/src/lib/models/layout.cpp
|
|
+++ b/src/lib/models/layout.cpp
|
|
@@ -257,7 +257,7 @@ int Layout::rowCount(const QModelIndex &parent) const
|
|
{
|
|
Q_UNUSED(parent)
|
|
Q_D(const Layout);
|
|
- return d->key_area.keys().count();
|
|
+ return d->key_area.keys().size();
|
|
}
|
|
|
|
|
|
@@ -267,7 +267,7 @@ QVariant Layout::data(const QModelIndex &index,
|
|
Q_D(const Layout);
|
|
|
|
const QVector<Key> &keys(d->key_area.keys());
|
|
- const Key &key(index.row() < keys.count()
|
|
+ const Key &key(index.row() < keys.size()
|
|
? keys.at(index.row())
|
|
: Key());
|
|
|
|
diff --git a/src/lib/models/wordribbon.cpp b/src/lib/models/wordribbon.cpp
|
|
index ba341535..ae6685e8 100644
|
|
--- a/src/lib/models/wordribbon.cpp
|
|
+++ b/src/lib/models/wordribbon.cpp
|
|
@@ -119,7 +119,7 @@ bool operator!=(const WordRibbon &lhs,
|
|
|
|
QVariant WordRibbon::data(const QModelIndex &index, int role) const
|
|
{
|
|
- if (index.row() < 0 || index.row() > m_candidates.count())
|
|
+ if (index.row() < 0 || index.row() > m_candidates.size())
|
|
return QVariant();
|
|
|
|
switch (role) {
|
|
@@ -182,7 +182,7 @@ void WordRibbon::onWordCandidatesChanged(const WordCandidateList &candidates)
|
|
qDebug() << "word ribbon: candidates changed";
|
|
clearCandidates();
|
|
|
|
- for (int index = 0; index < candidates.count(); ++index) {
|
|
+ for (int index = 0; index < candidates.size(); ++index) {
|
|
WordCandidate word_candidate(candidates.at(index));
|
|
appendCandidate(word_candidate);
|
|
}
|
|
diff --git a/src/plugin/keyboardsettings.cpp b/src/plugin/keyboardsettings.cpp
|
|
index f64af95f..c0a1bc72 100644
|
|
--- a/src/plugin/keyboardsettings.cpp
|
|
+++ b/src/plugin/keyboardsettings.cpp
|
|
@@ -31,6 +31,7 @@
|
|
|
|
#include <QDebug>
|
|
#include <QGSettings/QGSettings>
|
|
+#include <QVariant>
|
|
|
|
using namespace MaliitKeyboard;
|
|
|
|
diff --git a/src/view/abstracttexteditor.cpp b/src/view/abstracttexteditor.cpp
|
|
index bf7a69e1..e3db6441 100644
|
|
--- a/src/view/abstracttexteditor.cpp
|
|
+++ b/src/view/abstracttexteditor.cpp
|
|
@@ -34,6 +34,7 @@
|
|
#include "logic/abstractlanguagefeatures.h"
|
|
|
|
#include <QElapsedTimer>
|
|
+#include <QRegularExpression>
|
|
|
|
namespace MaliitKeyboard {
|
|
|
|
@@ -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();
|
|
@@ -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
|
|
@@ -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);
|
|
}
|
|
@@ -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;
|
|
}
|