#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 )
{
}
//=======================================================================
GraphicsView_Object::~GraphicsView_Object()
{
- QListIterator<QGraphicsItem*> 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<GraphicsView_Scene*>( 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);
-}*/
#define GRAPHICSVIEW_OBJECT_H
#include "GraphicsView.h"
-
-#include "GraphicsView_Defs.h"
-
#include <QGraphicsItem>
+class SUIT_DataOwner;
+
class GraphicsView_ViewPort;
/*
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
#include "GraphicsView_ViewPort.h"
#include "GraphicsView_ViewFrame.h"
-//int GraphicsView_Selector::appendKey = Qt::ShiftModifier;
-
//=======================================================================
// Name : GraphicsView_Selector
// Purpose : Constructor
{
}
-//================================================================
-// 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
//================================================================
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;
-}
-
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 );
GraphicsView_Viewer* myViewer;
bool myLocked;
-private:
- static int appendKey;
};
#endif
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* ) ) );
// 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:
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 :
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 );
myFitAllGap = 40;
myRectBand = nullptr;
+ myRectBandStart = QPoint();
+ myRectBandEnd = QPoint();
}
#include<iostream>
//=======================================================================
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);
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()
for (QGraphicsItem *item : selectedItems)
item->setSelected(true);
+ myRectBandStart = QPoint();
+ myRectBandEnd = QPoint();
delete myRectBand;
myRectBand = nullptr;
}
}
QGraphicsView::mousePressEvent(event);
+ emit vpMouseEvent(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)
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);
double myFitAllGap;
QRubberBand* myRectBand;
QPoint myRectBandStart;
+ QPoint myRectBandEnd;
};
#endif
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;
}
//================================================================
void GraphicsView_Viewer::onTransformationStarted()
{
+/*
if( GraphicsView_Selector* aSelector = getSelector() )
{
aSelector->undetectAll();
// watch events: any mouse/key event outside the
// viewport will be considered as the end of transform
+*/
if( myTransformer )
qApp->installEventFilter( this );
+
}
//================================================================
//================================================================
void GraphicsView_Viewer::onTransformationFinished()
{
+/*
if( GraphicsView_Selector* aSelector = getSelector() )
aSelector->lock( false ); // enable selection
-
+*/
// stop watching events
if( myTransformer )
qApp->removeEventFilter( this );
+
}
//================================================================
// 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 :
//================================================================
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();
- }
-*/
}
//================================================================
// 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 )
// 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 );
- }
- }
- }
-*/
}
class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QKeyEvent;
+class QMouseEvent;
class SUIT_ViewWindow;
protected slots:
virtual void onKeyEvent( QKeyEvent* );
- virtual void onMouseEvent( QGraphicsSceneMouseEvent* );
+ virtual void onMouseEvent( QMouseEvent* );
virtual void onWheelEvent( QGraphicsSceneWheelEvent* );
// virtual void onSketchingFinished( QPainterPath );
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
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<GraphicsView_Object*>(item))
+ {
+ LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( 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<QString, int> aSelected;
+ for ( SUIT_DataOwnerPtrList::const_iterator itr = theList.begin(); itr != theList.end(); ++itr )
+ {
+ const LightApp_DataOwner* owner = dynamic_cast<const LightApp_DataOwner*>( (*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<GraphicsView_Object*>(item))
+ {
+ LightApp_DataOwner* owner = dynamic_cast<LightApp_DataOwner*>( obj->owner() );
+ bool sel = owner && aSelected.contains(owner->entry());
+ obj->setSelected(sel);
+ }
+ }
+ }
}
void LightApp_GVSelector::onSelectionChanged( GV_SelectionChangeStatus )