From 0701ec72f1456d06392039582fbef42e4c4ae136 Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Wed, 13 Mar 2024 08:37:41 +0100 Subject: [PATCH] resize event + fit all fix --- src/GraphicsView/GraphicsView_ViewPort.cxx | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) 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