From 7d91639b99d107b1e22f2d6f22cce15f1643a6c8 Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 3 Mar 2011 09:16:35 +0000 Subject: [PATCH] Improvement of the dumpView() method for print functionality --- src/GraphicsView/GraphicsView_ViewPort.cxx | 18 +++++++++++++++--- src/GraphicsView/GraphicsView_ViewPort.h | 3 ++- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index daa1b7087..b95e1cf65 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -287,7 +287,8 @@ QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const // Function : dumpView // Purpose : //================================================================ -QImage GraphicsView_ViewPort::dumpView( bool theWholeScene ) +QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, + QSizeF theSize ) { if( !theWholeScene ) // just grab the view contents { @@ -301,10 +302,21 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene ) if( aRect.isNull() ) return QImage(); + QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() ); + if( theSize.isValid() ) + { + double aRatioX = theSize.width() / aTargetRect.width(); + double aRatioY = theSize.height() / aTargetRect.height(); + double aRatio = qMin( aRatioX, aRatioY ); + aTargetRect.setWidth( aTargetRect.width() * aRatio ); + aTargetRect.setHeight( aTargetRect.height() * aRatio ); + } + // render the scene to an image - QImage anImage( aRect.toRect().size(), QImage::Format_RGB32 ); + QImage anImage( aTargetRect.toRect().size(), QImage::Format_RGB32 ); QPainter aPainter( &anImage ); - QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() ); + aPainter.setRenderHints( renderHints() ); + myScene->render( &aPainter, aTargetRect, aRect ); return anImage; diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 59b1f61bb..39848652b 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -75,7 +75,8 @@ public: QRectF objectsBoundingRect( bool theOnlyVisible = false ) const; - QImage dumpView( bool theWholeScene = false ); + QImage dumpView( bool theWholeScene = false, + QSizeF theSize = QSizeF() ); public: // scene -- 2.39.2