From e158d3a0c23dd629359dcdf04ea5fda1d48ac51e Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Fri, 1 Mar 2024 14:46:32 +0100 Subject: [PATCH] Cleaning --- src/GraphicsView/GraphicsView_ViewPort.cxx | 103 +----------------- src/GraphicsView/GraphicsView_ViewPort.h | 1 - .../GraphicsView_ViewTransformer.cxx | 7 +- 3 files changed, 2 insertions(+), 109 deletions(-) diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 93f46d7b6..7876bd42e 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -68,12 +68,6 @@ void GraphicsView_ViewPort::fitAll() void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect) { -// double aGap = myFitAllGap; -// QRectF aRect = rect; -// aRect.adjusted(-aGap, -aGap, aGap, aGap); - // std::cout << "Update Scene Rect" << std::endl; -// scene()->setSceneRect(aRect); -// QGraphicsView::updateSceneRect(rect); } void GraphicsView_ViewPort::fitSelect() @@ -86,43 +80,7 @@ void GraphicsView_ViewPort::fitSelect() selectionRect = selectionRect.united(item->sceneBoundingRect()); if(!selectionRect.isNull()) - fitInView(selectionRect, Qt::KeepAspectRatio); -/* - QRectF visibleSceneRect = mapToScene(viewport()->rect()).boundingRect(); - - double vw = visibleSceneRect.width(); - double vh = visibleSceneRect.height(); - - double sw = selectionRect.width(); - double sh = selectionRect.height(); - - double vx = visibleSceneRect.center().x(); - double vy = visibleSceneRect.center().y(); - - double sx = selectionRect.center().x(); - double sy = selectionRect.center().y(); - - double dx = vx-sx; - double dy = sy-vy; - - std::cout << dx << " " << dy << std::endl; - - QGraphicsRectItem *sceneRectItem = new QGraphicsRectItem(selectionRect); - sceneRectItem->setPen(QPen(QColor("blue"),4)); - addItem(sceneRectItem); - - - selectionRect.translate(dx,0.); - - fitInView(selectionRect, Qt::KeepAspectRatio); - - QGraphicsRectItem *sceneRectItem = new QGraphicsRectItem(selectionRect); - sceneRectItem->setPen(QPen(QColor("green"),4)); - addItem(sceneRectItem); -*/ -// std::cout << "visibleSceneRect : " << visibleSceneRect.width() << " x " << visibleSceneRect.height() << std::endl; -// std::cout << "selectionRect : " << selectionRect.width() << " x " << selectionRect.height() << std::endl; - + fitInView(selectionRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio); } void GraphicsView_ViewPort::fitRect(const QRectF& theRect) @@ -156,7 +114,6 @@ void GraphicsView_ViewPort::finishSelectByRect() QRectF selectionRect = mapToScene(myRectBand->geometry()).boundingRect(); // fitInView(selectionRect, Qt::KeepAspectRatio); - QList selectedItems = scene()->items(selectionRect, Qt::IntersectsItemShape); for (QGraphicsItem *item : selectedItems) item->setSelected(true); @@ -192,62 +149,4 @@ void GraphicsView_ViewPort::mouseReleaseEvent(QMouseEvent *event) void GraphicsView_ViewPort::resizeEvent(QResizeEvent *event) { QGraphicsView::resizeEvent(event); - -/* - // Get the current visible scene rectangle - QRectF visibleSceneRect = mapToScene(viewport()->rect()).boundingRect(); - - // Calculate the scaling factors for both width and height - qreal widthScaleFactor = event->size().width() / event->oldSize().width(); - qreal heightScaleFactor = event->size().height() / event->oldSize().height(); - - // Apply the scaling factors to the visible scene rectangle - visibleSceneRect.setWidth(visibleSceneRect.width() * widthScaleFactor); - visibleSceneRect.setHeight(visibleSceneRect.height() * heightScaleFactor); - - // Map the adjusted visible scene rectangle back to viewport coordinates - QRectF viewportRect = mapFromScene(visibleSceneRect).boundingRect(); - - // Ensure that the viewport rectangle stays within the scene boundaries - - if (viewportRect.width() > sceneRect().width()) { - viewportRect.setWidth(sceneRect().width()); - } - if (viewportRect.height() > sceneRect().height()) { - viewportRect.setHeight(sceneRect().height()); - } - - // Update the viewport - fitInView(, Qt::KeepAspectRatio); -*/ -} -void GraphicsView_ViewPort::fitWidth() -{ - double aGap = myFitAllGap; - - QRectF aRect; - foreach (QGraphicsItem *item, scene()->selectedItems()) - aRect = aRect.united(item->sceneBoundingRect()); - - QRectF aRect1 = aRect; - - double aTop = aRect1.top(); - double aLeft = aRect1.left(); - double w = aRect1.width(); - double h = aRect1.height(); - - double aMargin = 10; - - aRect.setY( aRect.center().y() ); - aRect.setX( aRect.center().x() ); - aRect.setHeight( aMargin ); - aRect.setWidth( aMargin ); - - - addItem(new QGraphicsRectItem(aRect)); - - fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); - ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap ); -// ensureVisible(aRect1); - } diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 4929f4fad..977e81b44 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -47,7 +47,6 @@ public: void fitAll(); void fitSelect(); void fitRect(const QRectF& theRect); - void fitWidth(); // rectangle selection void startSelectByRect( int x, int y ); diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.cxx b/src/GraphicsView/GraphicsView_ViewTransformer.cxx index 4a4746e23..ac3ef73d8 100644 --- a/src/GraphicsView/GraphicsView_ViewTransformer.cxx +++ b/src/GraphicsView/GraphicsView_ViewTransformer.cxx @@ -140,12 +140,7 @@ void GraphicsView_ViewTransformer::exec() aViewPort->fitSelect(); onTransform( Finished ); break; -/* - case GraphicsView_Viewer::FitWidth: - aViewPort->fitWidth(); - onTransform( Finished ); - break; -*/ + default: break; } -- 2.39.2