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; }
#include <math.h>
+#define PREVIEW_Z_VALUE 2000
#define EPSILON 1e-6
#define PI 3.14159265359
//=======================================================================
GraphicsView_PrsImage::GraphicsView_PrsImage()
: GraphicsView_Object(),
+ myIsLockAspectRatio( false ),
myPixmapItem( 0 ),
myPreviewPixmapItem( 0 ),
myImageFrame( 0 ),
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 :
myImageFrame->setPrsImage( this );
}
- setZValue( 0 );
-
QSize aSourceSize = myPixmap.size();
QSize aScaledSize( aSourceSize.width() * myScaleX,
aSourceSize.height() * myScaleY );
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<GraphicsView_PrsImage*>( anIter.next() ) )
+ {
+ double aZValueRef = aPrs->zValue();
+ aZValue = qMax( aZValue, aZValueRef );
+ }
+ }
+ setZValue( aZValue + 1 );
}
//================================================================
{
if( theState )
{
- myPreviewPixmapItem->setZValue( 100 );
+ myPreviewPixmapItem->setZValue( PREVIEW_Z_VALUE );
myPreviewPixmapItem->setOpacity( opacity() / 2. );
myPreviewPixmapItem->setPos( pos() );
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;
protected:
QPixmap myPixmap;
+ bool myIsLockAspectRatio;
+
QGraphicsPixmapItem* myPixmapItem;
QGraphicsPixmapItem* myPreviewPixmapItem;
#include <math.h>
-#define PI 3.14159265359
-
+#define FRAME_Z_VALUE 1000
#define ANCHOR_RADIUS 10
+#define PI 3.14159265359
//=======================================================================
// name : GraphicsView_PrsImageFrame
}
}
- setZValue( 1000 );
+ setZValue( FRAME_Z_VALUE );
computeAnchorItems();
updateAnchorItems();
// 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;
#include <QtxDoubleSpinBox.h>
+#include <QCheckBox>
#include <QGroupBox>
#include <QLabel>
#include <QLayout>
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( 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 );
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 );
}
//=============================================================================
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();
}
#include <QtxDialog.h>
+class QCheckBox;
+
class QtxDoubleSpinBox;
/*
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;
QtxDoubleSpinBox* myScalingX;
QtxDoubleSpinBox* myScalingY;
QtxDoubleSpinBox* myRotationAngle;
+ QtxDoubleSpinBox* myOpacity;
+ QtxDoubleSpinBox* myZValue;
+ QCheckBox* myIsLockAspectRatio;
};
#endif
// 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
}
//================================================================
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() )
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;
const GraphicsView_ObjectList& getSelectedObjects() const { return mySelectedObjects; }
-
// rectangle selection
void startSelectByRect( int x, int y );
void drawSelectByRect( int x, int y );
}
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();
}
}
+//================================================================
+// 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 );
}
//================================================================
//================================================================
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<int> 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<int> 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;
+ }
+ }
+ }
}
//================================================================
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();
}
}
// testing ImageViewer
void onAddImage();
void onRemoveImages();
+ void onBringToFront();
+ void onSendToBack();
void onBringForward();
void onSendBackward();
void onPrsProperties();
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;
<source>REMOVE_IMAGES</source>
<translation>Remove image(s)</translation>
</message>
+ <message>
+ <source>BRING_TO_FRONT</source>
+ <translation>Bring to front</translation>
+ </message>
+ <message>
+ <source>SEND_TO_BACK</source>
+ <translation>Send to back</translation>
+ </message>
<message>
<source>BRING_FORWARD</source>
<translation>Bring forward</translation>
<source>ROTATION_ANGLE</source>
<translation>Rotation angle</translation>
</message>
+ <message>
+ <source>Z_VALUE</source>
+ <translation>Z value</translation>
+ </message>
+ <message>
+ <source>OPACITY</source>
+ <translation>Opacity</translation>
+ </message>
+ <message>
+ <source>LOCK_ASPECT_RATIO</source>
+ <translation>Lock aspect ratio</translation>
+ </message>
</context>
</TS>