Add support for Qt6

This commit is contained in:
Cacodemon345 2021-12-31 16:47:49 +06:00
parent 9b8650cae5
commit 17e657f0ee
10 changed files with 49 additions and 20 deletions

View File

@ -130,6 +130,11 @@ cmake_dependent_option(VGAWONDER "ATI VGA Wonder (ATI-18800)"
cmake_dependent_option(VNC "VNC renderer" OFF "DEV_BRANCH" OFF)
cmake_dependent_option(XL24 "ATI VGA Wonder XL24 (ATI-28800-6)" ON "DEV_BRANCH" OFF)
# Ditto but for Qt
if (QT)
option(USE_QT6 "Use Qt6 instead of Qt5" OFF)
endif()
# Determine the build type
set(RELEASE_BUILD OFF)
set(BETA_BUILD OFF)

View File

@ -75,22 +75,31 @@ if(APPLE)
# Force using the newest library if it's installed by homebrew
set(CMAKE_FIND_FRAMEWORK LAST)
# setting our compilation target to macOS 10.13 High Sierra
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
# setting our compilation target to macOS 10.15 Catalina if targetting Qt6, macOS 10.13 High Sierra otherwise
if (USE_QT6)
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.15")
else()
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13")
endif()
endif()
if(QT)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (USE_QT6)
set(QT_MAJOR 6)
else()
set(QT_MAJOR 5)
endif()
# if we want to use qt5-static to eliminate need for bundling qt dlls (windows)
#set(QT_STATIC ON)
# needed to build with qt5-static if both qt5 and qt5-static are installed
#set(CMAKE_PREFIX_PATH "path/to/qt5-static")
find_package(Qt5 COMPONENTS Core Widgets REQUIRED)
find_package(Qt5LinguistTools REQUIRED)
find_package(Qt${QT_MAJOR} COMPONENTS Core Widgets OpenGL REQUIRED)
find_package(Qt${QT_MAJOR}LinguistTools REQUIRED)
endif()
find_package(Freetype REQUIRED)
@ -178,7 +187,7 @@ if(APPLE)
if (QT)
# needed for Qt packaging
# get the macdeployqt path
get_target_property(_qmake_executable Qt5::qmake IMPORTED_LOCATION)
get_target_property(_qmake_executable Qt${QT_MAJOR}::qmake IMPORTED_LOCATION)
get_filename_component(_qt_bin_dir "${_qmake_executable}" DIRECTORY)
find_program(MACDEPLOYQT_EXECUTABLE macdeployqt HINTS "${_qt_bin_dir}")

View File

@ -125,22 +125,23 @@ endif()
target_link_libraries(
plat
PRIVATE
Qt5::Widgets
Qt5::Gui
Qt${QT_MAJOR}::Widgets
Qt${QT_MAJOR}::Gui
Threads::Threads
)
target_link_libraries(
ui
PRIVATE
Qt5::Widgets
Qt5::Gui
Qt${QT_MAJOR}::Widgets
Qt${QT_MAJOR}::Gui
Qt${QT_MAJOR}::OpenGL
Threads::Threads
)
# needed for static builds
if (WIN32)
qt_import_plugins(plat INCLUDE Qt5::QWindowsIntegrationPlugin Qt5::QICOPlugin QWindowsVistaStylePlugin)
qt_import_plugins(plat INCLUDE Qt${QT_MAJOR}::QWindowsIntegrationPlugin Qt${QT_MAJOR}::QICOPlugin QWindowsVistaStylePlugin)
endif()
if (UNIX AND NOT APPLE)
@ -165,13 +166,13 @@ if (UNIX AND NOT APPLE)
set(WL_SOURCE_VAR)
ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/relative-pointer-unstable-v1.xml BASENAME relative-pointer-unstable-v1)
ecm_add_wayland_client_protocol(WL_SOURCE_VAR PROTOCOL ${CMAKE_SOURCE_DIR}/wl_protocols/pointer-constraints-unstable-v1.xml BASENAME pointer-constraints-unstable-v1)
target_include_directories(ui PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${Qt5Gui_PRIVATE_INCLUDE_DIRS})
target_include_directories(ui PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${Qt${QT_MAJOR}Gui_PRIVATE_INCLUDE_DIRS})
target_sources(ui PRIVATE ${WL_SOURCE_VAR} wl_mouse.cpp)
target_compile_definitions(ui PRIVATE WAYLAND)
endif()
endif()
endif()
endif()
qt5_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} 86box_en.ts 86box_en-GB.ts 86box_de.ts 86box_es.ts 86box_fi.ts 86box_fr.ts 86box_hr.ts 86box_hu.ts 86box_it.ts 86box_ja.ts 86box_ko.ts 86box_pt-BR.ts 86box_pt-PT.ts 86box_ru.ts 86box_sl.ts 86box_tr.ts 86box_zh.ts)
qt_create_translation(QM_FILES ${CMAKE_CURRENT_SOURCE_DIR} 86box_en.ts 86box_en-GB.ts 86box_de.ts 86box_es.ts 86box_fi.ts 86box_fr.ts 86box_hr.ts 86box_hu.ts 86box_it.ts 86box_ja.ts 86box_ko.ts 86box_pt-BR.ts 86box_pt-PT.ts 86box_ru.ts 86box_sl.ts 86box_tr.ts 86box_zh.ts)
configure_file(qt_translations.qrc ${CMAKE_CURRENT_BINARY_DIR} COPYONLY)
target_sources(ui PRIVATE ${QM_FILES} ${CMAKE_CURRENT_BINARY_DIR}/qt_translations.qrc)

View File

@ -1,10 +1,16 @@
#include <QAbstractNativeEventFilter>
#include <QByteArray>
#if QT_VERSION_MAJOR >= 6
#define result_t qintptr
#else
#define result_t long
#endif
class CocoaEventFilter : public QAbstractNativeEventFilter
{
public:
CocoaEventFilter() {};
~CocoaEventFilter();
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) override;
};

View File

@ -31,7 +31,7 @@ CocoaEventFilter::~CocoaEventFilter()
}
bool CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
bool CocoaEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, result_t *result)
{
if (mouse_capture)
{

View File

@ -2,7 +2,6 @@
#include <QOpenGLFunctions>
#include <QOpenGLBuffer>
#include <QOpenGLWidget>
#include <QOpenGLWindow>
#include <QOpenGLVertexArrayObject>
#include <QOpenGLTexture>
@ -12,6 +11,7 @@
#include <QPainter>
#include <QEvent>
#include <QKeyEvent>
#include <QWidget>
#include <atomic>
#include <mutex>

View File

@ -337,6 +337,7 @@ void MainWindow::showEvent(QShowEvent *event) {
scrnsz_x = window_w;
scrnsz_y = window_h;
}
if (settings_only) QTimer::singleShot(0, this, [this] () { ui->actionSettings->trigger(); });
}
void MainWindow::on_actionKeyboard_requires_capture_triggered() {
@ -1060,8 +1061,7 @@ void MainWindow::on_actionHardware_Renderer_OpenGL_ES_triggered() {
void MainWindow::focusInEvent(QFocusEvent* event)
{
if (settings_only) ui->actionSettings->trigger();
else this->grabKeyboard();
this->grabKeyboard();
}
void MainWindow::focusOutEvent(QFocusEvent* event)

View File

@ -108,7 +108,7 @@ void plat_get_exe_name(char *s, int size)
{
QByteArray exepath_temp = QCoreApplication::applicationDirPath().toLocal8Bit();
memcpy(s, exepath_temp.data(), std::min(exepath_temp.size(),size));
memcpy(s, exepath_temp.data(), std::min((qsizetype)exepath_temp.size(),(qsizetype)size));
plat_path_slash(s);
}

View File

@ -2,6 +2,7 @@
#include <QRect>
#include <QImage>
#include <QEvent>
class QWidget;

View File

@ -40,6 +40,13 @@
#include <memory>
#if QT_VERSION_MAJOR >= 6
#define result_t qintptr
#else
#define result_t long
#endif
class WindowsRawInputFilter : public QObject, public QAbstractNativeEventFilter
{
Q_OBJECT
@ -47,7 +54,7 @@ class WindowsRawInputFilter : public QObject, public QAbstractNativeEventFilter
public:
static std::unique_ptr<WindowsRawInputFilter> Register(QMainWindow *window);
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
bool nativeEventFilter(const QByteArray &eventType, void *message, result_t *result) override;
~WindowsRawInputFilter();
@ -72,4 +79,4 @@ private:
void keyboard_getkeymap();
};
#endif
#endif