]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Connect hilight and tooltip for QxGraph_ActiveItem.
authormzn <mzn@opencascade.com>
Fri, 6 Apr 2007 11:30:14 +0000 (11:30 +0000)
committermzn <mzn@opencascade.com>
Fri, 6 Apr 2007 11:30:14 +0000 (11:30 +0000)
src/QxGraph/QxGraph_ActiveItem.h
src/QxGraph/QxGraph_CanvasView.cxx
src/QxGraph/QxGraph_CanvasView.h

index 9b2085ae41ee8d189cbd580916248e384533f3c4..bddc1eeb4d3ee09d20e000330eb257a0a3a052dc 100644 (file)
@@ -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
index 8ceeb499ef43d0cd90edbc7acb44cc282a4ae106..7a3df1dbe7adb8288bf9f3afa0ace91705ac885c 100644 (file)
@@ -27,7 +27,6 @@
 #include "QxGraph_Def.h"
 
 #include <qwmatrix.h>
-
 #include <math.h>
 
 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<QxGraph_ActiveItem*>( *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<QxGraph_ViewWindow*>( 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<QxGraph_ActiveItem*>( *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);
+      }
+  }
+}
index 2acf19f8cc014f2040a04bb0028560d02cbadd5a..a2e6ba381bb4a4d84c6f8db03e45001cab595833 100644 (file)
 #include <qcanvas.h>
 #include <qcursor.h>
 #include <qtimer.h>
+#include <qtooltip.h>
 
 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