From: ouv Date: Mon, 1 Jul 2013 13:52:48 +0000 (+0000) Subject: Raw development for ImageViewer. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2a3bd8f36790b8edad1e67ec3683cbf32d37d71c;p=modules%2Fgui.git Raw development for ImageViewer. --- diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index 40c891867..6693df0cc 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -54,6 +54,8 @@ public: virtual bool isOnTop() const { return myIsOnTop; } virtual void setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; } + virtual bool hasSpecificZValue() const { return false; } + virtual bool isSelectable() const { return true; } virtual bool isMovable() const { return true; } diff --git a/src/GraphicsView/GraphicsView_PrsImage.cxx b/src/GraphicsView/GraphicsView_PrsImage.cxx index f327118f4..86c3a3171 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.cxx +++ b/src/GraphicsView/GraphicsView_PrsImage.cxx @@ -33,6 +33,7 @@ #include +#define PREVIEW_Z_VALUE 2000 #define EPSILON 1e-6 #define PI 3.14159265359 @@ -42,6 +43,7 @@ //======================================================================= GraphicsView_PrsImage::GraphicsView_PrsImage() : GraphicsView_Object(), + myIsLockAspectRatio( false ), myPixmapItem( 0 ), myPreviewPixmapItem( 0 ), myImageFrame( 0 ), @@ -178,6 +180,24 @@ void GraphicsView_PrsImage::getRotationAngle( double& theRotationAngle ) const theRotationAngle = myRotationAngle; } +//================================================================ +// Function : setIsLockAspectRatio +// Purpose : +//================================================================ +void GraphicsView_PrsImage::setIsLockAspectRatio( const bool theIsLockAspectRatio ) +{ + myIsLockAspectRatio = theIsLockAspectRatio; +} + +//================================================================ +// Function : getIsLockAspectRatio +// Purpose : +//================================================================ +bool GraphicsView_PrsImage::getIsLockAspectRatio() const +{ + return myIsLockAspectRatio; +} + //================================================================ // Function : boundingRect // Purpose : @@ -209,8 +229,6 @@ void GraphicsView_PrsImage::compute() myImageFrame->setPrsImage( this ); } - setZValue( 0 ); - QSize aSourceSize = myPixmap.size(); QSize aScaledSize( aSourceSize.width() * myScaleX, aSourceSize.height() * myScaleY ); @@ -235,6 +253,18 @@ void GraphicsView_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) GraphicsView_Object::addTo( theViewPort ); theViewPort->addItem( myImageFrame ); theViewPort->addItem( myPreviewPixmapItem ); + + double aZValue = 0; + GraphicsView_ObjectListIterator anIter( theViewPort->getObjects() ); + while( anIter.hasNext() ) + { + if( GraphicsView_PrsImage* aPrs = dynamic_cast( anIter.next() ) ) + { + double aZValueRef = aPrs->zValue(); + aZValue = qMax( aZValue, aZValueRef ); + } + } + setZValue( aZValue + 1 ); } //================================================================ @@ -529,7 +559,7 @@ void GraphicsView_PrsImage::enablePreview( const bool theState ) { if( theState ) { - myPreviewPixmapItem->setZValue( 100 ); + myPreviewPixmapItem->setZValue( PREVIEW_Z_VALUE ); myPreviewPixmapItem->setOpacity( opacity() / 2. ); myPreviewPixmapItem->setPos( pos() ); diff --git a/src/GraphicsView/GraphicsView_PrsImage.h b/src/GraphicsView/GraphicsView_PrsImage.h index a63440c4e..5faadb72a 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.h +++ b/src/GraphicsView/GraphicsView_PrsImage.h @@ -54,6 +54,9 @@ public: void setRotationAngle( const double theRotationAngle ); void getRotationAngle( double& theRotationAngle ) const; + void setIsLockAspectRatio( const bool theIsLockAspectRatio ); + bool getIsLockAspectRatio() const; + public: // from QGraphicsItem virtual QRectF boundingRect() const; @@ -99,6 +102,8 @@ protected: protected: QPixmap myPixmap; + bool myIsLockAspectRatio; + QGraphicsPixmapItem* myPixmapItem; QGraphicsPixmapItem* myPreviewPixmapItem; diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index d3ebcdd32..649147683 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -32,9 +32,9 @@ #include -#define PI 3.14159265359 - +#define FRAME_Z_VALUE 1000 #define ANCHOR_RADIUS 10 +#define PI 3.14159265359 //======================================================================= // name : GraphicsView_PrsImageFrame @@ -137,7 +137,7 @@ void GraphicsView_PrsImageFrame::compute() } } - setZValue( 1000 ); + setZValue( FRAME_Z_VALUE ); computeAnchorItems(); updateAnchorItems(); diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.h b/src/GraphicsView/GraphicsView_PrsImageFrame.h index 07b443a86..24b5f7a3b 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.h +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.h @@ -58,6 +58,8 @@ public: // from GraphicsView_Object virtual void compute(); + virtual bool hasSpecificZValue() const { return true; } + virtual bool isMovable() const { return false; } virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const; diff --git a/src/GraphicsView/GraphicsView_PrsPropDlg.cxx b/src/GraphicsView/GraphicsView_PrsPropDlg.cxx index d134f5ff3..3a4e654d4 100644 --- a/src/GraphicsView/GraphicsView_PrsPropDlg.cxx +++ b/src/GraphicsView/GraphicsView_PrsPropDlg.cxx @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -56,6 +57,14 @@ GraphicsView_PrsPropDlg::GraphicsView_PrsPropDlg( QWidget* theParent ) QLabel* aRotationAngleLabel = new QLabel( tr( "ROTATION_ANGLE" ), aPropGroup ); myRotationAngle = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup ); + QLabel* anOpacityLabel = new QLabel( tr( "OPACITY" ), aPropGroup ); + myOpacity = new QtxDoubleSpinBox( 0, 1, 0.1, aPropGroup ); + + QLabel* aZValueLabel = new QLabel( tr( "Z_VALUE" ), aPropGroup ); + myZValue = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup ); + + myIsLockAspectRatio = new QCheckBox( tr( "LOCK_ASPECT_RATIO" ), aPropGroup ); + QGridLayout* aPropLayout = new QGridLayout( aPropGroup ); aPropLayout->setMargin( 5 ); aPropLayout->setSpacing( 5 ); @@ -69,6 +78,11 @@ GraphicsView_PrsPropDlg::GraphicsView_PrsPropDlg( QWidget* theParent ) aPropLayout->addWidget( myScalingY, 3, 1 ); aPropLayout->addWidget( aRotationAngleLabel, 4, 0 ); aPropLayout->addWidget( myRotationAngle, 4, 1 ); + aPropLayout->addWidget( aZValueLabel, 5, 0 ); + aPropLayout->addWidget( myZValue, 5, 1 ); + aPropLayout->addWidget( anOpacityLabel, 6, 0 ); + aPropLayout->addWidget( myOpacity, 6, 1 ); + aPropLayout->addWidget( myIsLockAspectRatio, 7, 0, 1, 2 ); aPropLayout->setColumnStretch( 1, 1 ); QVBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame ); @@ -97,13 +111,19 @@ void GraphicsView_PrsPropDlg::setData( const double thePositionX, const double thePositionY, const double theScalingX, const double theScalingY, - const double theRotationAngle ) + const double theRotationAngle, + const double theZValue, + const double theOpacity, + const bool theIsLockAspectRatio ) { myPositionX->setValue( thePositionX ); myPositionY->setValue( thePositionY ); myScalingX->setValue( theScalingX ); myScalingY->setValue( theScalingY ); myRotationAngle->setValue( theRotationAngle ); + myZValue->setValue( theZValue ); + myOpacity->setValue( theOpacity ); + myIsLockAspectRatio->setChecked( theIsLockAspectRatio ); } //============================================================================= @@ -114,11 +134,17 @@ void GraphicsView_PrsPropDlg::getData( double& thePositionX, double& thePositionY, double& theScalingX, double& theScalingY, - double& theRotationAngle ) const + double& theRotationAngle, + double& theZValue, + double& theOpacity, + bool& theIsLockAspectRatio ) const { thePositionX = myPositionX->value(); thePositionY = myPositionY->value(); theScalingX = myScalingX->value(); theScalingY = myScalingY->value(); theRotationAngle = myRotationAngle->value(); + theZValue = myZValue->value(); + theOpacity = myOpacity->value(); + theIsLockAspectRatio = myIsLockAspectRatio->isChecked(); } diff --git a/src/GraphicsView/GraphicsView_PrsPropDlg.h b/src/GraphicsView/GraphicsView_PrsPropDlg.h index 52b07a8ad..b870d4902 100644 --- a/src/GraphicsView/GraphicsView_PrsPropDlg.h +++ b/src/GraphicsView/GraphicsView_PrsPropDlg.h @@ -27,6 +27,8 @@ #include +class QCheckBox; + class QtxDoubleSpinBox; /* @@ -46,13 +48,19 @@ public: const double thePositionY, const double theScalingX, const double theScalingY, - const double theRotationAngle ); + const double theRotationAngle, + const double theZValue, + const double theOpacity, + const bool theIsLockAspectRatio ); void getData( double& thePositionX, double& thePositionY, double& theScalingX, double& theScalingY, - double& theRotationAngle ) const; + double& theRotationAngle, + double& theZValue, + double& theOpacity, + bool& theIsLockAspectRatio ) const; private: QtxDoubleSpinBox* myPositionX; @@ -60,6 +68,9 @@ private: QtxDoubleSpinBox* myScalingX; QtxDoubleSpinBox* myScalingY; QtxDoubleSpinBox* myRotationAngle; + QtxDoubleSpinBox* myOpacity; + QtxDoubleSpinBox* myZValue; + QCheckBox* myIsLockAspectRatio; }; #endif diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 8892099ce..49f809f45 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -278,57 +278,80 @@ void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem ) // Function : getObjects // Purpose : //================================================================ -GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( bool theIsSortSelected ) const +GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( SortType theSortType ) const { - if( !theIsSortSelected ) - return myObjects; - - // 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( theSortType == SelectedFirst ) { - if( GraphicsView_Object* anObject = anIter.next() ) + // 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( anObject->isOnTop() ) + if( GraphicsView_Object* anObject = anIter.next() ) { - aTopmostObjects.append( anObject ); - continue; - } + if( anObject->isOnTop() ) + { + aTopmostObjects.append( anObject ); + continue; + } - int aPriority = anObject->getPriority(); - if( aPriority > aCurrentPriority ) - { - if( !aSelectedObjects.isEmpty() ) + int aPriority = anObject->getPriority(); + if( aPriority > aCurrentPriority ) { - aList.append( aSelectedObjects ); - aSelectedObjects.clear(); + if( !aSelectedObjects.isEmpty() ) + { + aList.append( aSelectedObjects ); + aSelectedObjects.clear(); + } + aCurrentPriority = aPriority; } - aCurrentPriority = aPriority; + + if( anObject->isSelected() ) + aSelectedObjects.append( anObject ); + else + aList.append( anObject ); } + } - 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; } - // for selected objects with highest priority, - // which were not pushed to the result list yet - if( !aSelectedObjects.isEmpty() ) + if( theSortType == SortByZLevel ) // double loop, needs to be optimized { - aList.append( aSelectedObjects ); - aSelectedObjects.clear(); - } + GraphicsView_ObjectList aList; - aList.append( aTopmostObjects ); + 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 aList; + return myObjects; // theSortType == NoSorting } //================================================================ @@ -893,7 +916,7 @@ void GraphicsView_ViewPort::highlight( double theX, double theY ) QCursor aCursor; - GraphicsView_ObjectList aList = getObjects( false ); + GraphicsView_ObjectList aList = getObjects( SortByZLevel ); GraphicsView_ObjectListIterator anIter( aList ); anIter.toBack(); // objects with higher priority have to be checked earlier while( anIter.hasPrevious() ) diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index e3420e07c..6dbc74023 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -82,7 +82,8 @@ public: void addItem( QGraphicsItem* theItem ); void removeItem( QGraphicsItem* theItem ); - GraphicsView_ObjectList getObjects( bool theIsSortSelected = false ) const; + enum SortType { NoSorting, SelectedFirst, SortByZLevel }; + GraphicsView_ObjectList getObjects( SortType theSortType = NoSorting ) const; QRectF objectsBoundingRect( bool theOnlyVisible = false ) const; @@ -170,7 +171,6 @@ public: const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; } - // rectangle selection void startSelectByRect( int x, int y ); void drawSelectByRect( int x, int y ); diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 360433f1b..df19f1b75 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -116,14 +116,18 @@ void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) } 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( "BRING_FORWARD" ), this, SLOT( onBringForward() ) ); - thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) ); - thePopup->addSeparator(); thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) ); thePopup->addSeparator(); } + thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) ); } thePopup->addSeparator(); @@ -580,13 +584,31 @@ void GraphicsView_Viewer::onRemoveImages() } } +//================================================================ +// 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() { - // to do + processQueueOperation( BringForward ); } //================================================================ @@ -595,7 +617,89 @@ void GraphicsView_Viewer::onBringForward() //================================================================ void GraphicsView_Viewer::onSendBackward() { - // to do + 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; + } + } + } } //================================================================ @@ -616,14 +720,28 @@ void GraphicsView_Viewer::onPrsProperties() aPrs->getScaling( aScaleX, aScaleY ); aPrs->getRotationAngle( aRotationAngle ); + double aZValue = aPrs->zValue(); + double anOpacity = aPrs->opacity(); + + bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio(); + GraphicsView_PrsPropDlg aDlg( aViewPort ); - aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle ); + aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, + aZValue, anOpacity, anIsLockAspectRatio ); if( aDlg.exec() ) { - aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle ); + aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, + aZValue, anOpacity, anIsLockAspectRatio ); + aPrs->setPosition( aPosX, aPosY ); aPrs->setScaling( aScaleX, aScaleY ); aPrs->setRotationAngle( aRotationAngle ); + + aPrs->setZValue( aZValue ); + aPrs->setOpacity( anOpacity ); + + aPrs->setIsLockAspectRatio( anIsLockAspectRatio ); + aPrs->compute(); } } diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index a9aac5e54..3dcce3db5 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -102,6 +102,8 @@ protected slots: // testing ImageViewer void onAddImage(); void onRemoveImages(); + void onBringToFront(); + void onSendToBack(); void onBringForward(); void onSendBackward(); void onPrsProperties(); @@ -115,6 +117,10 @@ private: void handleMouseRelease( QGraphicsSceneMouseEvent* ); void handleWheel( QGraphicsSceneWheelEvent* ); + // testing ImageViewer + enum QueueOperation { BringToFront, SendToBack, BringForward, SendBackward }; + void processQueueOperation( const QueueOperation ); + protected: GraphicsView_Selector* mySelector; GraphicsView_ViewTransformer* myTransformer; diff --git a/src/GraphicsView/resources/GraphicsView_msg_en.ts b/src/GraphicsView/resources/GraphicsView_msg_en.ts index 6c0eaae65..dcb33723d 100644 --- a/src/GraphicsView/resources/GraphicsView_msg_en.ts +++ b/src/GraphicsView/resources/GraphicsView_msg_en.ts @@ -85,6 +85,14 @@ REMOVE_IMAGES Remove image(s) + + BRING_TO_FRONT + Bring to front + + + SEND_TO_BACK + Send to back + BRING_FORWARD Bring forward @@ -135,5 +143,17 @@ ROTATION_ANGLE Rotation angle + + Z_VALUE + Z value + + + OPACITY + Opacity + + + LOCK_ASPECT_RATIO + Lock aspect ratio +