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[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
25 "................................", "................................",
26 ".#######........................", "..aaaaaaa.......................",
27 "................................", ".............#####..............",
28 "...........##.aaaa##............", "..........#.aa.....a#...........",
29 ".........#.a.........#..........", ".........#a..........#a.........",
30 "........#.a...........#.........", "........#a............#a........",
31 "........#a............#a........", "........#a............#a........",
32 "........#a............#a........", ".........#...........#.a........",
33 ".........#a..........#a.........", ".........##.........#.a.........",
34 "........#####.....##.a..........", ".......###aaa#####.aa...........",
35 "......###aa...aaaaa.......#.....", ".....###aa................#a....",
36 "....###aa.................#a....", "...###aa...............#######..",
37 "....#aa.................aa#aaaa.", ".....a....................#a....",
38 "..........................#a....", "...........................a....",
39 "................................", "................................",
40 "................................", "................................" };
42 const char* imageRotateCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
43 "................................", "................................",
44 "................................", "................................",
45 "........#.......................", ".......#.a......................",
46 "......#######...................", ".......#aaaaa#####..............",
47 "........#..##.a#aa##........##..", ".........a#.aa..#..a#.....##.aa.",
48 ".........#.a.....#...#..##.aa...", ".........#a.......#..###.aa.....",
49 "........#.a.......#a..#aa.......", "........#a.........#..#a........",
50 "........#a.........#a.#a........", "........#a.........#a.#a........",
51 "........#a.........#a.#a........", ".........#.........#a#.a........",
52 "........##a........#a#a.........", "......##.a#.......#.#.a.........",
53 "....##.aa..##.....##.a..........", "..##.aa.....a#####.aa...........",
54 "...aa.........aaa#a.............", "................#.a.............",
55 "...............#.a..............", "..............#.a...............",
56 "...............a................", "................................",
57 "................................", "................................",
58 "................................", "................................" };
60 const char* imageCrossCursor[] = { "32 32 3 1", ". c None", "a c #000000", "# c #ffffff",
61 "................................", "................................",
62 "................................", "................................",
63 "................................", "................................",
64 "................................", "...............#................",
65 "...............#a...............", "...............#a...............",
66 "...............#a...............", "...............#a...............",
67 "...............#a...............", "...............#a...............",
68 "...............#a...............", ".......#################........",
69 "........aaaaaaa#aaaaaaaaa.......", "...............#a...............",
70 "...............#a...............", "...............#a...............",
71 "...............#a...............", "...............#a...............",
72 "...............#a...............", "...............#a...............",
73 "................a...............", "................................",
74 "................................", "................................",
75 "................................", "................................",
76 "................................", "................................" };
78 //**************************************************************************
79 void ViewerToolbar::paintEvent(QPaintEvent* theEvent)
84 QRect aVPRect = myVPort->rect();
85 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
86 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
89 QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
90 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
91 //QString aMsg = QString("### Painted in %1").arg(aTime.elapsed());
92 //qDebug(qPrintable(aMsg));
95 //**************************************************************************
96 void ViewerLabel::paintEvent(QPaintEvent* theEvent)
99 QRect aVPRect = myVPort->rect();
100 QPoint aGlobPnt = mapToGlobal(aRect.topLeft());
101 QPoint aPnt = myVPort->mapFromGlobal(aGlobPnt);
104 QRect(aPnt.x(), aPnt.y() + aVPRect.height() - aRect.height(), aRect.width(), aRect.height()));
105 QPainter(this).drawImage(aRect, myVPort->dumpView(aImgRect, false));
106 QLabel::paintEvent(theEvent);
109 //**************************************************************************
110 //**************************************************************************
111 //**************************************************************************
112 XGUI_ViewWindow::XGUI_ViewWindow(XGUI_Viewer* theViewer, V3d_TypeOfView theType)
113 : QFrame(), myViewer(theViewer), myMoving(false), MinimizeIco(":pictures/wnd_minimize.png"), MaximizeIco(
114 ":pictures/wnd_maximize.png"), CloseIco(":pictures/wnd_close.png"), RestoreIco(
115 ":pictures/wnd_restore.png"), myInteractionStyle(XGUI::STANDARD), myRectBand(0), myIsKeyFree(
116 false), my2dMode(XGUI::No2dMode), myCurrPointType(XGUI::GRAVITY), myPrevPointType(
117 XGUI::GRAVITY), myRotationPointSelection(false)
119 mySelectedPoint = gp_Pnt(0., 0., 0.);
120 setFrameStyle(QFrame::Raised);
121 setFrameShape(QFrame::Panel);
122 setLineWidth(BORDER_SIZE);
123 setMouseTracking(true);
125 QVBoxLayout* aLay = new QVBoxLayout(this);
126 aLay->setContentsMargins(BORDER_SIZE, BORDER_SIZE, BORDER_SIZE, BORDER_SIZE);
127 myViewPort = new XGUI_ViewPort(this, myViewer->v3dViewer(), theType);
128 myViewPort->installEventFilter(this);
129 aLay->addWidget(myViewPort);
131 myPicture = new QLabel();
132 myPicture->setFrameStyle(QFrame::Sunken);
133 myPicture->setFrameShape(QFrame::Panel);
134 myPicture->setMouseTracking(true);
135 myPicture->installEventFilter(this);
138 QStringList aPictures;
139 aPictures << ":pictures/occ_view_camera_dump.png" << ":pictures/occ_view_style_switch.png";
140 aPictures << ":pictures/occ_view_triedre.png" << ":pictures/occ_view_fitall.png";
141 aPictures << ":pictures/occ_view_fitarea.png" << ":pictures/occ_view_zoom.png";
142 aPictures << ":pictures/occ_view_pan.png" << ":pictures/occ_view_glpan.png";
143 aPictures << ":pictures/occ_view_rotate.png" << ":pictures/occ_view_front.png";
144 aPictures << ":pictures/occ_view_back.png" << ":pictures/occ_view_left.png";
145 aPictures << ":pictures/occ_view_right.png" << ":pictures/occ_view_top.png";
146 aPictures << ":pictures/occ_view_bottom.png" << ":pictures/occ_view_clone.png";
149 aTitles << "Dump view" << "Mouse style switch" << "Show trihedron" << "Fit all";
150 aTitles << "Fit area" << "Zoom" << "Panning" << "Global panning" << "Rotate";
151 aTitles << "Front" << "Back" << "Left" << "Right" << "Top" << "Bottom" << "Clone view";
153 myGripWgt = new ViewerLabel(this, myViewPort);
154 myGripWgt->setPixmap(QPixmap(":pictures/wnd_grip.png"));
155 myGripWgt->setGeometry(BORDER_SIZE + 2, BORDER_SIZE + 2, 19, 32);
156 myGripWgt->setMouseTracking(true);
157 myGripWgt->installEventFilter(this);
158 connect(myViewPort, SIGNAL(vpTransformed()), myGripWgt, SLOT(update()));
159 connect(myViewPort, SIGNAL(vpUpdated()), myGripWgt, SLOT(update()));
161 myViewBar = new ViewerToolbar(this, myViewPort);
164 for(int i = 0; i < aTitles.length(); i++) {
165 aBtn = new QAction(QIcon(aPictures.at(i)), aTitles.at(i), myViewBar);
166 myViewBar->addAction(aBtn);
168 connect(myViewPort, SIGNAL(vpTransformed()), myViewBar, SLOT(update()));
169 connect(myViewPort, SIGNAL(vpUpdated()), myViewBar, SLOT(update()));
171 myWindowBar = new ViewerToolbar(this, myViewPort);
172 connect(myViewPort, SIGNAL(vpTransformed()), myWindowBar, SLOT(update()));
173 connect(myViewPort, SIGNAL(vpUpdated()), myWindowBar, SLOT(update()));
175 myMinimizeBtn = new QAction(myWindowBar);
176 myMinimizeBtn->setIcon(MinimizeIco);
177 myWindowBar->addAction(myMinimizeBtn);
178 connect(myMinimizeBtn, SIGNAL(triggered()), SLOT(onMinimize()));
180 myMaximizeBtn = new QAction(myWindowBar);
181 myMaximizeBtn->setIcon(MaximizeIco);
182 myWindowBar->addAction(myMaximizeBtn);
183 connect(myMaximizeBtn, SIGNAL(triggered()), SLOT(onMaximize()));
185 aBtn = new QAction(myWindowBar);
186 aBtn->setIcon(CloseIco);
187 myWindowBar->addAction(aBtn);
188 connect(aBtn, SIGNAL(triggered()), SLOT(onClose()));
195 //****************************************************************
196 XGUI_ViewWindow::~XGUI_ViewWindow()
200 //****************************************************************
201 void XGUI_ViewWindow::resizeEvent(QResizeEvent* theEvent)
203 QSize aSize = theEvent->size();
204 QSize aWndBarSize = myWindowBar->sizeHint();
205 QSize myViewBarSize = myViewBar->sizeHint();
207 myWindowBar->move(aSize.width() - aWndBarSize.width() - BORDER_SIZE - 4,
209 int aViewBarWidth = aSize.width() - aWndBarSize.width() - myGripWgt->width() - 8;
210 if (aViewBarWidth > myViewBarSize.width())
211 aViewBarWidth = myViewBarSize.width();
212 myViewBar->setGeometry(BORDER_SIZE + 18, BORDER_SIZE + 2, aViewBarWidth, myViewBarSize.height());
215 //****************************************************************
216 void XGUI_ViewWindow::changeEvent(QEvent* theEvent)
219 if (theEvent->type() == QEvent::WindowStateChange) {
221 if (!myPicture->parentWidget()) {
222 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
223 QMdiArea* aMDIArea = aParent->mdiArea();
224 myPicture->setParent(aMDIArea);
226 myPicture->move(parentWidget()->x(), parentWidget()->y());
231 myMinimizeBtn->setIcon(MinimizeIco);
232 myMaximizeBtn->setIcon(RestoreIco);
236 QWidget::changeEvent(theEvent);
239 //****************************************************************
240 void XGUI_ViewWindow::onClose()
243 parentWidget()->close();
247 //****************************************************************
248 void XGUI_ViewWindow::enterEvent(QEvent* theEvent)
250 if (!isMinimized()) {
258 //****************************************************************
259 void XGUI_ViewWindow::leaveEvent(QEvent* theEvent)
266 //****************************************************************
267 void XGUI_ViewWindow::onMinimize()
269 QPixmap aPMap = QPixmap::fromImage(myViewPort->dumpView());
272 double aR = aW / 100.;
273 myPicture->setPixmap(aPMap.scaled(100, int(aH / aR)));
275 myLastState = isMaximized() ? MaximizedState : NormalState;
279 //****************************************************************
280 void XGUI_ViewWindow::onMaximize()
283 myMaximizeBtn->setIcon(MaximizeIco);
287 myMaximizeBtn->setIcon(RestoreIco);
291 myMinimizeBtn->setIcon(MinimizeIco);
294 //****************************************************************
295 bool XGUI_ViewWindow::processWindowControls(QObject *theObj, QEvent *theEvent)
297 QWidget* aWgt = (theObj == myPicture) ? myPicture : static_cast<QWidget*>(parentWidget());
298 switch(theEvent->type()) {
299 case QEvent::MouseButtonPress: {
300 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
301 if ((aEvent->button() == Qt::LeftButton) && (!myMoving)) {
303 myMousePnt = aEvent->globalPos();
308 case QEvent::MouseButtonRelease: {
309 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
310 if ((aEvent->button() == Qt::LeftButton) && myMoving) {
316 case QEvent::MouseMove: {
317 QMouseEvent* aEvent = static_cast<QMouseEvent*>(theEvent);
319 QMdiSubWindow* aParent = static_cast<QMdiSubWindow*>(parentWidget());
320 QMdiArea* aMDIArea = aParent->mdiArea();
322 QPoint aPnt = aEvent->globalPos();
323 QPoint aMDIPnt = aMDIArea->mapFromGlobal(aPnt);
324 if (aMDIArea->rect().contains(aMDIPnt)) {
325 int aX = aWgt->x() + (aPnt.x() - myMousePnt.x());
326 int aY = aWgt->y() + (aPnt.y() - myMousePnt.y());
334 case QEvent::MouseButtonDblClick:
335 if (theObj == myPicture) {
337 if (myLastState == MaximizedState)
347 //****************************************************************
348 bool XGUI_ViewWindow::processViewPort(QEvent *theEvent)
350 switch(theEvent->type()) {
351 case QEvent::MouseButtonPress:
352 vpMousePressEvent((QMouseEvent*) theEvent);
355 case QEvent::MouseButtonRelease:
356 vpMouseReleaseEvent((QMouseEvent*) theEvent);
359 case QEvent::MouseMove:
360 vpMouseMoveEvent((QMouseEvent*) theEvent);
363 case QEvent::MouseButtonDblClick:
364 emit mouseDoubleClicked(this, (QMouseEvent*) theEvent);
370 //****************************************************************
371 bool XGUI_ViewWindow::eventFilter(QObject *theObj, QEvent *theEvent)
373 if ((theObj == myGripWgt) || (theObj == myPicture)) {
374 if (processWindowControls(theObj, theEvent))
376 } else if (theObj == myViewPort) {
377 if (processViewPort(theEvent))
380 return QFrame::eventFilter(theObj, theEvent);
383 //****************************************************************
384 XGUI_ViewWindow::OperationType XGUI_ViewWindow::getButtonState(
385 QMouseEvent* theEvent, XGUI::InteractionStyle theInteractionStyle)
387 OperationType aOp = NOTHING;
388 XGUI::InteractionStyle aStyle = (XGUI::InteractionStyle) theInteractionStyle;
389 if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ZOOM])
390 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ZOOM]))
392 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::PAN])
393 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::PAN]))
395 else if ((theEvent->modifiers() == XGUI_Viewer::myStateMap[aStyle][XGUI::ROTATE])
396 && (theEvent->buttons() == XGUI_Viewer::myButtonMap[aStyle][XGUI::ROTATE])
397 && (my2dMode == XGUI::No2dMode))
403 //****************************************************************
404 void XGUI_ViewWindow::vpMousePressEvent(QMouseEvent* theEvent)
406 myStartX = theEvent->x();
407 myStartY = theEvent->y();
408 XGUI::InteractionStyle anInteractionStyle = interactionStyle();
410 // in "key free" interaction style zoom operation is activated by two buttons (simultaneously pressed),
411 // which are assigned for pan and rotate - these operations are activated immediately after pressing
412 // of the first button, so it is necessary to switch to zoom when the second button is pressed
413 bool aSwitchToZoom = false;
414 if ((anInteractionStyle == XGUI::KEY_FREE) && (myOperation == PANVIEW || myOperation == ROTATE)) {
415 aSwitchToZoom = getButtonState(theEvent, anInteractionStyle) == ZOOMVIEW;
418 switch(myOperation) {
420 if (theEvent->button() == Qt::LeftButton)
421 emit vpTransformationStarted(WINDOWFIT);
425 if (theEvent->button() == Qt::LeftButton)
426 emit vpTransformationStarted(PANGLOBAL);
430 if (theEvent->button() == Qt::LeftButton) {
431 myViewPort->startZoomAtPoint(myStartX, myStartY);
432 emit vpTransformationStarted(ZOOMVIEW);
438 myViewPort->startZoomAtPoint(myStartX, myStartY);
440 } else if (theEvent->button() == Qt::LeftButton)
441 emit vpTransformationStarted(PANVIEW);
446 myViewPort->startZoomAtPoint(myStartX, myStartY);
448 } else if (theEvent->button() == Qt::LeftButton) {
449 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
450 emit vpTransformationStarted(ROTATE);
455 /* Try to activate a transformation */
456 OperationType aState;
457 if (interactionStyle() == XGUI::STANDARD)
458 aState = getButtonState(theEvent, anInteractionStyle);
460 aState = XGUI_ViewWindow::NOTHING;
465 myViewPort->startZoomAtPoint(myStartX, myStartY);
473 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
476 if (myRotationPointSelection) {
477 if (theEvent->button() == Qt::LeftButton) {
478 Handle(AIS_InteractiveContext) ic = myViewer->AISContext();
480 for(ic->InitSelected(); ic->MoreSelected(); ic->NextSelected()) {
481 TopoDS_Shape aShape = ic->SelectedShape();
482 if (!aShape.IsNull() && aShape.ShapeType() == TopAbs_VERTEX) {
483 gp_Pnt aPnt = BRep_Tool::Pnt(TopoDS::Vertex(ic->SelectedShape()));
484 /*if ( mySetRotationPointDlg ) {
485 myRotationPointSelection = false;
486 mySetRotationPointDlg->setCoords(aPnt.X(), aPnt.Y(), aPnt.Z());
489 myCurrPointType = myPrevPointType;
493 if (ic->NbSelected() == 0)
494 myCurrPointType = myPrevPointType;
495 //if ( mySetRotationPointDlg ) mySetRotationPointDlg->toggleChange();
496 ic->CloseAllContexts();
497 myOperation = NOTHING;
498 myViewPort->setCursor(myCursor);
499 myCursorIsHand = false;
500 myRotationPointSelection = false;
503 emit mousePressed(this, theEvent);
506 /* notify that we start a transformation */
507 if (transformRequested())
508 emit vpTransformationStarted(myOperation);
510 if (transformRequested())
511 setTransformInProcess(true);
513 /* we may need it for sketching... */
514 /* if ( l_mbPressEvent )
515 delete l_mbPressEvent;
516 l_mbPressEvent = new QMouseEvent( *theEvent );*/
519 //****************************************************************
520 void XGUI_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent)
522 switch(myOperation) {
524 int prevState = myCurSketch;
525 /* if(theEvent->button() == Qt::RightButton) {
526 QList<OCCViewer_ViewSketcher*>::Iterator it;
527 for ( it = mySketchers.begin(); it != mySketchers.end() && myCurSketch != -1; ++it ) {
528 OCCViewer_ViewSketcher* sk = (*it);
529 if( ( sk->sketchButton() & theEvent->button() ) && sk->sketchButton() == myCurSketch )
534 emit mouseReleased(this, theEvent);
535 if (theEvent->button() == Qt::RightButton && prevState == -1) {
536 QContextMenuEvent aEvent(QContextMenuEvent::Mouse, theEvent->pos(), theEvent->globalPos());
537 emit contextMenuRequested(&aEvent);
542 myViewPort->endRotation();
552 if (theEvent->button() == Qt::LeftButton) {
553 myViewPort->setCenter(theEvent->x(), theEvent->y());
554 myViewPort->getView()->SetScale(myCurScale);
560 if (theEvent->button() == Qt::LeftButton) {
561 myCurrX = theEvent->x();
562 myCurrY = theEvent->y();
564 QRect rect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
566 myViewPort->fitRect(rect);
573 // NOTE: viewer 3D detects a rectangle of selection using this event
574 // so we must emit it BEFORE resetting the selection rectangle
575 if (theEvent->button() == Qt::LeftButton && myDrawRect) {
579 myViewPort->update();
581 /* if ( l_mbPressEvent ) {
582 delete l_mbPressEvent;
587 //****************************************************************
588 void XGUI_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent)
590 if (myIsKeyFree && interactionStyle() == XGUI::KEY_FREE) {
592 switch(getButtonState(theEvent, interactionStyle())) {
594 myViewPort->startZoomAtPoint(myStartX, myStartY);
602 myViewPort->startRotation(myStartX, myStartY, myCurrPointType, mySelectedPoint);
609 myCurrX = theEvent->x();
610 myCurrY = theEvent->y();
611 switch(myOperation) {
613 myViewPort->rotate(myCurrX, myCurrY, myCurrPointType, mySelectedPoint);
617 myViewPort->zoom(myStartX, myStartY, myCurrX, myCurrY);
623 myViewPort->pan(myCurrX - myStartX, myStartY - myCurrY);
632 if (myRotationPointSelection /*|| isSketcherStyle()*/) {
633 emit mouseMoving(this, theEvent);
635 int aState = theEvent->modifiers();
636 int aButton = theEvent->buttons();
637 int anInteractionStyle = interactionStyle();
638 if (((anInteractionStyle == XGUI::STANDARD) && (aButton == Qt::LeftButton)
639 && (aState == Qt::NoModifier || Qt::ShiftModifier))
640 || ((anInteractionStyle == XGUI::KEY_FREE) && (aButton == Qt::LeftButton)
641 && (aState == Qt::ControlModifier
642 || aState == (Qt::ControlModifier | Qt::ShiftModifier)))) {
643 myDrawRect = myEnableDrawMode;
646 if (!myCursorIsHand) { // we are going to sketch a rectangle
647 QCursor handCursor(Qt::PointingHandCursor);
648 myCursorIsHand = true;
650 myViewPort->setCursor(handCursor);
653 emit mouseMoving(this, theEvent);
654 } /* else if ( ( (anInteractionStyle == XGUI::STANDARD) &&
655 (aButton == Qt::RightButton) &&
656 ( aState == Qt::NoModifier || Qt::ShiftModifier ) ) ||
657 ( (anInteractionStyle == XGUI::KEY_FREE) &&
658 (aButton == Qt::RightButton) &&
659 ( aState == Qt::ControlModifier || aState == ( Qt::ControlModifier|Qt::ShiftModifier ) ) ) ) {
660 OCCViewer_ViewSketcher* sketcher = 0;
661 QList<OCCViewer_ViewSketcher*>::Iterator it;
662 for ( it = mySketchers.begin(); it != mySketchers.end() && !sketcher; ++it ) {
663 OCCViewer_ViewSketcher* sk = (*it);
664 if( sk->isDefault() && sk->sketchButton() == aButton )
667 if ( sketcher && myCurSketch == -1 ) {
668 activateSketching( sketcher->type() );
670 myCurSketch = mypSketcher->sketchButton();
672 if ( l_mbPressEvent ) {
673 QApplication::sendEvent( getViewPort(), l_mbPressEvent );
674 delete l_mbPressEvent;
677 QApplication::sendEvent( getViewPort(), theEvent );
681 emit mouseMoving(this, theEvent);
687 \brief Draw rubber band rectangle.
689 void XGUI_ViewWindow::drawRect()
692 myRectBand = new XGUI_RectRubberBand(myViewPort);
695 myRectBand->setUpdatesEnabled(false);
696 QRect aRect = makeRect(myStartX, myStartY, myCurrX, myCurrY);
697 myRectBand->initGeometry(aRect);
699 if (!myRectBand->isVisible())
702 myRectBand->setUpdatesEnabled(true);
706 \brief Clear rubber band rectangle on the end on the dragging operation.
708 void XGUI_ViewWindow::endDrawRect()
711 myRectBand->clearGeometry();
716 void XGUI_ViewWindow::activateZoom()
718 if (!transformRequested() && !myCursorIsHand)
719 myCursor = cursor(); /* save old cursor */
721 if (myOperation != ZOOMVIEW) {
722 QPixmap zoomPixmap(imageZoomCursor);
723 QCursor zoomCursor(zoomPixmap);
724 if (setTransformRequested(ZOOMVIEW))
725 myViewPort->setCursor(zoomCursor);
729 bool XGUI_ViewWindow::transformRequested() const
731 return (myOperation != NOTHING);
735 \brief Start delayed viewer operation.
737 bool XGUI_ViewWindow::setTransformRequested(OperationType op)
739 bool ok = transformEnabled(op);
740 myOperation = ok ? op : NOTHING;
741 myViewPort->setMouseTracking(myOperation == NOTHING);
746 Set enabled state of transformation (rotate, zoom, etc)
748 void XGUI_ViewWindow::setTransformEnabled(const OperationType id, const bool on)
751 myStatus.insert(id, on);
755 \return enabled state of transformation (rotate, zoom, etc)
757 bool XGUI_ViewWindow::transformEnabled(const OperationType id) const
759 return myStatus.contains(id) ? myStatus[id] : true;
763 \brief Start panning operation.
765 Sets the corresponding cursor for the widget.
767 void XGUI_ViewWindow::activatePanning()
769 if (!transformRequested() && !myCursorIsHand)
770 myCursor = cursor(); // save old cursor
772 if (myOperation != PANVIEW) {
773 QCursor panCursor(Qt::SizeAllCursor);
774 if (setTransformRequested(PANVIEW))
775 myViewPort->setCursor(panCursor);
780 \brief Start rotation operation
782 Sets the corresponding cursor for the widget.
784 void XGUI_ViewWindow::activateRotation()
786 if (!transformRequested() && !myCursorIsHand)
787 myCursor = cursor(); // save old cursor
789 if (myOperation != ROTATE) {
790 QPixmap rotatePixmap(imageRotateCursor);
791 QCursor rotCursor(rotatePixmap);
792 if (setTransformRequested(ROTATE))
793 myViewPort->setCursor(rotCursor);
798 \brief Reset the viewport to its initial state
799 ( no transformations in process etc. )
801 void XGUI_ViewWindow::resetState()
805 if (myRotationPointSelection) {
806 QCursor handCursor(Qt::PointingHandCursor);
807 myViewPort->setCursor(handCursor);
809 if (transformRequested() || myCursorIsHand)
810 myViewPort->setCursor(myCursor);
811 myCursorIsHand = false;
814 if (transformRequested())
815 emit vpTransformationFinished(myOperation);
817 setTransformInProcess(false);
818 setTransformRequested(NOTHING);
821 XGUI_ViewBackground XGUI_ViewWindow::background() const
823 return myViewPort ? myViewPort->background() : XGUI_ViewBackground();
826 void XGUI_ViewWindow::setBackground(const XGUI_ViewBackground& theBackground)
829 myViewPort->setBackground(theBackground);