Skip to content

Commit

Permalink
works with Qt5
Browse files Browse the repository at this point in the history
  • Loading branch information
LiangliangNan committed Dec 14, 2024
1 parent 862bb32 commit e06cff0
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 47 deletions.
23 changes: 1 addition & 22 deletions code/3rd_QGLViewer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
1 change: 1 addition & 0 deletions code/3rd_QGLViewer/QGLViewer/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define QGLVIEWER_CAMERA_H

#include "../basic/canvas.h"
#include <QMap>
#include "keyFrameInterpolator.h"
class QGLViewer;

Expand Down
8 changes: 8 additions & 0 deletions code/3rd_QGLViewer/QGLViewer/qglviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,20 +659,28 @@ 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;

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();
Expand Down
4 changes: 4 additions & 0 deletions code/3rd_QGLViewer/QGLViewer/saveSnapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
26 changes: 1 addition & 25 deletions code/PolyFit/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
80 changes: 80 additions & 0 deletions code/cmake/UseQt.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# *************************************************************************
# Copyright (C) 2015 Liangliang Nan <[email protected]>
# 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 <http://www.gnu.org/licenses/>.
# *************************************************************************


# ------------------------------------------------------------------------------
# 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()

0 comments on commit e06cff0

Please sign in to comment.