Navigation Menu

Skip to content

Commit

Permalink
Qt5OpenGL: fix creating thumbnals, pdf, print preview and snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Mar 21, 2017
1 parent 4bf14e7 commit 5bf326c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
4 changes: 3 additions & 1 deletion src/Gui/Thumbnail.cpp
Expand Up @@ -134,9 +134,11 @@ void Thumbnail::RestoreDocFile(Base::Reader &reader)
void Thumbnail::createThumbnailFromFramebuffer(QImage& img) const
{
// Alternative way of off-screen rendering
QtGLFramebufferObject fbo(this->size, this->size,QtGLFramebufferObject::Depth);
if (this->viewer->isActiveWindow()) {
static_cast<QtGLWidget*>(this->viewer->getGLWidget())->makeCurrent();
QtGLFramebufferObject fbo(this->size, this->size,QtGLFramebufferObject::Depth);
this->viewer->renderToFramebuffer(&fbo);
img = fbo.toImage();
static_cast<QtGLWidget*>(this->viewer->getGLWidget())->doneCurrent();
}
}
5 changes: 5 additions & 0 deletions src/Gui/View3DInventor.cpp
Expand Up @@ -545,6 +545,7 @@ void View3DInventor::print(QPrinter* printer)
#else
QImage img;
QPainter p(printer);
p.setRenderHints(QPainter::Antialiasing | QPainter::HighQualityAntialiasing);
if (!p.isActive() && !printer->outputFileName().isEmpty()) {
qApp->setOverrideCursor(Qt::ArrowCursor);
QMessageBox::critical(this, tr("Opening file failed"),
Expand Down Expand Up @@ -579,6 +580,8 @@ void View3DInventor::print(QPrinter* printer)

void View3DInventor::previewFromFramebuffer(const QRect& rect, QImage& img)
{
static_cast<QtGLWidget*>(_viewer->getGLWidget())->makeCurrent();

#if QT_VERSION >= 0x040600
QtGLFramebufferObjectFormat format;
format.setSamples(8);
Expand All @@ -595,6 +598,8 @@ void View3DInventor::previewFromFramebuffer(const QRect& rect, QImage& img)
_viewer->setBackgroundColor(col);
_viewer->setGradientBackground(on);
img = fbo.toImage();

static_cast<QtGLWidget*>(_viewer->getGLWidget())->doneCurrent();
}

// **********************************************************************************
Expand Down
19 changes: 12 additions & 7 deletions src/Gui/View3DPy.cpp
Expand Up @@ -696,6 +696,9 @@ Py::Object View3DInventorPy::isAnimationEnabled(const Py::Tuple& args)

void View3DInventorPy::createImageFromFramebuffer(int width, int height, const QColor& bgcolor, QImage& img)
{
View3DInventorViewer* viewer = _view->getViewer();
static_cast<QtGLWidget*>(viewer->getGLWidget())->makeCurrent();

const QtGLContext* context = QtGLContext::currentContext();
if (!context) {
Base::Console().Warning("createImageFromFramebuffer failed because no context is active\n");
Expand All @@ -709,18 +712,20 @@ void View3DInventorPy::createImageFromFramebuffer(int width, int height, const Q
#else
QtGLFramebufferObject fbo(width, height, QtGLFramebufferObject::Depth);
#endif
const QColor col = _view->getViewer()->backgroundColor();
bool on = _view->getViewer()->hasGradientBackground();
const QColor col = viewer->backgroundColor();
bool on = viewer->hasGradientBackground();

if (bgcolor.isValid()) {
_view->getViewer()->setBackgroundColor(bgcolor);
_view->getViewer()->setGradientBackground(false);
viewer->setBackgroundColor(bgcolor);
viewer->setGradientBackground(false);
}

_view->getViewer()->renderToFramebuffer(&fbo);
_view->getViewer()->setBackgroundColor(col);
_view->getViewer()->setGradientBackground(on);
viewer->renderToFramebuffer(&fbo);
viewer->setBackgroundColor(col);
viewer->setGradientBackground(on);
img = fbo.toImage();

static_cast<QtGLWidget*>(viewer->getGLWidget())->doneCurrent();
}

Py::Object View3DInventorPy::saveImage(const Py::Tuple& args)
Expand Down

0 comments on commit 5bf326c

Please sign in to comment.