From f51b7df68eb8553a9cd9fd91d1a991d1e78e3c85 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 5 Jul 2013 07:37:15 +0000 Subject: [PATCH] 1) Smooth Transformation mode 2) Lock Aspect Ratio mode --- src/GraphicsView/GraphicsView_PrsImage.cxx | 96 ++++++++++---- src/GraphicsView/GraphicsView_PrsImage.h | 3 + .../GraphicsView_PrsImageFrame.cxx | 7 +- src/GraphicsView/GraphicsView_PrsPropDlg.cxx | 121 +++++++++++------- src/GraphicsView/GraphicsView_PrsPropDlg.h | 9 +- src/GraphicsView/GraphicsView_Viewer.cxx | 8 +- .../resources/GraphicsView_msg_en.ts | 16 +++ 7 files changed, 183 insertions(+), 77 deletions(-) diff --git a/src/GraphicsView/GraphicsView_PrsImage.cxx b/src/GraphicsView/GraphicsView_PrsImage.cxx index bdfbac267..45cefcd63 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.cxx +++ b/src/GraphicsView/GraphicsView_PrsImage.cxx @@ -204,6 +204,26 @@ bool GraphicsView_PrsImage::getIsLockAspectRatio() const return myIsLockAspectRatio; } +//================================================================ +// Function : setIsSmoothTransformation +// Purpose : +//================================================================ +void GraphicsView_PrsImage::setIsSmoothTransformation( const bool theIsSmoothTransformation ) +{ + Qt::TransformationMode aMode = theIsSmoothTransformation ? + Qt::SmoothTransformation : Qt::FastTransformation; + myPixmapItem->setTransformationMode( aMode ); +} + +//================================================================ +// Function : getIsSmoothTransformation +// Purpose : +//================================================================ +bool GraphicsView_PrsImage::getIsSmoothTransformation() const +{ + return myPixmapItem->transformationMode() == Qt::SmoothTransformation; +} + //================================================================ // Function : boundingRect // Purpose : @@ -227,6 +247,7 @@ void GraphicsView_PrsImage::compute() if( !myPreviewPixmapItem ) { myPreviewPixmapItem = new QGraphicsPixmapItem(); + myPreviewPixmapItem->setTransformationMode( Qt::FastTransformation ); // always //addToGroup( myPreviewPixmapItem ); // don't add } if( !myPrsImageFrame ) @@ -391,56 +412,87 @@ void GraphicsView_PrsImage::processResize( const int theAnchor, double aSizeDX = aDist * cos( anAngle2 ); double aSizeDY = -aDist * sin( anAngle2 ); - QPointF aPosShift; QPointF aSizeShift; switch( theAnchor ) + { + case GraphicsView_PrsImageFrame::Top: aSizeShift = QPointF( 0, -aSizeDY ); break; + case GraphicsView_PrsImageFrame::Bottom: aSizeShift = QPointF( 0, aSizeDY ); break; + case GraphicsView_PrsImageFrame::Left: aSizeShift = QPointF( -aSizeDX, 0 ); break; + case GraphicsView_PrsImageFrame::Right: aSizeShift = QPointF( aSizeDX, 0 ); break; + case GraphicsView_PrsImageFrame::TopLeft: aSizeShift = QPointF( -aSizeDX, -aSizeDY ); break; + case GraphicsView_PrsImageFrame::TopRight: aSizeShift = QPointF( aSizeDX, -aSizeDY ); break; + case GraphicsView_PrsImageFrame::BottomLeft: aSizeShift = QPointF( -aSizeDX, aSizeDY ); break; + case GraphicsView_PrsImageFrame::BottomRight: aSizeShift = QPointF( aSizeDX, aSizeDY ); break; + } + + double aWidth = (double)myPixmap.width() * myScaleX; + double aHeight = (double)myPixmap.height() * myScaleY; + + double aNewWidth = aWidth + aSizeShift.x(); + double aNewHeight = aHeight + aSizeShift.y(); + + double aRatio = fabs( aHeight ) > EPSILON ? aWidth / aHeight : 1.0; + double aNewRatio = fabs( aNewHeight ) > EPSILON ? aNewWidth / aNewHeight : 1.0; + + double aDiffX = 0, aDiffY = 0; // only for TopLeft anchor + if( myIsLockAspectRatio && fabs( aRatio ) > EPSILON && + ( theAnchor == GraphicsView_PrsImageFrame::TopLeft || + theAnchor == GraphicsView_PrsImageFrame::TopRight || + theAnchor == GraphicsView_PrsImageFrame::BottomLeft || + theAnchor == GraphicsView_PrsImageFrame::BottomRight ) ) + { + double aCurrentSizeShiftX = aSizeShift.x(); + double aCurrentSizeShiftY = aSizeShift.y(); + + double aSign = myScaleX * myScaleY > 0 ? 1.0 : -1.0; + if( aSign * aNewRatio > aSign * aRatio ) + aSizeShift.setY( aSizeShift.x() / aRatio ); + else + aSizeShift.setX( aSizeShift.y() * aRatio ); + + aDiffX = aSizeShift.x() - aCurrentSizeShiftX; + aDiffY = aSizeShift.y() - aCurrentSizeShiftY; + + aNewWidth = aWidth + aSizeShift.x(); + aNewHeight = aHeight + aSizeShift.y(); + } + + QPointF aPosShift; + switch( theAnchor ) { case GraphicsView_PrsImageFrame::Top: - aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) ); - aSizeShift = QPointF( 0, -aSizeDY ); + aPosShift = QPointF( -aSizeShift.y() * sin( anAngle ), -aSizeShift.y() * cos( anAngle ) ); break; case GraphicsView_PrsImageFrame::Bottom: aPosShift = QPointF( 0, 0 ); - aSizeShift = QPointF( 0, aSizeDY ); break; case GraphicsView_PrsImageFrame::Left: - aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) ); - aSizeShift = QPointF( -aSizeDX, 0 ); + aPosShift = QPointF( -aSizeShift.x() * cos( anAngle ), aSizeShift.x() * sin( anAngle ) ); break; case GraphicsView_PrsImageFrame::Right: aPosShift = QPointF( 0, 0 ); - aSizeShift = QPointF( aSizeDX, 0 ); break; case GraphicsView_PrsImageFrame::TopLeft: - aPosShift = QPointF( theDX, theDY ); - aSizeShift = QPointF( -aSizeDX, -aSizeDY ); + aPosShift = QPointF( theDX - aDiffX * cos( anAngle ) - aDiffY * sin( anAngle ), + theDY + aDiffX * sin( anAngle ) - aDiffY * cos( anAngle ) ); break; case GraphicsView_PrsImageFrame::TopRight: - aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) ); - aSizeShift = QPointF( aSizeDX, -aSizeDY ); + aPosShift = QPointF( -aSizeShift.y() * sin( anAngle ), -aSizeShift.y() * cos( anAngle ) ); break; case GraphicsView_PrsImageFrame::BottomLeft: - aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) ); - aSizeShift = QPointF( -aSizeDX, aSizeDY ); + aPosShift = QPointF( -aSizeShift.x() * cos( anAngle ), aSizeShift.x() * sin( anAngle ) ); break; case GraphicsView_PrsImageFrame::BottomRight: aPosShift = QPointF( 0, 0 ); - aSizeShift = QPointF( aSizeDX, aSizeDY ); break; } - double aWidth = (double)myPixmap.width() * myScaleX; - double aHeight = (double)myPixmap.height() * myScaleY; - - double aNewWidth = aWidth + aSizeShift.x(); - double aNewHeight = aHeight + aSizeShift.y(); + myPreviewPosX = myPosX + aPosShift.x(); + myPreviewPosY = myPosY + aPosShift.y(); myPreviewScaleX = myScaleX * aNewWidth / aWidth; myPreviewScaleY = myScaleY * aNewHeight / aHeight; - myPreviewPosX = myPosX + aPosShift.x(); - myPreviewPosY = myPosY + aPosShift.y(); - updateTransform(); } diff --git a/src/GraphicsView/GraphicsView_PrsImage.h b/src/GraphicsView/GraphicsView_PrsImage.h index c472225cb..b30999ee7 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.h +++ b/src/GraphicsView/GraphicsView_PrsImage.h @@ -59,6 +59,9 @@ public: void setIsLockAspectRatio( const bool theIsLockAspectRatio ); bool getIsLockAspectRatio() const; + void setIsSmoothTransformation( const bool theIsSmoothTransformation ); + bool getIsSmoothTransformation() const; + public: // from QGraphicsItem virtual QRectF boundingRect() const; diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index 9a6f1d632..14951a3b9 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -34,6 +34,7 @@ #define FRAME_Z_VALUE 1000 #define ANCHOR_RADIUS 3 +#define EPSILON 1e-6 #define PI 3.14159265359 //======================================================================= @@ -484,9 +485,9 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c QTransform aTransform = aParent->getViewTransform(); double aScale = aTransform.m11(); // same as m22(), viewer specific - if( fabs( aScale ) < 1e-10 || - fabs( myScaleX ) < 1e-10 || - fabs( myScaleY ) < 1e-10 ) + if( fabs( aScale ) < EPSILON || + fabs( myScaleX ) < EPSILON || + fabs( myScaleY ) < EPSILON ) return aRect; QPointF aCenter = aRect.center(); diff --git a/src/GraphicsView/GraphicsView_PrsPropDlg.cxx b/src/GraphicsView/GraphicsView_PrsPropDlg.cxx index 3a4e654d4..dd925c7e6 100644 --- a/src/GraphicsView/GraphicsView_PrsPropDlg.cxx +++ b/src/GraphicsView/GraphicsView_PrsPropDlg.cxx @@ -40,59 +40,80 @@ GraphicsView_PrsPropDlg::GraphicsView_PrsPropDlg( QWidget* theParent ) QFrame* aMainFrame = mainFrame(); - QGroupBox* aPropGroup = new QGroupBox( aMainFrame ); - - QLabel* aPositionXLabel = new QLabel( tr( "POSITION_X" ), aPropGroup ); - myPositionX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup ); - - QLabel* aPositionYLabel = new QLabel( tr( "POSITION_Y" ), aPropGroup ); - myPositionY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup ); - - QLabel* aScalingXLabel = new QLabel( tr( "SCALING_X" ), aPropGroup ); - myScalingX = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup ); - - QLabel* aScalingYLabel = new QLabel( tr( "SCALING_Y" ), aPropGroup ); - myScalingY = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup ); - - 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 ); - aPropLayout->addWidget( aPositionXLabel, 0, 0 ); - aPropLayout->addWidget( myPositionX, 0, 1 ); - aPropLayout->addWidget( aPositionYLabel, 1, 0 ); - aPropLayout->addWidget( myPositionY, 1, 1 ); - aPropLayout->addWidget( aScalingXLabel, 2, 0 ); - aPropLayout->addWidget( myScalingX, 2, 1 ); - aPropLayout->addWidget( aScalingYLabel, 3, 0 ); - 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 ); + // Geometry + QGroupBox* aGeomGroup = new QGroupBox( tr( "GEOMETRY" ), aMainFrame ); + + QLabel* aPositionXLabel = new QLabel( tr( "POSITION_X" ), aGeomGroup ); + myPositionX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup ); + + QLabel* aPositionYLabel = new QLabel( tr( "POSITION_Y" ), aGeomGroup ); + myPositionY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup ); + + QLabel* aScalingXLabel = new QLabel( tr( "SCALING_X" ), aGeomGroup ); + myScalingX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup ); + + QLabel* aScalingYLabel = new QLabel( tr( "SCALING_Y" ), aGeomGroup ); + myScalingY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup ); + + QLabel* aRotationAngleLabel = new QLabel( tr( "ROTATION_ANGLE" ), aGeomGroup ); + myRotationAngle = new QtxDoubleSpinBox( -1e6, 1e6, 1, aGeomGroup ); + + QGridLayout* aGeomLayout = new QGridLayout( aGeomGroup ); + aGeomLayout->setMargin( 5 ); + aGeomLayout->setSpacing( 5 ); + aGeomLayout->addWidget( aPositionXLabel, 0, 0 ); + aGeomLayout->addWidget( myPositionX, 0, 1 ); + aGeomLayout->addWidget( aPositionYLabel, 1, 0 ); + aGeomLayout->addWidget( myPositionY, 1, 1 ); + aGeomLayout->addWidget( aScalingXLabel, 2, 0 ); + aGeomLayout->addWidget( myScalingX, 2, 1 ); + aGeomLayout->addWidget( aScalingYLabel, 3, 0 ); + aGeomLayout->addWidget( myScalingY, 3, 1 ); + aGeomLayout->addWidget( aRotationAngleLabel, 4, 0 ); + aGeomLayout->addWidget( myRotationAngle, 4, 1 ); + aGeomLayout->setColumnStretch( 1, 1 ); + + // Representation + QGroupBox* aReprGroup = new QGroupBox( tr( "REPRESENTATION" ), aMainFrame ); + + QLabel* aZValueLabel = new QLabel( tr( "Z_VALUE" ), aReprGroup ); + myZValue = new QtxDoubleSpinBox( -1e6, 1e6, 1, aReprGroup ); + + QLabel* anOpacityLabel = new QLabel( tr( "OPACITY" ), aReprGroup ); + myOpacity = new QtxDoubleSpinBox( 0, 1, 0.1, aReprGroup ); + + QGridLayout* aReprLayout = new QGridLayout( aReprGroup ); + aReprLayout->setMargin( 5 ); + aReprLayout->setSpacing( 5 ); + aReprLayout->addWidget( aZValueLabel, 0, 0 ); + aReprLayout->addWidget( myZValue, 0, 1 ); + aReprLayout->addWidget( anOpacityLabel, 1, 0 ); + aReprLayout->addWidget( myOpacity, 1, 1 ); + aReprLayout->setColumnStretch( 1, 1 ); + + // Interaction + QGroupBox* anInterGroup = new QGroupBox( tr( "INTERACTION" ), aMainFrame ); + + myIsLockAspectRatio = new QCheckBox( tr( "LOCK_ASPECT_RATIO" ), anInterGroup ); + myIsSmoothTransformation = new QCheckBox( tr( "SMOOTH_TRANSFORMATION" ), anInterGroup ); + + QGridLayout* anInterLayout = new QGridLayout( anInterGroup ); + anInterLayout->setMargin( 5 ); + anInterLayout->setSpacing( 5 ); + anInterLayout->addWidget( myIsLockAspectRatio, 0, 0 ); + anInterLayout->addWidget( myIsSmoothTransformation, 1, 0 ); + anInterLayout->setColumnStretch( 1, 1 ); QVBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame ); aMainLayout->setMargin( 5 ); aMainLayout->setSpacing( 5 ); - aMainLayout->addWidget( aPropGroup ); + aMainLayout->addWidget( aGeomGroup ); + aMainLayout->addWidget( aReprGroup ); + aMainLayout->addWidget( anInterGroup ); setButtonPosition( Center, OK ); setButtonPosition( Center, Cancel ); - setMinimumWidth( 300 ); + setMinimumWidth( 250 ); } //================================================================ @@ -114,7 +135,8 @@ void GraphicsView_PrsPropDlg::setData( const double thePositionX, const double theRotationAngle, const double theZValue, const double theOpacity, - const bool theIsLockAspectRatio ) + const bool theIsLockAspectRatio, + const bool theIsSmoothTransformation ) { myPositionX->setValue( thePositionX ); myPositionY->setValue( thePositionY ); @@ -124,6 +146,7 @@ void GraphicsView_PrsPropDlg::setData( const double thePositionX, myZValue->setValue( theZValue ); myOpacity->setValue( theOpacity ); myIsLockAspectRatio->setChecked( theIsLockAspectRatio ); + myIsSmoothTransformation->setChecked( theIsSmoothTransformation ); } //============================================================================= @@ -137,7 +160,8 @@ void GraphicsView_PrsPropDlg::getData( double& thePositionX, double& theRotationAngle, double& theZValue, double& theOpacity, - bool& theIsLockAspectRatio ) const + bool& theIsLockAspectRatio, + bool& theIsSmoothTransformation ) const { thePositionX = myPositionX->value(); thePositionY = myPositionY->value(); @@ -147,4 +171,5 @@ void GraphicsView_PrsPropDlg::getData( double& thePositionX, theZValue = myZValue->value(); theOpacity = myOpacity->value(); theIsLockAspectRatio = myIsLockAspectRatio->isChecked(); + theIsSmoothTransformation = myIsSmoothTransformation->isChecked(); } diff --git a/src/GraphicsView/GraphicsView_PrsPropDlg.h b/src/GraphicsView/GraphicsView_PrsPropDlg.h index b870d4902..f34723fbd 100644 --- a/src/GraphicsView/GraphicsView_PrsPropDlg.h +++ b/src/GraphicsView/GraphicsView_PrsPropDlg.h @@ -51,7 +51,8 @@ public: const double theRotationAngle, const double theZValue, const double theOpacity, - const bool theIsLockAspectRatio ); + const bool theIsLockAspectRatio, + const bool theIsSmoothTransformation ); void getData( double& thePositionX, double& thePositionY, @@ -60,7 +61,8 @@ public: double& theRotationAngle, double& theZValue, double& theOpacity, - bool& theIsLockAspectRatio ) const; + bool& theIsLockAspectRatio, + bool& theIsSmoothTransformation ) const; private: QtxDoubleSpinBox* myPositionX; @@ -68,9 +70,12 @@ private: QtxDoubleSpinBox* myScalingX; QtxDoubleSpinBox* myScalingY; QtxDoubleSpinBox* myRotationAngle; + QtxDoubleSpinBox* myOpacity; QtxDoubleSpinBox* myZValue; + QCheckBox* myIsLockAspectRatio; + QCheckBox* myIsSmoothTransformation; }; #endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 56c4bc2e6..cace48376 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -726,14 +726,17 @@ void GraphicsView_Viewer::onPrsProperties() 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 ); + aZValue, anOpacity, anIsLockAspectRatio, + anIsSmoothTransformation ); if( aDlg.exec() ) { aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle, - aZValue, anOpacity, anIsLockAspectRatio ); + aZValue, anOpacity, anIsLockAspectRatio, + anIsSmoothTransformation ); aPrs->setPosition( aPosX, aPosY ); aPrs->setScaling( aScaleX, aScaleY ); @@ -743,6 +746,7 @@ void GraphicsView_Viewer::onPrsProperties() aPrs->setOpacity( anOpacity ); aPrs->setIsLockAspectRatio( anIsLockAspectRatio ); + aPrs->setIsSmoothTransformation( anIsSmoothTransformation ); aPrs->compute(); } diff --git a/src/GraphicsView/resources/GraphicsView_msg_en.ts b/src/GraphicsView/resources/GraphicsView_msg_en.ts index dcb33723d..10b14bfa3 100644 --- a/src/GraphicsView/resources/GraphicsView_msg_en.ts +++ b/src/GraphicsView/resources/GraphicsView_msg_en.ts @@ -123,6 +123,10 @@ PROPERTIES Properties + + GEOMETRY + Geometry + POSITION_X Position X @@ -143,6 +147,10 @@ ROTATION_ANGLE Rotation angle + + REPRESENTATION + Representation + Z_VALUE Z value @@ -151,9 +159,17 @@ OPACITY Opacity + + INTERACTION + Interaction + LOCK_ASPECT_RATIO Lock aspect ratio + + SMOOTH_TRANSFORMATION + Smooth transformation + -- 2.39.2