From 2dd14b751833ac887e81011f1f93ccd5d5566b5b Mon Sep 17 00:00:00 2001 From: ouv Date: Thu, 4 Jul 2013 09:30:03 +0000 Subject: [PATCH] Raw development for ImageViewer. --- src/GraphicsView/GraphicsView_Object.cxx | 13 +++++ src/GraphicsView/GraphicsView_PrsImage.cxx | 58 ++++++------------- src/GraphicsView/GraphicsView_PrsImage.h | 2 +- .../GraphicsView_PrsImageFrame.cxx | 28 +++++---- src/GraphicsView/GraphicsView_PrsImageFrame.h | 2 +- 5 files changed, 50 insertions(+), 53 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Object.cxx b/src/GraphicsView/GraphicsView_Object.cxx index 9338b9373..648f9d294 100644 --- a/src/GraphicsView/GraphicsView_Object.cxx +++ b/src/GraphicsView/GraphicsView_Object.cxx @@ -51,6 +51,19 @@ GraphicsView_Object::~GraphicsView_Object() delete myHighlightCursor; myHighlightCursor = 0; } + + QListIterator aChildIter( children() ); + while( aChildIter.hasNext() ) + { + if( QGraphicsItem* aChild = aChildIter.next() ) + { + removeFromGroup( aChild ); + if( QGraphicsScene* aScene = aChild->scene() ) + aScene->removeItem( aChild ); + delete aChild; + aChild = 0; + } + } } //================================================================ diff --git a/src/GraphicsView/GraphicsView_PrsImage.cxx b/src/GraphicsView/GraphicsView_PrsImage.cxx index 1bb7afe59..bdfbac267 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.cxx +++ b/src/GraphicsView/GraphicsView_PrsImage.cxx @@ -26,7 +26,6 @@ #include "GraphicsView_ViewPort.h" #include -#include #include #include #include @@ -34,8 +33,8 @@ #include #define PREVIEW_Z_VALUE 2000 -#define EPSILON 1e-6 -#define PI 3.14159265359 +#define EPSILON 1e-6 +#define PI 3.14159265359 //======================================================================= // name : GraphicsView_PrsImage @@ -46,7 +45,7 @@ GraphicsView_PrsImage::GraphicsView_PrsImage() myIsLockAspectRatio( false ), myPixmapItem( 0 ), myPreviewPixmapItem( 0 ), - myImageFrame( 0 ), + myPrsImageFrame( 0 ), myPosX( 0.0 ), myPosY( 0.0 ), myScaleX( 1.0 ), @@ -66,31 +65,10 @@ GraphicsView_PrsImage::GraphicsView_PrsImage() //======================================================================= GraphicsView_PrsImage::~GraphicsView_PrsImage() { - /* to be revised - if( myPreviewPixmapItem ) + if( myPrsImageFrame ) { - delete myPreviewPixmapItem; - myPreviewPixmapItem = 0; - } - - if( myImageFrame ) - { - delete myImageFrame; - myImageFrame = 0; - } - */ - - QListIterator 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; } } @@ -103,11 +81,11 @@ void GraphicsView_PrsImage::updateTransform() 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 ); @@ -251,10 +229,10 @@ void GraphicsView_PrsImage::compute() 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 ); @@ -262,7 +240,7 @@ void GraphicsView_PrsImage::compute() myPreviewPixmapItem->setPixmap( myPixmap ); myPreviewPixmapItem->setVisible( false ); - myImageFrame->compute(); + myPrsImageFrame->compute(); updateTransform(); } @@ -274,7 +252,7 @@ void GraphicsView_PrsImage::compute() void GraphicsView_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) { GraphicsView_Object::addTo( theViewPort ); - theViewPort->addItem( myImageFrame ); + theViewPort->addItem( myPrsImageFrame ); theViewPort->addItem( myPreviewPixmapItem ); double aZValue = 0; @@ -297,7 +275,7 @@ void GraphicsView_PrsImage::addTo( GraphicsView_ViewPort* theViewPort ) void GraphicsView_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort ) { GraphicsView_Object::removeFrom( theViewPort ); - theViewPort->removeItem( myImageFrame ); + theViewPort->removeItem( myPrsImageFrame ); theViewPort->removeItem( myPreviewPixmapItem ); } @@ -324,7 +302,7 @@ bool GraphicsView_PrsImage::checkHighlight( double theX, double theY, QCursor& t 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; } @@ -335,7 +313,7 @@ bool GraphicsView_PrsImage::select( double theX, double theY, const QRectF& theR void GraphicsView_PrsImage::unselect() { GraphicsView_Object::unselect(); - myImageFrame->updateAnchorItems(); + myPrsImageFrame->updateVisibility(); } //================================================================ @@ -345,7 +323,7 @@ void GraphicsView_PrsImage::unselect() void GraphicsView_PrsImage::setSelected( bool theState ) { GraphicsView_Object::setSelected( theState ); - myImageFrame->updateAnchorItems(); + myPrsImageFrame->updateVisibility(); } //================================================================ diff --git a/src/GraphicsView/GraphicsView_PrsImage.h b/src/GraphicsView/GraphicsView_PrsImage.h index fba539426..c472225cb 100644 --- a/src/GraphicsView/GraphicsView_PrsImage.h +++ b/src/GraphicsView/GraphicsView_PrsImage.h @@ -104,7 +104,7 @@ protected: QGraphicsPixmapItem* myPixmapItem; QGraphicsPixmapItem* myPreviewPixmapItem; - GraphicsView_PrsImageFrame* myImageFrame; + GraphicsView_PrsImageFrame* myPrsImageFrame; double myPosX; double myPosY; diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index a341534fc..9a6f1d632 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -32,9 +32,9 @@ #include -#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 @@ -139,7 +139,7 @@ void GraphicsView_PrsImageFrame::compute() setZValue( FRAME_Z_VALUE ); computeAnchorItems(); - updateAnchorItems(); + updateVisibility(); } //================================================================ @@ -342,16 +342,12 @@ void GraphicsView_PrsImageFrame::computeAnchorItems() } //================================================================ -// 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() ); } //================================================================ @@ -504,6 +500,10 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c aCenter.y() - aHeight / 2 + anOffsetY, aWidth, aHeight ); + // to do + //QRectF aBaseRect( myBasePoint, QSizeF( 1, 1 ) ); + //aRect |= aBaseRect; + return aRect; } @@ -553,4 +553,10 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint( QGraphicsEllipseItem::paint( thePainter, theOption, theWidget ); thePainter->restore(); + + // for debug + //thePainter->save(); + //thePainter->setPen( QPen( Qt::magenta ) ); + //thePainter->drawRect( boundingRect() ); + //thePainter->restore(); } diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.h b/src/GraphicsView/GraphicsView_PrsImageFrame.h index 3ccecd047..350a73a95 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.h +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.h @@ -76,7 +76,7 @@ public: void setPrsImage( GraphicsView_PrsImage* ); void computeAnchorItems(); - void updateAnchorItems(); + void updateVisibility(); void setScaling( const double theScaleX, const double theScaleY ); void setRotationAngle( const double theRotationAngle ); -- 2.39.2