From 3be2cd2ae8cb2216786a6b20715cd9b1d38c844d Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Fri, 9 Feb 2024 11:23:49 +0100 Subject: [PATCH] working Version --- src/GraphicsView/GraphicsView_Object.cxx | 54 +- src/GraphicsView/GraphicsView_Object.h | 20 +- src/GraphicsView/GraphicsView_Scene.cxx | 24 +- src/GraphicsView/GraphicsView_Scene.h | 1 + src/GraphicsView/GraphicsView_Selector.cxx | 14 +- src/GraphicsView/GraphicsView_ViewFrame.cxx | 15 +- src/GraphicsView/GraphicsView_ViewPort.cxx | 1879 +---------------- src/GraphicsView/GraphicsView_ViewPort.h | 310 +-- .../GraphicsView_ViewTransformer.cxx | 7 +- src/GraphicsView/GraphicsView_Viewer.cxx | 430 +--- src/GraphicsView/GraphicsView_Viewer.h | 17 +- src/LightApp/LightApp_GVSelector.cxx | 2 + 12 files changed, 109 insertions(+), 2664 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index 5b5753efc..01ba1b669 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -27,9 +27,9 @@ // Purpose : Constructor //======================================================================= GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent ) -: QGraphicsItem( theParent ), - myPriority( 0 ), - myIsOnTop( false ) +: QGraphicsItem( theParent ) +// myPriority( 0 ), +// myIsOnTop( false ) // myIsHighlighted( false ), //myIsSelected( false ), // myIsMoving( false ), @@ -56,10 +56,20 @@ GraphicsView_Object::~GraphicsView_Object() } } +//================================================================ +// 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() ) @@ -75,16 +85,9 @@ void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort ) if( QGraphicsScene* aScene = theViewPort->scene() ) aScene->removeItem( this ); } +*/ -//================================================================ -// Function : setName -// Purpose : -//================================================================ -void GraphicsView_Object::setName( const QString& theName ) -{ - myName = theName; -} - +/* //================================================================ // Function : getRect // Purpose : @@ -99,7 +102,7 @@ QRectF GraphicsView_Object::getRect() const // Function : checkHighlight // Purpose : //================================================================ -bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& /*theCursor*/ ) const +bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& ) const { return !getRect().isNull() && getRect().contains( theX, theY ); } @@ -110,13 +113,11 @@ bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& /*t //================================================================ bool GraphicsView_Object::highlight( double theX, double theY ) { -/* + QCursor aCursor; if( (myIsHighlighted = isVisible()) ) myIsHighlighted = checkHighlight( theX, theY, aCursor ); return myIsHighlighted; -*/ - return false; } //================================================================ @@ -125,16 +126,17 @@ bool GraphicsView_Object::highlight( double theX, double theY ) //================================================================ void GraphicsView_Object::unhighlight() { -// myIsHighlighted = false; + myIsHighlighted = false; } //================================================================ // Function : select // Purpose : //================================================================ + bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect ) { -/* + QCursor aCursor; if( (myIsSelected = isVisible()) ) { @@ -144,7 +146,7 @@ bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRec myIsSelected = checkHighlight( theX, theY, aCursor ); } return myIsSelected; -*/ + return false; } @@ -152,9 +154,10 @@ bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRec // Function : unselect // Purpose : //================================================================ + void GraphicsView_Object::unselect() { -// myIsSelected = false; + myIsSelected = false; } //================================================================ @@ -163,7 +166,7 @@ void GraphicsView_Object::unselect() //================================================================ void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) { -/* + if( !myIsMovable ) return; @@ -175,7 +178,7 @@ void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) myIsMoving = true; moveBy( theDX, theDY ); -*/ + } //================================================================ @@ -184,14 +187,12 @@ void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce ) //================================================================ bool GraphicsView_Object::finishMove( bool theStatus ) { -/* + myIsMoving = false; if( theStatus ) if( GraphicsView_Scene* aScene = dynamic_cast( scene() ) ) aScene->processRectChanged(); return true; -*/ - return false; } //================================================================ @@ -203,7 +204,6 @@ void GraphicsView_Object::setViewTransform( const QTransform& theTransform ) myViewTransform = theTransform; } - bool GraphicsView_Object::isMovable() const { return (flags() & QGraphicsItem::ItemIsMovable); @@ -212,4 +212,4 @@ bool GraphicsView_Object::isMovable() const 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 913678267..3f684bdbf 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -40,12 +40,12 @@ public: virtual void compute() = 0; - virtual void addTo( GraphicsView_ViewPort* theViewPort ); - virtual void removeFrom( GraphicsView_ViewPort* theViewPort ); +// 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; } @@ -82,10 +82,10 @@ public: // virtual bool isMoving() const { return myIsMoving; } virtual bool isMoving() const { return false; } - virtual bool isMovingByXAllowed( double /*theDX*/ ) { return true; } - virtual bool isMovingByYAllowed( double /*theDY*/ ) { return true; } + virtual bool isMovingByXAllowed( double ) { return true; } + virtual bool isMovingByYAllowed( double ) { return true; } - virtual bool updateScale( bool /*theIsScaleUp*/, bool /*theIsCtrl*/ ) { return false; } + virtual bool updateScale( bool, bool ) { return false; } virtual QRectF getPullingRect() const { return getRect(); } virtual bool portContains( const QPointF& ) { return false; } @@ -102,12 +102,12 @@ public: virtual QTransform getViewTransform() const { return myViewTransform; } virtual void setViewTransform( const QTransform& theTransform ); - +*/ protected: QString myName; - int myPriority; - bool myIsOnTop; +// int myPriority; +// bool myIsOnTop; // bool myIsHighlighted; // bool myIsSelected; @@ -115,7 +115,7 @@ protected: // bool myIsMoving; // bool myIsMovable; - QTransform myViewTransform; +// QTransform myViewTransform; }; #endif diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx index d0dc1a9cf..dbf869f76 100644 --- a/src/GraphicsView/GraphicsView_Scene.cxx +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -127,15 +127,10 @@ void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e ) for (it = items1.constBegin(); it != items1.constEnd(); ++it) { - GraphicsView_Object* anItem = (GraphicsView_Object*)(*it); + GraphicsView_Object* anItem = (GraphicsView_Object*)(*it); std::cout << "Item at pos : " << anItem->getName().toStdString() << std::endl; } */ - //QGraphicsItem* gitem = mouseGrabberItem(); - GraphicsView_Object* gitem = (GraphicsView_Object*)mouseGrabberItem(); - std::cout << "Grabber : " << mouseGrabberItem() << std::endl; - if (gitem) - std::cout << "Grabber item : " << gitem->getName().toStdString() << std::endl; QGraphicsScene::mousePressEvent( e ); } @@ -157,15 +152,26 @@ void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e ) { // emit gsMouseEvent( e ); + QGraphicsScene::mouseReleaseEvent( e ); std::cout << "QGraphicsScene::mouseReleaseEvent --> nb selected : " << selectedItems().count() << std::endl; - +/* if (!selectedItems().isEmpty()) { GraphicsView_Object* obj = (GraphicsView_Object*) selectedItems().front(); std::cout << " Item : " << obj->getName().toStdString() << std::endl; } - - QGraphicsScene::mouseReleaseEvent( e ); + + + QList items1 = items(e->scenePos()); + QList::const_iterator it; + + for (it = selectedItems().constBegin(); it != selectedItems().constEnd(); ++it) + { + GraphicsView_Object* anItem = (GraphicsView_Object*)(*it); + std::cout << "Item selected : " << anItem->getName().toStdString() << std::endl; + } + +*/ } //================================================================ diff --git a/src/GraphicsView/GraphicsView_Scene.h b/src/GraphicsView/GraphicsView_Scene.h index e7896ea43..f0c6b7a47 100644 --- a/src/GraphicsView/GraphicsView_Scene.h +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -59,6 +59,7 @@ protected: virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* ); virtual void dropEvent( QGraphicsSceneDragDropEvent* ); + signals: void gsKeyEvent( QKeyEvent* ); void gsMouseEvent( QGraphicsSceneMouseEvent* ); diff --git a/src/GraphicsView/GraphicsView_Selector.cxx b/src/GraphicsView/GraphicsView_Selector.cxx index 50e4f491a..f9e51871b 100644 --- a/src/GraphicsView/GraphicsView_Selector.cxx +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -22,7 +22,7 @@ #include "GraphicsView_ViewPort.h" #include "GraphicsView_ViewFrame.h" -int GraphicsView_Selector::appendKey = Qt::ShiftModifier; +//int GraphicsView_Selector::appendKey = Qt::ShiftModifier; //======================================================================= // Name : GraphicsView_Selector @@ -49,11 +49,13 @@ GraphicsView_Selector::~GraphicsView_Selector() //================================================================ void GraphicsView_Selector::detect( double x, double y ) { +/* if ( myLocked ) return; if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) aViewPort->highlight( x, y ); +*/ } //================================================================ @@ -62,11 +64,13 @@ void GraphicsView_Selector::detect( double x, double y ) //================================================================ void GraphicsView_Selector::undetectAll() { +/* if ( myLocked ) return; if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) aViewPort->clearHighlighted(); +*/ } //================================================================ @@ -75,6 +79,7 @@ void GraphicsView_Selector::undetectAll() //================================================================ void GraphicsView_Selector::select( const QRectF& selRect, bool append ) { +/* if ( myLocked ) return; @@ -84,6 +89,7 @@ void GraphicsView_Selector::select( const QRectF& selRect, bool append ) int aStatus = aViewPort->select( selRect, append ); checkSelection( selBefore, append, aStatus ); } +*/ } //================================================================ @@ -92,11 +98,13 @@ void GraphicsView_Selector::select( const QRectF& selRect, bool append ) //================================================================ void GraphicsView_Selector::unselectAll() { +/* if ( myLocked ) return; if ( numSelected() > 0 ) emit selSelectionCancel(); +*/ } //================================================================ @@ -105,6 +113,7 @@ void GraphicsView_Selector::unselectAll() //================================================================ void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int theStatus ) { +/* int selAfter = numSelected(); if ( selBefore > 0 && selAfter < 1 ) emit selSelectionCancel(); @@ -120,6 +129,7 @@ void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int break; } } +*/ } //================================================================ @@ -128,8 +138,10 @@ void GraphicsView_Selector::checkSelection( int selBefore, bool /*append*/, int //================================================================ int GraphicsView_Selector::numSelected() const { +/* if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) return aViewPort->nbSelected(); +*/ return 0; } diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index 292cc1ec1..7a8ce637d 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -65,7 +65,7 @@ GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Vi myViewPort = new GraphicsView_ViewPort( aFrame ); aLayout->addWidget( myViewPort ); - +/* connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) ); connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ), @@ -77,6 +77,7 @@ GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Vi connect( myViewPort, SIGNAL( vpSketchingFinished( QPainterPath ) ), this, SIGNAL( sketchingFinished( QPainterPath ) ) ); +*/ } //======================================================================= @@ -208,7 +209,8 @@ int GraphicsView_ViewFrame::getToolBarId() //================================================================ QImage GraphicsView_ViewFrame::dumpView() { - return myViewPort->dumpView(); + return QImage(); +// return myViewPort->dumpView(); } //================================================================ @@ -217,10 +219,13 @@ QImage GraphicsView_ViewFrame::dumpView() //================================================================ bool GraphicsView_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format ) { +/* bool isOK = myViewPort->dumpViewToFormat(fileName, format); if( !isOK ) isOK = SUIT_ViewWindow::dumpViewToFormat( image, fileName, format ); return isOK; +*/ + return false; } //================================================================ @@ -263,8 +268,8 @@ void GraphicsView_ViewFrame::setVisualParameters( const QString& theParameters ) if( !anIsOk[ i ] ) return; - myViewPort->setTransform( aTransform ); - myViewPort->applyTransform(); +// myViewPort->setTransform( aTransform ); +// myViewPort->applyTransform(); } //================================================================ @@ -364,6 +369,7 @@ void GraphicsView_ViewFrame::onViewReset() //================================================================ void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) { +/* switch ( e->type() ) { case QEvent::KeyPress: @@ -375,6 +381,7 @@ void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) default: break; } +*/ } //================================================================ diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index aa6396174..74a63f5fa 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -18,200 +18,17 @@ // #include "GraphicsView_ViewPort.h" - -#include "GraphicsView_Object.h" #include "GraphicsView_Scene.h" -#include "GraphicsView_ViewTransformer.h" - -#include "SUIT_ResourceMgr.h" -#include "SUIT_Session.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include #include -#define FOREGROUND_Z_VALUE -2 -#define GRID_Z_VALUE -1 -#define SKETCH_Z_VALUE 3000 - -int GraphicsView_ViewPort::nCounter = 0; -QCursor* GraphicsView_ViewPort::defCursor = 0; -QCursor* GraphicsView_ViewPort::handCursor = 0; -QCursor* GraphicsView_ViewPort::panCursor = 0; -QCursor* GraphicsView_ViewPort::panglCursor = 0; -QCursor* GraphicsView_ViewPort::zoomCursor = 0; -QCursor* GraphicsView_ViewPort::sketchCursor = 0; - -//======================================================================= -// Name : GraphicsView_ViewPort::ViewLabel -// Purpose : Wrapper for label, which can ignore move events sent from -// QGraphicsView::scrollContentsBy() method, which, -// in its turn, called from GraphicsView_ViewPort::pan() -//======================================================================= -class GraphicsView_ViewPort::ViewLabel : public QLabel -{ -public: - ViewLabel( QWidget* theParent ) - : QLabel( theParent ), - myAcceptMoveEvents( false ) - { - } - ~ViewLabel() {} - - void setAcceptMoveEvents( bool theFlag ) - { - myAcceptMoveEvents = theFlag; - } - -protected: - virtual void moveEvent( QMoveEvent* theEvent ) - { - if( myAcceptMoveEvents ) - QLabel::moveEvent( theEvent ); - else // return the label to the initial position - { - myAcceptMoveEvents = true; - move( theEvent->oldPos() ); - myAcceptMoveEvents = false; - } - } - -private: - bool myAcceptMoveEvents; -}; - -//================================================================ -// Function : createCursors -// Purpose : -//================================================================ -void GraphicsView_ViewPort::createCursors () -{ - defCursor = new QCursor( Qt::ArrowCursor ); - handCursor = new QCursor( Qt::PointingHandCursor ); - panCursor = new QCursor( Qt::SizeAllCursor ); - panglCursor = new QCursor( Qt::CrossCursor ); - - SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr(); - zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) ); - - sketchCursor = new QCursor( Qt::CrossCursor ); -} - -//================================================================ -// Function : destroyCursors -// Purpose : -//================================================================ -void GraphicsView_ViewPort::destroyCursors() -{ - delete defCursor; defCursor = 0; - delete handCursor; handCursor = 0; - delete panCursor; panCursor = 0; - delete panglCursor; panglCursor = 0; - delete zoomCursor; zoomCursor = 0; - delete sketchCursor; sketchCursor = 0; -} //======================================================================= // Name : GraphicsView_ViewPort // Purpose : Constructor //======================================================================= GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) -: QGraphicsView( theParent ), - myInteractionFlags( 0 ), - myViewLabel( 0 ), - myViewLabelPosition( VLP_None ), - myViewLabelLayout( 0 ), - myIsMousePositionEnabled( false ), - myForegroundItem( 0 ), - myGridItem( 0 ), - myIsTransforming( false ), - myUnlimitedPanning( false ), - myHighlightedObject( 0 ), - myHighlightX( 0 ), - myHighlightY( 0 ), - myIsHighlighting( false ), - mySelectionIterator( 0 ), - myRectBand( 0 ), - myAreSelectionPointsInitialized( false ), - mySketchingItem( 0 ), - myIsPrepareToSketch( false ), - myIsSketching( false ), - myIsSketchingByPath( false ), - myIsDragging( false ), - myIsDragPositionInitialized( false ), - myDraggingSelectedByLeftButton( false ), - myIsPulling( false ), - myPullingObject( 0 ), - myStoredCursor( Qt::ArrowCursor ), - myZoomCoeff( 100 ) +: QGraphicsView( theParent ) { - // scene - myScene = new GraphicsView_Scene( this ); - setScene( myScene ); - - mySceneGap = 20; - myFitAllGap = 40; - - // interaction flags - setInteractionFlags( EditFlags ); - //setInteractionFlag( TraceBoundingRect ); - //setInteractionFlag( DraggingByMiddleButton ); - //setInteractionFlag( ImmediateContextMenu ); - //setInteractionFlag( ImmediateSelection ); - //setInteractionFlag( Sketching ); - - // background - setBackgroundBrush( QBrush( Qt::white ) ); - - // foreground - myIsForegroundEnabled = false; - myForegroundSize = QSizeF( 100, 30 ); - myForegroundMargin = 0.0; - myForegroundColor = Qt::white; - myForegroundFrameColor = Qt::black; - myForegroundFrameLineWidth = 1.0; - - // grid - myIsGridEnabled = false; - myGridCellSize = 100; - myGridLineStyle = Qt::DotLine; - myGridLineColor = Qt::darkGray; - - // default index method (BspTreeIndex) leads to - // crashes in QGraphicsView::paintEvent() method - myScene->setItemIndexMethod( QGraphicsScene::NoIndex ); - - // render hints (default - TextAntialiasing only) - setRenderHints( QPainter::Antialiasing | - QPainter::TextAntialiasing | - QPainter::SmoothPixmapTransform | - QPainter::HighQualityAntialiasing ); - - myHBarPolicy = horizontalScrollBarPolicy(); - myVBarPolicy = verticalScrollBarPolicy(); - - connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ), - this, SLOT( onKeyEvent( QKeyEvent* ) ) ); -// connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ), -// this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) ); - connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ), - this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) ); - connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ), - this, SLOT( onContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) ); - - connect( myScene, SIGNAL( gsBoundingRectChanged() ), - this, SLOT( onBoundingRectChanged() ) ); - - initialize(); + setScene(new GraphicsView_Scene(this)); } //======================================================================= @@ -220,1700 +37,10 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) //======================================================================= GraphicsView_ViewPort::~GraphicsView_ViewPort() { - cleanup(); - - if( myScene ) - { - delete myScene; - myScene = 0; - } } -//================================================================ -// Function : initialize -// Purpose : -//================================================================ -void GraphicsView_ViewPort::initialize() -{ - if ( nCounter++ == 0 ) - createCursors(); - - setMouseTracking( true ); - setFocusPolicy( Qt::StrongFocus ); -} - -//================================================================ -// Function : cleanup -// Purpose : -//================================================================ -void GraphicsView_ViewPort::cleanup() -{ - if ( --nCounter == 0 ) - destroyCursors(); -} - -//================================================================ -// Function : addItem -// Purpose : -//================================================================ void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem ) { - if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) - { - int aPriority = anObject->getPriority(); - GraphicsView_ObjectList::iterator anIter, anIterEnd = myObjects.end(); - for( anIter = myObjects.begin(); anIter != anIterEnd; anIter++ ) - { - if( GraphicsView_Object* anObjectRef = *anIter ) - { - if( anObjectRef->getPriority() > aPriority ) - break; - } - } - myObjects.insert( anIter, anObject ); - anObject->setViewTransform( transform() ); - anObject->addTo( this ); - } - else - myScene->addItem( theItem ); - onBoundingRectChanged(); -} - -//================================================================ -// Function : isItemAdded -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::isItemAdded( QGraphicsItem* theItem ) -{ - if( dynamic_cast( theItem ) ) - { - for( GraphicsView_ObjectList::iterator anIter = myObjects.begin(); anIter != myObjects.end(); anIter++ ) - if( theItem == *anIter ) - return true; - } - else { - for( int i = 0; i < myScene->items().size(); i++ ) - if( theItem == myScene->items().at(i) ) - return true; - } - return false; -} - -//================================================================ -// Function : removeItem -// Purpose : -//================================================================ -void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem ) -{ - if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) - { - if( myHighlightedObject == anObject ) - myHighlightedObject = 0; - mySelectedObjects.removeAll( anObject ); - myObjects.removeAll( anObject ); - anObject->removeFrom( this ); - } - else - myScene->removeItem( theItem ); - onBoundingRectChanged(); -} - -void GraphicsView_ViewPort::clearItems() -{ - myHighlightedObject = 0; - mySelectedObjects.clear(); - myObjects.clear(); - myScene->clear(); - onBoundingRectChanged(); -} - -//================================================================ -// Function : getObjects -// Purpose : -//================================================================ -GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( SortType theSortType ) const -{ - if( theSortType == SelectedFirst ) - { - // to append selected objects after their non-selected siblings with similar priority - int aCurrentPriority = -1; - GraphicsView_ObjectList aSelectedObjects; - GraphicsView_ObjectList aTopmostObjects; - - GraphicsView_ObjectList aList; - GraphicsView_ObjectListIterator anIter( myObjects ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = anIter.next() ) - { - if( anObject->isOnTop() ) - { - aTopmostObjects.append( anObject ); - continue; - } - - int aPriority = anObject->getPriority(); - if( aPriority > aCurrentPriority ) - { - if( !aSelectedObjects.isEmpty() ) - { - aList.append( aSelectedObjects ); - aSelectedObjects.clear(); - } - aCurrentPriority = aPriority; - } - - if( anObject->isSelected() ) - aSelectedObjects.append( anObject ); - else - aList.append( anObject ); - } - } - - // for selected objects with highest priority, - // which were not pushed to the result list yet - if( !aSelectedObjects.isEmpty() ) - { - aList.append( aSelectedObjects ); - aSelectedObjects.clear(); - } - - aList.append( aTopmostObjects ); - - return aList; - } - - if( theSortType == SortByZLevel ) // double loop, needs to be optimized - { - GraphicsView_ObjectList aList; - - GraphicsView_ObjectListIterator anIter( myObjects ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = anIter.next() ) - { - double aZValue = anObject->zValue(); - GraphicsView_ObjectList::iterator anIter1, anIter1End = aList.end(); - for( anIter1 = aList.begin(); anIter1 != anIter1End; anIter1++ ) - if( GraphicsView_Object* anObjectRef = *anIter1 ) - if( anObjectRef->zValue() > aZValue ) - break; - aList.insert( anIter1, anObject ); - } - } - return aList; - } - - return myObjects; // theSortType == NoSorting -} - -//================================================================ -// Function : objectsBoundingRect -// Purpose : -//================================================================ -QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const -{ - QRectF aRect; - QListIterator anIter( items() ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) - { - if( theOnlyVisible && !anObject->isVisible() ) - continue; - - QRectF anObjectRect = anObject->getRect(); - if( !anObjectRect.isNull() ) - { - if( aRect.isNull() ) - aRect = anObject->getRect(); - else - aRect |= anObject->getRect(); - } - } - } - return aRect; -} - -//================================================================ -// Function : dumpView -// Purpose : -//================================================================ -QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, - QSizeF theSize ) -{ - if( !theWholeScene ) // just grab the view contents - { - QPixmap aPixmap = QPixmap::grabWindow( viewport()->winId() ); - return aPixmap.toImage(); - } - - // get a bounding rect of all presented objects - // (itemsBoundingRect() method is unsuitable) - QRectF aRect = objectsBoundingRect(); - if( aRect.isNull() ) - return QImage(); - - QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() ); - if( theSize.isValid() ) - { - double aRatioX = theSize.width() / aTargetRect.width(); - double aRatioY = theSize.height() / aTargetRect.height(); - double aRatio = qMin( aRatioX, aRatioY ); - aTargetRect.setWidth( aTargetRect.width() * aRatio ); - aTargetRect.setHeight( aTargetRect.height() * aRatio ); - } - - // render the scene to an image - QImage anImage( aTargetRect.toRect().size(), QImage::Format_RGB32 ); - QPainter aPainter( &anImage ); - aPainter.setRenderHints( renderHints() ); - - myScene->render( &aPainter, aTargetRect, aRect ); - - return anImage; -} - -bool GraphicsView_ViewPort::dumpViewToFormat(const QString& fileName, const QString& format) -{ - if( format!="PS" && format!="EPS" ) - return false; - - QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFormat(QPrinter::PdfFormat); - printer.setOutputFileName(fileName); - QPainter painter; - if (!painter.begin(&printer)) - return false; - - QRect view( 0, 0, printer.pageRect().width(), printer.paperRect().height() ); - QRectF bounds = myScene->itemsBoundingRect(); - - if( !view.isEmpty() && !bounds.isEmpty() ) - { - float SCALE = 0.5;//qMin( view.width()/bounds.width(), view.height()/bounds.height() ); - painter.setViewport( view ); - painter.scale( SCALE, SCALE ); - } - myScene->render( &painter, QRectF( view ), bounds ); - - if (!painter.end()) - return false; - return true; -} - -//================================================================ -// Function : setSceneGap -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setSceneGap( double theSceneGap ) -{ - mySceneGap = theSceneGap; - onBoundingRectChanged(); -} - -//================================================================ -// Function : setFitAllGap -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap ) -{ - myFitAllGap = theFitAllGap; -} - -//================================================================ -// Function : interactionFlags -// Purpose : -//================================================================ -int GraphicsView_ViewPort::interactionFlags() const -{ - return myInteractionFlags; -} - -//================================================================ -// Function : hasInteractionFlag -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::hasInteractionFlag( InteractionFlag theFlag ) -{ - return ( interactionFlags() & theFlag ) == theFlag; -} - -//================================================================ -// Function : setInteractionFlag -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setInteractionFlag( InteractionFlag theFlag, - bool theIsEnabled ) -{ - if( theIsEnabled ) - setInteractionFlags( myInteractionFlags | theFlag ); - else - setInteractionFlags( myInteractionFlags & ~theFlag ); -} - -//================================================================ -// Function : setInteractionFlags -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setInteractionFlags( InteractionFlags theFlags ) -{ - myInteractionFlags = theFlags; -} - -//================================================================ -// Function : setViewLabelPosition -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setViewLabelPosition( ViewLabelPosition thePosition, - bool theIsForced ) -{ - if( theIsForced && !myViewLabel ) - myViewLabel = new ViewLabel( viewport() ); - - if( !myViewLabel ) - return; - - if( thePosition == VLP_None ) - { - myViewLabel->setVisible( false ); - return; - } - - if( myViewLabelLayout ) - delete myViewLabelLayout; - - myViewLabelLayout = new QGridLayout( viewport() ); - myViewLabelLayout->setMargin( 10 ); - myViewLabelLayout->setSpacing( 0 ); - - int aRow = 0, aColumn = 0; - switch( thePosition ) - { - case VLP_TopLeft: aRow = 0; aColumn = 0; break; - case VLP_TopRight: aRow = 0; aColumn = 1; break; - case VLP_BottomLeft: aRow = 1; aColumn = 0; break; - case VLP_BottomRight: aRow = 1; aColumn = 1; break; - default: break; - } - - myViewLabelLayout->addWidget( myViewLabel, aRow, aColumn ); - myViewLabelLayout->setRowStretch( 1 - aRow, 1 ); - myViewLabelLayout->setColumnStretch( 1 - aColumn, 1 ); - - myViewLabel->setVisible( true ); -} - -//================================================================ -// Function : setViewLabelText -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setViewLabelText( const QString& theText ) -{ - if( myViewLabel ) - myViewLabel->setText( theText ); -} - -//================================================================ -// Function : setMousePositionEnabled -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setMousePositionEnabled( bool theState ) -{ - myIsMousePositionEnabled = theState; - - if( theState ) - { - setViewLabelPosition( VLP_BottomLeft, true ); - - int aMouseX = 0, aMouseY = 0; - setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) ); - } - else - setViewLabelPosition( VLP_None ); -} - -//================================================================ -// Function : backgroundColor -// Purpose : -//================================================================ -QColor GraphicsView_ViewPort::backgroundColor() const -{ - return backgroundBrush().color(); -} - -//================================================================ -// Function : setBackgroundColor -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor ) -{ - setBackgroundBrush( QBrush( theColor ) ); -} - -//================================================================ -// Function : setForegroundEnabled -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundEnabled( bool theState ) -{ - myIsForegroundEnabled = theState; -} - -//================================================================ -// Function : setForegroundSize -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize ) -{ - myForegroundSize = theSize; -} - -//================================================================ -// Function : setForegroundMargin -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundMargin( double theMargin ) -{ - myForegroundMargin = theMargin; -} - -//================================================================ -// Function : setForegroundColor -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor ) -{ - myForegroundColor = theColor; -} - -//================================================================ -// Function : setForegroundFrameColor -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor ) -{ - myForegroundFrameColor = theColor; -} - -//================================================================ -// Function : setForegroundFrameLineWidth -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth ) -{ - myForegroundFrameLineWidth = theLineWidth; -} - -//================================================================ -// Function : updateForeground -// Purpose : -//================================================================ -void GraphicsView_ViewPort::updateForeground() -{ - if( myIsForegroundEnabled ) - { - if( !myForegroundItem ) - myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) ); - myForegroundItem->setZValue( FOREGROUND_Z_VALUE ); - - QPointF aPoint = QPointF(); - QRectF aRect( aPoint, myForegroundSize ); - aRect.adjust( -myForegroundMargin, -myForegroundMargin, - myForegroundMargin, myForegroundMargin ); - myForegroundItem->setRect( aRect ); - - QBrush aBrush = myForegroundItem->brush(); - aBrush.setColor( myForegroundColor ); - myForegroundItem->setBrush( aBrush ); - - QPen aPen = myForegroundItem->pen(); - aPen.setColor( myForegroundFrameColor ); - aPen.setWidthF( myForegroundFrameLineWidth ); - myForegroundItem->setPen( aPen ); - - myForegroundItem->setVisible( true ); - - myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); - } - else - { - if( myForegroundItem ) - myForegroundItem->setVisible( false ); - } - - updateGrid(); // foreground size could be changed -} - -//================================================================ -// Function : setGridEnabled -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setGridEnabled( bool theState ) -{ - myIsGridEnabled = theState; -} - -//================================================================ -// Function : setGridCellSize -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setGridCellSize( int theCellSize ) -{ - myGridCellSize = theCellSize; -} - -//================================================================ -// Function : setGridLineStyle -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setGridLineStyle( int theLineStyle ) -{ - myGridLineStyle = theLineStyle; -} - -//================================================================ -// Function : setGridLineColor -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setGridLineColor( const QColor& theLineColor ) -{ - myGridLineColor = theLineColor; -} - -//================================================================ -// Function : updateGrid -// Purpose : -//================================================================ -void GraphicsView_ViewPort::updateGrid() -{ - if( myIsGridEnabled ) - { - if( !myGridItem ) - myGridItem = myScene->addPath( QPainterPath() ); - myGridItem->setZValue( GRID_Z_VALUE ); - - double aWidth = myForegroundSize.width(); - double aHeight = myForegroundSize.height(); - - int aGridNbX = int( aWidth / myGridCellSize ) + 1; - int aGridNbY = int( aHeight / myGridCellSize ) + 1; - - int anIndex; - QPainterPath aPath; - for( anIndex = 0; anIndex < aGridNbX; anIndex++ ) - { - double x = myGridCellSize * (double)anIndex; - aPath.moveTo( x, 0 ); - aPath.lineTo( x, aHeight ); - } - for( anIndex = 0; anIndex < aGridNbY; anIndex++ ) - { - double y = myGridCellSize * (double)anIndex; - aPath.moveTo( 0, y ); - aPath.lineTo( aWidth, y ); - } - myGridItem->setPath( aPath ); - - QPen aPen = myGridItem->pen(); - aPen.setStyle( (Qt::PenStyle)myGridLineStyle ); - aPen.setColor( myGridLineColor ); - myGridItem->setPen( aPen ); - - myGridItem->setVisible( true ); - } - else - { - if( myGridItem ) - myGridItem->setVisible( false ); - } -} - -//================================================================ -// Function : reset -// Purpose : -//================================================================ -void GraphicsView_ViewPort::reset() -{ - fitAll(); -} - -//================================================================ -// Function : pan -// Purpose : -//================================================================ -void GraphicsView_ViewPort::pan( double theDX, double theDY ) -{ - myIsTransforming = true; - - if( myViewLabel ) - myViewLabel->setAcceptMoveEvents( false ); - - if( QScrollBar* aHBar = horizontalScrollBar() ) - { - if( isUnlimitedPanning() ) - { - int aNewValue = aHBar->value() - theDX; - if( aNewValue < aHBar->minimum() ) - aHBar->setMinimum( aNewValue ); - if( aNewValue > aHBar->maximum() ) - aHBar->setMaximum( aNewValue ); - } - aHBar->setValue( aHBar->value() - theDX ); - } - if( QScrollBar* aVBar = verticalScrollBar() ) - { - if( isUnlimitedPanning() ) - { - int aNewValue = aVBar->value() + theDY; - if( aNewValue < aVBar->minimum() ) - aVBar->setMinimum( aNewValue ); - if( aNewValue > aVBar->maximum() ) - aVBar->setMaximum( aNewValue ); - } - aVBar->setValue( aVBar->value() + theDY ); - } - - if( myViewLabel ) - myViewLabel->setAcceptMoveEvents( true ); - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : setCenter -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setCenter( double theX, double theY ) -{ - myIsTransforming = true; - - setTransform( myCurrentTransform ); - centerOn( theX, theY ); - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : zoom -// Purpose : -//================================================================ -void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 ) -{ - myIsTransforming = true; - - double aDX = theX2 - theX1; - double aDY = theY2 - theY1; - double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1; - aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom; - - QTransform aTransform = transform(); - aTransform.scale( aZoom, aZoom ); - double aM11 = aTransform.m11(); - double aM22 = aTransform.m22(); - - - QGraphicsView::ViewportAnchor old_anchor = transformationAnchor(); - setTransformationAnchor( QGraphicsView::AnchorUnderMouse ); - - // increasing of diagonal coefficients (>300) leads to a crash sometimes - // at the values of 100 some primitives are drawn incorrectly - if( myZoomCoeff < 0 || qMax( aM11, aM22 ) < myZoomCoeff ) - setTransform( aTransform ); - - myIsTransforming = false; - - applyTransform(); - - setTransformationAnchor( old_anchor ); -} - -//================================================================ -// Function : fitRect -// Purpose : -//================================================================ -void GraphicsView_ViewPort::fitRect( const QRectF& theRect ) -{ - myIsTransforming = true; - - fitInView( theRect, Qt::KeepAspectRatio ); - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : fitSelect -// Purpose : -//================================================================ -void GraphicsView_ViewPort::fitSelect() -{ - myIsTransforming = true; - - QRectF aGlobalRect; - for( initSelected(); moreSelected(); nextSelected() ) - { - if( GraphicsView_Object* aMovingObject = selectedObject() ) - { - QRectF aRect = aMovingObject->getRect(); - if( aGlobalRect.isNull() ) - aGlobalRect = aRect; - else - aGlobalRect |= aRect; - } - } - - if( !aGlobalRect.isNull() ) - { - double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5; - aGlobalRect.adjust( -aGap, -aGap, aGap, aGap ); - fitInView( aGlobalRect, Qt::KeepAspectRatio ); - } - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : fitAll -// Purpose : -//================================================================ -void GraphicsView_ViewPort::fitAll( bool theKeepScale ) -{ - myIsTransforming = true; - - if( theKeepScale ) - myCurrentTransform = transform(); - - double aGap = myFitAllGap; - QRectF aRect = objectsBoundingRect( true ); - fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : fitWidth -// Purpose : -//================================================================ -void GraphicsView_ViewPort::fitWidth() -{ - myIsTransforming = true; - - double aGap = myFitAllGap; - QRectF aRect = objectsBoundingRect( true ); - - double aTop = aRect.top(); - double aLeft = aRect.left(); - double aMargin = 10; - - aRect.setY( aRect.center().y() ); - aRect.setHeight( aMargin ); - - fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio ); - ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap ); - - myIsTransforming = false; - - applyTransform(); -} - -//================================================================ -// Function : applyTransform -// Purpose : -//================================================================ -void GraphicsView_ViewPort::applyTransform() -{ - GraphicsView_ObjectListIterator anIter( getObjects() ); - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - anObject->setViewTransform( transform() ); -} - -//================================================================ -// Function : setZoomCoeff -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setZoomCoeff( const int& theZoomCoeff ) -{ - myZoomCoeff = theZoomCoeff; -} - -//================================================================ -// Function : setUnlimitedPanning -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setUnlimitedPanning( const bool& theValue ) -{ - if ( myUnlimitedPanning == theValue ) - return; - - myUnlimitedPanning = theValue; - - if( myUnlimitedPanning ) - { - myHBarPolicy = horizontalScrollBarPolicy(); - myVBarPolicy = verticalScrollBarPolicy(); - - setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); - } - else - { - setHorizontalScrollBarPolicy( myHBarPolicy ); - setVerticalScrollBarPolicy( myVBarPolicy ); - } -} - -//================================================================ -// Function : currentBlock -// Purpose : -//================================================================ -GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock() -{ - if( isDragging() && !myDragPosition.isNull() ) - return BlockStatus( BS_Selection ); - - if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) ) - return BlockStatus( BS_Selection ); - - if( isPulling() ) - return BlockStatus( BS_Selection ); - - return BS_NoBlock; -} - -//================================================================ -// Function : highlight -// Purpose : -//================================================================ -void GraphicsView_ViewPort::highlight( double theX, double theY ) -{ - myIsHighlighting = true; - myHighlightX = theX; - myHighlightY = theY; - - bool anIsHighlighted = false; - bool anIsOnObject = false; - - GraphicsView_Object* aHighlightedObject = 0; - - QCursor aCursor; - - GraphicsView_ObjectList aList = getObjects( SortByZLevel ); - GraphicsView_ObjectListIterator anIter( aList ); - anIter.toBack(); // objects with higher priority have to be checked earlier - while( anIter.hasPrevious() ) - { - if( GraphicsView_Object* anObject = anIter.previous() ) - { - if( anObject->isVisible() && anObject->isSelectable() ) - { - if( anObject->checkHighlight( theX, theY, aCursor ) ) - { - anIsOnObject = true; - anIsHighlighted = anObject->highlight( theX, theY ); - } - - if( anIsHighlighted ) - { - aHighlightedObject = anObject; - break; - } - } - } - } - - setCursor( aCursor ); - - if( !anIsOnObject ) - { - anIter = aList; - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - anObject->unhighlight(); - - myHighlightedObject = 0; - return; - } - else if( !myHighlightedObject && anIsHighlighted ) - { - myHighlightedObject = aHighlightedObject; - } - else if( myHighlightedObject && !anIsHighlighted ) - { - myHighlightedObject->unhighlight(); - myHighlightedObject = 0; - } - else if( myHighlightedObject && anIsHighlighted ) - { - myHighlightedObject->highlight( theX, theY ); - if( myHighlightedObject != aHighlightedObject ) - { - myHighlightedObject->unhighlight(); - myHighlightedObject = aHighlightedObject; - } - } -} - -//================================================================ -// Function : clearHighlighted -// Purpose : -//================================================================ -void GraphicsView_ViewPort::clearHighlighted() -{ - if( myHighlightedObject ) - { - myHighlightedObject->unhighlight(); - myHighlightedObject = 0; - } -} - -//================================================================ -// Function : select -// Purpose : -//================================================================ -int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend ) -{ - if( !myIsHighlighting ) - return GVSS_NoChanged; - - GV_SelectionStatus aStatus = GVSS_Invalid; - if( theRect.isNull() ) // point selection - { - if( myHighlightedObject ) - { - if( mySelectedObjects.count() == 1 && - mySelectedObjects.first() == myHighlightedObject ) - aStatus = GVSS_LocalChanged; - - if( !theIsAppend ) - { - GraphicsView_ObjectListIterator anIter( mySelectedObjects ); - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - if( myHighlightedObject != anObject ) - anObject->unselect(); - - if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) - aStatus = GVSS_GlobalChanged; - mySelectedObjects.clear(); - } - else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged ) - { - mySelectedObjects.removeAll( myHighlightedObject ); - myHighlightedObject->unselect(); - - if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid ) - aStatus = GVSS_GlobalChanged; - - return aStatus; - } - - if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) && - mySelectedObjects.indexOf( myHighlightedObject ) == -1 ) - { - mySelectedObjects.append( myHighlightedObject ); - if( aStatus == GVSS_Invalid ) - aStatus = GVSS_GlobalChanged; - } - else if( aStatus == GVSS_LocalChanged ) - aStatus = GVSS_GlobalChanged; - - return aStatus; - } - - if( !myHighlightedObject ) - { - if( !theIsAppend ) - { - GraphicsView_ObjectListIterator anIter( mySelectedObjects ); - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - if( myHighlightedObject != anObject ) - anObject->unselect(); - - if( !mySelectedObjects.isEmpty() ) - aStatus = GVSS_GlobalChanged; - mySelectedObjects.clear(); - } - return aStatus; - } - - return GVSS_NoChanged; - } - else // rectangle selection - { - aStatus = GVSS_NoChanged; - - if( !theIsAppend ) - { - if( !mySelectedObjects.isEmpty() ) - aStatus = GVSS_GlobalChanged; - - GraphicsView_ObjectListIterator anIter( mySelectedObjects ); - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - if( myHighlightedObject != anObject ) - anObject->unselect(); - mySelectedObjects.clear(); - } - - QListIterator anIter( items() ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) - { - if( anObject->isVisible() && anObject->isSelectable() ) - { - bool anIsSelected = false; - QRectF aRect = anObject->getRect(); - if( theRect.contains( aRect ) && myIsHighlighting ) - anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect ); - - if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 ) - { - mySelectedObjects.append( anObject ); - aStatus = GVSS_GlobalChanged; - } - } - } - } - } - return aStatus; - -// return false; -} - -//================================================================ -// Function : clearSelected -// Purpose : -//================================================================ -void GraphicsView_ViewPort::clearSelected() -{ - GraphicsView_ObjectListIterator anIter( mySelectedObjects ); - while( anIter.hasNext() ) - if( GraphicsView_Object* anObject = anIter.next() ) - anObject->unselect(); - mySelectedObjects.clear(); -} - -//================================================================ -// Function : setSelected -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject ) -{ - if( theObject ) - { - theObject->setSelected( true ); - mySelectedObjects.append( theObject ); - } -} - -//================================================================ -// Function : nbSelected -// Purpose : -//================================================================ -int GraphicsView_ViewPort::nbSelected() const -{ - return mySelectedObjects.count(); -} - -//================================================================ -// Function : initSelected -// Purpose : -//================================================================ -void GraphicsView_ViewPort::initSelected() -{ - mySelectionIterator = 0; -} - -//================================================================ -// Function : moreSelected -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::moreSelected() -{ - return mySelectionIterator < nbSelected(); -} - -//================================================================ -// Function : nextSelected -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::nextSelected() -{ - if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() ) - { - mySelectionIterator++; - return true; - } - return false; -} - -//================================================================ -// Function : selectedObject -// Purpose : -//================================================================ -GraphicsView_Object* GraphicsView_ViewPort::selectedObject() -{ - if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() ) - return mySelectedObjects[ mySelectionIterator ]; - return 0; -} - -//================================================================ -// Function : startSelectByRect -// Purpose : -//================================================================ -void GraphicsView_ViewPort::startSelectByRect( int x, int y ) -{ - if( !myAreSelectionPointsInitialized ) - { - myFirstSelectionPoint = QPoint( x, y ); - myLastSelectionPoint = QPoint( x, y ); - myAreSelectionPointsInitialized = true; - } - - if( !myRectBand ) - { - myRectBand = new QRubberBand( QRubberBand::Rectangle, this ); - QPalette palette; - palette.setColor( myRectBand->foregroundRole(), Qt::white ); - myRectBand->setPalette( palette ); - } - myRectBand->hide(); -} - -//================================================================ -// Function : drawSelectByRect -// Purpose : -//================================================================ -void GraphicsView_ViewPort::drawSelectByRect( int x, int y ) -{ - if( myAreSelectionPointsInitialized ) - { - myRectBand->hide(); - - myLastSelectionPoint.setX( x ); - myLastSelectionPoint.setY( y ); - - QRect aRect = selectionRect(); - myRectBand->setGeometry( aRect ); - myRectBand->setVisible( aRect.isValid() ); - } -} - -//================================================================ -// Function : isSelectByRect -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::isSelectByRect() const -{ - return myAreSelectionPointsInitialized; -} - -//================================================================ -// Function : finishSelectByRect -// Purpose : -//================================================================ -void GraphicsView_ViewPort::finishSelectByRect() -{ - if( myAreSelectionPointsInitialized ) - { - if( myRectBand ) - { - myRectBand->hide(); - delete myRectBand; - myRectBand = 0; - } - - myAreSelectionPointsInitialized = false; - } -} - -//================================================================ -// Function : selectionRect -// Purpose : -//================================================================ -QRect GraphicsView_ViewPort::selectionRect() -{ - QRect aRect; - if( myAreSelectionPointsInitialized ) - { - aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); - aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); - aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) ); - aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) ); - } - return aRect; -} - -//================================================================ -// Function : prepareToSketch -// Purpose : -//================================================================ -void GraphicsView_ViewPort::prepareToSketch( bool theStatus ) -{ - myIsPrepareToSketch = theStatus; - if( theStatus ) - setCursor( *getSketchCursor() ); -} - -//================================================================ -// Function : isPrepareToSketch -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::isPrepareToSketch() -{ - return myIsPrepareToSketch; -} - -//================================================================ -// Function : startSketching -// Purpose : -//================================================================ -void GraphicsView_ViewPort::startSketching( const QPointF& thePoint, - bool theIsPath ) -{ - prepareToSketch( false ); - - if( !mySketchingItem ) - { - mySketchingItem = new QGraphicsPathItem(); - mySketchingItem->setZValue( SKETCH_Z_VALUE ); - - QPen aPen = mySketchingItem->pen(); - aPen.setStyle( Qt::DotLine ); - mySketchingItem->setPen( aPen ); - - addItem( mySketchingItem ); - } - - mySketchingPoint = thePoint; - - QPainterPath aPath; - aPath.moveTo( mySketchingPoint ); - mySketchingItem->setPath( aPath ); - mySketchingItem->setVisible( true ); - - myIsSketching = true; - myIsSketchingByPath = theIsPath; -} - -//================================================================ -// Function : drawSketching -// Purpose : -//================================================================ -void GraphicsView_ViewPort::drawSketching( const QPointF& thePoint ) -{ - bool anIsPath = false; - if( mySketchingItem && isSketching( &anIsPath ) ) - { - QPainterPath aPath = mySketchingItem->path(); - if( anIsPath ) // arbitrary path - aPath.lineTo( thePoint ); - else // rectangle - { - // make a valid rectangle - double x1 = mySketchingPoint.x(), y1 = mySketchingPoint.y(); - double x2 = thePoint.x(), y2 = thePoint.y(); - QPointF aPoint1( qMin( x1, x2 ), qMin( y1, y2 ) ); - QPointF aPoint2( qMax( x1, x2 ), qMax( y1, y2 ) ); - QRectF aRect( aPoint1, aPoint2 ); - - aPath = QPainterPath(); - aPath.addRect( aRect ); - } - mySketchingItem->setPath( aPath ); - } -} - -//================================================================ -// Function : finishSketching -// Purpose : -//================================================================ -void GraphicsView_ViewPort::finishSketching( bool theStatus ) -{ - prepareToSketch( false ); - - mySketchingItem->setVisible( false ); - myIsSketching = false; - - setCursor( *getDefaultCursor() ); - - if( theStatus ) - { - QPainterPath aPath = mySketchingItem->path(); - emit vpSketchingFinished( aPath ); - } -} - -//================================================================ -// Function : isSketching -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const -{ - if( theIsPath ) - *theIsPath = myIsSketchingByPath; - return myIsSketching; -} - -//================================================================ -// Function : setDraggingSelectedByLeftButton -// Purpose : -//================================================================ -void GraphicsView_ViewPort::setDraggingSelectedByLeftButton( const bool& theValue ) -{ - myDraggingSelectedByLeftButton = theValue; -} - -//================================================================ -// Function : dragObjects -// Purpose : -//================================================================ -void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e ) -{ - GraphicsView_Object* anObject = getHighlightedObject(); - - if( myDragPosition.isNull() ) - { - myDragPosition = e->scenePos(); - return; - } - - GraphicsView_ObjectList anObjectsToMove; - if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) ) - { - if( anObject->isSelected() ) - { - for( initSelected(); moreSelected(); nextSelected() ) - if( GraphicsView_Object* aMovingObject = selectedObject() ) - if( aMovingObject->isMovable() ) - anObjectsToMove.append( aMovingObject ); - } - else - anObjectsToMove.append( anObject ); - } - else if( ( ( hasInteractionFlag( DraggingByMiddleButton ) && ( e->buttons() & Qt::MidButton ) ) || - ( isDraggingSelectedByLeftButton() && ( e->buttons() & Qt::LeftButton ) ) ) && - nbSelected() ) - { - for( initSelected(); moreSelected(); nextSelected() ) - if( GraphicsView_Object* aMovingObject = selectedObject() ) - if( aMovingObject->isMovable() ) - anObjectsToMove.append( aMovingObject ); - } - - if( anObjectsToMove.isEmpty() ) - return; - - double aDX = e->scenePos().x() - myDragPosition.x(); - double aDY = e->scenePos().y() - myDragPosition.y(); - - bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true; - GraphicsView_ObjectListIterator anIter( anObjectsToMove ); - while( anIter.hasNext() ) - if( GraphicsView_Object* aMovingObject = anIter.next() ) - { - if( !aMovingObject->isMovingByXAllowed( aDX ) ) - anIsMovingByXAllowed = false; - if( !aMovingObject->isMovingByYAllowed( aDY ) ) - anIsMovingByYAllowed = false; - } - - if( !anIsMovingByXAllowed && !anIsMovingByYAllowed ) - return; // myDragPosition shouldn't be changed - - if( !anIsMovingByXAllowed ) - aDX = 0; - - if( !anIsMovingByYAllowed ) - aDY = 0; - - anIter = anObjectsToMove; - while( anIter.hasNext() ) - if( GraphicsView_Object* aMovingObject = anIter.next() ) - aMovingObject->move( aDX, aDY ); - - if( anIsMovingByXAllowed ) - myDragPosition.setX( e->scenePos().x() ); - - if( anIsMovingByYAllowed ) - myDragPosition.setY( e->scenePos().y() ); -} - -//================================================================ -// Function : startPulling -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint ) -{ - QListIterator anIter( items() ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) - { - QRectF aRect = anObject->getPullingRect(); - if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) ) - { - myIsPulling = true; - myPullingObject = anObject; - //setCursor( *getHandCursor() ); // testing ImageViewer - return true; - } - } - } - return false; -} - -//================================================================ -// Function : drawPulling -// Purpose : -//================================================================ -void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint ) -{ - GraphicsView_Object* aLockedObject = 0; - - QListIterator anIter( items() ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = dynamic_cast( anIter.next() ) ) - { - if( !anObject->isVisible() ) - continue; - - QRectF aRect = anObject->getPullingRect(); - if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) ) - { - aLockedObject = anObject; - break; - } - } - } - - myPullingObject->pull( thePoint, aLockedObject, getSelectedObjects() ); -} - -//================================================================ -// Function : finishPulling -// Purpose : -//================================================================ -void GraphicsView_ViewPort::finishPulling( bool theStatus ) -{ - myIsPulling = false; - myPullingObject->finishPulling( theStatus, getSelectedObjects() ); - setCursor( *getDefaultCursor() ); -} - -//================================================================ -// Function : cancelCurrentOperation -// Purpose : -//================================================================ -bool GraphicsView_ViewPort::cancelCurrentOperation() -{ - myIsHighlighting = false; - - if( isDragging() ) - { - for( initSelected(); moreSelected(); nextSelected() ) - if( GraphicsView_Object* aMovingObject = selectedObject() ) - aMovingObject->finishMove( false ); - - if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) - aMovingObject->finishMove( false ); - - myIsDragging = false; - myDragPosition = QPointF(); - //setCursor( myStoredCursor ); - setCursor( *getDefaultCursor() ); - - return true; - } - - if( isPulling() ) - { - finishPulling( false ); - return true; - } - - if( isSketching() || isPrepareToSketch() ) - { - finishSketching( false ); - return true; - } - - return false; -} - -//================================================================ -// Function : onBoundingRectChanged -// Purpose : -//================================================================ -void GraphicsView_ViewPort::onBoundingRectChanged() -{ - if( hasInteractionFlag( TraceBoundingRect ) ) - { - QRectF aRect = objectsBoundingRect( true ); - myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) ); - } -} - -//================================================================ -// Function : onKeyEvent -// Purpose : -//================================================================ -void GraphicsView_ViewPort::onKeyEvent( QKeyEvent* e ) -{ - emit vpKeyEvent( e ); -} - -//================================================================ -// Function : onMouseEvent -// Purpose : -//================================================================ -void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) -{ - emit vpMouseEvent( e ); - - bool anIsHandled = false; - switch( e->type() ) - { - case QEvent::GraphicsSceneMousePress: - { - std::cout << "GraphicsView_ViewPort::onMousePressEvent" << std::endl; - if( hasInteractionFlag( EditFlags ) && nbSelected() ) - for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) - if( GraphicsView_Object* anObject = selectedObject() ) - anIsHandled = anObject->handleMousePress( e ); - - if( !anIsHandled && hasInteractionFlag( Dragging ) ) - { - bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey(); - if( ( getHighlightedObject() && - getHighlightedObject()->isMovable() && - !( anAccel || e->button() != Qt::LeftButton ) ) || - ( ( ( hasInteractionFlag( DraggingByMiddleButton ) && e->button() == Qt::MidButton ) || - ( isDraggingSelectedByLeftButton() && e->button() == Qt::LeftButton ) ) && - nbSelected() && !anAccel ) ) - { - myIsDragging = true; - myStoredCursor = cursor(); - setCursor( Qt::ClosedHandCursor ); - } - } - break; - } - case QEvent::GraphicsSceneMouseMove: - { - if( hasInteractionFlag( EditFlags ) && nbSelected() ) - for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) - if( GraphicsView_Object* anObject = selectedObject() ) - anIsHandled = anObject->handleMouseMove( e ); - - if( !anIsHandled && !isPulling() && myIsDragging ) - dragObjects( e ); - break; - } - case QEvent::GraphicsSceneMouseRelease: - { - if( hasInteractionFlag( EditFlags ) && nbSelected() ) - for( initSelected(); moreSelected() && !anIsHandled; nextSelected() ) - if( GraphicsView_Object* anObject = selectedObject() ) - anIsHandled = anObject->handleMouseRelease( e ); - - if( !anIsHandled && !isPulling() && myIsDragging ) - { - emit vpObjectBeforeMoving(); - - bool anIsMoved = false; - for( initSelected(); moreSelected(); nextSelected() ) - if( GraphicsView_Object* aMovingObject = selectedObject() ) - anIsMoved = aMovingObject->finishMove( true ) || anIsMoved; - - if( GraphicsView_Object* aMovingObject = getHighlightedObject() ) - anIsMoved = aMovingObject->finishMove( true ) || anIsMoved; - - myIsDragging = false; - myDragPosition = QPointF(); - setCursor( myStoredCursor ); - - emit vpObjectAfterMoving( anIsMoved ); - } - break; - } - case QEvent::GraphicsSceneMouseDoubleClick: - break; // do nothing, just emit the signal - default: - break; - } - - if( myIsMousePositionEnabled ) - { - int aMouseX = (int)e->scenePos().x(); - int aMouseY = (int)e->scenePos().y(); - setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) ); - } -} - -//================================================================ -// Function : onWheelEvent -// Purpose : -//================================================================ -void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e ) -{ - emit vpWheelEvent( e ); -} - -//================================================================ -// Function : onContextMenuEvent -// Purpose : -//================================================================ -void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e ) -{ - emit vpContextMenuEvent( e ); -} - -//================================================================ -// Function : scrollContentsBy -// Purpose : -//================================================================ -void GraphicsView_ViewPort::scrollContentsBy( int theDX, int theDY ) -{ - if( myViewLabel ) - myViewLabel->setAcceptMoveEvents( false ); - - QGraphicsView::scrollContentsBy( theDX, theDY ); - - if( myViewLabel ) - myViewLabel->setAcceptMoveEvents( true ); -} - -void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event) -{ -// std::cout << "QGraphicsView::mousePressEvent" << std::endl; - QGraphicsView::mousePressEvent(event); -} - -void GraphicsView_ViewPort::mouseReleaseEvent(QMouseEvent *event) -{ - std::cout << "QGraphicsView::mouseReleaseEvent --> nb selected : " << scene()->selectedItems().count() << std::endl; - - if (!scene()->selectedItems().isEmpty()) - { - GraphicsView_Object* obj = (GraphicsView_Object*) scene()->selectedItems().front(); - std::cout << " Item : " << obj->getName().toStdString() << std::endl; - } - QGraphicsView::mouseReleaseEvent(event); + scene()->addItem(theItem); } diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index 1fdd117bc..80c077158 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -41,320 +41,14 @@ class GRAPHICSVIEW_API GraphicsView_ViewPort : public QGraphicsView { Q_OBJECT -public: - class ViewLabel; - - enum InteractionFlag - { - // main flags - Dragging = 0x0001, - Pulling = 0x0002, - WheelScaling = 0x0004, - EditFlags = Dragging | Pulling | WheelScaling, - // advanced flags - TraceBoundingRect = 0x0008, - DraggingByMiddleButton = 0x0010, - ImmediateContextMenu = 0x0020, - ImmediateSelection = 0x0040, - Sketching = 0x0080, - - GlobalWheelScaling = 0x0100 - }; - Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag ) - - enum BlockStatus - { - BS_NoBlock = 0x0000, - BS_Selection = 0x0001, // and highlighting - BS_Dragging = 0x0002 // currently unused - }; - - enum ViewLabelPosition - { - VLP_None = 0, - VLP_TopLeft = 1, - VLP_TopRight = 2, - VLP_BottomLeft = 3, - VLP_BottomRight = 4 - }; - public: GraphicsView_ViewPort( QWidget* theParent ); ~GraphicsView_ViewPort(); -public: - GraphicsView_Scene* getScene() { return myScene; } - void addItem( QGraphicsItem* theItem ); - bool isItemAdded( QGraphicsItem* theItem ); - void removeItem( QGraphicsItem* theItem ); - void clearItems(); - - enum SortType { NoSorting, SelectedFirst, SortByZLevel }; - GraphicsView_ObjectList getObjects( SortType theSortType = NoSorting ) const; - - QRectF objectsBoundingRect( bool theOnlyVisible = false ) const; - - QImage dumpView( bool theWholeScene = false, - QSizeF theSize = QSizeF() ); - - bool dumpViewToFormat(const QString& fileName, const QString& format); - -public: - // scene - void setSceneGap( double theSceneGap ); - void setFitAllGap( double theFitAllGap ); - - // interaction flags - int interactionFlags() const; - bool hasInteractionFlag( InteractionFlag theFlag ); - void setInteractionFlag( InteractionFlag theFlag, - bool theIsEnabled = true ); - void setInteractionFlags( InteractionFlags theFlags ); - - // view label - void setViewLabelPosition( ViewLabelPosition thePosition, - bool theIsForced = false ); - void setViewLabelText( const QString& theText ); - - // displaying mouse position (currently, overlaps with view label feature) - void setMousePositionEnabled( bool theState ); - - // background / foreground - QColor backgroundColor() const; - void setBackgroundColor( const QColor& theColor ); - - bool isForegroundEnabled() const { return myIsForegroundEnabled; } - void setForegroundEnabled( bool theState ); - - QSizeF foregroundSize() const { return myForegroundSize; } - void setForegroundSize( const QSizeF& theRect ); - - double foregroundMargin() const { return myForegroundMargin; } - void setForegroundMargin( double theMargin ); - - QColor foregroundColor() const { return myForegroundColor; } - void setForegroundColor( const QColor& theColor ); - - QColor foregroundFrameColor() const { return myForegroundFrameColor; } - void setForegroundFrameColor( const QColor& theColor ); - - double foregroundFrameLineWidth() const { return myForegroundFrameLineWidth; } - void setForegroundFrameLineWidth( double theLineWidth ); - - void updateForeground(); - - // grid - void setGridEnabled( bool theState ); - void setGridCellSize( int theCellSize ); - void setGridLineStyle( int theLineStyle ); - void setGridLineColor( const QColor& theLineColor ); - void updateGrid(); - - // transformation - void reset(); - void pan( double theDX, double theDY ); - void setCenter( double theX, double theY ); - void zoom( double theX1, double theY1, double theX2, double theY2 ); - void fitRect( const QRectF& theRect ); - void fitSelect(); - void fitAll( bool theKeepScale = false ); - void fitWidth(); - - bool isTransforming() const { return myIsTransforming; } - - void applyTransform(); - - int zoomCoeff() const { return myZoomCoeff; } - void setZoomCoeff( const int& theZoomCoeff ); - - bool isUnlimitedPanning() const { return myUnlimitedPanning; } - void setUnlimitedPanning( const bool& theValue ); - - // block status - BlockStatus currentBlock(); - - // highlighting - virtual void highlight( double theX, double theY ); - void clearHighlighted(); - - GraphicsView_Object* getHighlightedObject() const { return myHighlightedObject; } - - // selection - virtual int select( const QRectF& theRect, bool theIsAppend ); - void clearSelected(); - void setSelected( GraphicsView_Object* theObject ); - - int nbSelected() const; - void initSelected(); - bool moreSelected(); - bool nextSelected(); - GraphicsView_Object* selectedObject(); - - const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; } - - // rectangle selection - void startSelectByRect( int x, int y ); - void drawSelectByRect( int x, int y ); - void finishSelectByRect(); - bool isSelectByRect() const; - QRect selectionRect(); - - // sketching - void prepareToSketch( bool theStatus ); - bool isPrepareToSketch(); - void startSketching( const QPointF& thePoint, - bool theIsPath ); - void drawSketching( const QPointF& thePoint ); - void finishSketching( bool theStatus ); - bool isSketching( bool* theIsPath = 0 ) const; - - // dragging - bool isDragging() { return myIsDragging; } - - bool isDraggingSelectedByLeftButton() const { return myDraggingSelectedByLeftButton; } - void setDraggingSelectedByLeftButton( const bool& theValue ); - - // pulling - bool startPulling( const QPointF& ); - void drawPulling( const QPointF& ); - void finishPulling( bool theStatus ); - bool isPulling() const { return myIsPulling; } - - // other - bool cancelCurrentOperation(); - -public: - static void createCursors(); - static void destroyCursors(); - static QCursor* getDefaultCursor() { return defCursor; } - static QCursor* getHandCursor() { return handCursor; } - static QCursor* getPanCursor() { return panCursor; } - static QCursor* getPanglCursor() { return panglCursor; } - static QCursor* getZoomCursor() { return zoomCursor; } - static QCursor* getSketchCursor() { return sketchCursor; } - -public slots: - void onBoundingRectChanged(); - -protected slots: - void onKeyEvent( QKeyEvent* ); - void onMouseEvent( QGraphicsSceneMouseEvent* ); - void onWheelEvent( QGraphicsSceneWheelEvent* ); - void onContextMenuEvent( QGraphicsSceneContextMenuEvent* ); - -protected: - virtual void scrollContentsBy( int theDX, int theDY ); - virtual void mousePressEvent(QMouseEvent *event); - virtual void mouseReleaseEvent(QMouseEvent *event); - -signals: - void vpKeyEvent( QKeyEvent* ); - void vpMouseEvent( QGraphicsSceneMouseEvent* ); - void vpWheelEvent( QGraphicsSceneWheelEvent* ); - void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ); - - void vpSketchingFinished( QPainterPath ); - - void vpObjectBeforeMoving(); - void vpObjectAfterMoving( bool ); - -private: - void initialize(); - void cleanup(); - - void dragObjects( QGraphicsSceneMouseEvent* ); - + void addItem( QGraphicsItem* theItem ); + private: - static int nCounter; - static QCursor* defCursor; - static QCursor* handCursor; - static QCursor* panCursor; - static QCursor* panglCursor; - static QCursor* zoomCursor; - static QCursor* sketchCursor; -private: - // scene - GraphicsView_Scene* myScene; - double mySceneGap; - double myFitAllGap; - GraphicsView_ObjectList myObjects; - - // interaction flags - InteractionFlags myInteractionFlags; - - // view label - ViewLabel* myViewLabel; - ViewLabelPosition myViewLabelPosition; - QGridLayout* myViewLabelLayout; - - // displaying mouse position (currently, overlaps with view label feature) - bool myIsMousePositionEnabled; - - // foreground - bool myIsForegroundEnabled; - QSizeF myForegroundSize; - double myForegroundMargin; - QColor myForegroundColor; - QColor myForegroundFrameColor; - double myForegroundFrameLineWidth; - QGraphicsRectItem* myForegroundItem; - - // grid - bool myIsGridEnabled; - int myGridCellSize; - int myGridLineStyle; - QColor myGridLineColor; - QGraphicsPathItem* myGridItem; - - // transformation - bool myIsTransforming; - QTransform myCurrentTransform; - - bool myUnlimitedPanning; - Qt::ScrollBarPolicy myHBarPolicy; - Qt::ScrollBarPolicy myVBarPolicy; - - // highlighting - GraphicsView_Object* myHighlightedObject; - double myHighlightX; - double myHighlightY; - bool myIsHighlighting; - - // selection - GraphicsView_ObjectList mySelectedObjects; - int mySelectionIterator; - - // rectangle selection - QRubberBand* myRectBand; - QPoint myFirstSelectionPoint; - QPoint myLastSelectionPoint; - bool myAreSelectionPointsInitialized; - - // sketching - QGraphicsPathItem* mySketchingItem; - QPointF mySketchingPoint; - bool myIsPrepareToSketch; - bool myIsSketching; - bool myIsSketchingByPath; - - // dragging - int myIsDragging; - QPointF myDragPosition; - bool myIsDragPositionInitialized; - bool myDraggingSelectedByLeftButton; - - // pulling - bool myIsPulling; - GraphicsView_Object* myPullingObject; - - // cursor - QCursor myStoredCursor; - - // zoom diagonal coefficient - int myZoomCoeff; }; -Q_DECLARE_OPERATORS_FOR_FLAGS( GraphicsView_ViewPort::InteractionFlags ) - #endif diff --git a/src/GraphicsView/GraphicsView_ViewTransformer.cxx b/src/GraphicsView/GraphicsView_ViewTransformer.cxx index 4e2640163..a3f11fc6d 100644 --- a/src/GraphicsView/GraphicsView_ViewTransformer.cxx +++ b/src/GraphicsView/GraphicsView_ViewTransformer.cxx @@ -75,7 +75,8 @@ void GraphicsView_ViewTransformer::initTransform( bool init ) { if( GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort() ) { - if( GraphicsView_Scene* aScene = aViewPort->getScene() ) +// if( GraphicsView_Scene* aScene = aViewPort->getScene() ) + if( GraphicsView_Scene* aScene = dynamic_cast(aViewPort->scene())) { if( init ) { @@ -100,6 +101,7 @@ void GraphicsView_ViewTransformer::initTransform( bool init ) //================================================================ void GraphicsView_ViewTransformer::exec() { +/* GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); if( !aViewPort ) return; @@ -141,6 +143,7 @@ void GraphicsView_ViewTransformer::exec() break; default: break; } +*/ } //================================================================ @@ -191,6 +194,7 @@ bool GraphicsView_ViewTransformer::eventFilter( QObject* o, QEvent* e ) //================================================================ void GraphicsView_ViewTransformer::onTransform( TransformState state ) { +/* GraphicsView_ViewPort* aViewPort = myViewer->getActiveViewPort(); if( !aViewPort || aViewPort->isTransforming() ) return; @@ -245,6 +249,7 @@ void GraphicsView_ViewTransformer::onTransform( TransformState state ) if ( state == Finished ) myViewer->activateTransform( GraphicsView_Viewer::NoTransform ); +*/ } //================================================================ diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 5f337ca75..eb5bbe8e3 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -80,7 +80,7 @@ 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* ) ) ); @@ -101,7 +101,7 @@ SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop ) connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ), this, SLOT( onSketchingFinished( QPainterPath ) ) ); - +*/ return aViewFrame; } @@ -114,40 +114,7 @@ void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) if( thePopup->actions().count() > 0 ) thePopup->addSeparator(); - // testing ImageViewer - /* - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - int aNbSelected = aViewPort->nbSelected(); - if( aNbSelected == 0 ) - { - thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) ); - thePopup->addSeparator(); - - thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) ); - thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) ); - } - else - { - thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) ); - thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) ); - thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) ); - thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) ); - thePopup->addSeparator(); - - if( aNbSelected == 1 ) - { - thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) ); - thePopup->addSeparator(); - } - - thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) ); - } - thePopup->addSeparator(); - } - */ - - thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); +// thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); } //================================================================ @@ -283,6 +250,7 @@ void GraphicsView_Viewer::onTransformationFinished() //================================================================ void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) { +/* switch( e->type() ) { case QEvent::KeyPress: @@ -293,6 +261,7 @@ void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) break; default: break; } +*/ } //================================================================ @@ -339,6 +308,7 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) //================================================================ void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e ) { +/* if( e->key() == Qt::Key_Escape ) { // Cancel current operation @@ -360,6 +330,7 @@ void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e ) if( GraphicsView_Selector* aSelector = getSelector() ) aSelector->unselectAll(); } +*/ } //================================================================ @@ -376,6 +347,7 @@ void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* /*e*/ ) //!< TODO: unused //================================================================ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) { +/* std::cout << "GraphicsView_Viewer::handleMousePress" << std::endl; // test accel for transforms if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() ) @@ -434,6 +406,11 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) } } } +*/ +} + +void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) +{ } //================================================================ @@ -442,6 +419,7 @@ void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e ) //================================================================ void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) { +/* GraphicsView_ViewPort* aViewPort = getActiveViewPort(); // highlight for selection @@ -478,6 +456,7 @@ void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) aViewPort->drawSelectByRect( p.x(), p.y() ); } } +*/ } //================================================================ @@ -486,6 +465,7 @@ void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e ) //================================================================ void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) { +/* std::cout << "GraphicsView_Viewer::handleMouseRelease" << std::endl; // selection if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) @@ -524,54 +504,9 @@ void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e ) } } } +*/ } -//================================================================ -// Function : handleWheel -// Purpose : -//================================================================ -void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ) ) - { - const double d = 1.05; - double q = pow( d, e->delta()/120 ); - QGraphicsView::ViewportAnchor old_anchor = aViewPort->transformationAnchor(); - aViewPort->setTransformationAnchor( QGraphicsView::AnchorUnderMouse ); - aViewPort->scale( q, q ); - aViewPort->setTransformationAnchor( old_anchor ); - } - - if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) ) - { - bool anIsScaleUp = e->delta() > 0; - bool anIsCtrl = e->modifiers() & Qt::ControlModifier; - - bool anIsScaleChanged = false; - for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() ) - if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) - anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged; - - if( anIsScaleChanged ) - { - emit wheelScaleChanged(); - aViewPort->onBoundingRectChanged(); - } - } - } -} - -//================================================================ -// Function : onSketchingFinished -// Purpose : -//================================================================ -void GraphicsView_Viewer::onSketchingFinished( QPainterPath /*thePath*/ ) -{ - // testing ImageViewer - //onTestCropOperatorPerform( thePath ); -} //================================================================ // Function : onSelectionDone @@ -582,30 +517,6 @@ void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus ) emit selectionChanged( theStatus ); } -//================================================================ -// Function : onChangeBgColor -// Purpose : -//================================================================ -void GraphicsView_Viewer::onChangeBgColor() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - QColor aColor = aViewPort->isForegroundEnabled() ? - aViewPort->foregroundColor() : aViewPort->backgroundColor(); - aColor = QColorDialog::getColor( aColor, aViewPort ); - if ( aColor.isValid() ) - { - if( aViewPort->isForegroundEnabled() ) - { - aViewPort->setForegroundColor( aColor ); - aViewPort->updateForeground(); - } - else - aViewPort->setBackgroundColor( aColor ); - } - } -} - //================================================================ // Function : onSelectionCancel // Purpose : @@ -614,310 +525,3 @@ void GraphicsView_Viewer::onSelectionCancel() { emit selectionChanged( GVSCS_Invalid ); } - -/* -//================================================================ -// Function : onAddImage -// Purpose : -//================================================================ -void GraphicsView_Viewer::onAddImage() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - QString aFileName = QFileDialog::getOpenFileName(); - if( aFileName.isEmpty() ) - return; - - GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage(); - - QImage anImage( aFileName ); - aPrs->setImage( anImage ); - - aPrs->compute(); - - aViewPort->addItem( aPrs ); - aViewPort->fitAll(); - } -} - -//================================================================ -// Function : onRemoveImages -// Purpose : -//================================================================ -void GraphicsView_Viewer::onRemoveImages() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() ); - while( anIter.hasNext() ) - { - if( GraphicsView_PrsImage* aPrs = dynamic_cast( anIter.next() ) ) - { - aViewPort->removeItem( aPrs ); - delete aPrs; - } - } - } -} - -//================================================================ -// Function : onBringToFront -// Purpose : -//================================================================ -void GraphicsView_Viewer::onBringToFront() -{ - processQueueOperation( BringToFront ); -} - -//================================================================ -// Function : onSendToBack -// Purpose : -//================================================================ -void GraphicsView_Viewer::onSendToBack() -{ - processQueueOperation( SendToBack ); -} - -//================================================================ -// Function : onBringForward -// Purpose : -//================================================================ -void GraphicsView_Viewer::onBringForward() -{ - processQueueOperation( BringForward ); -} - -//================================================================ -// Function : onSendBackward -// Purpose : -//================================================================ -void GraphicsView_Viewer::onSendBackward() -{ - processQueueOperation( SendBackward ); -} - -//================================================================ -// Function : processQueueOperation -// Purpose : -//================================================================ -void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation ) -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects(); - - GraphicsView_ObjectList aSortedList; - - GraphicsView_ObjectList aList = aViewPort->getObjects(); - GraphicsView_ObjectListIterator anIter( aList ); - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = anIter.next() ) - { - if( !anObject->hasSpecificZValue() ) - { - double aZValue = anObject->zValue(); - GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end(); - for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ ) - if( GraphicsView_Object* anObjectRef = *anIter1 ) - if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue ) - break; - aSortedList.insert( anIter1, anObject ); - } - } - } - - QList anIndicesToMove; - - int anIndex = 0; - anIter = aSortedList; - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = anIter.next() ) - if( aSelectedList.contains( anObject ) ) - anIndicesToMove.append( anIndex ); - anIndex++; - } - - bool anIsReverse = theOperation == BringToFront || theOperation == BringForward; - QListIterator anIndicesIter( anIndicesToMove ); - if( anIsReverse ) - anIndicesIter.toBack(); - - int aShiftForMultiple = 0; - int anObjectCount = aSortedList.count(); - while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() ) - { - int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next(); - int aNewIndex = anIndex; - switch( theOperation ) - { - case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break; - case SendToBack: aNewIndex = aShiftForMultiple; break; - case BringForward: aNewIndex = anIndex + 1; break; - case SendBackward: aNewIndex = anIndex - 1; break; - } - aShiftForMultiple++; - - if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 ) - break; - - aSortedList.move( anIndex, aNewIndex ); - } - - double aZValue = 1.0; - anIter = aSortedList; - while( anIter.hasNext() ) - { - if( GraphicsView_Object* anObject = anIter.next() ) - { - anObject->setZValue( aZValue ); - aZValue += 1.0; - } - } - } -} - -//================================================================ -// Function : onPrsProperties -// Purpose : -//================================================================ -void GraphicsView_Viewer::onPrsProperties() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - aViewPort->initSelected(); - if( GraphicsView_Object* anObject = aViewPort->selectedObject() ) - { - if( GraphicsView_PrsImage* aPrs = dynamic_cast( anObject ) ) - { - double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; - aPrs->getPosition( aPosX, aPosY ); - aPrs->getScaling( aScaleX, aScaleY ); - aPrs->getRotationAngle( aRotationAngle ); - - double aZValue = aPrs->zValue(); - double anOpacity = aPrs->opacity(); - - bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio(); - bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation(); - - GraphicsView_PrsPropDlg aDlg( aViewPort ); - aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, - aZValue, anOpacity, anIsLockAspectRatio, - anIsSmoothTransformation ); - if( aDlg.exec() ) - { - aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, - aZValue, anOpacity, anIsLockAspectRatio, - anIsSmoothTransformation ); - - aPrs->setPosition( aPosX, aPosY ); - aPrs->setScaling( aScaleX, aScaleY ); - aPrs->setRotationAngle( aRotationAngle ); - - aPrs->setZValue( aZValue ); - aPrs->setOpacity( anOpacity ); - - aPrs->setIsLockAspectRatio( anIsLockAspectRatio ); - aPrs->setIsSmoothTransformation( anIsSmoothTransformation ); - - aPrs->compute(); - } - } - } - } -} - -//================================================================ -// Function : onTestFuseOperator -// Purpose : -//================================================================ -void GraphicsView_Viewer::onTestFuseOperator() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - GraphicsView_ObjectList aList = aViewPort->getObjects(); - if( aList.count() < 3 ) - return; - - GraphicsView_PrsImage* anObj1 = dynamic_cast( aList[0] ); - GraphicsView_PrsImage* anObj2 = dynamic_cast( aList[2] ); - - ImageComposer_Image anImage1; - anImage1 = anObj1->getImage(); - anImage1.setTransform( anObj1->getTransform() ); - - ImageComposer_Image anImage2; - anImage2 = anObj2->getImage(); - anImage2.setTransform( anObj2->getTransform() ); - - ImageComposer_Image aResult = anImage1 | anImage2; - GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage(); - aResPrs->setImage( aResult ); - - double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; - anObj1->getPosition( aPosX, aPosY ); - anObj1->getScaling( aScaleX, aScaleY ); - anObj1->getRotationAngle( aRotationAngle ); - - aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() ); - aResPrs->setScaling( aScaleX, aScaleY ); - aResPrs->setRotationAngle( aRotationAngle ); - - aResPrs->compute(); - - aViewPort->addItem( aResPrs ); - aViewPort->removeItem( anObj1 ); - aViewPort->removeItem( anObj2 ); - } -} - -//================================================================ -// Function : onTestCropOperatorPrepare -// Purpose : -//================================================================ -void GraphicsView_Viewer::onTestCropOperatorPrepare() -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - aViewPort->prepareToSketch( true ); -} - -//================================================================ -// Function : onTestCropOperatorPerform -// Purpose : -//================================================================ -void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath ) -{ - if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) - { - GraphicsView_ObjectList aList = aViewPort->getObjects(); - if( aList.count() < 1 ) - return; - - GraphicsView_PrsImage* anObj = dynamic_cast( aList[0] ); - - ImageComposer_Image anImage; - anImage = anObj->getImage(); - anImage.setTransform( anObj->getTransform() ); - - ImageComposer_Image aResult = anImage & thePath; - GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage(); - aResPrs->setImage( aResult ); - - double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle; - anObj->getPosition( aPosX, aPosY ); - anObj->getScaling( aScaleX, aScaleY ); - anObj->getRotationAngle( aRotationAngle ); - - aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() ); - aResPrs->setScaling( aScaleX, aScaleY ); - aResPrs->setRotationAngle( aRotationAngle ); - - aResPrs->compute(); - - aViewPort->addItem( aResPrs ); - aViewPort->removeItem( anObj ); - } -} -*/ diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index 153699b0f..d79afb251 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -91,26 +91,13 @@ protected slots: virtual void onMouseEvent( QGraphicsSceneMouseEvent* ); virtual void onWheelEvent( QGraphicsSceneWheelEvent* ); - virtual void onSketchingFinished( QPainterPath ); +// virtual void onSketchingFinished( QPainterPath ); virtual void onSelectionDone( GV_SelectionChangeStatus ); virtual void onSelectionCancel(); - virtual void onChangeBgColor(); +// virtual void onChangeBgColor(); - // testing ImageViewer - /* - void onAddImage(); - void onRemoveImages(); - void onBringToFront(); - void onSendToBack(); - void onBringForward(); - void onSendBackward(); - void onPrsProperties(); - void onTestFuseOperator(); - void onTestCropOperatorPrepare(); - void onTestCropOperatorPerform( QPainterPath thePath ); - */ protected: virtual void handleKeyPress( QKeyEvent* ); diff --git a/src/LightApp/LightApp_GVSelector.cxx b/src/LightApp/LightApp_GVSelector.cxx index da88424d5..eba0cbb4b 100644 --- a/src/LightApp/LightApp_GVSelector.cxx +++ b/src/LightApp/LightApp_GVSelector.cxx @@ -45,9 +45,11 @@ QString LightApp_GVSelector::type() const void LightApp_GVSelector::getSelection( SUIT_DataOwnerPtrList& theList ) const { +/* if( GraphicsView_ViewPort* aViewport = myViewer->getActiveViewPort() ) for( aViewport->initSelected(); aViewport->moreSelected(); aViewport->nextSelected() ) theList.append( new LightApp_DataOwner( aViewport->selectedObject()->getName() ) ); +*/ } void LightApp_GVSelector::setSelection( const SUIT_DataOwnerPtrList& /*theList*/ ) -- 2.39.2