Skip to content

Commit

Permalink
Qt6 compatibility (#3779)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgritz committed Mar 1, 2023
1 parent 3954b09 commit 7abc4fa
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 24 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/build-scripts/gh-installdeps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/build-scripts/install_homebrew_deps.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
23 changes: 12 additions & 11 deletions src/cmake/externalpackages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()




###########################################################################
Expand Down
19 changes: 16 additions & 3 deletions src/iv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
$<TARGET_NAME_IF_EXISTS:Qt5::Core>
$<TARGET_NAME_IF_EXISTS:Qt5::Gui>
$<TARGET_NAME_IF_EXISTS:Qt5::Widgets>
$<TARGET_NAME_IF_EXISTS:Qt5::OpenGL>
$<TARGET_NAME_IF_EXISTS:Qt6::Core>
$<TARGET_NAME_IF_EXISTS:Qt6::Gui>
$<TARGET_NAME_IF_EXISTS:Qt6::Widgets>
$<TARGET_NAME_IF_EXISTS:Qt6::OpenGLWidgets>
${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 ()
20 changes: 16 additions & 4 deletions src/iv/imageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
#endif
#include <vector>

#ifndef OIIO_QT_MAJOR
# error "Build problem? OIIO_QT_MAJOR not defined."
#endif

#include "imageviewer.h"
#include "ivgl.h"

#include <QApplication>
#include <QComboBox>
#include <QDesktopWidget>
#include <QFileDialog>
#include <QKeyEvent>
#include <QLabel>
Expand All @@ -28,6 +31,10 @@
#include <QStatusBar>
#include <QTimer>

#if OIIO_QT_MAJOR < 6
# include <QDesktopWidget>
#endif

#include <OpenImageIO/dassert.h>
#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/imagecache.h>
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion src/iv/imageviewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
#include <QAction>
#include <QCheckBox>
#include <QDialog>
#include <QGLWidget>
#include <QMainWindow>

#if OIIO_QT_MAJOR < 6
# include <QGLWidget>
#else
# include <QOpenGLWidget>
#endif

#ifndef QT_NO_PRINTER
// #include <QPrinter>
#endif
Expand Down
4 changes: 4 additions & 0 deletions src/iv/ivgl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include <QLabel>
#include <QMouseEvent>
#include <QProgressBar>
#if OIIO_QT_MAJOR >= 6
# include <QPainter>
# include <QPen>
#endif

#include "ivutils.h"
#include <OpenImageIO/strutil.h>
Expand Down

0 comments on commit 7abc4fa

Please sign in to comment.