Back to index

salome-gui  6.5.0
QxGraph_CanvasView.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME QxGraph : build Supervisor viewer into desktop
00024 //
00025 #include "QxGraph_CanvasView.h"
00026 #include "QxGraph_Canvas.h"
00027 #include "QxGraph_ViewWindow.h"
00028 #include "QxGraph_ActiveItem.h"
00029 #include "QxGraph_Def.h"
00030 
00031 #include <qwmatrix.h>
00032 #include <math.h>
00033 
00034 const char* imageZoomCursor[] = { 
00035 "32 32 3 1",
00036 ". c None",
00037 "a c #000000",
00038 "# c #ffffff",
00039 "................................",
00040 "................................",
00041 ".#######........................",
00042 "..aaaaaaa.......................",
00043 "................................",
00044 ".............#####..............",
00045 "...........##.aaaa##............",
00046 "..........#.aa.....a#...........",
00047 ".........#.a.........#..........",
00048 ".........#a..........#a.........",
00049 "........#.a...........#.........",
00050 "........#a............#a........",
00051 "........#a............#a........",
00052 "........#a............#a........",
00053 "........#a............#a........",
00054 ".........#...........#.a........",
00055 ".........#a..........#a.........",
00056 ".........##.........#.a.........",
00057 "........#####.....##.a..........",
00058 ".......###aaa#####.aa...........",
00059 "......###aa...aaaaa.......#.....",
00060 ".....###aa................#a....",
00061 "....###aa.................#a....",
00062 "...###aa...............#######..",
00063 "....#aa.................aa#aaaa.",
00064 ".....a....................#a....",
00065 "..........................#a....",
00066 "...........................a....",
00067 "................................",
00068 "................................",
00069 "................................",
00070 "................................"};
00071 
00072 const char* imageCrossCursor[] = { 
00073   "32 32 3 1",
00074   ". c None",
00075   "a c #000000",
00076   "# c #ffffff",
00077   "................................",
00078   "................................",
00079   "................................",
00080   "................................",
00081   "................................",
00082   "................................",
00083   "................................",
00084   "...............#................",
00085   "...............#a...............",
00086   "...............#a...............",
00087   "...............#a...............",
00088   "...............#a...............",
00089   "...............#a...............",
00090   "...............#a...............",
00091   "...............#a...............",
00092   ".......#################........",
00093   "........aaaaaaa#aaaaaaaaa.......",
00094   "...............#a...............",
00095   "...............#a...............",
00096   "...............#a...............",
00097   "...............#a...............",
00098   "...............#a...............",
00099   "...............#a...............",
00100   "...............#a...............",
00101   "................a...............",
00102   "................................",
00103   "................................",
00104   "................................",
00105   "................................",
00106   "................................",
00107   "................................",
00108   "................................"};
00109 
00113 QxGraph_CanvasView::QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWindow* theViewWindow) :
00114   QCanvasView(theCanvas, theViewWindow, 0, Qt::WRepaintNoErase),
00115   myCurrentItem(0),
00116   myHilightedItem(0),
00117   mySelectedItem(0),
00118   myMovingDone(false),
00119   myCenter(0,0)
00120 {
00121   printf("Construct QxGraph_CanvasView\n");
00122   setName("QxGraph_CanvasView");
00123 
00124   myOperation = NOTHING;
00125   myCursor = cursor();
00126   mySelectedRect = 0;
00127 
00128   myTimer = new QTimer(this);
00129   connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
00130 
00131   viewport()->setMouseTracking(true);
00132 }
00133 
00137 QxGraph_CanvasView::~QxGraph_CanvasView()
00138 {
00139 }
00140 
00141 void QxGraph_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
00142 {
00143   myPoint = inverseWorldMatrix().map(theEvent->pos());
00144   myGlobalPoint = theEvent->globalPos();
00145   myCurrentItem = 0;
00146 
00147   if ( theEvent->button() == Qt::MidButton && theEvent->state() == Qt::ControlButton
00148        || 
00149        myOperation == PANVIEW )
00150   { // Panning
00151     if ( myOperation != PANVIEW ) {
00152       myOperation = PANVIEW;
00153       myCursor = cursor(); // save old cursor
00154       QCursor panCursor (Qt::SizeAllCursor);
00155       setCursor(panCursor);
00156     }
00157     return;
00158   }
00159 
00160   if ( myOperation == PANGLOBAL )
00161   { // Global panning
00162     return;
00163   }
00164 
00165   if ( myOperation == WINDOWFIT )
00166   { // Fit area
00167     return;
00168   }
00169 
00170   if ( theEvent->button() == Qt::LeftButton && theEvent->state() == Qt::ControlButton
00171        || 
00172        myOperation == ZOOMVIEW )
00173   { // Zoom
00174     if ( myOperation != ZOOMVIEW ) {
00175       myOperation = ZOOMVIEW;
00176       myCursor = cursor(); // save old cursor
00177       QPixmap zoomPixmap (imageZoomCursor);
00178       QCursor zoomCursor (zoomPixmap);
00179       setCursor(zoomCursor);
00180 
00181       // the center of the view before zooming
00182       int aXVCenter = viewport()->width()/2;
00183       int aYVCenter = viewport()->height()/2;
00184       myCenter = viewportToContents(QPoint(aXVCenter,aYVCenter));
00185     }
00186     return;
00187   }
00188 
00189   if ( theEvent->button() == Qt::LeftButton )
00190   {
00191     QCanvasItemList aList = canvas()->collisions(myPoint);
00192     // to move items on canvas view
00193     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00194       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00195       int aCursorType;
00196       if ( anActItem && anActItem->isResizable(myPoint,aCursorType) )
00197       { // resize itself only active items if it is resizable
00198         anActItem->beforeResizing(aCursorType);
00199         myCurrentItem = *it;
00200         return;
00201       }
00202       else if ( anActItem && anActItem->isMoveable() )
00203       { // move itself only active items if it is moveable
00204         anActItem->beforeMoving();
00205         myCurrentItem = *it;
00206         return;
00207       }
00208     }
00209   }
00210 }
00211 
00212 void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
00213 {
00214   QPoint aPoint = inverseWorldMatrix().map(theEvent->pos());
00215   QPoint aGlobalPoint = theEvent->globalPos();
00216 
00217   if (myTimer->isActive()) myTimer->stop();
00218 
00219   if ( myOperation == PANVIEW )
00220   { // Panning
00221     scrollBy(myGlobalPoint.x() - aGlobalPoint.x(),
00222              myGlobalPoint.y() - aGlobalPoint.y());
00223     myGlobalPoint = aGlobalPoint;
00224     myMovingDone = true;
00225     return;
00226   }
00227 
00228   if ( myOperation == WINDOWFIT )
00229   { // Fit within rectangle
00230     int aLX, aTY; //left x and top y
00231     if (myPoint.x() < aPoint.x()) aLX = myPoint.x();
00232     else aLX = aPoint.x();
00233     if (myPoint.y() < aPoint.y()) aTY = myPoint.y();
00234     else aTY = aPoint.y();
00235     QRect aRect(aLX, aTY, abs(myPoint.x()-aPoint.x()), abs(myPoint.y()-aPoint.y()));
00236     QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
00237 
00238     //hide old selected rectangle
00239     if (mySelectedRect)
00240       mySelectedRect->hide();
00241     //draw new selected rectangle
00242     QPen pen(Qt::black,1,Qt::SolidLine);
00243     aRect1->setPen(pen);
00244     aRect1->setZ(1E+6);
00245     aRect1->show();
00246 
00247     mySelectedRect = aRect1;
00248     canvas()->update();
00249 
00250     return;
00251   }
00252 
00253   if ( myOperation == ZOOMVIEW )
00254   { // Zoom
00255     QCanvasItemList aList = canvas()->allItems();
00256     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it)
00257       (*it)->hide();
00258 
00259     int aXContCenter = myCenter.x();
00260     int aYContCenter = myCenter.y();
00261     
00262     QWMatrix m = worldMatrix();
00263 
00264     double dx = aGlobalPoint.x() - myGlobalPoint.x();
00265     double s = 1. + fabs(dx)*( (m.m11() < 1) ? m.m11() : 1. )/70.;
00266     if (dx < 0) s = 1./s;
00267     
00268     int aXContCenterScaled = aXContCenter*s;
00269     int aYContCenterScaled = aYContCenter*s;
00270     
00271     m.scale(s, s);
00272     setWorldMatrix(m);
00273 
00274     center(aXContCenterScaled,aYContCenterScaled);
00275 
00276     myCenter.setX(aXContCenterScaled);
00277     myCenter.setY(aYContCenterScaled);
00278 
00279     // remember the canvas view's current transformation matrix in all canvas items
00280     aList = canvas()->allItems();
00281     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00282       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00283       if ( anActItem ) anActItem->setTMatrix(m);
00284       (*it)->show();
00285     }
00286         
00287     myGlobalPoint = aGlobalPoint;
00288     myMovingDone = true;
00289 
00290     return;
00291   }
00292 
00293   if ( myCurrentItem )
00294   {
00295     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( myCurrentItem );
00296     if ( anActItem && anActItem->isResizing() )
00297     { // to resize items on canvas view
00298       anActItem->resize(aPoint);
00299       myMovingDone = true;
00300       return;
00301     }
00302 
00303     // to move items on canvas view
00304     if ( myCurrentItem->x() && myCurrentItem->y() ) {
00305       double cx = myCurrentItem->x() - myPoint.x();
00306       double cy = myCurrentItem->y() - myPoint.y();
00307         
00308       if (aPoint.x()+cx < 0) aPoint.setX(-(int)cx);
00309       if (aPoint.y()+cy < 0) aPoint.setY(-(int)cy);
00310     }
00311     myCurrentItem->moveBy(aPoint.x() - myPoint.x(), 
00312                           aPoint.y() - myPoint.y());
00313     myMovingDone = true;
00314     myPoint = aPoint;
00315     canvas()->update();
00316 
00317     // scroll contents if mouse is outside
00318     QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
00319     if (!r.contains(theEvent->pos())) {
00320       int dx = 0, dy = 0;
00321       if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
00322       if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
00323       if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
00324       if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
00325       scrollBy(dx, dy);
00326       // start timer to scroll in silent mode
00327       myDX = dx; myDY = dy;
00328       myTimer->start(100);
00329     }
00330     
00331     return;
00332   }
00333   else
00334   {
00335     QCanvasItemList aList = canvas()->collisions(aPoint);
00336     // perform actions for active items
00337     bool isHilightPerformed = false;
00338 
00339     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00340       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00341     
00342       if (!isHilightPerformed && anActItem) {
00343         // hilight
00344         anActItem->hilight(aPoint);
00345         if (anActItem != myHilightedItem) {
00346           if (myHilightedItem)
00347             myHilightedItem->hilight(aPoint, false);
00348           myHilightedItem = anActItem;
00349         }
00350         isHilightPerformed = true;
00351         
00352         // show tooltip
00353         QxGraph_ToolTip* aToolTip = new QxGraph_ToolTip(this);
00354         aToolTip->maybeTip(aPoint);
00355       }
00356       
00357       int aCursorType;
00358       if ( anActItem && anActItem->isResizable(aPoint,aCursorType) ) {
00359         // set resize cursor
00360         QCursor resizeCursor;
00361         switch (aCursorType)
00362           {
00363           case 1: //left
00364           case 3: //right
00365             resizeCursor = QCursor(Qt::SizeHorCursor);
00366             break;
00367           case 2: //top
00368           case 4: //bottom
00369             resizeCursor = QCursor(Qt::SizeVerCursor); 
00370             break;
00371           case 5: //left-top
00372           case 7: //right-bottom
00373             resizeCursor = QCursor(Qt::SizeFDiagCursor);
00374             break;
00375           case 6: //right-top
00376           case 8: //left-bottom
00377             resizeCursor = QCursor(Qt::SizeBDiagCursor); 
00378             break;
00379           default : 
00380             resizeCursor = QCursor(Qt::ArrowCursor);
00381             break;
00382           }
00383         setCursor(resizeCursor);
00384         return;
00385       }
00386       else {
00387         // reset old cursor
00388         setCursor(QCursor(Qt::ArrowCursor));
00389         return;
00390       }
00391     }
00392     
00393     if (!isHilightPerformed && myHilightedItem) {
00394       myHilightedItem->hilight(aPoint, false);
00395       myHilightedItem = 0;
00396       QToolTip::hide(); //@ temporary solution
00397     }
00398 
00399     if ( cursor().shape() == Qt::SizeVerCursor || cursor().shape() == Qt::SizeHorCursor
00400          || cursor().shape() == Qt::SizeBDiagCursor || cursor().shape() == Qt::SizeFDiagCursor)
00401       setCursor(QCursor(Qt::ArrowCursor));
00402   }
00403 }
00404 
00409 void QxGraph_CanvasView::itemRemoved( QCanvasItem* theItem )
00410 {
00411   if ( myCurrentItem == theItem )
00412     myCurrentItem = 0;
00413 
00414   QxGraph_ActiveItem* anActiveItem = dynamic_cast<QxGraph_ActiveItem*>( theItem );
00415   if ( anActiveItem )
00416   {
00417     if ( myHilightedItem == anActiveItem )
00418       myHilightedItem = 0;
00419     if ( mySelectedItem == anActiveItem )
00420       mySelectedItem = 0;
00421   }
00422 }
00423 
00424 void QxGraph_CanvasView::setSelectedItem( QxGraph_ActiveItem* theItem )
00425 {
00426   mySelectedItem = theItem;
00427 }
00428 
00429 QxGraph_ActiveItem* QxGraph_CanvasView::getSelectedItem() const
00430 {
00431   return mySelectedItem;
00432 }
00433 
00434 void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
00435 {
00436   QPoint aPoint = inverseWorldMatrix().map(theEvent->pos());
00437 
00438   if (myTimer->isActive()) myTimer->stop();
00439 
00440   if (myCurrentItem)
00441   { // to move items on canvas view    
00442     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( myCurrentItem );
00443     if ( anActItem && anActItem->isResizing() )
00444     {
00445       anActItem->afterResizing();
00446       // reset old cursor
00447       setCursor(QCursor(Qt::ArrowCursor));
00448     }
00449     else if ( anActItem && anActItem->isMoveable() )
00450       anActItem->afterMoving();
00451   }
00452   myCurrentItem = 0;
00453 
00454   if ( myOperation == PANVIEW )
00455   { // Panning
00456     myOperation = NOTHING;
00457     viewport()->setMouseTracking(true);
00458     setCursor(myCursor);
00459 
00460     emit viewOperationDone();
00461   }
00462 
00463   if ( myOperation == PANGLOBAL )
00464   { // Global panning
00465     myOperation = NOTHING;
00466     center( theEvent->x(), theEvent->y() );
00467     setCursor(myCursor);
00468 
00469     emit viewOperationDone();
00470   }
00471 
00472   if ( myOperation == WINDOWFIT )
00473   { // Fit within rectangle
00474     myOperation = NOTHING;
00475     
00476     if (mySelectedRect) {
00477       mySelectedRect->hide();
00478       mySelectedRect = 0;
00479       //canvas()->update();
00480     }
00481 
00482     //myPoint is the start point for selecting rectangle now
00483     int aLX, aTY; //left x and top y
00484     if (myPoint.x() < aPoint.x()) aLX = myPoint.x();
00485     else aLX = aPoint.x();
00486     if (myPoint.y() < aPoint.y()) aTY = myPoint.y();
00487     else aTY = aPoint.y();
00488 
00489     //calculate width and height for new view and new zoom factor
00490     double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-aPoint.x())));
00491     double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-aPoint.y())));
00492     if (aXzoom > aYzoom) aXzoom = aYzoom;
00493     
00494     QWMatrix m;
00495     m.scale(aXzoom, aXzoom);
00496     setWorldMatrix(m);
00497 
00498     // remember the canvas view's current transformation matrix in all canvas items
00499     QCanvasItemList aList = canvas()->allItems();
00500     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00501       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00502       if ( anActItem ) anActItem->setTMatrix(m);
00503     }
00504 
00505     setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
00506 
00507     canvas()->update();
00508     
00509     viewport()->setMouseTracking(true);
00510     setCursor(myCursor);
00511 
00512     emit viewOperationDone();
00513   }
00514 
00515   if ( myOperation == ZOOMVIEW )
00516   { // Zoom
00517     myOperation = NOTHING;
00518     viewport()->setMouseTracking(true);
00519     setCursor(myCursor);
00520 
00521     emit viewOperationDone();
00522   }
00523 
00524   if ( theEvent->button() == RightButton )
00525   { 
00526     // Selection mechanism
00527     QCanvasItemList aList = canvas()->collisions(aPoint);
00528     bool isSelectionPerformed = false;
00529 
00530     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00531       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00532       if (!isSelectionPerformed && anActItem) 
00533       {
00534         anActItem->select(aPoint);
00535         if (anActItem != mySelectedItem) 
00536         {
00537           if (mySelectedItem && isSelectedItemInCanvas() &&
00538               !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false);
00539           mySelectedItem = anActItem;
00540 
00541           // unhilight hilighted item if selection was performed
00542           if (myHilightedItem) {
00543             myHilightedItem->hilight(aPoint, false);
00544             myHilightedItem = 0;
00545           }
00546         }
00547         isSelectionPerformed = true;
00548       }
00549     }
00550 
00551     if (!isSelectionPerformed)
00552     { 
00553       if ( mySelectedItem )
00554       {
00555         if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
00556         mySelectedItem = 0;
00557       }
00558       
00559       // Background popup
00560       printf("Background popup\n");
00561       QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
00562                                 theEvent->pos(), theEvent->globalPos(),
00563                                 theEvent->state() );
00564       if ( getViewWindow() )
00565         getViewWindow()->contextPopupEvent(&aEvent); // => emit contextMenuRequested( &aEvent );
00566     }
00567     else
00568     { // show context popup for the selected item
00569       mySelectedItem->showPopup(viewport(), theEvent, aPoint);
00570     }
00571   }
00572 
00573   if ( theEvent->button() == LeftButton && !myMovingDone )
00574   {
00575     // Selection mechanism
00576     QCanvasItemList aList = canvas()->collisions(aPoint);
00577 
00578     if ( aList.empty() && mySelectedItem )
00579     {
00580       if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
00581       mySelectedItem = 0;
00582     }
00583     else
00584     {
00585       for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00586         QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00587         if (anActItem) 
00588         {
00589           anActItem->select(aPoint);
00590           if (anActItem != mySelectedItem) 
00591           {
00592             if (mySelectedItem && isSelectedItemInCanvas() &&
00593                 !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false);
00594             mySelectedItem = anActItem;
00595           }
00596           break;
00597         }
00598       }
00599     }
00600   }
00601 
00602   myMovingDone = false;
00603 }
00604 
00605 void QxGraph_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
00606 {
00607   
00608 }
00609 
00610 bool QxGraph_CanvasView::isSelectedItemInCanvas()
00611 {
00612   // check if mySelectedItem is included into the canvas:
00613   // if yes => unselect it
00614   // if no => do nothing
00615   bool anIsInCanvas = false;
00616   QCanvasItemList aListC = canvas()->allItems();
00617   for (QCanvasItemList::Iterator itC = aListC.begin(); itC != aListC.end(); ++itC) {
00618     QxGraph_ActiveItem* anActItemC = dynamic_cast<QxGraph_ActiveItem*>( *itC );
00619     if ( anActItemC && anActItemC == mySelectedItem ) {
00620       anIsInCanvas = true;
00621       break;
00622     }
00623   }
00624   return anIsInCanvas;
00625 }
00626 
00627 void QxGraph_CanvasView::activateFitAll()
00628 {
00629   //myOperation = FITALL;
00630   int w = 0, h = 0;
00631   QCanvasItemList l = canvas()->allItems();
00632   for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
00633     QRect r = (*it)->boundingRect();
00634     if (w < r.right()) w = r.right();
00635     if (h < r.bottom()) h = r.bottom();
00636   }
00637   w += GRAPH_MARGIN; h += GRAPH_MARGIN;
00638   double s = ((double)visibleWidth())/((double)w);
00639   double s1 = ((double)visibleHeight())/((double)h);
00640   if (s > s1) s = s1;
00641 
00642   setContentsPos(0,0);
00643   QWMatrix m;
00644   m.scale(s, s);
00645   setWorldMatrix(m);
00646 
00647   // remember the canvas view's current transformation matrix in all canvas items
00648   QCanvasItemList aList = canvas()->allItems();
00649   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00650     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00651     if ( anActItem ) anActItem->setTMatrix(m);
00652   }
00653   
00654   canvas()->update();
00655   //myOperation = NOTHING;
00656 
00657   emit viewOperationDone();
00658 }
00659 
00660 void QxGraph_CanvasView::activateFitRect()
00661 {
00662   myOperation = WINDOWFIT;
00663   viewport()->setMouseTracking(false);
00664   myCursor = cursor(); // save old cursor
00665   QCursor handCursor (Qt::PointingHandCursor);
00666   setCursor(handCursor);
00667 }
00668 
00669 void QxGraph_CanvasView::activateZoom()
00670 {
00671   myOperation = ZOOMVIEW;
00672   viewport()->setMouseTracking(false);
00673   myCursor = cursor(); // save old cursor
00674   QPixmap zoomPixmap (imageZoomCursor);
00675   QCursor zoomCursor (zoomPixmap);
00676   setCursor(zoomCursor);
00677 }
00678 
00679 void QxGraph_CanvasView::activatePanning()
00680 {
00681   myOperation = PANVIEW;
00682   viewport()->setMouseTracking(false);
00683   myCursor = cursor(); // save old cursor
00684   QCursor panCursor (Qt::SizeAllCursor);
00685   setCursor(panCursor);
00686 }
00687 
00688 void QxGraph_CanvasView::activateGlobalPanning()
00689 {
00690   myOperation = PANGLOBAL;
00691   myCursor = cursor(); // save old cursor
00692   QPixmap globalPanPixmap (imageCrossCursor);
00693   QCursor glPanCursor (globalPanPixmap);
00694   setCursor(glPanCursor);
00695 }
00696 
00697 void QxGraph_CanvasView::activateReset()
00698 {
00699   //myOperation = RESETVIEW;
00700   setContentsPos(0,0);
00701   QWMatrix m;
00702   setWorldMatrix(m);
00703   
00704   // remember the canvas view's current transformation matrix in all canvas items
00705   QCanvasItemList aList = canvas()->allItems();
00706   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00707     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00708     if ( anActItem ) anActItem->setTMatrix(m);
00709   }
00710 
00711   //myOperation = NOTHING;
00712 
00713   emit viewOperationDone();
00714 }
00715 
00716 void QxGraph_CanvasView::onTimeout() 
00717 {
00718   if (myCurrentItem) {
00719     scrollBy(myDX, myDY);
00720 
00721     double cx, cy;
00722     inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
00723     if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
00724     if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
00725     myCurrentItem->moveBy(cx, cy);
00726     myPoint.setX(myPoint.x()+(int)cx);
00727     myPoint.setY(myPoint.y()+(int)cy);
00728     canvas()->update();
00729   }
00730 }
00731 
00732 QxGraph_ViewWindow* QxGraph_CanvasView::getViewWindow() const
00733 {
00734   return dynamic_cast<QxGraph_ViewWindow*>( parent() );
00735 }
00736 
00740 void QxGraph_ToolTip::maybeTip(const QPoint& theMousePos) {
00741   QCanvasItemList aList = ((QCanvasView*)parentWidget())->canvas()->collisions(theMousePos);
00742   
00743   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
00744     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
00745     if (anActItem)
00746       {
00747         QRect aRect;
00748         QString aText = anActItem->getToolTipText(theMousePos, aRect);
00749         int avX, avY;
00750         QWMatrix aWM = ((QCanvasView*)parentWidget())->worldMatrix();
00751         ((QCanvasView*)parentWidget())->contentsToViewport((int)(aRect.left()*aWM.m11()), 
00752                                                            (int)(aRect.top()*aWM.m22()), 
00753                                                            avX, avY);
00754         QRect aTipRect(avX, avY, (int)(aRect.width()*aWM.m11()), (int)(aRect.height()*aWM.m22()));
00755         if (!aText.isEmpty())
00756           tip(aTipRect, aText);
00757         return;
00758       }
00759   }
00760 }
00761 
00762 
00763