From 14b34873c9531acfad882791154c103e4c1b985d Mon Sep 17 00:00:00 2001 From: asl Date: Tue, 19 Mar 2013 05:41:41 +0000 Subject: [PATCH] patch for CHARM: correct drawing of the selection rectangle --- src/OCCViewer/OCCViewer_ViewWindow.cxx | 55 ++++++++++++++++++++++---- src/OCCViewer/OCCViewer_ViewWindow.h | 7 ++-- 2 files changed, 51 insertions(+), 11 deletions(-) diff --git a/src/OCCViewer/OCCViewer_ViewWindow.cxx b/src/OCCViewer/OCCViewer_ViewWindow.cxx index e62b48c92..89df6ebe0 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.cxx +++ b/src/OCCViewer/OCCViewer_ViewWindow.cxx @@ -34,6 +34,7 @@ #include #include +#include #include #include @@ -173,6 +174,12 @@ OCCViewer_ViewWindow::OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_V updateEnabledDrawMode(); myClippingDlg = 0; myToolbarId = -1; + myRectBand = 0; +} + +OCCViewer_ViewWindow::~OCCViewer_ViewWindow() +{ + endDrawRect(); } /*! @@ -457,7 +464,7 @@ void OCCViewer_ViewWindow::vpMouseMoveEvent(QMouseEvent* theEvent) default: int aState = theEvent->modifiers(); - int aButton = theEvent->button(); + int aButton = theEvent->buttons(); if ( aButton == Qt::LeftButton ) { myDrawRect = myEnableDrawMode; @@ -519,6 +526,7 @@ void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent) myCurrY = theEvent->y(); QRect rect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY); if ( !rect.isEmpty() ) myViewPort->fitRect(rect); + endDrawRect(); resetState(); } break; @@ -530,6 +538,7 @@ void OCCViewer_ViewWindow::vpMouseReleaseEvent(QMouseEvent* theEvent) if ( theEvent->button() == Qt::LeftButton && myDrawRect ) { myDrawRect = false; drawRect(); + endDrawRect(); resetState(); myViewPort->update(); } @@ -564,14 +573,44 @@ void OCCViewer_ViewWindow::resetState() */ void OCCViewer_ViewWindow::drawRect() { - QPainter aPainter(myViewPort); - aPainter.setCompositionMode( QPainter::RasterOp_SourceXorDestination ); - aPainter.setPen(Qt::white); + if ( !myRectBand ) { + myRectBand = new QtxRectRubberBand( myViewPort ); + //QPalette palette; + //palette.setColor(myRectBand->foregroundRole(), Qt::white); + //myRectBand->setPalette(palette); + } + //myRectBand->hide(); + + myRectBand->setUpdatesEnabled ( false ); QRect aRect = SUIT_Tools::makeRect(myStartX, myStartY, myCurrX, myCurrY); - if ( !myRect.isEmpty() ) - aPainter.drawRect( myRect ); - aPainter.drawRect(aRect); - myRect = aRect; + myRectBand->initGeometry( aRect ); + + if ( !myRectBand->isVisible() ) + myRectBand->show(); + + myRectBand->setUpdatesEnabled ( true ); + //myRectBand->repaint(); + + //myRectBand->setVisible( aRect.isValid() ); + //if ( myRectBand->isVisible() ) + // myRectBand->repaint(); + //else + // myRectBand->show(); + //myRectBand->repaint(); +} + +/*! + \brief Clear rubber band rectangle on the end on the dragging operation. +*/ +void OCCViewer_ViewWindow::endDrawRect() +{ + //delete myRectBand; + //myRectBand = 0; + if ( myRectBand ) + { + myRectBand->clearGeometry(); + myRectBand->hide(); + } } /*! diff --git a/src/OCCViewer/OCCViewer_ViewWindow.h b/src/OCCViewer/OCCViewer_ViewWindow.h index adbc77651..36fc7dbd0 100755 --- a/src/OCCViewer/OCCViewer_ViewWindow.h +++ b/src/OCCViewer/OCCViewer_ViewWindow.h @@ -28,9 +28,9 @@ #include #include +class QtxRectRubberBand; class SUIT_Desktop; class OCCViewer_ViewPort3d; - class OCCViewer_ClippingDlg; #ifdef WIN32 @@ -46,7 +46,7 @@ public: FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW }; OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel); - virtual ~OCCViewer_ViewWindow() {}; + virtual ~OCCViewer_ViewWindow(); OCCViewer_ViewPort3d* getViewPort() { return myViewPort; } @@ -118,6 +118,7 @@ protected: void resetState(); void drawRect(); + void endDrawRect(); void createActions(); void createToolBar(); @@ -152,7 +153,7 @@ protected: private: OCCViewer_ClippingDlg* myClippingDlg; QtxAction* myClippingAction; - + QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band }; #ifdef WIN32 -- 2.39.2