From: mzn Date: Fri, 6 Apr 2007 11:30:14 +0000 (+0000) Subject: Connect hilight and tooltip for QxGraph_ActiveItem. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0375170befa46f3362b4a4df31ee09771e72d937;p=modules%2Fgui.git Connect hilight and tooltip for QxGraph_ActiveItem. --- diff --git a/src/QxGraph/QxGraph_ActiveItem.h b/src/QxGraph/QxGraph_ActiveItem.h index 9b2085ae4..bddc1eeb4 100644 --- a/src/QxGraph/QxGraph_ActiveItem.h +++ b/src/QxGraph/QxGraph_ActiveItem.h @@ -39,9 +39,11 @@ class QXGRAPH_EXPORT QxGraph_ActiveItem virtual void resize(QPoint thePoint) {} virtual void afterResizing() {} - virtual void hilight() = 0; + virtual void hilight(const bool toHilight = true) = 0; virtual void select() = 0; virtual void showPopup() = 0; + + virtual QString getToolTipText(const QPoint& theMousePos, QRect& theRect) const = 0; }; #endif diff --git a/src/QxGraph/QxGraph_CanvasView.cxx b/src/QxGraph/QxGraph_CanvasView.cxx index 8ceeb499e..7a3df1dbe 100644 --- a/src/QxGraph/QxGraph_CanvasView.cxx +++ b/src/QxGraph/QxGraph_CanvasView.cxx @@ -27,7 +27,6 @@ #include "QxGraph_Def.h" #include - #include const char* imageZoomCursor[] = { @@ -111,7 +110,8 @@ const char* imageCrossCursor[] = { */ QxGraph_CanvasView::QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWindow* theViewWindow) : QCanvasView(theCanvas, theViewWindow), - myCurrentItem(0) + myCurrentItem(0), + myHilightedItem(0) { printf("Construct QxGraph_CanvasView\n"); setName("QxGraph_CanvasView"); @@ -287,9 +287,25 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) else { QCanvasItemList aList = canvas()->collisions(aPoint); - // to set resize cursor if needed + // to set hilight and resize cursor if needed + bool isHilightPerformed = false; + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + + // hilight + if (!isHilightPerformed && anActItem) + { + if (anActItem != myHilightedItem) + { + anActItem->hilight(); + if (myHilightedItem) + myHilightedItem->hilight(false); + myHilightedItem = anActItem; + isHilightPerformed = true; + } + } + int aCursorType; if ( anActItem && anActItem->isResizable(aPoint,aCursorType) ) { // set resize cursor @@ -325,10 +341,21 @@ void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent) return; } } + + if (!isHilightPerformed && myHilightedItem) + { + myHilightedItem->hilight(false); + myHilightedItem = 0; + } + if ( cursor().shape() == Qt::SizeVerCursor || cursor().shape() == Qt::SizeHorCursor || cursor().shape() == Qt::SizeBDiagCursor || cursor().shape() == Qt::SizeFDiagCursor) setCursor(QCursor(Qt::ArrowCursor)); } + + // show tooltip + QxGraph_ToolTip* aToolTip = new QxGraph_ToolTip(this); + aToolTip->maybeTip(aPoint); } void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent) @@ -509,3 +536,27 @@ QxGraph_ViewWindow* QxGraph_CanvasView::getViewWindow() const { return dynamic_cast( parent() ); } + +/*! + Shows tooltip if necessary +*/ +void QxGraph_ToolTip::maybeTip(const QPoint& theMousePos) { + QCanvasItemList aList = ((QCanvasView*)parentWidget())->canvas()->collisions(theMousePos); + + for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) { + QxGraph_ActiveItem* anActItem = dynamic_cast( *it ); + if (anActItem) + { + QRect aRect; + QString aText = anActItem->getToolTipText(theMousePos, aRect); + int avX, avY; + QWMatrix aWM = ((QCanvasView*)parentWidget())->worldMatrix(); + ((QCanvasView*)parentWidget())->contentsToViewport((int)(aRect.left()*aWM.m11()), + (int)(aRect.top()*aWM.m22()), + avX, avY); + QRect aTipRect(avX, avY, (int)(aRect.width()*aWM.m11()), (int)(aRect.height()*aWM.m22())); + if (!aText.isEmpty()) + tip(aTipRect, aText); + } + } +} diff --git a/src/QxGraph/QxGraph_CanvasView.h b/src/QxGraph/QxGraph_CanvasView.h index 2acf19f8c..a2e6ba381 100644 --- a/src/QxGraph/QxGraph_CanvasView.h +++ b/src/QxGraph/QxGraph_CanvasView.h @@ -28,9 +28,11 @@ #include #include #include +#include class QxGraph_Canvas; class QxGraph_ViewWindow; +class QxGraph_ActiveItem; class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { Q_OBJECT @@ -76,6 +78,20 @@ class QXGRAPH_EXPORT QxGraph_CanvasView : public QCanvasView { QTimer* myTimer; int myDX; int myDY; + + // for hilight + QxGraph_ActiveItem* myHilightedItem; +}; + + +class QxGraph_ToolTip: public QToolTip { + + public: + QxGraph_ToolTip(QWidget* theWidget, QToolTipGroup* theGroup = 0): + QToolTip(theWidget, theGroup) {} + ~QxGraph_ToolTip() { remove(parentWidget()); } + + virtual void maybeTip(const QPoint& theMousePos); }; #endif