#include "QxGraph.h"
#include <qpoint.h>
-#include <qwmatrix.h>
+#include <qwmatrix.h>
+#include <qevent.h>
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; }
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;
}
{
if ( mySelectedItem )
{
- mySelectedItem->select(aPoint, false);
- mySelectedItem = 0;
+ if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
+ mySelectedItem = 0;
}
// Background popup
}
else
{ // show context popup for the selected item
-
+ mySelectedItem->showPopup(viewport(), theEvent, aPoint);
}
}
if ( aList.empty() && mySelectedItem )
{
- mySelectedItem->select(aPoint, false);
+ if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
mySelectedItem = 0;
}
else
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;
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<QxGraph_ActiveItem*>( *itC );
+ if ( anActItemC && anActItemC == mySelectedItem ) {
+ anIsInCanvas = true;
+ break;
+ }
+ }
+ return anIsInCanvas;
}
void QxGraph_CanvasView::activateFitAll()