#include "GraphicsView_ViewPort.h"
#include <QCursor>
-#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPainter>
#include <QVector2D>
#include <math.h>
#define PREVIEW_Z_VALUE 2000
-#define EPSILON 1e-6
-#define PI 3.14159265359
+#define EPSILON 1e-6
+#define PI 3.14159265359
//=======================================================================
// name : GraphicsView_PrsImage
myIsLockAspectRatio( false ),
myPixmapItem( 0 ),
myPreviewPixmapItem( 0 ),
- myImageFrame( 0 ),
+ myPrsImageFrame( 0 ),
myPosX( 0.0 ),
myPosY( 0.0 ),
myScaleX( 1.0 ),
//=======================================================================
GraphicsView_PrsImage::~GraphicsView_PrsImage()
{
- /* to be revised
- if( myPreviewPixmapItem )
+ if( myPrsImageFrame )
{
- delete myPreviewPixmapItem;
- myPreviewPixmapItem = 0;
- }
-
- if( myImageFrame )
- {
- delete myImageFrame;
- myImageFrame = 0;
- }
- */
-
- QListIterator<QGraphicsItem*> aChildIter( children() );
- while( aChildIter.hasNext() )
- {
- if( QGraphicsItem* aChild = aChildIter.next() )
- {
- removeFromGroup( aChild );
- if( QGraphicsScene* aScene = aChild->scene() )
- aScene->removeItem( aChild );
- delete aChild;
- aChild = 0;
- }
+ delete myPrsImageFrame;
+ myPrsImageFrame = 0;
}
}
QTransform aTransform = getTransform();
setTransform( aTransform );
- myImageFrame->setTransform( aTransform );
+ myPrsImageFrame->setTransform( aTransform );
// for anchors
- myImageFrame->setScaling( myScaleX, myScaleY );
- myImageFrame->setRotationAngle( myRotationAngle );
+ myPrsImageFrame->setScaling( myScaleX, myScaleY );
+ myPrsImageFrame->setRotationAngle( myRotationAngle );
aTransform = getTransform( true );
myPreviewPixmapItem->setTransform( aTransform );
myPreviewPixmapItem = new QGraphicsPixmapItem();
//addToGroup( myPreviewPixmapItem ); // don't add
}
- if( !myImageFrame )
+ if( !myPrsImageFrame )
{
- myImageFrame = new GraphicsView_PrsImageFrame();
- myImageFrame->setPrsImage( this );
+ myPrsImageFrame = new GraphicsView_PrsImageFrame();
+ myPrsImageFrame->setPrsImage( this );
}
myPixmapItem->setPixmap( myPixmap );
myPreviewPixmapItem->setPixmap( myPixmap );
myPreviewPixmapItem->setVisible( false );
- myImageFrame->compute();
+ myPrsImageFrame->compute();
updateTransform();
}
void GraphicsView_PrsImage::addTo( GraphicsView_ViewPort* theViewPort )
{
GraphicsView_Object::addTo( theViewPort );
- theViewPort->addItem( myImageFrame );
+ theViewPort->addItem( myPrsImageFrame );
theViewPort->addItem( myPreviewPixmapItem );
double aZValue = 0;
void GraphicsView_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort )
{
GraphicsView_Object::removeFrom( theViewPort );
- theViewPort->removeItem( myImageFrame );
+ theViewPort->removeItem( myPrsImageFrame );
theViewPort->removeItem( myPreviewPixmapItem );
}
bool GraphicsView_PrsImage::select( double theX, double theY, const QRectF& theRect )
{
bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect );
- myImageFrame->updateAnchorItems();
+ myPrsImageFrame->updateVisibility();
return anIsSelected;
}
void GraphicsView_PrsImage::unselect()
{
GraphicsView_Object::unselect();
- myImageFrame->updateAnchorItems();
+ myPrsImageFrame->updateVisibility();
}
//================================================================
void GraphicsView_PrsImage::setSelected( bool theState )
{
GraphicsView_Object::setSelected( theState );
- myImageFrame->updateAnchorItems();
+ myPrsImageFrame->updateVisibility();
}
//================================================================
#include <math.h>
-#define FRAME_Z_VALUE 1000
-#define ANCHOR_RADIUS 3
-#define PI 3.14159265359
+#define FRAME_Z_VALUE 1000
+#define ANCHOR_RADIUS 3
+#define PI 3.14159265359
//=======================================================================
// name : GraphicsView_PrsImageFrame
setZValue( FRAME_Z_VALUE );
computeAnchorItems();
- updateAnchorItems();
+ updateVisibility();
}
//================================================================
}
//================================================================
-// Function : updateAnchorItems
+// Function : updateVisibility
// Purpose :
//================================================================
-void GraphicsView_PrsImageFrame::updateAnchorItems()
+void GraphicsView_PrsImageFrame::updateVisibility()
{
- if( !myPrsImage )
- return;
-
- bool anIsSelected = myPrsImage->isSelected();
- setVisible( anIsSelected );
+ setVisible( myPrsImage && myPrsImage->isSelected() );
}
//================================================================
aCenter.y() - aHeight / 2 + anOffsetY,
aWidth, aHeight );
+ // to do
+ //QRectF aBaseRect( myBasePoint, QSizeF( 1, 1 ) );
+ //aRect |= aBaseRect;
+
return aRect;
}
QGraphicsEllipseItem::paint( thePainter, theOption, theWidget );
thePainter->restore();
+
+ // for debug
+ //thePainter->save();
+ //thePainter->setPen( QPen( Qt::magenta ) );
+ //thePainter->drawRect( boundingRect() );
+ //thePainter->restore();
}