From 552de3e0d511dfbd0f334fcc8e90f04c646ce515 Mon Sep 17 00:00:00 2001 From: Simon Quigley Date: Sat, 12 Aug 2023 23:15:16 -0500 Subject: [PATCH] Allow a build with Qt 6 --- CMakeLists.txt | 65 ++++++++++++----------- src/dbusaddressable.cpp | 2 +- src/dbusaddressable.h | 3 +- src/main.cpp | 3 +- src/mainwindow.cpp | 1 + src/tabwidget.cpp | 1 + src/terminalconfig.cpp | 4 +- src/termwidget.h | 7 ++- src/third-party/qxtglobalshortcut_p.h | 2 +- src/third-party/qxtglobalshortcut_x11.cpp | 6 +-- test/CMakeLists.txt | 21 +++++++- 11 files changed, 72 insertions(+), 43 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e0ca0258..5d57d3f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,24 +21,23 @@ endif() # we need qpa/qplatformnativeinterface.h for global shortcut # Minimum Versions -set(LXQTBT_MINIMUM_VERSION "0.13.0") -set(QTERMWIDGET_MINIMUM_VERSION "1.4.0") -set(QT_MINIMUM_VERSION "5.15.0") - -find_package(Qt5Gui ${QT_MINIMUM_VERSION} REQUIRED) -find_package(Qt5LinguistTools ${QT_MINIMUM_VERSION} REQUIRED) -find_package(Qt5Widgets ${QT_MINIMUM_VERSION} REQUIRED) +set(LXQTBT_MINIMUM_VERSION "2.0.0") +set(QT_MINIMUM_VERSION "6.3.0") +set(QT_MAJOR_VERSION "6") + +find_package(Qt6Core ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt6Gui ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt6LinguistTools ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt6Widgets ${QT_MINIMUM_VERSION} REQUIRED) if(UNIX) - find_package(Qt5DBus ${QT_MINIMUM_VERSION} REQUIRED) - if (NOT APPLE) - find_package(Qt5X11Extras ${QT_MINIMUM_VERSION} REQUIRED) - endif (NOT APPLE) + find_package(Qt6DBus ${QT_MINIMUM_VERSION} REQUIRED) + find_package(Qt6 COMPONENTS Core Core5Compat REQUIRED) endif() -find_package(QTermWidget5 ${QTERMWIDGET_MINIMUM_VERSION} REQUIRED) -find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) +find_package(QTermWidget6 ${QTERMWIDGET_MINIMUM_VERSION} REQUIRED) +find_package(lxqt2-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) if (BUILD_TESTS) - find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test) + find_package(Qt6 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test) endif() include(LXQtPreventInSourceBuilds) @@ -47,13 +46,17 @@ pkg_check_modules(LIBCANBERRA libcanberra) include(LXQtTranslateTs) include(LXQtTranslateDesktop) include(LXQtCompilerSettings NO_POLICY_SCOPE) -message(STATUS "Qt version: ${Qt5Core_VERSION}") +message(STATUS "Qt version: ${Qt6Core_VERSION}") # TODO remove Qxt message(STATUS "Using bundled Qxt...") set(QXT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party") +find_path(QTERMWIDGET6_INCLUDE_DIR NAMES qtermwidget6/qtermwidget.h) +add_definitions(-DUSE_QTERMWIDGET6) +include_directories(${QTERMWIDGET6_INCLUDE_DIR}) + if(APPLE) find_library(CARBON_LIBRARY Carbon REQUIRED) message(STATUS "CARBON_LIBRARY: ${CARBON_LIBRARY}") @@ -98,14 +101,15 @@ set(QTERM_MOC_SRC src/tab-switcher.h ) -if (Qt5DBus_FOUND) +if (Qt6DBus_FOUND) add_definitions(-DHAVE_QDBUS) - QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Window.xml mainwindow.h MainWindow) - QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Tab.xml termwidgetholder.h TermWidgetHolder) - QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Terminal.xml termwidget.h TermWidget) - QT5_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Process.xml qterminalapp.h QTerminalApp) + QT6_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Window.xml mainwindow.h MainWindow) + QT6_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Tab.xml termwidgetholder.h TermWidgetHolder) + QT6_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Terminal.xml termwidget.h TermWidget) + QT6_ADD_DBUS_ADAPTOR(QTERM_SRC src/org.lxqt.QTerminal.Process.xml qterminalapp.h QTerminalApp) + set(QTERM_MOC_SRC ${QTERM_MOC_SRC} src/dbusaddressable.h) - message(STATUS "Building with Qt5DBus support") + message(STATUS "Building with Qt6DBus support") endif() if(NOT QXT_FOUND) @@ -132,9 +136,10 @@ set(QTERM_RCC_SRC src/icons.qrc ) -qt5_wrap_ui( QTERM_UI ${QTERM_UI_SRC} ) -qt5_wrap_cpp( QTERM_MOC ${QTERM_MOC_SRC} ) -qt5_add_resources( QTERM_RCC ${QTERM_RCC_SRC} ) +qt6_wrap_ui( QTERM_UI ${QTERM_UI_SRC} ) +qt6_wrap_cpp( QTERM_MOC ${QTERM_MOC_SRC} ) +qt6_add_resources( QTERM_RCC ${QTERM_RCC_SRC} ) + lxqt_translate_ts(QTERM_QM UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} @@ -202,22 +207,22 @@ add_executable(${EXE_NAME} ${GUI_TYPE} ) target_link_libraries(${EXE_NAME} - Qt5::Gui - qtermwidget5 + Qt6::Core + Qt6::Gui + Qt6::Widgets + qtermwidget6 util ) if(QXT_FOUND) target_link_libraries(${EXE_NAME} ${QXT_CORE_LIB} ${QXT_GUI_LIB}) endif() -if (Qt5DBus_FOUND) - target_link_libraries(${EXE_NAME} ${Qt5DBus_LIBRARIES}) +if (Qt6DBus_FOUND) + target_link_libraries(${EXE_NAME} ${Qt6DBus_LIBRARIES}) endif() if(APPLE) target_link_libraries(${EXE_NAME} ${CARBON_LIBRARY}) -elseif(UNIX) - target_link_libraries(${EXE_NAME} Qt5::X11Extras) endif() if(X11_FOUND) diff --git a/src/dbusaddressable.cpp b/src/dbusaddressable.cpp index b03a4f2f..54754e29 100644 --- a/src/dbusaddressable.cpp +++ b/src/dbusaddressable.cpp @@ -20,6 +20,6 @@ DBusAddressable::DBusAddressable(const QString& prefix) { #ifdef HAVE_QDBUS QString uuidString = QUuid::createUuid().toString(); - m_path = prefix + QLatin1Char('/') + uuidString.replace(QRegExp(QStringLiteral("[\\{\\}\\-]")), QString()); + m_path = prefix + QLatin1Char('/') + uuidString.replace(QRegularExpression(QStringLiteral("[\\{\\}\\-]")), QString()); #endif } diff --git a/src/dbusaddressable.h b/src/dbusaddressable.h index 430f713b..b3463eab 100644 --- a/src/dbusaddressable.h +++ b/src/dbusaddressable.h @@ -1,6 +1,7 @@ #ifndef DBUSADDRESSABLE_H #define DBUSADDRESSABLE_H +#include #include #ifdef HAVE_QDBUS #include @@ -31,4 +32,4 @@ template void registerAdapter(WClass *obj) #endif -#endif \ No newline at end of file +#endif diff --git a/src/main.cpp b/src/main.cpp index f436749d..8b456298 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -168,7 +168,6 @@ int main(int argc, char *argv[]) // icons /* setup our custom icon theme if there is no system theme (OS X, Windows) */ - QCoreApplication::instance()->setAttribute(Qt::AA_UseHighDpiPixmaps); //Fix for High-DPI systems if (QIcon::themeName().isEmpty()) QIcon::setThemeName(QStringLiteral("QTerminal")); @@ -176,7 +175,7 @@ int main(int argc, char *argv[]) // install the translations built-into Qt itself QTranslator qtTranslator; - qtTranslator.load(QStringLiteral("qt_") + QLocale::system().name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath)); + qtTranslator.load(QStringLiteral("qt_") + QLocale::system().name(), QLibraryInfo::path(QLibraryInfo::TranslationsPath)); app->installTranslator(&qtTranslator); QTranslator translator; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 44f9d27c..479d037b 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef HAVE_QDBUS #include diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 31bbc41a..213df2ed 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include "mainwindow.h" #include "termwidgetholder.h" diff --git a/src/terminalconfig.cpp b/src/terminalconfig.cpp index 5e30ce88..552a4158 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -80,14 +80,14 @@ TerminalConfig TerminalConfig::fromDbus(const QHash &termArgsC static QString variantToString(const QVariant& variant, QString &defaultVal) { - if (variant.type() == QVariant::String) + if (variant.typeId() == QMetaType::type("QString")) return qvariant_cast(variant); return defaultVal; } static QStringList variantToStringList(const QVariant& variant, QStringList &defaultVal) { - if (variant.type() == QVariant::StringList) + if (variant.typeId() == QMetaType::type("QStringList")) return qvariant_cast(variant); return defaultVal; } diff --git a/src/termwidget.h b/src/termwidget.h index 75600b73..907bc531 100644 --- a/src/termwidget.h +++ b/src/termwidget.h @@ -19,7 +19,12 @@ #ifndef TERMWIDGET_H #define TERMWIDGET_H -#include +#ifdef USE_QTERMWIDGET5 + #include +#elif defined(USE_QTERMWIDGET6) + #include +#endif + #include "terminalconfig.h" #include diff --git a/src/third-party/qxtglobalshortcut_p.h b/src/third-party/qxtglobalshortcut_p.h index 45cc2b2f..6d0e3c2e 100644 --- a/src/third-party/qxtglobalshortcut_p.h +++ b/src/third-party/qxtglobalshortcut_p.h @@ -58,7 +58,7 @@ class QxtGlobalShortcutPrivate : public QxtPrivate static bool error; #ifndef Q_OS_MAC static int ref; - bool nativeEventFilter(const QByteArray & eventType, void * message, long * result) override; + bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result); #endif static void activateShortcut(quint32 nativeKey, quint32 nativeMods); diff --git a/src/third-party/qxtglobalshortcut_x11.cpp b/src/third-party/qxtglobalshortcut_x11.cpp index ecaf5c34..5ace2752 100644 --- a/src/third-party/qxtglobalshortcut_x11.cpp +++ b/src/third-party/qxtglobalshortcut_x11.cpp @@ -38,7 +38,6 @@ #include #include -#include #include #include @@ -95,7 +94,8 @@ class QxtX11Data { public: QxtX11Data() { - m_display = QX11Info::display(); + auto *x11Application = qGuiApp->nativeInterface(); + m_display = x11Application ? x11Application->display() : nullptr; } bool isValid() @@ -149,7 +149,7 @@ class QxtX11Data { } // namespace bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType, - void *message, long *result) + void *message, qintptr *result) { Q_UNUSED(result); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 5f332a04..4df9caa3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,24 @@ -qt5_wrap_cpp(QTERM_TEST_MOC qterminal_test.h) +# Check if QT_MAJOR_VERSION was not defined +if(NOT DEFINED QT_MAJOR_VERSION) + message(FATAL_ERROR "QT_MAJOR_VERSION not set.") +endif() + +# Use appropriate wrap_cpp command based on QT_MAJOR_VERSION +if("${QT_MAJOR_VERSION}" STREQUAL "5") + qt5_wrap_cpp(QTERM_TEST_MOC qterminal_test.h) + set(QT_TEST_LIB Qt5::Test) +elseif("${QT_MAJOR_VERSION}" STREQUAL "6") + qt6_wrap_cpp(QTERM_TEST_MOC qterminal_test.h) + set(QT_TEST_LIB Qt6::Test) +else() + message(FATAL_ERROR "Unsupported QT_MAJOR_VERSION: ${QT_MAJOR_VERSION}") +endif() + add_executable(qterminal_test qterminal_test.cpp ${CMAKE_SOURCE_DIR}/src/qterminalutils.cpp ${QTERM_TEST_MOC}) -target_link_libraries(qterminal_test Qt5::Test) + +target_link_libraries(qterminal_test ${QT_TEST_LIB}) + add_test(NAME qterminal_test COMMAND qterminal_test)