From 6ac3f581319a59e07f020c715f27f9e12550cd72 Mon Sep 17 00:00:00 2001 From: mkr Date: Wed, 25 Apr 2007 14:32:37 +0000 Subject: [PATCH] Modifications to edit links presentations : add and delete links points, move links points and links edges. --- src/QxGraph/QxGraph_ActiveItem.h | 7 ++++-- src/QxGraph/QxGraph_CanvasView.cxx | 39 ++++++++++++++++++++++++------ src/QxGraph/QxGraph_CanvasView.h | 2 ++ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/QxGraph/QxGraph_ActiveItem.h b/src/QxGraph/QxGraph_ActiveItem.h index 4f84089ca..fc9f008e7 100644 --- a/src/QxGraph/QxGraph_ActiveItem.h +++ b/src/QxGraph/QxGraph_ActiveItem.h @@ -22,7 +22,8 @@ #include "QxGraph.h" #include -#include +#include +#include class QXGRAPH_EXPORT QxGraph_ActiveItem { @@ -42,10 +43,12 @@ class QXGRAPH_EXPORT QxGraph_ActiveItem virtual void hilight(const QPoint& theMousePos, const bool toHilight = true) = 0; virtual void select(const QPoint& theMousePos, const bool toSelect = true) = 0; - virtual void showPopup() = 0; + virtual void showPopup(QWidget* theParent, QMouseEvent* theEvent, const QPoint& theMousePos = QPoint()) = 0; virtual QString getToolTipText(const QPoint& theMousePos, QRect& theRect) const = 0; + virtual bool arePartsOfOtherItem(QxGraph_ActiveItem* theSecondItem) { return false; } + void setTMatrix(QWMatrix theMatrix) { myTMatrix = theMatrix; } QWMatrix getTMatrix() const { return myTMatrix; } diff --git a/src/QxGraph/QxGraph_CanvasView.cxx b/src/QxGraph/QxGraph_CanvasView.cxx index 7cfc82d6d..a563bc5c2 100644 --- a/src/QxGraph/QxGraph_CanvasView.cxx +++ b/src/QxGraph/QxGraph_CanvasView.cxx @@ -459,9 +459,15 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) anActItem->select(aPoint); if (anActItem != mySelectedItem) { - if (mySelectedItem) - mySelectedItem->select(aPoint, false); + if (mySelectedItem && isSelectedItemInCanvas() && + !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false); mySelectedItem = anActItem; + + // unhilight hilighted item if selection was performed + if (myHilightedItem) { + myHilightedItem->hilight(aPoint, false); + myHilightedItem = 0; + } } isSelectionPerformed = true; } @@ -471,8 +477,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) { if ( mySelectedItem ) { - mySelectedItem->select(aPoint, false); - mySelectedItem = 0; + if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false); + mySelectedItem = 0; } // Background popup @@ -485,7 +491,7 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) } else { // show context popup for the selected item - + mySelectedItem->showPopup(viewport(), theEvent, aPoint); } } @@ -496,7 +502,7 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) if ( aList.empty() && mySelectedItem ) { - mySelectedItem->select(aPoint, false); + if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false); mySelectedItem = 0; } else @@ -508,8 +514,8 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) anActItem->select(aPoint); if (anActItem != mySelectedItem) { - if (mySelectedItem) - mySelectedItem->select(aPoint, false); + if (mySelectedItem && isSelectedItemInCanvas() && + !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false); mySelectedItem = anActItem; } break; @@ -521,7 +527,24 @@ void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) void QxGraph_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent) { + +} +bool QxGraph_CanvasView::isSelectedItemInCanvas() +{ + // check if mySelectedItem is included into the canvas: + // if yes => unselect it + // if no => do nothing + bool anIsInCanvas = false; + QCanvasItemList aListC = canvas()->allItems(); + for (QCanvasItemList::Iterator itC = aListC.begin(); itC != aListC.end(); ++itC) { + QxGraph_ActiveItem* anActItemC = dynamic_cast( *itC ); + if ( anActItemC && anActItemC == mySelectedItem ) { + anIsInCanvas = true; + break; + } + } + return anIsInCanvas; } void QxGraph_CanvasView::activateFitAll() diff --git a/src/QxGraph/QxGraph_CanvasView.h b/src/QxGraph/QxGraph_CanvasView.h index 484f7f978..5bd14f740 100644 --- a/src/QxGraph/QxGraph_CanvasView.h +++ b/src/QxGraph/QxGraph_CanvasView.h @@ -63,6 +63,8 @@ class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { void contentsMouseReleaseEvent(QMouseEvent* theEvent); void contentsMouseDoubleClickEvent(QMouseEvent* theEvent); + bool isSelectedItemInCanvas(); + private: // for moving items QCanvasItem* myCurrentItem; -- 2.39.2