]> SALOME platform Git repositories - modules/gui.git/blob - src/QxGraph/QxGraph_CanvasView.cxx
Salome HOME
b9fd4377a9ac43edcf959a80cf554ec684317fd6
[modules/gui.git] / src / QxGraph / QxGraph_CanvasView.cxx
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME QxGraph : build Supervisor viewer into desktop
24 //
25 #include "QxGraph_CanvasView.h"
26 #include "QxGraph_Canvas.h"
27 #include "QxGraph_ViewWindow.h"
28 #include "QxGraph_ActiveItem.h"
29 #include "QxGraph_Def.h"
30
31 #include <qwmatrix.h>
32 #include <math.h>
33
34 const char* imageZoomCursor[] = { 
35 "32 32 3 1",
36 ". c None",
37 "a c #000000",
38 "# c #ffffff",
39 "................................",
40 "................................",
41 ".#######........................",
42 "..aaaaaaa.......................",
43 "................................",
44 ".............#####..............",
45 "...........##.aaaa##............",
46 "..........#.aa.....a#...........",
47 ".........#.a.........#..........",
48 ".........#a..........#a.........",
49 "........#.a...........#.........",
50 "........#a............#a........",
51 "........#a............#a........",
52 "........#a............#a........",
53 "........#a............#a........",
54 ".........#...........#.a........",
55 ".........#a..........#a.........",
56 ".........##.........#.a.........",
57 "........#####.....##.a..........",
58 ".......###aaa#####.aa...........",
59 "......###aa...aaaaa.......#.....",
60 ".....###aa................#a....",
61 "....###aa.................#a....",
62 "...###aa...............#######..",
63 "....#aa.................aa#aaaa.",
64 ".....a....................#a....",
65 "..........................#a....",
66 "...........................a....",
67 "................................",
68 "................................",
69 "................................",
70 "................................"};
71
72 const char* imageCrossCursor[] = { 
73   "32 32 3 1",
74   ". c None",
75   "a c #000000",
76   "# c #ffffff",
77   "................................",
78   "................................",
79   "................................",
80   "................................",
81   "................................",
82   "................................",
83   "................................",
84   "...............#................",
85   "...............#a...............",
86   "...............#a...............",
87   "...............#a...............",
88   "...............#a...............",
89   "...............#a...............",
90   "...............#a...............",
91   "...............#a...............",
92   ".......#################........",
93   "........aaaaaaa#aaaaaaaaa.......",
94   "...............#a...............",
95   "...............#a...............",
96   "...............#a...............",
97   "...............#a...............",
98   "...............#a...............",
99   "...............#a...............",
100   "...............#a...............",
101   "................a...............",
102   "................................",
103   "................................",
104   "................................",
105   "................................",
106   "................................",
107   "................................",
108   "................................"};
109
110 /*!
111   Constructor
112 */
113 QxGraph_CanvasView::QxGraph_CanvasView(QxGraph_Canvas* theCanvas, QxGraph_ViewWindow* theViewWindow) :
114   QCanvasView(theCanvas, theViewWindow, 0, Qt::WRepaintNoErase),
115   myCurrentItem(0),
116   myHilightedItem(0),
117   mySelectedItem(0),
118   myMovingDone(false),
119   myCenter(0,0)
120 {
121   printf("Construct QxGraph_CanvasView\n");
122   setName("QxGraph_CanvasView");
123
124   myOperation = NOTHING;
125   myCursor = cursor();
126   mySelectedRect = 0;
127
128   myTimer = new QTimer(this);
129   connect(myTimer, SIGNAL(timeout()), this, SLOT(onTimeout()));
130
131   viewport()->setMouseTracking(true);
132 }
133
134 /*!
135   Destructor
136 */
137 QxGraph_CanvasView::~QxGraph_CanvasView()
138 {
139 }
140
141 void QxGraph_CanvasView::contentsMousePressEvent(QMouseEvent* theEvent)
142 {
143   myPoint = inverseWorldMatrix().map(theEvent->pos());
144   myGlobalPoint = theEvent->globalPos();
145   myCurrentItem = 0;
146
147   if ( theEvent->button() == Qt::MidButton && theEvent->state() == Qt::ControlButton
148        || 
149        myOperation == PANVIEW )
150   { // Panning
151     if ( myOperation != PANVIEW ) {
152       myOperation = PANVIEW;
153       myCursor = cursor(); // save old cursor
154       QCursor panCursor (Qt::SizeAllCursor);
155       setCursor(panCursor);
156     }
157     return;
158   }
159
160   if ( myOperation == PANGLOBAL )
161   { // Global panning
162     return;
163   }
164
165   if ( myOperation == WINDOWFIT )
166   { // Fit area
167     return;
168   }
169
170   if ( theEvent->button() == Qt::LeftButton && theEvent->state() == Qt::ControlButton
171        || 
172        myOperation == ZOOMVIEW )
173   { // Zoom
174     if ( myOperation != ZOOMVIEW ) {
175       myOperation = ZOOMVIEW;
176       myCursor = cursor(); // save old cursor
177       QPixmap zoomPixmap (imageZoomCursor);
178       QCursor zoomCursor (zoomPixmap);
179       setCursor(zoomCursor);
180
181       // the center of the view before zooming
182       int aXVCenter = viewport()->width()/2;
183       int aYVCenter = viewport()->height()/2;
184       myCenter = viewportToContents(QPoint(aXVCenter,aYVCenter));
185     }
186     return;
187   }
188
189   if ( theEvent->button() == Qt::LeftButton )
190   {
191     QCanvasItemList aList = canvas()->collisions(myPoint);
192     // to move items on canvas view
193     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
194       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
195       int aCursorType;
196       if ( anActItem && anActItem->isResizable(myPoint,aCursorType) )
197       { // resize itself only active items if it is resizable
198         anActItem->beforeResizing(aCursorType);
199         myCurrentItem = *it;
200         return;
201       }
202       else if ( anActItem && anActItem->isMoveable() )
203       { // move itself only active items if it is moveable
204         anActItem->beforeMoving();
205         myCurrentItem = *it;
206         return;
207       }
208     }
209   }
210 }
211
212 void QxGraph_CanvasView::contentsMouseMoveEvent(QMouseEvent* theEvent)
213 {
214   QPoint aPoint = inverseWorldMatrix().map(theEvent->pos());
215   QPoint aGlobalPoint = theEvent->globalPos();
216
217   if (myTimer->isActive()) myTimer->stop();
218
219   if ( myOperation == PANVIEW )
220   { // Panning
221     scrollBy(myGlobalPoint.x() - aGlobalPoint.x(),
222              myGlobalPoint.y() - aGlobalPoint.y());
223     myGlobalPoint = aGlobalPoint;
224     myMovingDone = true;
225     return;
226   }
227
228   if ( myOperation == WINDOWFIT )
229   { // Fit within rectangle
230     int aLX, aTY; //left x and top y
231     if (myPoint.x() < aPoint.x()) aLX = myPoint.x();
232     else aLX = aPoint.x();
233     if (myPoint.y() < aPoint.y()) aTY = myPoint.y();
234     else aTY = aPoint.y();
235     QRect aRect(aLX, aTY, abs(myPoint.x()-aPoint.x()), abs(myPoint.y()-aPoint.y()));
236     QCanvasRectangle* aRect1 = new QCanvasRectangle(aRect, canvas());
237
238     //hide old selected rectangle
239     if (mySelectedRect)
240       mySelectedRect->hide();
241     //draw new selected rectangle
242     QPen pen(Qt::black,1,Qt::SolidLine);
243     aRect1->setPen(pen);
244     aRect1->setZ(1E+6);
245     aRect1->show();
246
247     mySelectedRect = aRect1;
248     canvas()->update();
249
250     return;
251   }
252
253   if ( myOperation == ZOOMVIEW )
254   { // Zoom
255     QCanvasItemList aList = canvas()->allItems();
256     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it)
257       (*it)->hide();
258
259     int aXContCenter = myCenter.x();
260     int aYContCenter = myCenter.y();
261     
262     QWMatrix m = worldMatrix();
263
264     double dx = aGlobalPoint.x() - myGlobalPoint.x();
265     double s = 1. + fabs(dx)*( (m.m11() < 1) ? m.m11() : 1. )/70.;
266     if (dx < 0) s = 1./s;
267     
268     int aXContCenterScaled = aXContCenter*s;
269     int aYContCenterScaled = aYContCenter*s;
270     
271     m.scale(s, s);
272     setWorldMatrix(m);
273
274     center(aXContCenterScaled,aYContCenterScaled);
275
276     myCenter.setX(aXContCenterScaled);
277     myCenter.setY(aYContCenterScaled);
278
279     // remember the canvas view's current transformation matrix in all canvas items
280     aList = canvas()->allItems();
281     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
282       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
283       if ( anActItem ) anActItem->setTMatrix(m);
284       (*it)->show();
285     }
286         
287     myGlobalPoint = aGlobalPoint;
288     myMovingDone = true;
289
290     return;
291   }
292
293   if ( myCurrentItem )
294   {
295     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( myCurrentItem );
296     if ( anActItem && anActItem->isResizing() )
297     { // to resize items on canvas view
298       anActItem->resize(aPoint);
299       myMovingDone = true;
300       return;
301     }
302
303     // to move items on canvas view
304     if ( myCurrentItem->x() && myCurrentItem->y() ) {
305       double cx = myCurrentItem->x() - myPoint.x();
306       double cy = myCurrentItem->y() - myPoint.y();
307         
308       if (aPoint.x()+cx < 0) aPoint.setX(-(int)cx);
309       if (aPoint.y()+cy < 0) aPoint.setY(-(int)cy);
310     }
311     myCurrentItem->moveBy(aPoint.x() - myPoint.x(), 
312                           aPoint.y() - myPoint.y());
313     myMovingDone = true;
314     myPoint = aPoint;
315     canvas()->update();
316
317     // scroll contents if mouse is outside
318     QRect r(contentsX(), contentsY(), visibleWidth(), visibleHeight());
319     if (!r.contains(theEvent->pos())) {
320       int dx = 0, dy = 0;
321       if (theEvent->pos().x() < r.left()) dx = theEvent->pos().x() - r.left();
322       if (theEvent->pos().x() > r.right()) dx = theEvent->pos().x() - r.right();
323       if (theEvent->pos().y() < r.top()) dy = theEvent->pos().y() - r.top();
324       if (theEvent->pos().y() > r.bottom()) dy = theEvent->pos().y() - r.bottom();
325       scrollBy(dx, dy);
326       // start timer to scroll in silent mode
327       myDX = dx; myDY = dy;
328       myTimer->start(100);
329     }
330     
331     return;
332   }
333   else
334   {
335     QCanvasItemList aList = canvas()->collisions(aPoint);
336     // perform actions for active items
337     bool isHilightPerformed = false;
338
339     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
340       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
341     
342       if (!isHilightPerformed && anActItem) {
343         // hilight
344         anActItem->hilight(aPoint);
345         if (anActItem != myHilightedItem) {
346           if (myHilightedItem)
347             myHilightedItem->hilight(aPoint, false);
348           myHilightedItem = anActItem;
349         }
350         isHilightPerformed = true;
351         
352         // show tooltip
353         QxGraph_ToolTip* aToolTip = new QxGraph_ToolTip(this);
354         aToolTip->maybeTip(aPoint);
355       }
356       
357       int aCursorType;
358       if ( anActItem && anActItem->isResizable(aPoint,aCursorType) ) {
359         // set resize cursor
360         QCursor resizeCursor;
361         switch (aCursorType)
362           {
363           case 1: //left
364           case 3: //right
365             resizeCursor = QCursor(Qt::SizeHorCursor);
366             break;
367           case 2: //top
368           case 4: //bottom
369             resizeCursor = QCursor(Qt::SizeVerCursor); 
370             break;
371           case 5: //left-top
372           case 7: //right-bottom
373             resizeCursor = QCursor(Qt::SizeFDiagCursor);
374             break;
375           case 6: //right-top
376           case 8: //left-bottom
377             resizeCursor = QCursor(Qt::SizeBDiagCursor); 
378             break;
379           default : 
380             resizeCursor = QCursor(Qt::ArrowCursor);
381             break;
382           }
383         setCursor(resizeCursor);
384         return;
385       }
386       else {
387         // reset old cursor
388         setCursor(QCursor(Qt::ArrowCursor));
389         return;
390       }
391     }
392     
393     if (!isHilightPerformed && myHilightedItem) {
394       myHilightedItem->hilight(aPoint, false);
395       myHilightedItem = 0;
396       QToolTip::hide(); //@ temporary solution
397     }
398
399     if ( cursor().shape() == Qt::SizeVerCursor || cursor().shape() == Qt::SizeHorCursor
400          || cursor().shape() == Qt::SizeBDiagCursor || cursor().shape() == Qt::SizeFDiagCursor)
401       setCursor(QCursor(Qt::ArrowCursor));
402   }
403 }
404
405 /*!
406   This method is called by QxGraph_Canvas when item is removed. 
407   QxGraph_CanvasView updates its own data accordingly
408 */
409 void QxGraph_CanvasView::itemRemoved( QCanvasItem* theItem )
410 {
411   if ( myCurrentItem == theItem )
412     myCurrentItem = 0;
413
414   QxGraph_ActiveItem* anActiveItem = dynamic_cast<QxGraph_ActiveItem*>( theItem );
415   if ( anActiveItem )
416   {
417     if ( myHilightedItem == anActiveItem )
418       myHilightedItem = 0;
419     if ( mySelectedItem == anActiveItem )
420       mySelectedItem = 0;
421   }
422 }
423
424 void QxGraph_CanvasView::setSelectedItem( QxGraph_ActiveItem* theItem )
425 {
426   mySelectedItem = theItem;
427 }
428
429 QxGraph_ActiveItem* QxGraph_CanvasView::getSelectedItem() const
430 {
431   return mySelectedItem;
432 }
433
434 void QxGraph_CanvasView::contentsMouseReleaseEvent(QMouseEvent* theEvent)
435 {
436   QPoint aPoint = inverseWorldMatrix().map(theEvent->pos());
437
438   if (myTimer->isActive()) myTimer->stop();
439
440   if (myCurrentItem)
441   { // to move items on canvas view    
442     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( myCurrentItem );
443     if ( anActItem && anActItem->isResizing() )
444     {
445       anActItem->afterResizing();
446       // reset old cursor
447       setCursor(QCursor(Qt::ArrowCursor));
448     }
449     else if ( anActItem && anActItem->isMoveable() )
450       anActItem->afterMoving();
451   }
452   myCurrentItem = 0;
453
454   if ( myOperation == PANVIEW )
455   { // Panning
456     myOperation = NOTHING;
457     viewport()->setMouseTracking(true);
458     setCursor(myCursor);
459
460     emit viewOperationDone();
461   }
462
463   if ( myOperation == PANGLOBAL )
464   { // Global panning
465     myOperation = NOTHING;
466     center( theEvent->x(), theEvent->y() );
467     setCursor(myCursor);
468
469     emit viewOperationDone();
470   }
471
472   if ( myOperation == WINDOWFIT )
473   { // Fit within rectangle
474     myOperation = NOTHING;
475     
476     if (mySelectedRect) {
477       mySelectedRect->hide();
478       mySelectedRect = 0;
479       //canvas()->update();
480     }
481
482     //myPoint is the start point for selecting rectangle now
483     int aLX, aTY; //left x and top y
484     if (myPoint.x() < aPoint.x()) aLX = myPoint.x();
485     else aLX = aPoint.x();
486     if (myPoint.y() < aPoint.y()) aTY = myPoint.y();
487     else aTY = aPoint.y();
488
489     //calculate width and height for new view and new zoom factor
490     double aXzoom = ((double)visibleWidth())/((double)(abs(myPoint.x()-aPoint.x())));
491     double aYzoom = ((double)visibleHeight())/((double)(abs(myPoint.y()-aPoint.y())));
492     if (aXzoom > aYzoom) aXzoom = aYzoom;
493     
494     QWMatrix m;
495     m.scale(aXzoom, aXzoom);
496     setWorldMatrix(m);
497
498     // remember the canvas view's current transformation matrix in all canvas items
499     QCanvasItemList aList = canvas()->allItems();
500     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
501       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
502       if ( anActItem ) anActItem->setTMatrix(m);
503     }
504
505     setContentsPos((int)(aLX*aXzoom), (int)(aTY*aYzoom));
506
507     canvas()->update();
508     
509     viewport()->setMouseTracking(true);
510     setCursor(myCursor);
511
512     emit viewOperationDone();
513   }
514
515   if ( myOperation == ZOOMVIEW )
516   { // Zoom
517     myOperation = NOTHING;
518     viewport()->setMouseTracking(true);
519     setCursor(myCursor);
520
521     emit viewOperationDone();
522   }
523
524   if ( theEvent->button() == RightButton )
525   { 
526     // Selection mechanism
527     QCanvasItemList aList = canvas()->collisions(aPoint);
528     bool isSelectionPerformed = false;
529
530     for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
531       QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
532       if (!isSelectionPerformed && anActItem) 
533       {
534         anActItem->select(aPoint);
535         if (anActItem != mySelectedItem) 
536         {
537           if (mySelectedItem && isSelectedItemInCanvas() &&
538               !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false);
539           mySelectedItem = anActItem;
540
541           // unhilight hilighted item if selection was performed
542           if (myHilightedItem) {
543             myHilightedItem->hilight(aPoint, false);
544             myHilightedItem = 0;
545           }
546         }
547         isSelectionPerformed = true;
548       }
549     }
550
551     if (!isSelectionPerformed)
552     { 
553       if ( mySelectedItem )
554       {
555         if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
556         mySelectedItem = 0;
557       }
558       
559       // Background popup
560       printf("Background popup\n");
561       QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
562                                 theEvent->pos(), theEvent->globalPos(),
563                                 theEvent->state() );
564       if ( getViewWindow() )
565         getViewWindow()->contextPopupEvent(&aEvent); // => emit contextMenuRequested( &aEvent );
566     }
567     else
568     { // show context popup for the selected item
569       mySelectedItem->showPopup(viewport(), theEvent, aPoint);
570     }
571   }
572
573   if ( theEvent->button() == LeftButton && !myMovingDone )
574   {
575     // Selection mechanism
576     QCanvasItemList aList = canvas()->collisions(aPoint);
577
578     if ( aList.empty() && mySelectedItem )
579     {
580       if ( isSelectedItemInCanvas() ) mySelectedItem->select(aPoint, false);
581       mySelectedItem = 0;
582     }
583     else
584     {
585       for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
586         QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
587         if (anActItem) 
588         {
589           anActItem->select(aPoint);
590           if (anActItem != mySelectedItem) 
591           {
592             if (mySelectedItem && isSelectedItemInCanvas() &&
593                 !mySelectedItem->arePartsOfOtherItem(anActItem)) mySelectedItem->select(aPoint, false);
594             mySelectedItem = anActItem;
595           }
596           break;
597         }
598       }
599     }
600   }
601
602   myMovingDone = false;
603 }
604
605 void QxGraph_CanvasView::contentsMouseDoubleClickEvent(QMouseEvent* theEvent)
606 {
607   
608 }
609
610 bool QxGraph_CanvasView::isSelectedItemInCanvas()
611 {
612   // check if mySelectedItem is included into the canvas:
613   // if yes => unselect it
614   // if no => do nothing
615   bool anIsInCanvas = false;
616   QCanvasItemList aListC = canvas()->allItems();
617   for (QCanvasItemList::Iterator itC = aListC.begin(); itC != aListC.end(); ++itC) {
618     QxGraph_ActiveItem* anActItemC = dynamic_cast<QxGraph_ActiveItem*>( *itC );
619     if ( anActItemC && anActItemC == mySelectedItem ) {
620       anIsInCanvas = true;
621       break;
622     }
623   }
624   return anIsInCanvas;
625 }
626
627 void QxGraph_CanvasView::activateFitAll()
628 {
629   //myOperation = FITALL;
630   int w = 0, h = 0;
631   QCanvasItemList l = canvas()->allItems();
632   for (QCanvasItemList::Iterator it = l.begin(); it != l.end(); ++it) {
633     QRect r = (*it)->boundingRect();
634     if (w < r.right()) w = r.right();
635     if (h < r.bottom()) h = r.bottom();
636   }
637   w += GRAPH_MARGIN; h += GRAPH_MARGIN;
638   double s = ((double)visibleWidth())/((double)w);
639   double s1 = ((double)visibleHeight())/((double)h);
640   if (s > s1) s = s1;
641
642   setContentsPos(0,0);
643   QWMatrix m;
644   m.scale(s, s);
645   setWorldMatrix(m);
646
647   // remember the canvas view's current transformation matrix in all canvas items
648   QCanvasItemList aList = canvas()->allItems();
649   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
650     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
651     if ( anActItem ) anActItem->setTMatrix(m);
652   }
653   
654   canvas()->update();
655   //myOperation = NOTHING;
656
657   emit viewOperationDone();
658 }
659
660 void QxGraph_CanvasView::activateFitRect()
661 {
662   myOperation = WINDOWFIT;
663   viewport()->setMouseTracking(false);
664   myCursor = cursor(); // save old cursor
665   QCursor handCursor (Qt::PointingHandCursor);
666   setCursor(handCursor);
667 }
668
669 void QxGraph_CanvasView::activateZoom()
670 {
671   myOperation = ZOOMVIEW;
672   viewport()->setMouseTracking(false);
673   myCursor = cursor(); // save old cursor
674   QPixmap zoomPixmap (imageZoomCursor);
675   QCursor zoomCursor (zoomPixmap);
676   setCursor(zoomCursor);
677 }
678
679 void QxGraph_CanvasView::activatePanning()
680 {
681   myOperation = PANVIEW;
682   viewport()->setMouseTracking(false);
683   myCursor = cursor(); // save old cursor
684   QCursor panCursor (Qt::SizeAllCursor);
685   setCursor(panCursor);
686 }
687
688 void QxGraph_CanvasView::activateGlobalPanning()
689 {
690   myOperation = PANGLOBAL;
691   myCursor = cursor(); // save old cursor
692   QPixmap globalPanPixmap (imageCrossCursor);
693   QCursor glPanCursor (globalPanPixmap);
694   setCursor(glPanCursor);
695 }
696
697 void QxGraph_CanvasView::activateReset()
698 {
699   //myOperation = RESETVIEW;
700   setContentsPos(0,0);
701   QWMatrix m;
702   setWorldMatrix(m);
703   
704   // remember the canvas view's current transformation matrix in all canvas items
705   QCanvasItemList aList = canvas()->allItems();
706   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
707     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
708     if ( anActItem ) anActItem->setTMatrix(m);
709   }
710
711   //myOperation = NOTHING;
712
713   emit viewOperationDone();
714 }
715
716 void QxGraph_CanvasView::onTimeout() 
717 {
718   if (myCurrentItem) {
719     scrollBy(myDX, myDY);
720
721     double cx, cy;
722     inverseWorldMatrix().map((double)myDX, (double)myDY, &cx, &cy);
723     if (myCurrentItem->x()+cx < 0) cx = -myCurrentItem->x();
724     if (myCurrentItem->y()+cy < 0) cy = -myCurrentItem->y();
725     myCurrentItem->moveBy(cx, cy);
726     myPoint.setX(myPoint.x()+(int)cx);
727     myPoint.setY(myPoint.y()+(int)cy);
728     canvas()->update();
729   }
730 }
731
732 QxGraph_ViewWindow* QxGraph_CanvasView::getViewWindow() const
733 {
734   return dynamic_cast<QxGraph_ViewWindow*>( parent() );
735 }
736
737 /*!
738   Shows tooltip if necessary
739 */
740 void QxGraph_ToolTip::maybeTip(const QPoint& theMousePos) {
741   QCanvasItemList aList = ((QCanvasView*)parentWidget())->canvas()->collisions(theMousePos);
742   
743   for (QCanvasItemList::Iterator it = aList.begin(); it != aList.end(); ++it) {
744     QxGraph_ActiveItem* anActItem = dynamic_cast<QxGraph_ActiveItem*>( *it );
745     if (anActItem)
746       {
747         QRect aRect;
748         QString aText = anActItem->getToolTipText(theMousePos, aRect);
749         int avX, avY;
750         QWMatrix aWM = ((QCanvasView*)parentWidget())->worldMatrix();
751         ((QCanvasView*)parentWidget())->contentsToViewport((int)(aRect.left()*aWM.m11()), 
752                                                            (int)(aRect.top()*aWM.m22()), 
753                                                            avX, avY);
754         QRect aTipRect(avX, avY, (int)(aRect.width()*aWM.m11()), (int)(aRect.height()*aWM.m22()));
755         if (!aText.isEmpty())
756           tip(aTipRect, aText);
757         return;
758       }
759   }
760 }
761
762
763