Skip to content

Commit

Permalink
Allow a build with Qt 6
Browse files Browse the repository at this point in the history
  • Loading branch information
tsimonq2 authored and yan12125 committed Apr 19, 2024
1 parent 05a0b64 commit 31936ae
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 43 deletions.
65 changes: 35 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}")
Expand Down Expand Up @@ -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)
Expand All @@ -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}
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/dbusaddressable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 2 additions & 1 deletion src/dbusaddressable.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef DBUSADDRESSABLE_H
#define DBUSADDRESSABLE_H

#include <QRegularExpression>
#include <QString>
#ifdef HAVE_QDBUS
#include <QtDBus/QtDBus>
Expand Down Expand Up @@ -31,4 +32,4 @@ template <class AClass, class WClass> void registerAdapter(WClass *obj)
#endif


#endif
#endif
3 changes: 1 addition & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,14 @@ 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"));

// translations

// 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;
Expand Down
1 change: 1 addition & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <QTimer>
#include <functional>
#include <QGuiApplication>
#include <QActionGroup>

#ifdef HAVE_QDBUS
#include <QtDBus/QtDBus>
Expand Down
1 change: 1 addition & 0 deletions src/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <QColorDialog>
#include <QMouseEvent>
#include <QMenu>
#include <QActionGroup>

#include "mainwindow.h"
#include "termwidgetholder.h"
Expand Down
4 changes: 2 additions & 2 deletions src/terminalconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ TerminalConfig TerminalConfig::fromDbus(const QHash<QString,QVariant> &termArgsC

static QString variantToString(const QVariant& variant, QString &defaultVal)
{
if (variant.type() == QVariant::String)
if (variant.typeId() == QMetaType::type("QString"))
return qvariant_cast<QString>(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<QStringList>(variant);
return defaultVal;
}
Expand Down
7 changes: 6 additions & 1 deletion src/termwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@
#ifndef TERMWIDGET_H
#define TERMWIDGET_H

#include <qtermwidget.h>
#ifdef USE_QTERMWIDGET5
#include <qtermwidget5/qtermwidget.h>
#elif defined(USE_QTERMWIDGET6)
#include <qtermwidget6/qtermwidget.h>
#endif

#include "terminalconfig.h"

#include <QAction>
Expand Down
2 changes: 1 addition & 1 deletion src/third-party/qxtglobalshortcut_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class QxtGlobalShortcutPrivate : public QxtPrivate<QxtGlobalShortcut>
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);
Expand Down
6 changes: 3 additions & 3 deletions src/third-party/qxtglobalshortcut_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <QGuiApplication>
#include <QVector>
#include <QtX11Extras/QX11Info>

#include <xcb/xcb.h>
#include <X11/Xlib.h>
Expand Down Expand Up @@ -95,7 +94,8 @@ class QxtX11Data {
public:
QxtX11Data()
{
m_display = QX11Info::display();
auto *x11Application = qGuiApp->nativeInterface<QNativeInterface::QX11Application>();
m_display = x11Application ? x11Application->display() : nullptr;
}

bool isValid()
Expand Down Expand Up @@ -149,7 +149,7 @@ class QxtX11Data {
} // namespace

bool QxtGlobalShortcutPrivate::nativeEventFilter(const QByteArray & eventType,
void *message, long *result)
void *message, qintptr *result)
{
Q_UNUSED(result);

Expand Down
21 changes: 19 additions & 2 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 31936ae

Please sign in to comment.