From: CHEMIN Sebastien Date: Mon, 4 Mar 2024 13:53:48 +0000 (+0100) Subject: Selection manager connexion X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a0daec35739810921f2987f892a3dedf21b4c83e;p=modules%2Fgui.git Selection manager connexion --- diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index 01ba1b669..224f580ba 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -19,21 +19,12 @@ #include "GraphicsView_Object.h" -#include "GraphicsView_Scene.h" -#include "GraphicsView_ViewPort.h" - //======================================================================= // Name : GraphicsView_Object // Purpose : Constructor //======================================================================= -GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) +GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) : QGraphicsItem( theParent ) -// myPriority( 0 ), -// myIsOnTop( false ) -// myIsHighlighted( false ), - //myIsSelected( false ), -// myIsMoving( false ), -// myIsMovable( true ) { } @@ -43,173 +34,4 @@ GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) //======================================================================= GraphicsView_Object::~GraphicsView_Object() { - QListIterator aChildIter( childItems() ); - while( aChildIter.hasNext() ) - { - if( QGraphicsItem* aChild = aChildIter.next() ) - { - if( QGraphicsScene* aScene = aChild->scene() ) - aScene->removeItem( aChild ); - delete aChild; - aChild = 0; - } - } -} - -//================================================================ -// Function : setName -// Purpose : -//================================================================ -void GraphicsView_Object::setName( const QString& theName ) -{ - myName = theName; -} - -//================================================================ -// Function : addTo -// Purpose : -//================================================================ -/* -void GraphicsView_Object::addTo( GraphicsView_ViewPort* theViewPort ) -{ - if( QGraphicsScene* aScene = theViewPort->scene() ) - aScene->addItem( this ); -} - -//================================================================ -// Function : removeFrom -// Purpose : -//================================================================ -void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort ) -{ - if( QGraphicsScene* aScene = theViewPort->scene() ) - aScene->removeItem( this ); -} -*/ - -/* -//================================================================ -// Function : getRect -// Purpose : -//================================================================ -QRectF GraphicsView_Object::getRect() const -{ -// return sceneBoundingRect(); - return boundingRect(); -} - -//================================================================ -// Function : checkHighlight -// Purpose : -//================================================================ -bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& ) const -{ - return !getRect().isNull() && getRect().contains( theX, theY ); -} - -//================================================================ -// Function : highlight -// Purpose : -//================================================================ -bool GraphicsView_Object::highlight( double theX, double theY ) -{ - - QCursor aCursor; - if( (myIsHighlighted = isVisible()) ) - myIsHighlighted = checkHighlight( theX, theY, aCursor ); - return myIsHighlighted; -} - -//================================================================ -// Function : unhighlight -// Purpose : -//================================================================ -void GraphicsView_Object::unhighlight() -{ - myIsHighlighted = false; -} - -//================================================================ -// Function : select -// Purpose : -//================================================================ - -bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect ) -{ - - QCursor aCursor; - if( (myIsSelected = isVisible()) ) - { - if( !theRect.isNull() ) - myIsSelected = theRect.contains( getRect() ); - else - myIsSelected = checkHighlight( theX, theY, aCursor ); - } - return myIsSelected; - - return false; } - -//================================================================ -// Function : unselect -// Purpose : -//================================================================ - -void GraphicsView_Object::unselect() -{ - myIsSelected = false; -} - -//================================================================ -// Function : move -// Purpose : -//================================================================ -void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) -{ - - if( !myIsMovable ) - return; - - if( theIsAtOnce ) - { - finishMove( true ); - return; - } - - myIsMoving = true; - moveBy( theDX, theDY ); - -} - -//================================================================ -// Function : finishMove -// Purpose : -//================================================================ -bool GraphicsView_Object::finishMove( bool theStatus ) -{ - - myIsMoving = false; - if( theStatus ) - if( GraphicsView_Scene* aScene = dynamic_cast( scene() ) ) - aScene->processRectChanged(); - return true; -} - -//================================================================ -// Function : setViewTransform -// Purpose : -//================================================================ -void GraphicsView_Object::setViewTransform( const QTransform& theTransform ) -{ - myViewTransform = theTransform; -} - -bool GraphicsView_Object::isMovable() const -{ - return (flags() & QGraphicsItem::ItemIsMovable); -} - -void GraphicsView_Object::setMovable(bool theMovable) -{ - setFlag(QGraphicsItem::ItemIsMovable, theMovable); -}*/ diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index 3f684bdbf..9d5793e5a 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -21,11 +21,10 @@ #define GRAPHICSVIEW_OBJECT_H #include "GraphicsView.h" - -#include "GraphicsView_Defs.h" - #include +class SUIT_DataOwner; + class GraphicsView_ViewPort; /* @@ -38,84 +37,15 @@ public: GraphicsView_Object( QGraphicsItem* theParent = 0 ); ~GraphicsView_Object(); - virtual void compute() = 0; - -// virtual void addTo( GraphicsView_ViewPort* theViewPort ); -// virtual void removeFrom( GraphicsView_ViewPort* theViewPort ); - - const QString& getName() const { return myName; } - virtual void setName( const QString& theName ); -/* - virtual int getPriority() const { return myPriority; } - - virtual bool isOnTop() const { return myIsOnTop; } - virtual void setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; } - - virtual bool hasSpecificZValue() const { return false; } - - virtual bool isSelectable() const { return true; } - -// virtual bool isMovable() const { return myIsMovable; } -// virtual void setMovable( bool theMovable ) { myIsMovable = theMovable; } - - virtual bool isMovable() const; - virtual void setMovable( bool theMovable ); - - virtual QRectF getRect() const; - - virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const; - - virtual bool highlight( double theX, double theY ); - virtual void unhighlight(); -// virtual bool isHighlighted() const { return myIsHighlighted; } + const QString& getName() const { return myName; } + virtual void setName( const QString& theName ) { myName = theName; } - virtual bool select( double theX, double theY, const QRectF& theRect ); - virtual void unselect(); + SUIT_DataOwner* owner() const { return myOwner; } + void setOwner( SUIT_DataOwner* owner ) { myOwner = owner; } -// virtual bool isSelected() const { return myIsSelected; } -// virtual void setSelected( bool theState ) { myIsSelected = theState; } - - virtual void setSelected( bool theState ) { } - - virtual void move( double theDX, double theDY, bool theIsAtOnce = false ); - virtual bool finishMove( bool theStatus ); - -// virtual bool isMoving() const { return myIsMoving; } - virtual bool isMoving() const { return false; } - virtual bool isMovingByXAllowed( double ) { return true; } - virtual bool isMovingByYAllowed( double ) { return true; } - - virtual bool updateScale( bool, bool ) { return false; } - - virtual QRectF getPullingRect() const { return getRect(); } - virtual bool portContains( const QPointF& ) { return false; } - virtual bool startPulling( const QPointF& ) { return false; } - virtual void pull( const QPointF&, - GraphicsView_Object*, - const GraphicsView_ObjectList& ) {} - virtual void finishPulling( bool, const GraphicsView_ObjectList& ) {} - virtual bool isPulling() { return false; } - - virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; } - virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; } - virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; } - - virtual QTransform getViewTransform() const { return myViewTransform; } - virtual void setViewTransform( const QTransform& theTransform ); -*/ protected: - QString myName; - -// int myPriority; -// bool myIsOnTop; - -// bool myIsHighlighted; -// bool myIsSelected; - -// bool myIsMoving; -// bool myIsMovable; - -// QTransform myViewTransform; + SUIT_DataOwner* myOwner; + QString myName; }; #endif diff --git a/src/GraphicsView/GraphicsView_Selector.cxx b/src/GraphicsView/GraphicsView_Selector.cxx index f9e51871b..8de409fec 100644 --- a/src/GraphicsView/GraphicsView_Selector.cxx +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -22,8 +22,6 @@ #include "GraphicsView_ViewPort.h" #include "GraphicsView_ViewFrame.h" -//int GraphicsView_Selector::appendKey = Qt::ShiftModifier; - //======================================================================= // Name : GraphicsView_Selector // Purpose : Constructor @@ -43,35 +41,7 @@ GraphicsView_Selector::~GraphicsView_Selector() { } -//================================================================ -// Function : detect -// Purpose : -//================================================================ -void GraphicsView_Selector::detect( double x, double y ) -{ -/* - if ( myLocked ) - return; - if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) - aViewPort->highlight( x, y ); -*/ -} - -//================================================================ -// Function : undetectAll -// Purpose : -//================================================================ -void GraphicsView_Selector::undetectAll() -{ -/* - if ( myLocked ) - return; - - if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) - aViewPort->clearHighlighted(); -*/ -} //================================================================ // Function : select @@ -79,69 +49,5 @@ void GraphicsView_Selector::undetectAll() //================================================================ void GraphicsView_Selector::select( const QRectF& selRect, bool append ) { -/* - if ( myLocked ) - return; - - int selBefore = numSelected(); - if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) - { - int aStatus = aViewPort->select( selRect, append ); - checkSelection( selBefore, append, aStatus ); - } -*/ -} - -//================================================================ -// Function : unselectAll -// Purpose : -//================================================================ -void GraphicsView_Selector::unselectAll() -{ -/* - if ( myLocked ) - return; - - if ( numSelected() > 0 ) - emit selSelectionCancel(); -*/ + emit selSelectionDone(GVSCS_Global); } - -//================================================================ -// Function : checkSelection -// Purpose : -//================================================================ -void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int theStatus ) -{ -/* - int selAfter = numSelected(); - if ( selBefore > 0 && selAfter < 1 ) - emit selSelectionCancel(); - else if ( selAfter > 0 ) - { - switch( theStatus ) - { - case GVSS_LocalChanged: - emit selSelectionDone( GVSCS_Local ); - break; - case GVSS_GlobalChanged: - emit selSelectionDone( GVSCS_Global ); - break; - } - } -*/ -} - -//================================================================ -// Function : numSelected -// Purpose : -//================================================================ -int GraphicsView_Selector::numSelected() const -{ -/* - if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) - return aViewPort->nbSelected(); -*/ - return 0; -} - diff --git a/src/GraphicsView/GraphicsView_Selector.h b/src/GraphicsView/GraphicsView_Selector.h index 1f605018a..e17639f4a 100644 --- a/src/GraphicsView/GraphicsView_Selector.h +++ b/src/GraphicsView/GraphicsView_Selector.h @@ -44,18 +44,7 @@ public: public: void lock( bool theState ) { myLocked = theState; } - static int getAppendKey() { return appendKey; } - static void setAppendKey( int k ) { appendKey = k; } - -public: - virtual void detect( double, double ); - virtual void undetectAll(); - virtual void select( const QRectF&, bool append = false ); - virtual void unselectAll(); - virtual int numSelected() const; - - virtual void checkSelection( int, bool, int ); signals: void selSelectionDone( GV_SelectionChangeStatus ); @@ -65,8 +54,6 @@ protected: GraphicsView_Viewer* myViewer; bool myLocked; -private: - static int appendKey; }; #endif diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index 7a8ce637d..9dd7639cf 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -65,6 +65,9 @@ GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Vi myViewPort = new GraphicsView_ViewPort( aFrame ); aLayout->addWidget( myViewPort ); + + connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), + this, SLOT( mouseEvent( QMouseEvent* ) ) ); /* connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) ); @@ -388,12 +391,12 @@ void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) // Function : mouseEvent // Purpose : //================================================================ +/* void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e ) { switch ( e->type() ) { case QEvent::GraphicsSceneMousePress: - std::cout << "GraphicsView_ViewFrame::mousePressEvent" << std::endl; emit mousePressed( e ); break; case QEvent::GraphicsSceneMouseMove: @@ -409,7 +412,27 @@ void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e ) break; } } - +*/ +void GraphicsView_ViewFrame::mouseEvent( QMouseEvent* e ) +{ + switch ( e->type() ) + { + case QEvent::MouseButtonPress: + emit mousePressed( e ); + break; + case QEvent::MouseMove: + emit mouseMoving( e ); + break; + case QEvent::MouseButtonRelease: + emit mouseReleased( e ); + break; + case QEvent::MouseButtonDblClick: + emit mouseDoubleClicked( e ); + break; + default: + break; + } +} //================================================================ // Function : wheelEvent // Purpose : diff --git a/src/GraphicsView/GraphicsView_ViewFrame.h b/src/GraphicsView/GraphicsView_ViewFrame.h index f68ca1b04..06f2d8254 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.h +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -77,17 +77,17 @@ protected slots: private slots: void keyEvent( QKeyEvent* ); - void mouseEvent( QGraphicsSceneMouseEvent* ); + void mouseEvent( QMouseEvent* ); void wheelEvent( QGraphicsSceneWheelEvent* ); void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); signals: void keyPressed( QKeyEvent* ); void keyReleased( QKeyEvent* ); - void mousePressed( QGraphicsSceneMouseEvent* ); - void mouseMoving( QGraphicsSceneMouseEvent* ); - void mouseReleased( QGraphicsSceneMouseEvent* ); - void mouseDoubleClicked( QGraphicsSceneMouseEvent* ); + void mousePressed( QMouseEvent* ); + void mouseMoving( QMouseEvent* ); + void mouseReleased( QMouseEvent* ); + void mouseDoubleClicked( QMouseEvent* ); void wheeling( QGraphicsSceneWheelEvent* ); void sketchingFinished( QPainterPath ); diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 7876bd42e..5c24397ce 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -40,6 +40,8 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myFitAllGap = 40; myRectBand = nullptr; + myRectBandStart = QPoint(); + myRectBandEnd = QPoint(); } #include //======================================================================= @@ -83,6 +85,20 @@ void GraphicsView_ViewPort::fitSelect() fitInView(selectionRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio); } +QRect GraphicsView_ViewPort::selectionRect() +{ + if (myRectBand) + { + QRect aRect; + aRect.setLeft(qMin( myRectBandStart.x(), myRectBandEnd.x())); + aRect.setTop(qMin( myRectBandStart.y(), myRectBandEnd.y())); + aRect.setRight(qMax( myRectBandStart.x(), myRectBandEnd.x())); + aRect.setBottom(qMax( myRectBandStart.y(), myRectBandEnd.y())); + return aRect; + } + return QRect(); +} + void GraphicsView_ViewPort::fitRect(const QRectF& theRect) { fitInView(theRect, Qt::KeepAspectRatio); @@ -102,9 +118,12 @@ void GraphicsView_ViewPort::startSelectByRect( int x, int y ) void GraphicsView_ViewPort::drawSelectByRect( int x, int y ) { - QPoint endPoint = QPoint(x,y); - if (myRectBand) - myRectBand->setGeometry(QRect(myRectBandStart, endPoint).normalized()); + myRectBandEnd = QPoint(x,y); + + if (myRectBand) + { + myRectBand->setGeometry(QRect(myRectBandStart, myRectBandEnd).normalized()); + } } void GraphicsView_ViewPort::finishSelectByRect() @@ -118,6 +137,8 @@ void GraphicsView_ViewPort::finishSelectByRect() for (QGraphicsItem *item : selectedItems) item->setSelected(true); + myRectBandStart = QPoint(); + myRectBandEnd = QPoint(); delete myRectBand; myRectBand = nullptr; } @@ -130,6 +151,7 @@ void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event) } QGraphicsView::mousePressEvent(event); + emit vpMouseEvent(event); } @@ -137,13 +159,16 @@ void GraphicsView_ViewPort::mouseMoveEvent(QMouseEvent *event) { drawSelectByRect(event->pos().x(), event->pos().y()); QGraphicsView::mouseMoveEvent(event); + emit vpMouseEvent(event); } void GraphicsView_ViewPort::mouseReleaseEvent(QMouseEvent *event) { if (myRectBand) finishSelectByRect(); + QGraphicsView::mouseReleaseEvent(event); + emit vpMouseEvent(event); } void GraphicsView_ViewPort::resizeEvent(QResizeEvent *event) diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 977e81b44..aecf6a82c 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -52,6 +52,11 @@ public: void startSelectByRect( int x, int y ); void drawSelectByRect( int x, int y ); void finishSelectByRect(); + QRect selectionRect(); + +signals: + void vpMouseEvent(QMouseEvent*); + public slots: virtual void updateSceneRect(const QRectF &rect); @@ -68,6 +73,7 @@ private: double myFitAllGap; QRubberBand* myRectBand; QPoint myRectBandStart; + QPoint myRectBandEnd; }; #endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index eb5bbe8e3..ee7878d40 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -80,28 +80,15 @@ GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theD SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop ) { GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget ); -/* - connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ), - this, SLOT( onKeyEvent( QKeyEvent* ) ) ); - - connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ), - this, SLOT( onKeyEvent( QKeyEvent* ) ) ); - - connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ), - this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); - - connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ), - this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); - connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ), - this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); + connect( aViewFrame, SIGNAL( mousePressed( QMouseEvent* ) ), + this, SLOT( onMouseEvent( QMouseEvent* ) ) ); - connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ), - this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); + connect( aViewFrame, SIGNAL( mouseMoving( QMouseEvent* ) ), + this, SLOT( onMouseEvent( QMouseEvent* ) ) ); - connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ), - this, SLOT( onSketchingFinished( QPainterPath ) ) ); -*/ + connect( aViewFrame, SIGNAL( mouseReleased( QMouseEvent* ) ), + this, SLOT( onMouseEvent( QMouseEvent* ) ) ); return aViewFrame; } @@ -218,6 +205,7 @@ GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theTyp //================================================================ void GraphicsView_Viewer::onTransformationStarted() { +/* if( GraphicsView_Selector* aSelector = getSelector() ) { aSelector->undetectAll(); @@ -226,8 +214,10 @@ void GraphicsView_Viewer::onTransformationStarted() // watch events: any mouse/key event outside the // viewport will be considered as the end of transform +*/ if( myTransformer ) qApp->installEventFilter( this ); + } //================================================================ @@ -236,12 +226,14 @@ void GraphicsView_Viewer::onTransformationStarted() //================================================================ void GraphicsView_Viewer::onTransformationFinished() { +/* if( GraphicsView_Selector* aSelector = getSelector() ) aSelector->lock( false ); // enable selection - +*/ // stop watching events if( myTransformer ) qApp->removeEventFilter( this ); + } //================================================================ @@ -268,25 +260,23 @@ void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) // Function : onMouseEvent // Purpose : //================================================================ -void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e ) +void GraphicsView_Viewer::onMouseEvent( QMouseEvent* e ) { switch( e->type() ) { - case QEvent::GraphicsSceneMousePress: - std::cout << "GraphicsView_Viewer::onMousePressEvent" << std::endl; + case QEvent::MouseButtonPress: handleMousePress( e ); break; - case QEvent::GraphicsSceneMouseMove: + case QEvent::MouseMove: handleMouseMove( e ); break; - case QEvent::GraphicsSceneMouseRelease: + case QEvent::MouseButtonRelease: handleMouseRelease( e ); break; default: break; } } - //================================================================ // Function : onWheelEvent // Purpose : @@ -308,29 +298,6 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) //================================================================ void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e ) { -/* - if( e->key() == Qt::Key_Escape ) - { - // Cancel current operation - bool anIsCancelled = false; - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - anIsCancelled = aViewPort->cancelCurrentOperation(); - - // Unselect all objects (if there is no operation to cancel) - if( !anIsCancelled ) - { - aViewPort->finishSelectByRect(); - aViewPort->clearSelected(); - } - } - - // Emit unselection signal - if( !anIsCancelled ) - if( GraphicsView_Selector* aSelector = getSelector() ) - aSelector->unselectAll(); - } -*/ } //================================================================ @@ -345,68 +312,8 @@ void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* /*e*/ ) //!< TODO: unused // Function : handleMousePress // Purpose : //================================================================ -void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) +void GraphicsView_Viewer::handleMousePress( QMouseEvent* e ) { -/* - std::cout << "GraphicsView_Viewer::handleMousePress" << std::endl; - // test accel for transforms - if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() ) - { - Qt::MouseButton bs = e->button(); - if ( (int)bs == GraphicsView_ViewTransformer::zoomButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint - activateTransform( Zoom ); - else if ( (int)bs == GraphicsView_ViewTransformer::panButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint - activateTransform( Pan ); - } - else // checking for other operations before selection in release event - { - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); - if( e->button() == Qt::LeftButton && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) && - aViewPort->isPrepareToSketch() ) - { - // Use 'append' flag for sketching by arbitrary path - aViewPort->startSketching( e->scenePos(), append ); - } - else if( e->button() == Qt::LeftButton && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) && - !aViewPort->isSelectByRect() && - !aViewPort->isDragging() && - aViewPort->startPulling( e->scenePos() ) ) - { - // Try to start pulling if rectangular selection is performed - aViewPort->finishSelectByRect(); - } - else if( e->button() == Qt::LeftButton && - !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) && - !aViewPort->getHighlightedObject() && - ( ( !aViewPort->isDraggingSelectedByLeftButton() ) || - ( aViewPort->isDraggingSelectedByLeftButton() && aViewPort->nbSelected() == 0 ) ) ) - { - // Start rectangular selection if pulling was not started - QPoint p = aViewPort->mapFromScene( e->scenePos() ); - aViewPort->startSelectByRect( p.x(), p.y() ); - } - else if( e->button() != Qt::MidButton && !append && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) && - aViewPort->nbSelected() < 2 ) - { - // Do not perform 'immediate selection' if the multiple objects are already selected - getSelector()->select( QRectF(), append ); - } - else if( e->button() == Qt::RightButton && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) && - aViewPort->nbSelected() < 1 ) - { - // If the 'immediate context menu' mode is enabled, - // try to perform selection before invoking context menu - getSelector()->select( QRectF(), append ); - } - } - } -*/ } void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) @@ -417,94 +324,21 @@ void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) // Function : handleMouseMove // Purpose : //================================================================ -void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) +void GraphicsView_Viewer::handleMouseMove( QMouseEvent* e ) { -/* - GraphicsView_ViewPort* aViewPort = getActiveViewPort(); - - // highlight for selection - bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) ); - bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch(); - if ( !anIsDragged && !anIsPrepareToSketch ) - { - if ( getSelector() ) - getSelector()->detect( e->scenePos().x(), e->scenePos().y() ); - } - - // try to activate other operations - if( aViewPort ) - { - if( aViewPort->isPulling() ) - { - aViewPort->drawPulling( e->scenePos() ); - } - else if( aViewPort->isSketching() ) - { - aViewPort->drawSketching( e->scenePos() ); - } - else if( e->button() == Qt::LeftButton && - aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) && - !aViewPort->isSelectByRect() && - !aViewPort->isDragging() && - aViewPort->startPulling( e->scenePos() ) ) - { - aViewPort->finishSelectByRect(); - } - else if( !aViewPort->getHighlightedObject() ) - { - QPoint p = aViewPort->mapFromScene( e->scenePos() ); - aViewPort->drawSelectByRect( p.x(), p.y() ); - } - } -*/ } //================================================================ // Function : handleMouseRelease // Purpose : //================================================================ -void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) +void GraphicsView_Viewer::handleMouseRelease( QMouseEvent* e ) { -/* - std::cout << "GraphicsView_Viewer::handleMouseRelease" << std::endl; - // selection - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + GraphicsView_ViewPort* aViewPort = getActiveViewPort(); + if ( getSelector() ) { - if( e->button() == Qt::LeftButton && - !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) ) - { - if ( getSelector() ) - { - bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); - getSelector()->select( QRectF(), append ); - } - } + getSelector()->select( aViewPort->selectionRect(), true ); } - - // try to finish active operations - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - if( aViewPort->isPulling() ) - { - aViewPort->finishPulling( true ); - } - else if( aViewPort->isSketching() ) - { - aViewPort->finishSketching( true ); - } - else if( !aViewPort->getHighlightedObject() ) - { - QRect aSelRect = aViewPort->selectionRect(); - aViewPort->finishSelectByRect(); - if ( getSelector() && !aSelRect.isNull() ) - { - bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() ); - QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect(); - getSelector()->select( aRect, append ); - } - } - } -*/ } diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index d79afb251..d941e6c72 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -31,6 +31,7 @@ class QGraphicsSceneMouseEvent; class QGraphicsSceneWheelEvent; class QKeyEvent; +class QMouseEvent; class SUIT_ViewWindow; @@ -88,7 +89,7 @@ protected: protected slots: virtual void onKeyEvent( QKeyEvent* ); - virtual void onMouseEvent( QGraphicsSceneMouseEvent* ); + virtual void onMouseEvent( QMouseEvent* ); virtual void onWheelEvent( QGraphicsSceneWheelEvent* ); // virtual void onSketchingFinished( QPainterPath ); @@ -102,9 +103,9 @@ protected slots: protected: virtual void handleKeyPress( QKeyEvent* ); virtual void handleKeyRelease( QKeyEvent* ); - virtual void handleMouseMove( QGraphicsSceneMouseEvent* ); - virtual void handleMousePress( QGraphicsSceneMouseEvent* ); - virtual void handleMouseRelease( QGraphicsSceneMouseEvent* ); + virtual void handleMouseMove( QMouseEvent* ); + virtual void handleMousePress( QMouseEvent* ); + virtual void handleMouseRelease( QMouseEvent* ); virtual void handleWheel( QGraphicsSceneWheelEvent* ); // testing ImageViewer diff --git a/src/LightApp/LightApp_GVSelector.cxx b/src/LightApp/LightApp_GVSelector.cxx index eba0cbb4b..061fcd943 100644 --- a/src/LightApp/LightApp_GVSelector.cxx +++ b/src/LightApp/LightApp_GVSelector.cxx @@ -45,15 +45,49 @@ QString LightApp_GVSelector::type() const void LightApp_GVSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const { -/* + if ( !myViewer ) + return; + if( GraphicsView_ViewPort* aViewport = myViewer->getActiveViewPort() ) - for( aViewport->initSelected(); aViewport->moreSelected(); aViewport->nextSelected() ) - theList.append( new LightApp_DataOwner( aViewport->selectedObject()->getName() ) ); -*/ + { + foreach (QGraphicsItem *item, aViewport->scene()->selectedItems()) + { + if (GraphicsView_Object* obj = dynamic_cast(item)) + { + LightApp_DataOwner* owner = dynamic_cast( obj->owner() ); + if ( owner ) + theList.append( SUIT_DataOwnerPtr( new LightApp_DataOwner( owner->entry() ) ) ); + } + } + } } -void LightApp_GVSelector::setSelection( const SUIT_DataOwnerPtrList& /*theList*/ ) -{ +void LightApp_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList) +{ + if ( !myViewer ) + return; + + QMap aSelected; + for ( SUIT_DataOwnerPtrList::const_iterator itr = theList.begin(); itr != theList.end(); ++itr ) + { + const LightApp_DataOwner* owner = dynamic_cast( (*itr).operator->() ); + + if ( owner ) + aSelected.insert( owner->entry(), 0 ); + } + + if( GraphicsView_ViewPort* aViewport = myViewer->getActiveViewPort() ) + { + foreach (QGraphicsItem *item, aViewport->items()) + { + if (GraphicsView_Object* obj = dynamic_cast(item)) + { + LightApp_DataOwner* owner = dynamic_cast( obj->owner() ); + bool sel = owner && aSelected.contains(owner->entry()); + obj->setSelected(sel); + } + } + } } void LightApp_GVSelector::onSelectionChanged( GV_SelectionChangeStatus )