From: mkr Date: Tue, 3 Apr 2007 09:00:07 +0000 (+0000) Subject: Bloc node presentation in expanded mode X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3980f7382b6f5a936cacae984146885d8fb2fb74;p=modules%2Fgui.git Bloc node presentation in expanded mode (without Gate ports and background color). Resize Bloc, move its content. --- diff --git a/src/QxGraph/QxGraph_ActiveItem.h b/src/QxGraph/QxGraph_ActiveItem.h index 5443e189a..9b2085ae4 100644 --- a/src/QxGraph/QxGraph_ActiveItem.h +++ b/src/QxGraph/QxGraph_ActiveItem.h @@ -21,6 +21,8 @@ #include "QxGraph.h" +#include + class QXGRAPH_EXPORT QxGraph_ActiveItem { public: @@ -31,6 +33,12 @@ class QXGRAPH_EXPORT QxGraph_ActiveItem virtual void beforeMoving() = 0; virtual void afterMoving() = 0; + virtual bool isResizable(QPoint thePoint, int& theCursorType) { return false; } + virtual bool isResizing() { return false; } + virtual void beforeResizing(int theCursorType) {} + virtual void resize(QPoint thePoint) {} + virtual void afterResizing() {} + virtual void hilight() = 0; virtual void select() = 0; virtual void showPopup() = 0; diff --git a/src/QxGraph/QxGraph_CanvasView.cxx b/src/QxGraph/QxGraph_CanvasView.cxx index 6b99e370c..8ceeb499e 100644 --- a/src/QxGraph/QxGraph_CanvasView.cxx +++ b/src/QxGraph/QxGraph_CanvasView.cxx @@ -177,7 +177,14 @@ void QxGraph_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent) // to move items on canvas view for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); - if ( anActItem && anActItem->isMoveable() ) + int aCursorType; + if ( anActItem && anActItem->isResizable(myPoint,aCursorType) ) + { // resize itself only active items if it is resizable + anActItem->beforeResizing(aCursorType); + myCurrentItem = *it; + return; + } + else if ( anActItem && anActItem->isMoveable() ) { // move itself only active items if it is moveable anActItem->beforeMoving(); myCurrentItem = *it; @@ -240,11 +247,19 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) } if ( myCurrentItem ) - { // to move items on canvas view + { + QxGraph_ActiveItem* anActItem = dynamic_cast( myCurrentItem ); + if ( anActItem && anActItem->isResizing() ) + { // to resize items on canvas view + anActItem->resize(aPoint); + return; + } + + // to move items on canvas view if ( myCurrentItem->x() && myCurrentItem->y() ) { double cx = myCurrentItem->x() - myPoint.x(); double cy = myCurrentItem->y() - myPoint.y(); - + if (aPoint.x()+cx < 0) aPoint.setX(-(int)cx); if (aPoint.y()+cy < 0) aPoint.setY(-(int)cy); } @@ -252,7 +267,7 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) aPoint.y() - myPoint.y()); myPoint = aPoint; canvas()->update(); - + // scroll contents if mouse is outside QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight()); if (!r.contains(theEvent->pos())) { @@ -269,6 +284,51 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) return; } + else + { + QCanvasItemList aList = canvas()->collisions(aPoint); + // to set resize cursor if needed + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + int aCursorType; + if ( anActItem && anActItem->isResizable(aPoint,aCursorType) ) + { // set resize cursor + QCursor resizeCursor; + switch (aCursorType) + { + case 1: //left + case 3: //right + resizeCursor = QCursor(Qt::SizeHorCursor); + break; + case 2: //top + case 4: //bottom + resizeCursor = QCursor(Qt::SizeVerCursor); + break; + case 5: //left-top + case 7: //right-bottom + resizeCursor = QCursor(Qt::SizeFDiagCursor); + break; + case 6: //right-top + case 8: //left-bottom + resizeCursor = QCursor(Qt::SizeBDiagCursor); + break; + default : + resizeCursor = QCursor(Qt::ArrowCursor); + break; + } + setCursor(resizeCursor); + return; + } + else + { // reset old cursor + setCursor(QCursor(Qt::ArrowCursor)); + return; + } + } + if ( cursor().shape() == Qt::SizeVerCursor || cursor().shape() == Qt::SizeHorCursor + || cursor().shape() == Qt::SizeBDiagCursor || cursor().shape() == Qt::SizeFDiagCursor) + setCursor(QCursor(Qt::ArrowCursor)); + } } void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) @@ -278,7 +338,13 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) if (myCurrentItem) { // to move items on canvas view QxGraph_ActiveItem* anActItem = dynamic_cast( myCurrentItem ); - if ( anActItem && anActItem->isMoveable() ) + if ( anActItem && anActItem->isResizing() ) + { + anActItem->afterResizing(); + // reset old cursor + setCursor(QCursor(Qt::ArrowCursor)); + } + else if ( anActItem && anActItem->isMoveable() ) anActItem->afterMoving(); } myCurrentItem = 0;