Qt5 port: Sandbox module

This commit is contained in:
wmayer
2017-10-26 13:12:15 +02:00
parent e332bfa172
commit f9485efb26
7 changed files with 95 additions and 32 deletions

View File

@@ -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

View File

@@ -45,7 +45,9 @@
#include <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#include <Gui/Application.h>
#ifdef HAVE_PART
#include <Mod/Part/App/PropertyGeometryList.h>
#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<const Part::PropertyGeometryList&>(Prop);
const std::vector<Part::Geometry*>& items = geom.getValues();
@@ -180,6 +183,10 @@ private:
Base::Console().Error("%s\n", e.what());
}
}
#else
(void)Obj;
(void)Prop;
#endif
}
App::DocumentObject* object;

View File

@@ -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}

View File

@@ -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
}
//===========================================================================

View File

@@ -23,8 +23,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QGLFramebufferObject>
# include <QGLWidget>
# include <QImage>
# include <QMouseEvent>
# include <QPainter>
@@ -32,6 +30,8 @@
# include <Inventor/nodes/SoImage.h>
#endif
#include <QtOpenGL.h>
#include <Gui/Application.h>
#include <Gui/Document.h>
#include <Gui/Selection.h>
@@ -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 <Gui/View3DInventor.h>
#include <Gui/View3DInventorViewer.h>
#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<QGLWidget*>(_pcView3D->getGLWidget())->makeCurrent();
static_cast<QtGLWidget*>(_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<Gui::View3DInventor*>(doc->getActiveView())->getViewer();

View File

@@ -24,13 +24,12 @@
#ifndef SANDBOXGUI_OVERLAY_H
#define SANDBOXGUI_OVERLAY_H
#include <QtOpenGL.h>
#include <Gui/MouseSelection.h>
#include <QColor>
#include <QPoint>
#include <QList>
class QGLFramebufferObject;
namespace SandboxGui {
class DrawingPlane : public Gui::BaseMouseSelection
{
@@ -56,7 +55,7 @@ private:
QPoint lastPoint;
QList<QPoint> selection;
QGLFramebufferObject* fbo;
QtGLFramebufferObject* fbo;
};
} // SandboxGui

View File

@@ -24,8 +24,8 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QGLWidget>
# include <QGridLayout>
# include <QPainter>
# include <Inventor/actions/SoAction.h>
# include <Inventor/elements/SoModelMatrixElement.h>
# include <Inventor/elements/SoViewVolumeElement.h>
@@ -34,6 +34,8 @@
# include <Inventor/SbLinear.h>
#endif
#include <QtOpenGL.h>
#include "Workbench.h"
#include <Gui/MenuManager.h>
#include <Gui/ToolBarManager.h>
@@ -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
}