From f9485efb26b3c55eba12fec0e6bc81cfcc9f7795 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 26 Oct 2017 13:12:15 +0200 Subject: [PATCH] Qt5 port: Sandbox module --- src/Mod/Sandbox/App/CMakeLists.txt | 11 ++++++- src/Mod/Sandbox/Gui/AppSandboxGui.cpp | 7 +++++ src/Mod/Sandbox/Gui/CMakeLists.txt | 19 +++++++++---- src/Mod/Sandbox/Gui/Command.cpp | 24 ++++++++++++++-- src/Mod/Sandbox/Gui/Overlay.cpp | 41 ++++++++++++++++----------- src/Mod/Sandbox/Gui/Overlay.h | 5 ++-- src/Mod/Sandbox/Gui/Workbench.cpp | 20 +++++++++---- 7 files changed, 95 insertions(+), 32 deletions(-) diff --git a/src/Mod/Sandbox/App/CMakeLists.txt b/src/Mod/Sandbox/App/CMakeLists.txt index 6efb1a6086..96646f3150 100644 --- a/src/Mod/Sandbox/App/CMakeLists.txt +++ b/src/Mod/Sandbox/App/CMakeLists.txt @@ -8,10 +8,19 @@ include_directories( ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${XercesC_INCLUDE_DIRS} - ${QT_QTCORE_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR} ) +if (BUILD_QT5) + include_directories( + ${Qt5Core_INCLUDE_DIRS} + ) +else() + include_directories( + ${QT_INCLUDE_DIR} + ) +endif() + set(Sandbox_LIBS Mesh diff --git a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp index f7d47abad4..e0eba5853a 100644 --- a/src/Mod/Sandbox/Gui/AppSandboxGui.cpp +++ b/src/Mod/Sandbox/Gui/AppSandboxGui.cpp @@ -45,7 +45,9 @@ #include #include #include +#ifdef HAVE_PART #include +#endif #include "Workbench.h" @@ -64,6 +66,7 @@ public: private: void slotChangedObject(const App::DocumentObject& Obj, const App::Property& Prop) { +#ifdef HAVE_PART if (object == &Obj && Prop.getTypeId() == Part::PropertyGeometryList::getClassTypeId()) { const Part::PropertyGeometryList& geom = static_cast(Prop); const std::vector& items = geom.getValues(); @@ -180,6 +183,10 @@ private: Base::Console().Error("%s\n", e.what()); } } +#else + (void)Obj; + (void)Prop; +#endif } App::DocumentObject* object; diff --git a/src/Mod/Sandbox/Gui/CMakeLists.txt b/src/Mod/Sandbox/Gui/CMakeLists.txt index 9d1500276a..2963f18335 100644 --- a/src/Mod/Sandbox/Gui/CMakeLists.txt +++ b/src/Mod/Sandbox/Gui/CMakeLists.txt @@ -1,7 +1,7 @@ if(MSVC) - add_definitions(-DHAVE_ACOSH -DHAVE_ATANH -DHAVE_ASINH) + add_definitions(-DHAVE_PART -DHAVE_ACOSH -DHAVE_ATANH -DHAVE_ASINH) else(MSVC) - add_definitions(-DHAVE_LIMITS_H -DHAVE_CONFIG_H) + add_definitions(-DHAVE_PART -DHAVE_LIMITS_H -DHAVE_CONFIG_H) endif(MSVC) include_directories( @@ -12,10 +12,19 @@ include_directories( ${OCC_INCLUDE_DIR} ${PYTHON_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIR} - ${QT_INCLUDE_DIR} ${XercesC_INCLUDE_DIRS} ) +if(BUILD_QT5) + include_directories( + ${Qt5Core_INCLUDE_DIRS} + ) +else() + include_directories( + ${QT_INCLUDE_DIR} + ) +endif() + link_directories(${OCC_LIBRARY_DIR}) set(SandboxGui_LIBS @@ -32,9 +41,9 @@ fc_wrap_cpp(SandboxGui_MOC_SRCS ${SandboxGui_MOC_HDRS}) SOURCE_GROUP("Moc" FILES ${SandboxGui_MOC_SRCS}) if(BUILD_QT5) -qt5_add_resources(Resource_SRCS Resources/Sandbox.qrc) + qt5_add_resources(Resource_SRCS Resources/Sandbox.qrc) else() -qt4_add_resources(Resource_SRCS Resources/Sandbox.qrc) + qt4_add_resources(Resource_SRCS Resources/Sandbox.qrc) endif() SET(Resource_SRCS ${Resource_SRCS} diff --git a/src/Mod/Sandbox/Gui/Command.cpp b/src/Mod/Sandbox/Gui/Command.cpp index c461de6674..2f49c67aee 100644 --- a/src/Mod/Sandbox/Gui/Command.cpp +++ b/src/Mod/Sandbox/Gui/Command.cpp @@ -1027,8 +1027,15 @@ class GDIWidget : public QWidget { public: GDIWidget(QWidget* parent) : QWidget(parent) - {setAttribute(Qt::WA_PaintOnScreen); } - QPaintEngine *paintEngine() const { return 0; } + { + setAttribute(Qt::WA_PaintOnScreen); +#if QT_VERSION >= 0x050000 + setAttribute(Qt::WA_NativeWindow); +#endif + } + QPaintEngine *paintEngine() const { + return 0; + } protected: void paintEvent(QPaintEvent *event) { #if QT_VERSION < 0x050000 @@ -1174,6 +1181,18 @@ CmdTestRedirectPaint::CmdTestRedirectPaint() void CmdTestRedirectPaint::activated(int) { +#if 1 //QT_VERSION >= 0x050000 + QCalendarWidget* cal = new QCalendarWidget(); + cal->setWindowTitle(QString::fromLatin1("QCalendarWidget")); + cal->show(); + QPixmap img(cal->size()); + cal->render(&img); + + QLabel* label = new QLabel(); + label->setPixmap(img); + label->show(); + label->setWindowTitle(QString::fromLatin1("QLabel")); +#else QCalendarWidget* cal = new QCalendarWidget(); QLabel* label = new QLabel(); QPainter::setRedirected(cal,label); @@ -1181,6 +1200,7 @@ void CmdTestRedirectPaint::activated(int) cal->show(); label->show(); label->setWindowTitle(QString::fromLatin1("QLabel")); +#endif } //=========================================================================== diff --git a/src/Mod/Sandbox/Gui/Overlay.cpp b/src/Mod/Sandbox/Gui/Overlay.cpp index 0956417b71..2ee380eea8 100644 --- a/src/Mod/Sandbox/Gui/Overlay.cpp +++ b/src/Mod/Sandbox/Gui/Overlay.cpp @@ -23,8 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include -# include # include # include # include @@ -32,6 +30,8 @@ # include #endif +#include + #include #include #include @@ -44,9 +44,10 @@ using namespace SandboxGui; + class MyPaintable : public Gui::GLGraphicsItem { - QGLFramebufferObject* fbo; + QtGLFramebufferObject* fbo; Gui::View3DInventorViewer* view; QImage img; public: @@ -62,18 +63,22 @@ public: p.drawText(200,200,QString::fromLatin1("Render to QImage")); } - img = QGLWidget::convertToGLFormat(img); - fbo = new QGLFramebufferObject(v->getGLWidget()->size()); +#if !defined(HAVE_QT5_OPENGL) + img = QtGLWidget::convertToGLFormat(img); +#endif + fbo = new QtGLFramebufferObject(v->getGLWidget()->size()); fbo->bind(); //glClear(GL_COLOR_BUFFER_BIT); fbo->release(); { +#if !defined(HAVE_QT5_OPENGL) QPainter p(fbo); p.setPen(Qt::white); - p.drawText(200,200,QString::fromLatin1("Render to QGLFramebufferObject")); + p.drawText(200,200,QString::fromLatin1("Render to QtGLFramebufferObject")); p.end(); +#endif //img = fbo->toImage(); - //img = QGLWidget::convertToGLFormat(img); + //img = QtGLWidget::convertToGLFormat(img); } //fbo->bind(); //glEnable(GL_DEPTH_TEST); @@ -84,7 +89,7 @@ public: //a.apply(v->getSceneManager()->getSceneGraph()); //fbo->release(); //img = fbo->toImage(); - //img = QGLWidget::convertToGLFormat(img); + //img = QtGLWidget::convertToGLFormat(img); view->getSoRenderManager()->scheduleRedraw(); } @@ -142,7 +147,7 @@ public: class Teapots : public Gui::GLGraphicsItem { - QGLFramebufferObject *fbObject; + QtGLFramebufferObject *fbObject; GLuint glTeapotObject; QPoint rubberBandCorner1; QPoint rubberBandCorner2; @@ -158,8 +163,8 @@ Teapots(Gui::View3DInventorViewer* v) :view(v) rubberBandIsShown = false; // makeCurrent(); - fbObject = new QGLFramebufferObject(size[0],size[1], - QGLFramebufferObject::Depth); + fbObject = new QtGLFramebufferObject(size[0],size[1], + QtGLFramebufferObject::Depth); //initializeGL(); resizeGL(size[0],size[1]); @@ -201,7 +206,7 @@ void initializeGL() glDepthFunc(GL_LESS); } -void resizeGL(int /*width*/, int /*height*/) +void resizeGL(int width, int height) { #if 0 fbObject->bind(); @@ -225,6 +230,8 @@ void resizeGL(int /*width*/, int /*height*/) fbObject->release(); #else + (void)width; + (void)height; fbObject->bind(); glDisable(GL_TEXTURE_2D); glEnable(GL_LIGHTING); @@ -441,7 +448,7 @@ void paintSelection() #include #include #if 0 -void MeshSelection::prepareBrushSelection(bool add) +void MeshSelection::prepareFreehandSelection(bool add) { // a rubberband to select a rectangle area of the meshes Gui::View3DInventorViewer* viewer = this->getViewer(); @@ -485,7 +492,7 @@ DrawingPlane::~DrawingPlane() void DrawingPlane::initialize() { - fbo = new QGLFramebufferObject(128, 128,QGLFramebufferObject::Depth); + fbo = new QtGLFramebufferObject(128, 128,QtGLFramebufferObject::Depth); } void DrawingPlane::terminate() @@ -506,7 +513,7 @@ void DrawingPlane::draw () {return; if (1/*mustRedraw*/) { SbVec2s view = _pcView3D->getSoRenderManager()->getSize(); - static_cast(_pcView3D->getGLWidget())->makeCurrent(); + static_cast(_pcView3D->getGLWidget())->makeCurrent(); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); @@ -556,7 +563,7 @@ void DrawingPlane::draw () int DrawingPlane::mouseButtonEvent(const SoMouseButtonEvent * const e, const QPoint& pos) { const int button = e->getButton(); - const SbBool press = e->getState() == SoButtonEvent::DOWN ? TRUE : FALSE; + const SbBool press = e->getState() == SoButtonEvent::DOWN ? true : false; if (press) { switch (button) @@ -618,6 +625,7 @@ int DrawingPlane::keyboardEvent(const SoKeyboardEvent * const) void DrawingPlane::drawLineTo(const QPoint &endPoint) { return; +#if !defined(HAVE_QT5_OPENGL) QPainter painter(fbo); //QPainter painter(_pcView3D->getGLWidget()); painter.setPen(QPen(myPenColor, myPenWidth, Qt::SolidLine, Qt::RoundCap, @@ -628,6 +636,7 @@ void DrawingPlane::drawLineTo(const QPoint &endPoint) //_pcView3D->scheduleRedraw(); lastPoint = endPoint; +#endif } //Gui::Document* doc = Gui::Application::Instance->activeDocument(); //Gui::View3DInventorViewer* view = static_cast(doc->getActiveView())->getViewer(); diff --git a/src/Mod/Sandbox/Gui/Overlay.h b/src/Mod/Sandbox/Gui/Overlay.h index 3127fdd811..b4342087df 100644 --- a/src/Mod/Sandbox/Gui/Overlay.h +++ b/src/Mod/Sandbox/Gui/Overlay.h @@ -24,13 +24,12 @@ #ifndef SANDBOXGUI_OVERLAY_H #define SANDBOXGUI_OVERLAY_H +#include #include #include #include #include -class QGLFramebufferObject; - namespace SandboxGui { class DrawingPlane : public Gui::BaseMouseSelection { @@ -56,7 +55,7 @@ private: QPoint lastPoint; QList selection; - QGLFramebufferObject* fbo; + QtGLFramebufferObject* fbo; }; } // SandboxGui diff --git a/src/Mod/Sandbox/Gui/Workbench.cpp b/src/Mod/Sandbox/Gui/Workbench.cpp index 5e8ba8de64..173baf9b29 100644 --- a/src/Mod/Sandbox/Gui/Workbench.cpp +++ b/src/Mod/Sandbox/Gui/Workbench.cpp @@ -24,8 +24,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include +# include # include # include # include @@ -34,6 +34,8 @@ # include #endif +#include + #include "Workbench.h" #include #include @@ -109,6 +111,7 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Sandbox_RedirectPaint" << "Std_TestGraphicsView" << "Std_TestTaskBox"; + return root; } @@ -153,9 +156,11 @@ SoWidgetShape::SoWidgetShape() void SoWidgetShape::GLRender(SoGLRenderAction * /*action*/) { -#if 1 +#if defined(HAVE_QT5_OPENGL) this->image = QPixmap::grabWidget(w, w->rect()).toImage(); - this->image = QGLWidget::convertToGLFormat(this->image); +#else + this->image = QPixmap::grabWidget(w, w->rect()).toImage(); + this->image = QtGLWidget::convertToGLFormat(this->image); #endif glRasterPos2d(10,10); glDrawPixels(this->image.width(),this->image.height(),GL_RGBA,GL_UNSIGNED_BYTE,this->image.bits()); @@ -273,7 +278,12 @@ void SoWidgetShape::setWidget(QWidget* w) { this->w = w; this->w->show(); - QPainter::setRedirected(this->w, &this->image); + QPixmap img(this->w->size()); + this->w->render(&img); + this->image = img.toImage(); + +#if !defined(HAVE_QT5_OPENGL) this->image = QPixmap::grabWidget(w, w->rect()).toImage(); - this->image = QGLWidget::convertToGLFormat(this->image); + this->image = QtGLWidget::convertToGLFormat(this->image); +#endif }