1 #include "XGUI_ViewWindow.h"
2 #include "XGUI_ViewPort.h"
3 #include "XGUI_Viewer.h"
4 #include "XGUI_Tools.h"
5 #include "XGUI_RubberBand.h"
11 #include <QResizeEvent>
12 #include <QApplication>
14 #include <QMdiSubWindow>
18 #include <TopoDS_Shape.hxx>
19 #include <BRep_Tool.hxx>
24 const char* imageZoomCursor[] = {
29 "................................",
30 "................................",
31 ".#######........................",
32 "..aaaaaaa.......................",
33 "................................",
34 ".............#####..............",
35 "...........##.aaaa##............",
36 "..........#.aa.....a#...........",
37 ".........#.a.........#..........",
38 ".........#a..........#a.........",
39 "........#.a...........#.........",
40 "........#a............#a........",
41 "........#a............#a........",
42 "........#a............#a........",
43 "........#a............#a........",
44 ".........#...........#.a........",
45 ".........#a..........#a.........",
46 ".........##.........#.a.........",
47 "........#####.....##.a..........",
48 ".......###aaa#####.aa...........",
49 "......###aa...aaaaa.......#.....",
50 ".....###aa................#a....",
51 "....###aa.................#a....",
52 "...###aa...............#######..",
53 "....#aa.................aa#aaaa.",
54 ".....a....................#a....",
55 "..........................#a....",
56 "...........................a....",
57 "................................",
58 "................................",
59 "................................",
60 "................................"};
62 const char* imageRotateCursor[] = {
67 "................................",
68 "................................",
69 "................................",
70 "................................",
71 "........#.......................",
72 ".......#.a......................",
73 "......#######...................",
74 ".......#aaaaa#####..............",
75 "........#..##.a#aa##........##..",
76 ".........a#.aa..#..a#.....##.aa.",
77 ".........#.a.....#...#..##.aa...",
78 ".........#a.......#..###.aa.....",
79 "........#.a.......#a..#aa.......",
80 "........#a.........#..#a........",
81 "........#a.........#a.#a........",
82 "........#a.........#a.#a........",
83 "........#a.........#a.#a........",
84 ".........#.........#a#.a........",
85 "........##a........#a#a.........",
86 "......##.a#.......#.#.a.........",
87 "....##.aa..##.....##.a..........",
88 "..##.aa.....a#####.aa...........",
89 "...aa.........aaa#a.............",
90 "................#.a.............",
91 "...............#.a..............",
92 "..............#.a...............",
93 "...............a................",
94 "................................",
95 "................................",
96 "................................",
97 "................................",
98 "................................"};
100 const char* imageCrossCursor[] = {
105 "................................",
106 "................................",
107 "................................",
108 "................................",
109 "................................",
110 "................................",
111 "................................",
112 "...............#................",
113 "...............#a...............",
114 "...............#a...............",
115 "...............#a...............",
116 "...............#a...............",
117 "...............#a...............",
118 "...............#a...............",
119 "...............#a...............",
120 ".......#################........",
121 "........aaaaaaa#aaaaaaaaa.......",
122 "...............#a...............",
123 "...............#a...............",
124 "...............#a...............",
125 "...............#a...............",
126 "...............#a...............",
127 "...............#a...............",
128 "...............#a...............",
129 "................a...............",
130 "................................",
131 "................................",
132 "................................",
133 "................................",
134 "................................",
135 "................................",
136 "................................"};
139 //**************************************************************************
140 void ViewerToolbar::paintEvent( QPaintEvent* theEvent)
144 QRect aRect = rect();
145 QRect aVPRect = myVPort->rect();
146 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
147 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
149 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
150 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
151 //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed());
152 //qDebug(qPrintable(aMsg));
155 //**************************************************************************
156 void ViewerLabel::paintEvent( QPaintEvent* theEvent)
158 QRect aRect = rect();
159 QRect aVPRect = myVPort->rect();
160 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
161 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
163 QRect aImgRect(QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
164 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
165 QLabel::paintEvent(theEvent);
168 //**************************************************************************
169 //**************************************************************************
170 //**************************************************************************
171 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer,
172 V3d_TypeOfView theType):
176 MinimizeIco(":pictures/wnd_minimize.png"),
177 MaximizeIco(":pictures/wnd_maximize.png"),
178 CloseIco(":pictures/wnd_close.png"),
179 RestoreIco(":pictures/wnd_restore.png"),
180 myInteractionStyle(XGUI::STANDARD),
183 my2dMode(XGUI::No2dMode),
184 myCurrPointType(XGUI::GRAVITY),
185 myPrevPointType(XGUI::GRAVITY),
186 myRotationPointSelection(false)
188 mySelectedPoint = gp_Pnt(0.,0.,0.);
189 setFrameStyle(QFrame::Raised);
190 setFrameShape(QFrame::Panel);
191 setLineWidth(BORDER_SIZE);
192 setMouseTracking(true);
194 QVBoxLayout* aLay = new QVBoxLayout(this);
195 aLay->setContentsMargins(BORDER_SIZE,BORDER_SIZE,BORDER_SIZE,BORDER_SIZE);
196 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
197 myViewPort->installEventFilter(this);
198 aLay->addWidget(myViewPort);
200 myPicture = new QLabel();
201 myPicture->setFrameStyle(QFrame::Sunken);
202 myPicture->setFrameShape(QFrame::Panel);
203 myPicture->setMouseTracking(true);
204 myPicture->installEventFilter(this);
207 QStringList aPictures;
208 aPictures<<":pictures/occ_view_camera_dump.png"<<":pictures/occ_view_style_switch.png";
209 aPictures<<":pictures/occ_view_triedre.png"<<":pictures/occ_view_fitall.png";
210 aPictures<<":pictures/occ_view_fitarea.png"<<":pictures/occ_view_zoom.png";
211 aPictures<<":pictures/occ_view_pan.png"<<":pictures/occ_view_glpan.png";
212 aPictures<<":pictures/occ_view_rotate.png"<<":pictures/occ_view_front.png";
213 aPictures<<":pictures/occ_view_back.png"<<":pictures/occ_view_left.png";
214 aPictures<<":pictures/occ_view_right.png"<<":pictures/occ_view_top.png";
215 aPictures<<":pictures/occ_view_bottom.png"<<":pictures/occ_view_clone.png";
218 aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all";
219 aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
220 aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
222 myGripWgt = new ViewerLabel(this, myViewPort);
223 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
224 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
225 myGripWgt->setMouseTracking(true);
226 myGripWgt->installEventFilter(this);
227 connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update()));
228 connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update()));
230 myViewBar = new ViewerToolbar(this, myViewPort);
233 for (int i = 0; i < aTitles.length(); i++) {
234 aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar);
235 myViewBar->addAction(aBtn);
237 connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update()));
238 connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update()));
240 myWindowBar = new ViewerToolbar(this, myViewPort);
241 connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update()));
242 connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update()));
244 myMinimizeBtn = new QAction(myWindowBar);
245 myMinimizeBtn->setIcon(MinimizeIco);
246 myWindowBar->addAction(myMinimizeBtn);
247 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
249 myMaximizeBtn = new QAction(myWindowBar);
250 myMaximizeBtn->setIcon(MaximizeIco);
251 myWindowBar->addAction(myMaximizeBtn);
252 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
254 aBtn = new QAction(myWindowBar);
255 aBtn->setIcon(CloseIco);
256 myWindowBar->addAction(aBtn);
257 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
264 //****************************************************************
265 XGUI_ViewWindow::~XGUI_ViewWindow()
269 //****************************************************************
270 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
272 QSize aSize = theEvent->size();
273 QSize aWndBarSize = myWindowBar->sizeHint();
274 QSize myViewBarSize = myViewBar->sizeHint();
276 myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4, BORDER_SIZE + 2);
277 int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
278 if (aViewBarWidth > myViewBarSize.width())
279 aViewBarWidth = myViewBarSize.width();
280 myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
283 //****************************************************************
284 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
287 if (theEvent->type() == QEvent::WindowStateChange) {
289 if (!myPicture->parentWidget()) {
290 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
291 QMdiArea* aMDIArea = aParent->mdiArea();
292 myPicture->setParent(aMDIArea);
294 myPicture->move(parentWidget()->x(), parentWidget()->y());
299 myMinimizeBtn->setIcon(MinimizeIco);
300 myMaximizeBtn->setIcon(RestoreIco);
304 QWidget::changeEvent(theEvent);
307 //****************************************************************
308 void XGUI_ViewWindow::onClose()
311 parentWidget()->close();
315 //****************************************************************
316 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
318 if (!isMinimized()) {
326 //****************************************************************
327 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
334 //****************************************************************
335 void XGUI_ViewWindow::onMinimize()
337 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
340 double aR = aW / 100.;
341 myPicture->setPixmap(aPMap.scaled(100, int(aH / aR)));
343 myLastState = isMaximized()? MaximizedState : NormalState;
347 //****************************************************************
348 void XGUI_ViewWindow::onMaximize()
351 myMaximizeBtn->setIcon(MaximizeIco);
355 myMaximizeBtn->setIcon(RestoreIco);
359 myMinimizeBtn->setIcon(MinimizeIco);
362 //****************************************************************
363 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
365 QWidget* aWgt = (theObj == myPicture)? myPicture : static_cast<QWidget*>(parentWidget());
366 switch (theEvent->type()) {
367 case QEvent::MouseButtonPress:
369 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
370 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)){
372 myMousePnt = aEvent->globalPos();
377 case QEvent::MouseButtonRelease:
379 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
380 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
386 case QEvent::MouseMove:
388 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
390 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
391 QMdiArea* aMDIArea = aParent->mdiArea();
393 QPoint aPnt = aEvent->globalPos();
394 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
395 if (aMDIArea->rect().contains(aMDIPnt)) {
396 int aX = aWgt->x() + (aPnt.x() - myMousePnt.x());
397 int aY = aWgt->y() + (aPnt.y() - myMousePnt.y());
405 case QEvent::MouseButtonDblClick:
406 if (theObj == myPicture) {
408 if (myLastState == MaximizedState)
418 //****************************************************************
419 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
421 switch(theEvent->type()) {
422 case QEvent::MouseButtonPress:
423 vpMousePressEvent((QMouseEvent*) theEvent);
426 case QEvent::MouseButtonRelease:
427 vpMouseReleaseEvent((QMouseEvent*) theEvent);
430 case QEvent::MouseMove:
431 vpMouseMoveEvent((QMouseEvent*) theEvent);
434 case QEvent::MouseButtonDblClick:
435 emit mouseDoubleClicked(this, (QMouseEvent*)theEvent);
441 //****************************************************************
442 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
444 if ((theObj == myGripWgt) || (theObj == myPicture)) {
445 if (processWindowControls(theObj, theEvent) )
447 } else if (theObj == myViewPort) {
448 if (processViewPort(theEvent))
451 return QFrame::eventFilter(theObj, theEvent);
454 //****************************************************************
455 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(QMouseEvent* theEvent,
456 XGUI::InteractionStyle theInteractionStyle)
458 OperationType aOp = NOTHING;
459 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle)theInteractionStyle;
460 if( (theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM]) &&
461 (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]) )
463 else if( (theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN]) &&
464 (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]) )
466 else if( (theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE]) &&
467 (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE]) &&
468 (my2dMode == XGUI::No2dMode))
474 //****************************************************************
475 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
477 myStartX = theEvent->x();
478 myStartY = theEvent->y();
479 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
481 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
482 // which are assigned for pan and rotate - these operations are activated immediately after pressing
483 // of the first button, so it is necessary to switch to zoom when the second button is pressed
484 bool aSwitchToZoom = false;
485 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
486 aSwitchToZoom = getButtonState( theEvent, anInteractionStyle ) == ZOOMVIEW;
489 switch ( myOperation ) {
491 if ( theEvent->button() == Qt::LeftButton )
492 emit vpTransformationStarted ( WINDOWFIT );
496 if ( theEvent->button() == Qt::LeftButton )
497 emit vpTransformationStarted ( PANGLOBAL );
501 if ( theEvent->button() == Qt::LeftButton ) {
502 myViewPort->startZoomAtPoint( myStartX, myStartY );
503 emit vpTransformationStarted ( ZOOMVIEW );
508 if ( aSwitchToZoom ) {
509 myViewPort->startZoomAtPoint( myStartX, myStartY );
511 } else if ( theEvent->button() == Qt::LeftButton )
512 emit vpTransformationStarted ( PANVIEW );
516 if ( aSwitchToZoom ) {
517 myViewPort->startZoomAtPoint( myStartX, myStartY );
519 } else if ( theEvent->button() == Qt::LeftButton ) {
520 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
521 emit vpTransformationStarted ( ROTATE );
526 /* Try to activate a transformation */
527 OperationType aState;
528 if ( interactionStyle() == XGUI::STANDARD )
529 aState = getButtonState(theEvent, anInteractionStyle);
531 aState = XGUI_ViewWindow::NOTHING;
536 myViewPort->startZoomAtPoint( myStartX, myStartY );
544 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
547 if ( myRotationPointSelection ) {
548 if ( theEvent->button() == Qt::LeftButton ) {
549 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
551 for ( ic->InitSelected(); ic->MoreSelected(); ic->NextSelected() ) {
552 TopoDS_Shape aShape = ic->SelectedShape();
553 if ( !aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX ) {
554 gp_Pnt aPnt = BRep_Tool::Pnt( TopoDS::Vertex( ic->SelectedShape() ) );
555 /*if ( mySetRotationPointDlg ) {
556 myRotationPointSelection = false;
557 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
560 myCurrPointType = myPrevPointType;
564 if ( ic->NbSelected() == 0 ) myCurrPointType = myPrevPointType;
565 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
566 ic->CloseAllContexts();
567 myOperation = NOTHING;
568 myViewPort->setCursor( myCursor );
569 myCursorIsHand = false;
570 myRotationPointSelection = false;
573 emit mousePressed(this, theEvent);
576 /* notify that we start a transformation */
577 if ( transformRequested() )
578 emit vpTransformationStarted ( myOperation );
580 if ( transformRequested() )
581 setTransformInProcess( true );
583 /* we may need it for sketching... */
584 /* if ( l_mbPressEvent )
585 delete l_mbPressEvent;
586 l_mbPressEvent = new QMouseEvent( *theEvent );*/
589 //****************************************************************
590 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
592 switch ( myOperation ) {
595 int prevState = myCurSketch;
596 /* if(theEvent->button() == Qt::RightButton) {
597 QList<OCCViewer_ViewSketcher*>::Iterator it;
598 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
599 OCCViewer_ViewSketcher* sk = (*it);
600 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
605 emit mouseReleased(this, theEvent);
606 if (theEvent->button() == Qt::RightButton && prevState == -1) {
607 QContextMenuEvent aEvent( QContextMenuEvent::Mouse,
608 theEvent->pos(), theEvent->globalPos() );
609 emit contextMenuRequested( &aEvent );
614 myViewPort->endRotation();
624 if ( theEvent->button() == Qt::LeftButton ) {
625 myViewPort->setCenter( theEvent->x(), theEvent->y() );
626 myViewPort->getView()->SetScale(myCurScale);
632 if ( theEvent->button() == Qt::LeftButton ) {
633 myCurrX = theEvent->x();
634 myCurrY = theEvent->y();
636 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
637 if ( !rect.isEmpty() ) myViewPort->fitRect(rect);
644 // NOTE: viewer 3D detects a rectangle of selection using this event
645 // so we must emit it BEFORE resetting the selection rectangle
646 if ( theEvent->button() == Qt::LeftButton && myDrawRect ) {
650 myViewPort->update();
652 /* if ( l_mbPressEvent ) {
653 delete l_mbPressEvent;
658 //****************************************************************
659 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
661 if ( myIsKeyFree && interactionStyle() == XGUI::KEY_FREE ) {
663 switch ( getButtonState( theEvent, interactionStyle() ) ) {
665 myViewPort->startZoomAtPoint( myStartX, myStartY );
673 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
680 myCurrX = theEvent->x();
681 myCurrY = theEvent->y();
682 switch (myOperation) {
684 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
688 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
694 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
703 if ( myRotationPointSelection /*|| isSketcherStyle()*/ ) {
704 emit mouseMoving( this, theEvent );
706 int aState = theEvent->modifiers();
707 int aButton = theEvent->buttons();
708 int anInteractionStyle = interactionStyle();
709 if ( ( (anInteractionStyle == XGUI::STANDARD) &&
710 (aButton == Qt::LeftButton) &&
711 (aState == Qt::NoModifier || Qt::ShiftModifier) ) ||
712 ( (anInteractionStyle == XGUI::KEY_FREE) &&
713 (aButton == Qt::LeftButton) &&
714 ( aState == Qt::ControlModifier || aState == (Qt::ControlModifier|Qt::ShiftModifier) ) ) ) {
715 myDrawRect = myEnableDrawMode;
718 if ( !myCursorIsHand ) { // we are going to sketch a rectangle
719 QCursor handCursor (Qt::PointingHandCursor);
720 myCursorIsHand = true;
722 myViewPort->setCursor( handCursor );
725 emit mouseMoving( this, theEvent );
726 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
727 (aButton == Qt::RightButton) &&
728 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
729 ( (anInteractionStyle == XGUI::KEY_FREE) &&
730 (aButton == Qt::RightButton) &&
731 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
732 OCCViewer_ViewSketcher* sketcher = 0;
733 QList<OCCViewer_ViewSketcher*>::Iterator it;
734 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
735 OCCViewer_ViewSketcher* sk = (*it);
736 if( sk->isDefault() && sk->sketchButton() == aButton )
739 if ( sketcher && myCurSketch == -1 ) {
740 activateSketching( sketcher->type() );
742 myCurSketch = mypSketcher->sketchButton();
744 if ( l_mbPressEvent ) {
745 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
746 delete l_mbPressEvent;
749 QApplication::sendEvent( getViewPort(), theEvent );
753 emit mouseMoving( this, theEvent );
760 \brief Draw rubber band rectangle.
762 void XGUI_ViewWindow::drawRect()
765 myRectBand = new XGUI_RectRubberBand( myViewPort );
768 myRectBand->setUpdatesEnabled ( false );
769 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
770 myRectBand->initGeometry( aRect );
772 if ( !myRectBand->isVisible() )
775 myRectBand->setUpdatesEnabled ( true );
779 \brief Clear rubber band rectangle on the end on the dragging operation.
781 void XGUI_ViewWindow::endDrawRect()
784 myRectBand->clearGeometry();
789 void XGUI_ViewWindow::activateZoom()
791 if ( !transformRequested() && !myCursorIsHand )
792 myCursor = cursor(); /* save old cursor */
794 if ( myOperation != ZOOMVIEW ) {
795 QPixmap zoomPixmap (imageZoomCursor);
796 QCursor zoomCursor (zoomPixmap);
797 if( setTransformRequested ( ZOOMVIEW ) )
798 myViewPort->setCursor( zoomCursor );
802 bool XGUI_ViewWindow::transformRequested() const
804 return ( myOperation != NOTHING );
808 \brief Start delayed viewer operation.
810 bool XGUI_ViewWindow::setTransformRequested( OperationType op )
812 bool ok = transformEnabled( op );
813 myOperation = ok ? op : NOTHING;
814 myViewPort->setMouseTracking( myOperation == NOTHING );
819 Set enabled state of transformation (rotate, zoom, etc)
821 void XGUI_ViewWindow::setTransformEnabled( const OperationType id, const bool on )
823 if ( id != NOTHING ) myStatus.insert( id, on );
827 \return enabled state of transformation (rotate, zoom, etc)
829 bool XGUI_ViewWindow::transformEnabled( const OperationType id ) const
831 return myStatus.contains( id ) ? myStatus[ id ] : true;
836 \brief Start panning operation.
838 Sets the corresponding cursor for the widget.
840 void XGUI_ViewWindow::activatePanning()
842 if ( !transformRequested() && !myCursorIsHand )
843 myCursor = cursor(); // save old cursor
845 if ( myOperation != PANVIEW ) {
846 QCursor panCursor (Qt::SizeAllCursor);
847 if( setTransformRequested ( PANVIEW ) )
848 myViewPort->setCursor( panCursor );
853 \brief Start rotation operation
855 Sets the corresponding cursor for the widget.
857 void XGUI_ViewWindow::activateRotation()
859 if ( !transformRequested() && !myCursorIsHand )
860 myCursor = cursor(); // save old cursor
862 if ( myOperation != ROTATE ) {
863 QPixmap rotatePixmap (imageRotateCursor);
864 QCursor rotCursor (rotatePixmap);
865 if( setTransformRequested ( ROTATE ) )
866 myViewPort->setCursor( rotCursor );
871 \brief Reset the viewport to its initial state
872 ( no transformations in process etc. )
874 void XGUI_ViewWindow::resetState()
878 if ( myRotationPointSelection ) {
879 QCursor handCursor (Qt::PointingHandCursor);
880 myViewPort->setCursor( handCursor );
882 if ( transformRequested() || myCursorIsHand )
883 myViewPort->setCursor( myCursor );
884 myCursorIsHand = false;
887 if ( transformRequested() )
888 emit vpTransformationFinished (myOperation);
890 setTransformInProcess( false );
891 setTransformRequested( NOTHING );