diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ff952df..68453872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ set(QTERMINAL_VERSION "1.3.0") option(UPDATE_TRANSLATIONS "Update source translation translations/*.ts files" OFF) option(BUILD_TESTS "Builds tests" ON) +option(USE_QT6 "Build with Qt 6 instead of Qt 5" OFF) if(APPLE) option(APPLEBUNDLE "Build as qterminal.app bundle" ON) @@ -21,24 +22,38 @@ endif() # we need qpa/qplatformnativeinterface.h for global shortcut # Minimum Versions -set(LXQTBT_MINIMUM_VERSION "0.13.0") set(QTERMWIDGET_MINIMUM_VERSION "1.3.0") -set(QT_MINIMUM_VERSION "5.15.0") +if(NOT USE_QT6) + set(LXQTBT_MINIMUM_VERSION "0.13.0") + set(QT_MINIMUM_VERSION "5.15.0") + set(QT_MAJOR_VERSION "5") +else() + set(LXQTBT_MINIMUM_VERSION "2.0.0") + set(QT_MINIMUM_VERSION "6.3.0") + set(QT_MAJOR_VERSION "6") +endif() -find_package(Qt5Gui ${QT_MINIMUM_VERSION} REQUIRED) -find_package(Qt5LinguistTools ${QT_MINIMUM_VERSION} REQUIRED) -find_package(Qt5Widgets ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt${QT_MAJOR_VERSION}Core ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt${QT_MAJOR_VERSION}Gui ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt${QT_MAJOR_VERSION}LinguistTools ${QT_MINIMUM_VERSION} REQUIRED) +find_package(Qt${QT_MAJOR_VERSION}Widgets ${QT_MINIMUM_VERSION} REQUIRED) if(UNIX) - find_package(Qt5DBus ${QT_MINIMUM_VERSION} REQUIRED) - if (NOT APPLE) + find_package(Qt${QT_MAJOR_VERSION}DBus ${QT_MINIMUM_VERSION} REQUIRED) + if(NOT APPLE AND QT_MAJOR_VERSION EQUAL 5) find_package(Qt5X11Extras ${QT_MINIMUM_VERSION} REQUIRED) - endif (NOT APPLE) + elseif(QT_MAJOR_VERSION EQUAL 6) + find_package(Qt6 COMPONENTS Core Core5Compat REQUIRED) + endif() +endif() +find_package(QTermWidget${QT_MAJOR_VERSION} ${QTERMWIDGET_MINIMUM_VERSION} REQUIRED) +if(QT_MAJOR_VERSION EQUAL 5) + find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) +else() + find_package(lxqt2-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) endif() -find_package(QTermWidget5 ${QTERMWIDGET_MINIMUM_VERSION} REQUIRED) -find_package(lxqt-build-tools ${LXQTBT_MINIMUM_VERSION} REQUIRED) if (BUILD_TESTS) - find_package(Qt5 ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test) + find_package(Qt${QT_MAJOR_VERSION} ${QT_MINIMUM_VERSION} CONFIG REQUIRED Test) endif() include(LXQtPreventInSourceBuilds) @@ -47,13 +62,23 @@ pkg_check_modules(LIBCANBERRA libcanberra) include(LXQtTranslateTs) include(LXQtTranslateDesktop) include(LXQtCompilerSettings NO_POLICY_SCOPE) -message(STATUS "Qt version: ${Qt5Core_VERSION}") +message(STATUS "Qt version: ${Qt${QT_MAJOR_VERSION}Core_VERSION}") # TODO remove Qxt message(STATUS "Using bundled Qxt...") set(QXT_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/src/third-party") +if(QT_MAJOR_VERSION EQUAL 5) + find_path(QTERMWIDGET5_INCLUDE_DIR NAMES qtermwidget5/qtermwidget.h) + add_definitions(-DUSE_QTERMWIDGET5) + include_directories(${QTERMWIDGET5_INCLUDE_DIR}) +elseif(QT_MAJOR_VERSION EQUAL 6) + find_path(QTERMWIDGET6_INCLUDE_DIR NAMES qtermwidget6/qtermwidget.h) + add_definitions(-DUSE_QTERMWIDGET6) + include_directories(${QTERMWIDGET6_INCLUDE_DIR}) +endif() + if(APPLE) find_library(CARBON_LIBRARY Carbon REQUIRED) message(STATUS "CARBON_LIBRARY: ${CARBON_LIBRARY}") @@ -98,14 +123,24 @@ set(QTERM_MOC_SRC src/tab-switcher.h ) -if (Qt5DBus_FOUND) +if (Qt${QT_MAJOR_VERSION}DBus_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) + + macro(ADD_DBUS_ADAPTOR_FOR_VERSION) + if("${QT_MAJOR_VERSION}" STREQUAL "5") + QT5_ADD_DBUS_ADAPTOR(${ARGV}) + elseif("${QT_MAJOR_VERSION}" STREQUAL "6") + QT6_ADD_DBUS_ADAPTOR(${ARGV}) + endif() + endmacro() + + ADD_DBUS_ADAPTOR_FOR_VERSION(QTERM_SRC src/org.lxqt.QTerminal.Window.xml mainwindow.h MainWindow) + ADD_DBUS_ADAPTOR_FOR_VERSION(QTERM_SRC src/org.lxqt.QTerminal.Tab.xml termwidgetholder.h TermWidgetHolder) + ADD_DBUS_ADAPTOR_FOR_VERSION(QTERM_SRC src/org.lxqt.QTerminal.Terminal.xml termwidget.h TermWidget) + ADD_DBUS_ADAPTOR_FOR_VERSION(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 Qt${QT_MAJOR_VERSION}DBus support") endif() if(NOT QXT_FOUND) @@ -132,9 +167,34 @@ 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} ) +macro(WRAP_UI_FOR_VERSION) + if("${QT_MAJOR_VERSION}" STREQUAL "5") + qt5_wrap_ui(${ARGV}) + elseif("${QT_MAJOR_VERSION}" STREQUAL "6") + qt6_wrap_ui(${ARGV}) + endif() +endmacro() + +macro(WRAP_CPP_FOR_VERSION) + if("${QT_MAJOR_VERSION}" STREQUAL "5") + qt5_wrap_cpp(${ARGV}) + elseif("${QT_MAJOR_VERSION}" STREQUAL "6") + qt6_wrap_cpp(${ARGV}) + endif() +endmacro() + +macro(ADD_RESOURCES_FOR_VERSION) + if("${QT_MAJOR_VERSION}" STREQUAL "5") + qt5_add_resources(${ARGV}) + elseif("${QT_MAJOR_VERSION}" STREQUAL "6") + qt6_add_resources(${ARGV}) + endif() +endmacro() + +WRAP_UI_FOR_VERSION(QTERM_UI ${QTERM_UI_SRC}) +WRAP_CPP_FOR_VERSION(QTERM_MOC ${QTERM_MOC_SRC}) +ADD_RESOURCES_FOR_VERSION(QTERM_RCC ${QTERM_RCC_SRC}) + lxqt_translate_ts(QTERM_QM UPDATE_TRANSLATIONS ${UPDATE_TRANSLATIONS} @@ -202,21 +262,23 @@ add_executable(${EXE_NAME} ${GUI_TYPE} ) target_link_libraries(${EXE_NAME} - Qt5::Gui - qtermwidget5 + Qt${QT_MAJOR_VERSION}::Core + Qt${QT_MAJOR_VERSION}::Gui + Qt${QT_MAJOR_VERSION}::Widgets + qtermwidget${QT_MAJOR_VERSION} 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 (Qt${QT_MAJOR_VERSION}DBus_FOUND) + target_link_libraries(${EXE_NAME} ${Qt${QT_MAJOR_VERSION}DBus_LIBRARIES}) endif() if(APPLE) target_link_libraries(${EXE_NAME} ${CARBON_LIBRARY}) -elseif(UNIX) +elseif(UNIX AND QT_MAJOR_VERSION EQUAL 5) target_link_libraries(${EXE_NAME} Qt5::X11Extras) endif() 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 dee72544..8d63ced0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -169,7 +169,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")); @@ -177,7 +176,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 18042ef2..ecd01c1d 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 1497a298..46241365 100644 --- a/src/terminalconfig.cpp +++ b/src/terminalconfig.cpp @@ -82,14 +82,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 01c356ce..6d080d36 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)