From 7abc4faf8933f39af8deedfd0a4457996601b35e Mon Sep 17 00:00:00 2001 From: Larry Gritz Date: Mon, 27 Feb 2023 16:37:30 -0800 Subject: [PATCH] Qt6 compatibility (#3779) --- .github/workflows/ci.yml | 5 +++-- src/build-scripts/gh-installdeps.bash | 8 +++++-- src/build-scripts/install_homebrew_deps.bash | 2 +- src/cmake/externalpackages.cmake | 23 ++++++++++---------- src/iv/CMakeLists.txt | 19 +++++++++++++--- src/iv/imageviewer.cpp | 20 +++++++++++++---- src/iv/imageviewer.h | 7 +++++- src/iv/ivgl.cpp | 4 ++++ 8 files changed, 64 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index af8bfda70c..8cb68516dc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -233,14 +233,14 @@ jobs: include: - desc: latest releases gcc11 C++17 avx2 exr3.1 ocio2.2 nametag: linux-latest-releases - os: ubuntu-20.04 + os: ubuntu-22.04 cc_compiler: gcc-11 cxx_compiler: g++-11 cxx_std: 17 fmt_ver: 9.1.0 openexr_ver: v3.1.5 pybind11_ver: v2.10.0 - python_ver: 3.8 + python_ver: "3.10" simd: avx2,f16c setenvs: export LIBRAW_VERSION=0.20.2 LIBTIFF_VERSION=v4.4.0 @@ -391,6 +391,7 @@ jobs: cxx_std: 17 python_ver: "3.9" aclang: 13 + setenvs: export QT_VERSION=@5 - desc: MacOS-12 os: macos-12 nametag: macos12-py310 diff --git a/src/build-scripts/gh-installdeps.bash b/src/build-scripts/gh-installdeps.bash index ef03a03fb5..67fd3a83c5 100755 --- a/src/build-scripts/gh-installdeps.bash +++ b/src/build-scripts/gh-installdeps.bash @@ -73,8 +73,12 @@ else libopencolorio-dev \ libopencv-dev \ libhdf5-dev - time sudo apt-get -q install -y \ - qt5-default || /bin/true + if [[ "${QT_VERSION:-5}" == "5" ]] ; then + time sudo apt-get -q install -y \ + qt5-default || /bin/true + elif [[ "${QT_VERSION}" == "6" ]] ; then + time sudo apt-get -q install -y qt6-base-dev || /bin/true + fi if [[ "${EXTRA_DEP_PACKAGES}" != "" ]] ; then time sudo apt-get -q install -y ${EXTRA_DEP_PACKAGES} fi diff --git a/src/build-scripts/install_homebrew_deps.bash b/src/build-scripts/install_homebrew_deps.bash index 84b39ed62a..6fad43d3a7 100755 --- a/src/build-scripts/install_homebrew_deps.bash +++ b/src/build-scripts/install_homebrew_deps.bash @@ -39,7 +39,7 @@ brew install --display-times -q ffmpeg libheif ptex || true brew install --display-times -q tbb || true brew install --display-times -q openvdb || true brew install --display-times -q opencv || true -brew install --display-times -q qt@5 +brew install --display-times -q qt${QT_VERSION} echo "" echo "After brew installs:" diff --git a/src/cmake/externalpackages.cmake b/src/cmake/externalpackages.cmake index 707af96ce1..43f252d398 100644 --- a/src/cmake/externalpackages.cmake +++ b/src/cmake/externalpackages.cmake @@ -248,21 +248,22 @@ checked_find_package (R3DSDK) # RED camera set (NUKE_VERSION "7.0" CACHE STRING "Nuke version to target") checked_find_package (Nuke) -checked_find_package (OpenGL) # used for iv # Qt -- used for iv -set (qt5_modules Core Gui Widgets) -if (OPENGL_FOUND) - list (APPEND qt5_modules OpenGL) -endif () option (USE_QT "Use Qt if found" ON) -checked_find_package (Qt5 COMPONENTS ${qt5_modules}) -if (USE_QT AND NOT Qt5_FOUND AND APPLE) - message (STATUS " If you think you installed qt5 with Homebrew and it still doesn't work,") - message (STATUS " try: export PATH=/usr/local/opt/qt5/bin:$PATH") +if (USE_QT) + checked_find_package (OpenGL) # used for iv +endif () +if (USE_QT AND OPENGL_FOUND) + checked_find_package (Qt6 COMPONENTS Core Gui Widgets OpenGLWidgets) + if (NOT Qt6_FOUND) + checked_find_package (Qt5 COMPONENTS Core Gui Widgets OpenGL) + endif () + if (NOT Qt5_FOUND AND NOT Qt6_FOUND AND APPLE) + message (STATUS " If you think you installed qt with Homebrew and it still doesn't work,") + message (STATUS " try: export PATH=/usr/local/opt/qt/bin:$PATH") + endif () endif () - - ########################################################################### diff --git a/src/iv/CMakeLists.txt b/src/iv/CMakeLists.txt index 88a2151b29..881463d5ba 100644 --- a/src/iv/CMakeLists.txt +++ b/src/iv/CMakeLists.txt @@ -3,23 +3,36 @@ # https://github.com/OpenImageIO/oiio set (CMAKE_AUTOMOC ON) -if (Qt5_POSITION_INDEPENDENT_CODE) +if (Qt5_POSITION_INDEPENDENT_CODE OR Qt6_POSITION_INDEPENDENT_CODE) set (CMAKE_POSITION_INDEPENDENT_CODE ON) endif() check_is_enabled (iv iv_enabled) -if (iv_enabled AND Qt5_FOUND AND OPENGL_FOUND) +if (iv_enabled AND (Qt5_FOUND OR Qt6_FOUND) AND OPENGL_FOUND) fancy_add_executable ( SYSTEM_INCLUDE_DIRS ${OPENGL_INCLUDE_DIR} LINK_LIBRARIES OpenImageIO - Qt5::Core Qt5::Gui Qt5::Widgets Qt5::OpenGL + $ + $ + $ + $ + $ + $ + $ + $ ${OPENGL_LIBRARIES} ) if (iv_enabled AND FORCE_OPENGL_1) target_compile_definitions(iv PRIVATE FORCE_OPENGL_1) endif() + if (Qt5_FOUND) + target_compile_definitions(iv PRIVATE OIIO_QT_MAJOR=5) + endif () + if (Qt6_FOUND) + target_compile_definitions(iv PRIVATE OIIO_QT_MAJOR=6) + endif () else () message (STATUS "\n\n WARNING: Qt or OpenGL not found -- 'iv' will not be built!\n") endif () diff --git a/src/iv/imageviewer.cpp b/src/iv/imageviewer.cpp index 79839dd5a3..06dff33b26 100644 --- a/src/iv/imageviewer.cpp +++ b/src/iv/imageviewer.cpp @@ -9,12 +9,15 @@ #endif #include +#ifndef OIIO_QT_MAJOR +# error "Build problem? OIIO_QT_MAJOR not defined." +#endif + #include "imageviewer.h" #include "ivgl.h" #include #include -#include #include #include #include @@ -28,6 +31,10 @@ #include #include +#if OIIO_QT_MAJOR < 6 +# include +#endif + #include #include #include @@ -1951,9 +1958,14 @@ ImageViewer::fitWindowToImage(bool zoomok, bool minsize) } if (!m_fullscreen) { - QDesktopWidget* desktop = QApplication::desktop(); - QRect availgeom = desktop->availableGeometry(this); - int availwidth = availgeom.width() - extraw - 20; +#if OIIO_QT_MAJOR >= 6 + auto desktop = this->screen(); + QRect availgeom = desktop->availableGeometry(); +#else + auto desktop = QApplication::desktop(); + QRect availgeom = desktop->availableGeometry(this); +#endif + int availwidth = availgeom.width() - extraw - 20; int availheight = availgeom.height() - extrah - menuBar()->height() - 20; #if 0 diff --git a/src/iv/imageviewer.h b/src/iv/imageviewer.h index f20b79aa33..878e884e8c 100644 --- a/src/iv/imageviewer.h +++ b/src/iv/imageviewer.h @@ -23,9 +23,14 @@ #include #include #include -#include #include +#if OIIO_QT_MAJOR < 6 +# include +#else +# include +#endif + #ifndef QT_NO_PRINTER // #include #endif diff --git a/src/iv/ivgl.cpp b/src/iv/ivgl.cpp index 2551d02ae9..19d17f88f2 100644 --- a/src/iv/ivgl.cpp +++ b/src/iv/ivgl.cpp @@ -11,6 +11,10 @@ #include #include #include +#if OIIO_QT_MAJOR >= 6 +# include +# include +#endif #include "ivutils.h" #include