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()
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)
QRectF selectionRect = mapToScene(myRectBand->geometry()).boundingRect();
// fitInView(selectionRect, Qt::KeepAspectRatio);
-
QList<QGraphicsItem *> selectedItems = scene()->items(selectionRect, Qt::IntersectsItemShape);
for (QGraphicsItem *item : selectedItems)
item->setSelected(true);
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);
-
}