]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Improvement of the dumpView() method for print functionality
authorouv <ouv@opencascade.com>
Thu, 3 Mar 2011 09:16:35 +0000 (09:16 +0000)
committerouv <ouv@opencascade.com>
Thu, 3 Mar 2011 09:16:35 +0000 (09:16 +0000)
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h

index daa1b70878d274dc3c11afd3a482a096ce443e7a..b95e1cf65b5022cf3e1ea12bf8efcc546d15f41c 100644 (file)
@@ -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;
index 59b1f61bb2f22bc5ebf630728d40ba41875fa315..39848652bf906e16e8c98ed94f48c3412e237f9a 100644 (file)
@@ -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