From 1286d8b6366201a5df3f5c1bbc3a6310a0d4e1f8 Mon Sep 17 00:00:00 2001 From: Nicolas Saillant Date: Mon, 19 Aug 2024 12:02:19 +0200 Subject: [PATCH] Remove deprecated Qt version checks --- .../GridGraphicsItem.cpp | 4 ---- GraphicsView/include/CGAL/Qt/qglviewer.h | 7 ++++++ GraphicsView/include/CGAL/Qt/qglviewer_impl.h | 22 +++++++++++++++++++ Lab/demo/Lab/CGAL_Lab.cpp | 3 +++ Lab/demo/Lab/MainWindow.cpp | 6 +++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GridGraphicsItem.cpp b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GridGraphicsItem.cpp index 535f46849759..01723db026eb 100644 --- a/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GridGraphicsItem.cpp +++ b/Arrangement_on_surface_2/demo/Arrangement_on_surface_2/GridGraphicsItem.cpp @@ -67,11 +67,7 @@ void GridGraphicsItem::setSpacing(int spacing_) static inline qreal horizontalAdvance(const QFontMetrics& fm, const QString& text) { -#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) return fm.horizontalAdvance(text); -#else - return fm.boundingRect(text).width(); -#endif } void GridGraphicsItem::paint( diff --git a/GraphicsView/include/CGAL/Qt/qglviewer.h b/GraphicsView/include/CGAL/Qt/qglviewer.h index 5c0726d5344c..e24a5fcd6d7f 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer.h @@ -478,6 +478,13 @@ public Q_SLOTS: qreal bufferTextureMaxU() const { return bufferTextureMaxU_; } /*! Same as bufferTextureMaxU(), but for the v texture coordinate. */ qreal bufferTextureMaxV() const { return bufferTextureMaxV_; } + // These methods are part of the QGLWidget public API. + // As of version 2.7.0, the use of QOpenGLWidget instead means that they have + // to be provided for backward compatibility. + void renderText(int x, int y, const QString &str, + const QFont &font = QFont()); + void renderText(double x, double y, double z, const QString &str, + const QFont &font = QFont()); public Q_SLOTS: void copyBufferToTexture(GLint, GLenum = GL_NONE); diff --git a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h index dc25f1d8675e..508444710add 100644 --- a/GraphicsView/include/CGAL/Qt/qglviewer_impl.h +++ b/GraphicsView/include/CGAL/Qt/qglviewer_impl.h @@ -720,6 +720,28 @@ CGAL_INLINE_FUNCTION void CGAL::QGLViewer::drawLight(GLenum, qreal ) const { } +CGAL_INLINE_FUNCTION +void CGAL::QGLViewer::renderText(int x, int y, const QString &str, + const QFont &font) { + QColor fontColor = QColor(0, 0, + 0, 255); + + // Render text + QPainter painter(this); + painter.setPen(fontColor); + painter.setFont(font); + painter.drawText(x, y, str); + painter.end(); +} + +CGAL_INLINE_FUNCTION +void CGAL::QGLViewer::renderText(double x, double y, double z, const QString &str, + const QFont &font) { + using CGAL::qglviewer::Vec; + const Vec proj = camera_->projectedCoordinatesOf(Vec(x, y, z)); + renderText(int(proj.x), int(proj.y), str, font); +} + /*! Draws \p text at position \p x, \p y (expressed in screen coordinates pixels, origin in the upper left corner of the widget). diff --git a/Lab/demo/Lab/CGAL_Lab.cpp b/Lab/demo/Lab/CGAL_Lab.cpp index d54813edda90..85880fb8addd 100644 --- a/Lab/demo/Lab/CGAL_Lab.cpp +++ b/Lab/demo/Lab/CGAL_Lab.cpp @@ -27,6 +27,9 @@ int& code_to_call_before_creation_of_QCoreApplication(int& i) { fmt.setOption(QSurfaceFormat::DebugContext); QSurfaceFormat::setDefaultFormat(fmt); + // for windows + QCoreApplication::setAttribute(Qt::AA_UseDesktopOpenGL); + return i; } diff --git a/Lab/demo/Lab/MainWindow.cpp b/Lab/demo/Lab/MainWindow.cpp index 7eff95e0b3dd..806f8b912cb0 100644 --- a/Lab/demo/Lab/MainWindow.cpp +++ b/Lab/demo/Lab/MainWindow.cpp @@ -663,6 +663,12 @@ void MainWindow::loadPlugins() } } QString env_path = qgetenv("LAB_DEMO_PLUGINS_PATH"); + QChar separator = QDir::listSeparator(); + #if defined(_WIN32) + QChar separator = ';'; + #else + QChar separator = ':'; + #endif if(!env_path.isEmpty()) { #if defined(_WIN32) QString path = qgetenv("PATH");