From 7e2aedf637733fa8df635005ec61c3658e16d740 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Sun, 5 Feb 2023 15:30:28 +0400 Subject: [PATCH] Add an initial Qt6 support --- CI/before_script.msvc.sh | 2 +- CMakeLists.txt | 20 ++++++++++++-------- apps/launcher/CMakeLists.txt | 6 +++--- apps/opencs/CMakeLists.txt | 6 +++--- apps/opencs/model/prefs/state.cpp | 2 ++ apps/opencs/view/doc/view.cpp | 17 ++++++++++++++--- apps/opencs/view/render/scenewidget.cpp | 4 ++++ apps/opencs/view/world/table.cpp | 6 ++++++ apps/wizard/CMakeLists.txt | 6 +++--- components/CMakeLists.txt | 4 ++-- 10 files changed, 50 insertions(+), 23 deletions(-) diff --git a/CI/before_script.msvc.sh b/CI/before_script.msvc.sh index 57e31c789d..28289cfb14 100644 --- a/CI/before_script.msvc.sh +++ b/CI/before_script.msvc.sh @@ -934,7 +934,7 @@ printf "Qt ${QT_VER}... " else DLLSUFFIX="" fi - add_runtime_dlls $CONFIGURATION "$(pwd)/bin/Qt5"{Core,Gui,Network,OpenGL,Widgets}${DLLSUFFIX}.dll + add_runtime_dlls $CONFIGURATION "$(pwd)/bin/Qt${QT_VER:0:1}"{Core,Gui,Network,OpenGL,Widgets}${DLLSUFFIX}.dll add_qt_platform_dlls $CONFIGURATION "$(pwd)/plugins/platforms/qwindows${DLLSUFFIX}.dll" add_qt_style_dlls $CONFIGURATION "$(pwd)/plugins/styles/qwindowsvistastyle${DLLSUFFIX}.dll" done diff --git a/CMakeLists.txt b/CMakeLists.txt index 53abdaeff2..f8bee32c86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -131,7 +131,7 @@ configure_file ("${OpenMW_SOURCE_DIR}/docs/mainpage.hpp.cmake" "${OpenMW_BINARY_ option(BOOST_STATIC "Link static build of Boost into the binaries" FALSE) option(SDL2_STATIC "Link static build of SDL into the binaries" FALSE) -option(QT_STATIC "Link static build of QT into the binaries" FALSE) +option(QT_STATIC "Link static build of Qt into the binaries" FALSE) option(OPENMW_USE_SYSTEM_BULLET "Use system provided bullet physics library" ON) if(OPENMW_USE_SYSTEM_BULLET) @@ -236,10 +236,14 @@ find_package(OpenGL REQUIRED) find_package(LZ4 REQUIRED) if (USE_QT) - find_package(Qt5Core 5.12 REQUIRED) - find_package(Qt5Widgets REQUIRED) - find_package(Qt5Network REQUIRED) - find_package(Qt5OpenGL REQUIRED) + find_package(Qt5 5.15 COMPONENTS Core Widgets Network OpenGL) + if (Qt5_FOUND) + message(STATUS "Using Qt5") + else() + find_package(Qt6 6.4 COMPONENTS Core Widgets Network OpenGL REQUIRED) + message(STATUS "Using Qt6") + message(STATUS "Warning: Qt6 support is experimental and incomplete") + endif() endif() set(USED_OSG_COMPONENTS @@ -618,7 +622,7 @@ endif (CMAKE_CXX_COMPILER_ID STREQUAL GNU OR CMAKE_CXX_COMPILER_ID STREQUAL Clan add_subdirectory (extern/osg-ffmpeg-videoplayer) add_subdirectory (extern/oics) add_subdirectory (extern/Base64) -if (BUILD_OPENCS) +if (BUILD_OPENCS AND Qt5_FOUND) add_subdirectory (extern/osgQt) endif() @@ -815,13 +819,13 @@ if (OPENMW_OSX_DEPLOYMENT AND APPLE) message(FATAL_ERROR "macOS packaging requires CMake 3.19 or higher to sign macOS app bundles.") endif () - get_property(QT_COCOA_PLUGIN_PATH TARGET Qt5::QCocoaIntegrationPlugin PROPERTY LOCATION_RELEASE) + get_property(QT_COCOA_PLUGIN_PATH TARGET Qt::QCocoaIntegrationPlugin PROPERTY LOCATION_RELEASE) get_filename_component(QT_COCOA_PLUGIN_DIR "${QT_COCOA_PLUGIN_PATH}" DIRECTORY) get_filename_component(QT_COCOA_PLUGIN_GROUP "${QT_COCOA_PLUGIN_DIR}" NAME) get_filename_component(QT_COCOA_PLUGIN_NAME "${QT_COCOA_PLUGIN_PATH}" NAME) configure_file("${QT_COCOA_PLUGIN_PATH}" "${APP_BUNDLE_DIR}/Contents/PlugIns/${QT_COCOA_PLUGIN_GROUP}/${QT_COCOA_PLUGIN_NAME}" COPYONLY) - get_property(QT_QMACSTYLE_PLUGIN_PATH TARGET Qt5::QMacStylePlugin PROPERTY LOCATION_RELEASE) + get_property(QT_QMACSTYLE_PLUGIN_PATH TARGET Qt::QMacStylePlugin PROPERTY LOCATION_RELEASE) get_filename_component(QT_QMACSTYLE_PLUGIN_DIR "${QT_QMACSTYLE_PLUGIN_PATH}" DIRECTORY) get_filename_component(QT_QMACSTYLE_PLUGIN_GROUP "${QT_QMACSTYLE_PLUGIN_DIR}" NAME) get_filename_component(QT_QMACSTYLE_PLUGIN_NAME "${QT_QMACSTYLE_PLUGIN_PATH}" NAME) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index 1fb69060bc..790c5436f0 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -54,8 +54,8 @@ if(WIN32) set(QT_USE_QTMAIN TRUE) endif(WIN32) -QT5_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc) -QT5_WRAP_UI(UI_HDRS ${LAUNCHER_UI}) +QT_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/launcher/launcher.qrc) +QT_WRAP_UI(UI_HDRS ${LAUNCHER_UI}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) if(NOT WIN32) @@ -82,7 +82,7 @@ target_link_libraries(openmw-launcher components_qt ) -target_link_libraries(openmw-launcher Qt5::Widgets Qt5::Core) +target_link_libraries(openmw-launcher Qt::Widgets Qt::Core) if (BUILD_WITH_CODE_COVERAGE) add_definitions (--coverage) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index 82d160cd20..ab63be0437 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -149,8 +149,8 @@ if(WIN32) set(QT_USE_QTMAIN TRUE) endif(WIN32) -qt5_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI}) -qt5_add_resources(OPENCS_RES_SRC ${OPENCS_RES}) +qt_wrap_ui(OPENCS_UI_HDR ${OPENCS_UI}) +qt_add_resources(OPENCS_RES_SRC ${OPENCS_RES}) # for compiled .ui files include_directories(${CMAKE_CURRENT_BINARY_DIR}) @@ -228,7 +228,7 @@ target_link_libraries(openmw-cs components_qt ) -target_link_libraries(openmw-cs Qt5::Widgets Qt5::Core Qt5::Network Qt5::OpenGL) +target_link_libraries(openmw-cs Qt::Widgets Qt::Core Qt::Network Qt::OpenGL) if (WIN32) target_link_libraries(openmw-cs ${Boost_LOCALE_LIBRARY}) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 5be3fa9746..97f29bc8be 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -66,11 +66,13 @@ void CSMPrefs::State::declare() .addValue(scrollbarOnly) .addValue("Grow Only", "The view window grows as subviews are added. No scrollbars.") .addValue("Grow then Scroll", "The view window grows. The scrollbar appears once it cannot grow any further."); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) declareBool("grow-limit", "Grow Limit Screen", false) .setTooltip( "When \"Grow then Scroll\" option is selected, the window size grows to" " the width of the virtual desktop. \nIf this option is selected the the window growth" "is limited to the current screen."); +#endif declareCategory("Records"); EnumValue iconAndText("Icon and Text"); diff --git a/apps/opencs/view/doc/view.cpp b/apps/opencs/view/doc/view.cpp index 1b5e34130f..914ca41217 100644 --- a/apps/opencs/view/doc/view.cpp +++ b/apps/opencs/view/doc/view.cpp @@ -2,7 +2,11 @@ #include #include + +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif + #include #include #include @@ -651,7 +655,11 @@ void CSVDoc::View::addSubView(const CSMWorld::UniversalId& id, const std::string // mScrollbarOnly = windows["mainwindow-scrollbar"].toString() == "Scrollbar Only"; +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) updateWidth(windows["grow-limit"].isTrue(), minWidth); +#else + updateWidth(true, minWidth); +#endif mSubViewWindow.addDockWidget(Qt::TopDockWidgetArea, view); @@ -1098,12 +1106,15 @@ void CSVDoc::View::merge() void CSVDoc::View::updateWidth(bool isGrowLimit, int minSubViewWidth) { - QDesktopWidget* dw = QApplication::desktop(); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) QRect rect; if (isGrowLimit) - rect = dw->screenGeometry(this); + rect = QApplication::screenAt(pos())->geometry(); else - rect = QGuiApplication::screens().at(dw->screenNumber(this))->geometry(); + rect = QGuiApplication::screens().at(QApplication::desktop()->screenNumber(this))->geometry(); +#else + QRect rect = QApplication::screenAt(pos())->geometry(); +#endif if (!mScrollbarOnly && mScroll && mSubViews.size() > 1) { diff --git a/apps/opencs/view/render/scenewidget.cpp b/apps/opencs/view/render/scenewidget.cpp index 9efbdcca5e..8d896f6913 100644 --- a/apps/opencs/view/render/scenewidget.cpp +++ b/apps/opencs/view/render/scenewidget.cpp @@ -13,7 +13,9 @@ #include #include +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) #include +#endif #include #include @@ -90,6 +92,7 @@ namespace CSVRender mView = new osgViewer::View; updateCameraParameters(traits->width / static_cast(traits->height)); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) osg::ref_ptr window = new osgQt::GraphicsWindowQt(traits.get()); QLayout* layout = new QHBoxLayout(this); layout->setContentsMargins(0, 0, 0, 0); @@ -97,6 +100,7 @@ namespace CSVRender setLayout(layout); mView->getCamera()->setGraphicsContext(window); +#endif mView->getCamera()->setViewport(new osg::Viewport(0, 0, traits->width, traits->height)); SceneUtil::LightManager* lightMgr = new SceneUtil::LightManager; diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index fa47ad69e0..035be5ffa2 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -141,6 +141,7 @@ void CSVWorld::Table::contextMenuEvent(QContextMenuEvent* event) } } +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) if (selectedRows.size() == 1) { int row = selectedRows.begin()->row(); @@ -172,6 +173,7 @@ void CSVWorld::Table::contextMenuEvent(QContextMenuEvent* event) menu.addAction(mPreviewAction); } } +#endif if (mHelpAction) menu.addAction(mHelpAction); @@ -388,14 +390,18 @@ CSVWorld::Table::Table(const CSMWorld::UniversalId& id, bool createAndDelete, bo mViewAction->setIcon(QIcon(":/cell.png")); addAction(mViewAction); CSMPrefs::Shortcut* viewShortcut = new CSMPrefs::Shortcut("table-view", this); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) viewShortcut->associateAction(mViewAction); +#endif mPreviewAction = new QAction(tr("Preview"), this); connect(mPreviewAction, &QAction::triggered, this, &Table::previewRecord); mPreviewAction->setIcon(QIcon(":edit-preview")); addAction(mPreviewAction); CSMPrefs::Shortcut* previewShortcut = new CSMPrefs::Shortcut("table-preview", this); +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) previewShortcut->associateAction(mPreviewAction); +#endif mExtendedDeleteAction = new QAction(tr("Extended Delete Record"), this); connect(mExtendedDeleteAction, &QAction::triggered, this, &Table::executeExtendedDelete); diff --git a/apps/wizard/CMakeLists.txt b/apps/wizard/CMakeLists.txt index 03cd63480a..895fe0ee46 100644 --- a/apps/wizard/CMakeLists.txt +++ b/apps/wizard/CMakeLists.txt @@ -62,8 +62,8 @@ if(WIN32) set(QT_USE_QTMAIN TRUE) endif(WIN32) -QT5_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/wizard/wizard.qrc) -QT5_WRAP_UI(UI_HDRS ${WIZARD_UI}) +QT_ADD_RESOURCES(RCC_SRCS ${CMAKE_SOURCE_DIR}/files/wizard/wizard.qrc) +QT_WRAP_UI(UI_HDRS ${WIZARD_UI}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) @@ -83,7 +83,7 @@ target_link_libraries(openmw-wizard components_qt ) -target_link_libraries(openmw-wizard Qt5::Widgets Qt5::Core) +target_link_libraries(openmw-wizard Qt::Widgets Qt::Core) if (OPENMW_USE_UNSHIELD) target_link_libraries(openmw-wizard ${LIBUNSHIELD_LIBRARIES}) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index f31120f181..b077957526 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -387,7 +387,7 @@ if (USE_QT) qtconfigpath ) - QT5_WRAP_UI(ESM_UI_HDR ${ESM_UI}) + QT_WRAP_UI(ESM_UI_HDR ${ESM_UI}) endif() if (CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") @@ -455,7 +455,7 @@ endif() if (USE_QT) add_library(components_qt STATIC ${COMPONENT_QT_FILES} ${ESM_UI_HDR}) - target_link_libraries(components_qt components Qt5::Widgets Qt5::Core) + target_link_libraries(components_qt components Qt::Widgets Qt::Core) target_compile_definitions(components_qt PRIVATE OPENMW_DOC_BASEURL="${OPENMW_DOC_BASEURL}") endif()