diff --git a/code/3rd_QGLViewer/CMakeLists.txt b/code/3rd_QGLViewer/CMakeLists.txt index 70c7bdc..1e1c907 100644 --- a/code/3rd_QGLViewer/CMakeLists.txt +++ b/code/3rd_QGLViewer/CMakeLists.txt @@ -5,28 +5,7 @@ endif() project(libQGLViewer LANGUAGES CXX VERSION 2.9.1) cmake_minimum_required(VERSION 3.16) -# Qt6 minimum compiler version -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Instruct CMake to run moc automatically when needed. -set(CMAKE_AUTOMOC ON) -# Instruct CMake to run uic automatically when needed. -set(CMAKE_AUTOUIC ON) - -# This will find the Qt files. -find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) -if (Qt6_FOUND) - message(STATUS "Building with Qt6") - set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) -else() - find_package(Qt5 COMPONENTS Core Widgets Xml OpenGL REQUIRED) - message(STATUS "Building with Qt5") - set(QtLibs Qt5Core Qt5OpenGL Qt5Widgets Qt5Xml) -endif() - +include(../cmake/UseQt.cmake) find_package(OpenGL REQUIRED) diff --git a/code/3rd_QGLViewer/QGLViewer/camera.h b/code/3rd_QGLViewer/QGLViewer/camera.h index 33fb325..0148532 100644 --- a/code/3rd_QGLViewer/QGLViewer/camera.h +++ b/code/3rd_QGLViewer/QGLViewer/camera.h @@ -2,6 +2,7 @@ #define QGLVIEWER_CAMERA_H #include "../basic/canvas.h" +#include #include "keyFrameInterpolator.h" class QGLViewer; diff --git a/code/3rd_QGLViewer/QGLViewer/qglviewer.cpp b/code/3rd_QGLViewer/QGLViewer/qglviewer.cpp index 3c99086..8073aa5 100644 --- a/code/3rd_QGLViewer/QGLViewer/qglviewer.cpp +++ b/code/3rd_QGLViewer/QGLViewer/qglviewer.cpp @@ -659,7 +659,9 @@ void QGLViewer::setCamera(Camera *const camera) { disconnect(this->camera()->frame(), SIGNAL(manipulated()), this, SLOT(update())); disconnect(this->camera()->frame(), SIGNAL(spun()), this, SLOT(update())); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) // The screen() function was introduced in the QWidget class starting from Qt 5.14. disconnect(screen(), SIGNAL(physicalDotsPerInchChanged(qreal)), this->camera(), SLOT(setDevicePixelRatio(qreal))); +#endif connectAllCameraKFIInterpolatedSignals(false); camera_ = camera; @@ -667,12 +669,18 @@ void QGLViewer::setCamera(Camera *const camera) { camera->setSceneRadius(sceneRadius()); camera->setSceneCenter(sceneCenter()); camera->setScreenWidthAndHeight(width(), height()); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) // The screen() function was introduced in the QWidget class starting from Qt 5.14. camera->setDevicePixelRatio(screen()->devicePixelRatio()); +#else + camera->setDevicePixelRatio(devicePixelRatioF()); +#endif // Connect camera frame to this viewer. connect(camera->frame(), SIGNAL(manipulated()), SLOT(update())); connect(camera->frame(), SIGNAL(spun()), SLOT(update())); +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) // The screen() function was introduced in the QWidget class starting from Qt 5.14. connect(screen(), SIGNAL(physicalDotsPerInchChanged(qreal)), camera, SLOT(setDevicePixelRatio(qreal))); +#endif connectAllCameraKFIInterpolatedSignals(); previousCameraZClippingCoefficient_ = this->camera()->zClippingCoefficient(); diff --git a/code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp b/code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp index 6ab357f..4ea90a1 100644 --- a/code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp +++ b/code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp @@ -303,7 +303,11 @@ class ImageInterface : public QDialog, public Ui::ImageInterface { // Returns false in case of problem. bool QGLViewer::saveImageSnapshot(const QString &fileName) { static ImageInterface *imageInterface = nullptr; +#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) // The screen() function was introduced in the QWidget class starting from Qt 5.14. qreal devicePixelRatio = screen()->devicePixelRatio(); +#else + qreal devicePixelRatio = devicePixelRatioF(); +#endif qreal dipWidth = devicePixelRatio * width(); qreal dipHeight = devicePixelRatio * height(); diff --git a/code/PolyFit/CMakeLists.txt b/code/PolyFit/CMakeLists.txt index 108bb2b..6fce6dd 100644 --- a/code/PolyFit/CMakeLists.txt +++ b/code/PolyFit/CMakeLists.txt @@ -1,31 +1,7 @@ get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME) project(${PROJECT_NAME}) - -# ------------------------------------------------------------------------------ -# Qt -# ------------------------------------------------------------------------------ - -# Find includes in corresponding build directories -set(CMAKE_INCLUDE_CURRENT_DIR ON) -# Instruct CMake to run moc automatically when needed. -set(CMAKE_AUTOMOC ON) -# Instruct CMake to run uic automatically when needed. -set(CMAKE_AUTOUIC ON) -# Instruct CMake to run rcc automatically when needed. -set(CMAKE_AUTORCC ON) - -# This will find the Qt files. -find_package(Qt6 COMPONENTS Core Widgets Xml OpenGL OpenGLWidgets) -if (Qt6_FOUND) - message(STATUS "Building with Qt6") - set(QtLibs Qt::Core Qt::Widgets Qt::Xml Qt::OpenGL Qt::OpenGLWidgets) -else() - find_package(Qt5 COMPONENTS Core Gui OpenGL Widgets Xml REQUIRED) - message(STATUS "Building with Qt5") - set(QtLibs Qt5Core Qt5Gui Qt5OpenGL Qt5Widgets Qt5Xml) -endif() - +include(../cmake/UseQt.cmake) set(${PROJECT_NAME}_HEADERS main_window.h diff --git a/code/cmake/UseQt.cmake b/code/cmake/UseQt.cmake new file mode 100644 index 0000000..92aff91 --- /dev/null +++ b/code/cmake/UseQt.cmake @@ -0,0 +1,80 @@ +# ************************************************************************* +# Copyright (C) 2015 Liangliang Nan +# https://3d.bk.tudelft.nl/liangliang/ +# +# This file is part of Easy3D. If it is useful in your research/work, +# I would be grateful if you show your appreciation by citing it: +# ------------------------------------------------------------------ +# Liangliang Nan. +# Easy3D: a lightweight, easy-to-use, and efficient C++ library +# for processing and rendering 3D data. +# Journal of Open Source Software, 6(64), 3255, 2021. +# ------------------------------------------------------------------ +# +# Easy3D is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License Version 3 +# as published by the Free Software Foundation. +# +# Easy3D is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# ************************************************************************* + + +# ------------------------------------------------------------------------------ +# This file sets up Qt for CMake. When Qt6 was setup successfully, Qt6_FOUND +# will be set. If Qt6 is not found, it will try to find Qt5. If Qt5 is found, +# Qt5_FOUND will be set. If both Qt6 and Qt5 are not found, it will stop the +# configuration and show an error message. +# If either Qt6 or Qt5 is found, it will set QtLibs to the corresponding Qt +# libraries, e.g., Qt5Core, Qt5Gui, Qt5Widgets, Qt5OpenGL, Qt5Xml, etc. +# +# To use Qt in your program, you only need to include this file and specifying +# Qt libraries to link against, e.g., +# ------------------------------------------------------------------------ +# project(${PROJECT_NAME}) +# include( ../cmake/UseQt5.cmake ) +# add_executable(${PROJECT_NAME}, main.cpp) +# target_link_libraries(${PROJECT_NAME} ${QtLibs}) +# ------------------------------------------------------------------------ +# NOTE: 'UseQt.cmake' must be included after you define your project but before +# 'add_executable()' or 'add_library()'. +# +# The recommended way to specify libraries and headers with CMake is to use the +# target_link_libraries command. This command automatically adds appropriate +# include directories, compile definitions, the position-independent-code flag, +# and links to the qtmain.lib library on Windows. +# ------------------------------------------------------------------------------ + + +# Qt6 minimum compiler version +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +# Find includes in corresponding build directories +set(CMAKE_INCLUDE_CURRENT_DIR ON) +# Instruct CMake to run moc automatically when needed. +set(CMAKE_AUTOMOC ON) +# Instruct CMake to run uic automatically when needed. +set(CMAKE_AUTOUIC ON) +# Instruct CMake to run rcc automatically when needed. +set(CMAKE_AUTORCC ON) + +# This will find the Qt files. +find_package(Qt6 COMPONENTS Core Widgets OpenGL OpenGLWidgets Xml QUIET) +if (Qt6_FOUND) + message(STATUS "Found Qt6 version: ${Qt5Core_VERSION}") + set(QtLibs Qt::Core Qt::Widgets Qt::OpenGL Qt::OpenGLWidgets Qt::Xml) +else() + find_package(Qt5 COMPONENTS Core Widgets OpenGL Xml QUIET) + if (Qt5_FOUND) + message(STATUS "Found Qt5 version: ${Qt5Core_VERSION}") + set(QtLibs Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Xml) + else() + message(FATAL_ERROR "Qt is required, either Qt6 or Qt5, but both cannot be found") + endif() +endif() \ No newline at end of file