From: CHEMIN Sebastien Date: Wed, 13 Mar 2024 07:37:41 +0000 (+0100) Subject: resize event + fit all fix X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0701ec72f1456d06392039582fbef42e4c4ae136;p=modules%2Fgui.git resize event + fit all fix --- diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 5c6e53b31..310ba387d 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -27,7 +27,7 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" -#include + //======================================================================= // 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(newSize.width()); + qreal h = static_cast(newSize.height()); + + qreal w0 = static_cast(oldSize.width()); + qreal h0 = static_cast(oldSize.height()); + + qreal widthRatio = w/w0; + qreal heightRatio = h/h0; + + + + if (widthRatio>0 && heightRatio>0) + { + qreal scaleFactor = w