From 4a84227aed9e2545925e50885ae6f038082a73d0 Mon Sep 17 00:00:00 2001 From: mkr Date: Fri, 8 Feb 2008 15:01:11 +0000 Subject: [PATCH] YACS GUI debug. --- src/QxGraph/QxGraph_CanvasView.cxx | 41 ++++++++++++++++++++++++++++-- src/QxGraph/QxGraph_CanvasView.h | 4 +++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/QxGraph/QxGraph_CanvasView.cxx b/src/QxGraph/QxGraph_CanvasView.cxx index be0d7dcbf..e7f726b13 100644 --- a/src/QxGraph/QxGraph_CanvasView.cxx +++ b/src/QxGraph/QxGraph_CanvasView.cxx @@ -113,7 +113,8 @@ QxGraph_CanvasView::QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWi myCurrentItem(0), myHilightedItem(0), mySelectedItem(0), - myMovingDone(false) + myMovingDone(false), + myCenter(0,0) { printf("Construct QxGraph_CanvasView\n"); setName("QxGraph_CanvasView"); @@ -174,6 +175,11 @@ void QxGraph_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent) QPixmap zoomPixmap (imageZoomCursor); QCursor zoomCursor (zoomPixmap); setCursor(zoomCursor); + + // the center of the view before zooming + int aXVCenter = viewport()->width()/2; + int aYVCenter = viewport()->height()/2; + myCenter = viewportToContents(QPoint(aXVCenter,aYVCenter)); } return; } @@ -213,6 +219,7 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) scrollBy(myGlobalPoint.x() - aGlobalPoint.x(), myGlobalPoint.y() - aGlobalPoint.y()); myGlobalPoint = aGlobalPoint; + myMovingDone = true; return; } @@ -243,23 +250,41 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) if ( myOperation == ZOOMVIEW ) { // Zoom + QCanvasItemList aList = canvas()->allItems(); + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) + (*it)->hide(); + + int aXContCenter = myCenter.x(); + int aYContCenter = myCenter.y(); + QWMatrix m = worldMatrix(); double dx = aGlobalPoint.x() - myGlobalPoint.x(); double s = 1. + fabs(dx)*( (m.m11() < 1) ? m.m11() : 1. )/70.; if (dx < 0) s = 1./s; + int aXContCenterScaled = aXContCenter*s; + int aYContCenterScaled = aYContCenter*s; + m.scale(s, s); setWorldMatrix(m); + center(aXContCenterScaled,aYContCenterScaled); + + myCenter.setX(aXContCenterScaled); + myCenter.setY(aYContCenterScaled); + // remember the canvas view's current transformation matrix in all canvas items - QCanvasItemList aList = canvas()->allItems(); + aList = canvas()->allItems(); for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); if ( anActItem ) anActItem->setTMatrix(m); + (*it)->show(); } myGlobalPoint = aGlobalPoint; + myMovingDone = true; + return; } @@ -429,6 +454,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) myOperation = NOTHING; viewport()->setMouseTracking(true); setCursor(myCursor); + + emit viewOperationDone(); } if ( myOperation == PANGLOBAL ) @@ -436,6 +463,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) myOperation = NOTHING; center( theEvent->x(), theEvent->y() ); setCursor(myCursor); + + emit viewOperationDone(); } if ( myOperation == WINDOWFIT ) @@ -477,6 +506,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) viewport()->setMouseTracking(true); setCursor(myCursor); + + emit viewOperationDone(); } if ( myOperation == ZOOMVIEW ) @@ -484,6 +515,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) myOperation = NOTHING; viewport()->setMouseTracking(true); setCursor(myCursor); + + emit viewOperationDone(); } if ( theEvent->button() == RightButton ) @@ -618,6 +651,8 @@ void QxGraph_CanvasView::activateFitAll() canvas()->update(); //myOperation = NOTHING; + + emit viewOperationDone(); } void QxGraph_CanvasView::activateFitRect() @@ -672,6 +707,8 @@ void QxGraph_CanvasView::activateReset() } //myOperation = NOTHING; + + emit viewOperationDone(); } void QxGraph_CanvasView::onTimeout() diff --git a/src/QxGraph/QxGraph_CanvasView.h b/src/QxGraph/QxGraph_CanvasView.h index f14e1277e..6aa5c3b79 100644 --- a/src/QxGraph/QxGraph_CanvasView.h +++ b/src/QxGraph/QxGraph_CanvasView.h @@ -58,6 +58,9 @@ class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { void setSelectedItem( QxGraph_ActiveItem* theItem ); QxGraph_ActiveItem* getSelectedItem() const; + signals: + void viewOperationDone(); + public slots: void onTimeout(); //void changeBackground(); @@ -76,6 +79,7 @@ class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { QPoint myPoint; QPoint myGlobalPoint; bool myMovingDone; + QPoint myCenter; // for control toolbar actions OperationType myOperation; -- 2.39.2