From 373d4a8ebe86aa9ed07c9a8eb5e5e7f1602baef9 Mon Sep 17 00:00:00 2001 From: Jonnhy Jazeix <jazeix@gmail.com> Date: Wed, 30 Oct 2013 20:30:28 +0000 Subject: [PATCH] conf and source code modified for compiling with qt5 (compiles with Qt4 if Qt5 is not found and Qt4 is installed) --- CMakeLists.txt | 24 ++++++++++++++++++++---- plugins/Distribution/CMakeLists.txt | 4 ++++ plugins/Distribution/Distribution.cpp | 11 ++++++----- plugins/TraceInfos/CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 18 +++++++++++++++++- src/interface/Interface_graphic.cpp | 6 +++++- src/interface/Interface_graphic.hpp | 6 +++++- 7 files changed, 61 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bbda8cc..dbdcea85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,26 @@ include (CheckLibraryExists) include (CMakeDependentOption) ### Required Packages -find_package(Qt4 COMPONENTS QtCore QtGui QtXml REQUIRED) -set(QT_USE_QTUITOOLS ON) -set(QT_USE_QTOPENGL ON) -include(${QT_USE_FILE}) +# Try to find Qt5 : http://forum.openscenegraph.org/viewtopic.php?t=11431 +set(USE_QT5 OFF) +# QUIET option disables messages if the package cannot be found. +find_package(Qt5Widgets QUIET) +if(Qt5Widgets_FOUND) +# CMake 2.8.8 or greater required for qt5 use + if("${CMAKE_VERSION}" VERSION_GREATER 2.8.7) + set(USE_QT5 ON) + endif() +endif() + +if(USE_QT5) + set(CMAKE_AUTOMOC ON) + find_package(Qt5 COMPONENTS Core Xml Widgets OpenGL UiTools REQUIRED) +else(USE_QT5) # Try Qt4 + find_package(Qt4 COMPONENTS QtCore QtGui QtXml REQUIRED) + set(QT_USE_QTUITOOLS ON) + set(QT_USE_QTOPENGL ON) + include(${QT_USE_FILE}) +endif(USE_QT5) #find_package(OpenGL) find_package(GLU) diff --git a/plugins/Distribution/CMakeLists.txt b/plugins/Distribution/CMakeLists.txt index 523c960c..df61d205 100644 --- a/plugins/Distribution/CMakeLists.txt +++ b/plugins/Distribution/CMakeLists.txt @@ -30,4 +30,8 @@ set(DISTRIBUTION_srcs add_library(Distribution SHARED ${DISTRIBUTION_srcs}) +IF(USE_QT5) + qt5_use_modules(Distribution Widgets Core) +ENDIF(USE_QT5) + install(TARGETS Distribution DESTINATION ${HOME}/.vite) \ No newline at end of file diff --git a/plugins/Distribution/Distribution.cpp b/plugins/Distribution/Distribution.cpp index 876d432f..c387207a 100644 --- a/plugins/Distribution/Distribution.cpp +++ b/plugins/Distribution/Distribution.cpp @@ -1,3 +1,4 @@ +#include <cmath> #include <set> #include <stack> #include <vector> @@ -6,15 +7,15 @@ #include <fstream> #include <algorithm> /* -- */ -#include <QWidget> #include <QSlider> #include <QPainter> #include <QTextEdit> #include <QHBoxLayout> #include <QTreeWidgetItem> #include <QStackedWidget> -#include <QApplication> -#include <QtGui> +#include <QGraphicsLineItem> +#include <QGraphicsScene> +#include <QGraphicsView> /* -- */ #include "plugin/Plugin.hpp" /* -- */ @@ -414,8 +415,8 @@ private: int width = 100; int offsety = 100; - scene->addItem(new QGraphicsLineItem(0, 0+offsety, 0, -height+offsety, NULL, scene)); - scene->addItem(new QGraphicsLineItem(0, 0+offsety, width, 0+offsety, NULL, scene)); + scene->addItem(new QGraphicsLineItem(0, 0+offsety, 0, -height+offsety, NULL)); + scene->addItem(new QGraphicsLineItem(0, 0+offsety, width, 0+offsety, NULL)); for (i = 0; i < nbreaks; i++) { diff --git a/plugins/TraceInfos/CMakeLists.txt b/plugins/TraceInfos/CMakeLists.txt index 967ef689..8561c106 100644 --- a/plugins/TraceInfos/CMakeLists.txt +++ b/plugins/TraceInfos/CMakeLists.txt @@ -30,4 +30,8 @@ set(TRACEINFOS_srcs add_library(TraceInfos SHARED ${TRACEINFOS_srcs}) +IF(USE_QT5) + qt5_use_modules(TraceInfos Widgets Core) +ENDIF(USE_QT5) + install(TARGETS TraceInfos DESTINATION ${HOME}/.vite) \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6d424c43..28d5efd5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -373,10 +373,18 @@ IF(VITE_ENABLE_SERIALIZATION) ENDIF(VITE_ENABLE_SERIALIZATION) - +############################################# +# QT5 +############################################# +IF(USE_QT5) + QT5_WRAP_UI(VITE_UIS_H ${VITE_UIS}) + QT5_WRAP_CPP(VITE_MOC ${VITE_UIS_H} ${VITE_MOC_HDRS}) + QT5_ADD_RESOURCES(VITE_RCC_SRCS ${VITE_RCCS}) + ADD_DEFINITIONS(-DQT_NO_DEBUG) ############################################# # QT4 ############################################# +ELSE(USE_QT5) QT4_AUTOMOC(${VITE_SRCS}) FOREACH(_hdrs_file ${VITE_HDRS}) GET_FILENAME_COMPONENT(_abs_file ${_hdrs_file} ABSOLUTE) @@ -393,6 +401,7 @@ QT4_ADD_RESOURCES(VITE_RCC_SRCS ${VITE_RCCS}) ADD_DEFINITIONS(-DQT_NO_DEBUG) +ENDIF(USE_QT5) ############################################# INCLUDE_DIRECTORIES( @@ -425,6 +434,13 @@ else( APPLE ) ADD_EXECUTABLE(vite ${VITE_SRCS} ${VITE_MOC} ${VITE_RCC_SRCS}) endif( APPLE ) +############################################# +# QT5 +############################################# +IF(USE_QT5) + qt5_use_modules(vite Widgets Core Xml OpenGL UiTools) +ENDIF(USE_QT5) + TARGET_LINK_LIBRARIES(vite ${QT_LIBRARIES} ${GLU_LIBRARY} diff --git a/src/interface/Interface_graphic.cpp b/src/interface/Interface_graphic.cpp index 2a4f8397..6c3f7ab6 100644 --- a/src/interface/Interface_graphic.cpp +++ b/src/interface/Interface_graphic.cpp @@ -1028,7 +1028,11 @@ void Interface_graphic::on_show_all_trace_triggered(){ _core->launch_action(Core::_STATE_RENDER_AREA_REGISTERED_TRANSLATE, &id); } -void Interface_graphic::on_zoom_box_textChanged(QString s){ +#if QT_VERSION < 0x050000 +void Interface_graphic::on_zoom_box_textChanged(const QString &s){ +#else +void Interface_graphic::on_zoom_box_currentTextChanged(const QString &s){ +#endif QRegExp reg_exp_number("^(\\d+)"); QString result; Element_pos d; diff --git a/src/interface/Interface_graphic.hpp b/src/interface/Interface_graphic.hpp index b6cdec9e..77c26776 100644 --- a/src/interface/Interface_graphic.hpp +++ b/src/interface/Interface_graphic.hpp @@ -685,7 +685,11 @@ protected slots: * * \param s The new string value of the zoom box. */ - void on_zoom_box_textChanged(QString s); +#if QT_VERSION < 0x050000 + void on_zoom_box_textChanged(const QString &s); +#else + void on_zoom_box_currentTextChanged(const QString &s); +#endif /*! * \brief Change the x position of camera view for state drawing area. -- GitLab