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 :
if( !myPreviewPixmapItem )
{
myPreviewPixmapItem = new QGraphicsPixmapItem();
+ myPreviewPixmapItem->setTransformationMode( Qt::FastTransformation ); // always
//addToGroup( myPreviewPixmapItem ); // don't add
}
if( !myPrsImageFrame )
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();
}
void setIsLockAspectRatio( const bool theIsLockAspectRatio );
bool getIsLockAspectRatio() const;
+ void setIsSmoothTransformation( const bool theIsSmoothTransformation );
+ bool getIsSmoothTransformation() const;
+
public:
// from QGraphicsItem
virtual QRectF boundingRect() const;
#define FRAME_Z_VALUE 1000
#define ANCHOR_RADIUS 3
+#define EPSILON 1e-6
#define PI 3.14159265359
//=======================================================================
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();
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 );
}
//================================================================
const double theRotationAngle,
const double theZValue,
const double theOpacity,
- const bool theIsLockAspectRatio )
+ const bool theIsLockAspectRatio,
+ const bool theIsSmoothTransformation )
{
myPositionX->setValue( thePositionX );
myPositionY->setValue( thePositionY );
myZValue->setValue( theZValue );
myOpacity->setValue( theOpacity );
myIsLockAspectRatio->setChecked( theIsLockAspectRatio );
+ myIsSmoothTransformation->setChecked( theIsSmoothTransformation );
}
//=============================================================================
double& theRotationAngle,
double& theZValue,
double& theOpacity,
- bool& theIsLockAspectRatio ) const
+ bool& theIsLockAspectRatio,
+ bool& theIsSmoothTransformation ) const
{
thePositionX = myPositionX->value();
thePositionY = myPositionY->value();
theZValue = myZValue->value();
theOpacity = myOpacity->value();
theIsLockAspectRatio = myIsLockAspectRatio->isChecked();
+ theIsSmoothTransformation = myIsSmoothTransformation->isChecked();
}
const double theRotationAngle,
const double theZValue,
const double theOpacity,
- const bool theIsLockAspectRatio );
+ const bool theIsLockAspectRatio,
+ const bool theIsSmoothTransformation );
void getData( double& thePositionX,
double& thePositionY,
double& theRotationAngle,
double& theZValue,
double& theOpacity,
- bool& theIsLockAspectRatio ) const;
+ bool& theIsLockAspectRatio,
+ bool& theIsSmoothTransformation ) const;
private:
QtxDoubleSpinBox* myPositionX;
QtxDoubleSpinBox* myScalingX;
QtxDoubleSpinBox* myScalingY;
QtxDoubleSpinBox* myRotationAngle;
+
QtxDoubleSpinBox* myOpacity;
QtxDoubleSpinBox* myZValue;
+
QCheckBox* myIsLockAspectRatio;
+ QCheckBox* myIsSmoothTransformation;
};
#endif
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 );
aPrs->setOpacity( anOpacity );
aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
+ aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
aPrs->compute();
}
<source>PROPERTIES</source>
<translation>Properties</translation>
</message>
+ <message>
+ <source>GEOMETRY</source>
+ <translation>Geometry</translation>
+ </message>
<message>
<source>POSITION_X</source>
<translation>Position X</translation>
<source>ROTATION_ANGLE</source>
<translation>Rotation angle</translation>
</message>
+ <message>
+ <source>REPRESENTATION</source>
+ <translation>Representation</translation>
+ </message>
<message>
<source>Z_VALUE</source>
<translation>Z value</translation>
<source>OPACITY</source>
<translation>Opacity</translation>
</message>
+ <message>
+ <source>INTERACTION</source>
+ <translation>Interaction</translation>
+ </message>
<message>
<source>LOCK_ASPECT_RATIO</source>
<translation>Lock aspect ratio</translation>
</message>
+ <message>
+ <source>SMOOTH_TRANSFORMATION</source>
+ <translation>Smooth transformation</translation>
+ </message>
</context>
</TS>