]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
resize event + fit all fix
authorCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Wed, 13 Mar 2024 07:37:41 +0000 (08:37 +0100)
committerCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Wed, 13 Mar 2024 07:37:41 +0000 (08:37 +0100)
src/GraphicsView/GraphicsView_ViewPort.cxx

index 5c6e53b319ed9950138969c5caa056285d388273..310ba387db2c12064eda446e0f282ee8daf68f3b 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_Session.h"
-#include <iostream>
+
 //=======================================================================
 // Name    : GraphicsView_ViewPort
 // Purpose : Constructor
@@ -78,12 +78,8 @@ void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem )
 
 void GraphicsView_ViewPort::fitAll()
 {
+  scene()->setSceneRect(scene()->itemsBoundingRect());
   QRectF aRect = scene()->sceneRect();
-/*
-  QGraphicsRectItem *sceneRectItem = new QGraphicsRectItem(aRect);
-  sceneRectItem->setPen(QPen(QColor("blue"),4));
-  addItem(sceneRectItem);
-*/
   fitInView( aRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio);
 }
 
@@ -227,7 +223,27 @@ void GraphicsView_ViewPort::mouseReleaseEvent(QMouseEvent *event)
 
 void GraphicsView_ViewPort::resizeEvent(QResizeEvent *event)
 {
-   QGraphicsView::resizeEvent(event);
+  QSize oldSize = event->oldSize();
+  QSize newSize = event->size();
+
+  qreal w = static_cast<qreal>(newSize.width());
+  qreal h = static_cast<qreal>(newSize.height());
+
+  qreal w0 = static_cast<qreal>(oldSize.width());
+  qreal h0 = static_cast<qreal>(oldSize.height());
+
+  qreal widthRatio = w/w0;
+  qreal heightRatio = h/h0;
+  
+
+  if (widthRatio>0 && heightRatio>0)
+    {
+      qreal scaleFactor = w<h ? widthRatio : heightRatio;
+      scale(scaleFactor, scaleFactor);
+    }
+
+  QGraphicsView::resizeEvent(event);
 }
 
 void GraphicsView_ViewPort::wheelEvent(QWheelEvent *event)