1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GraphicsView_Object.h"
22 #include "GraphicsView_Scene.h"
23 #include "GraphicsView_ViewPort.h"
25 //=======================================================================
26 // Name : GraphicsView_Object
27 // Purpose : Constructor
28 //=======================================================================
29 GraphicsView_Object::GraphicsView_Object( QGraphicsItem* theParent )
30 : QGraphicsItemGroup( theParent ),
33 myIsHighlighted( false ),
34 myIsSelected( false ),
39 //=======================================================================
40 // Name : GraphicsView_Object
41 // Purpose : Destructor
42 //=======================================================================
43 GraphicsView_Object::~GraphicsView_Object()
45 QListIterator<QGraphicsItem*> aChildIter( children() );
46 while( aChildIter.hasNext() )
48 if( QGraphicsItem* aChild = aChildIter.next() )
50 removeFromGroup( aChild );
51 if( QGraphicsScene* aScene = aChild->scene() )
52 aScene->removeItem( aChild );
59 //================================================================
62 //================================================================
63 void GraphicsView_Object::addTo( GraphicsView_ViewPort* theViewPort )
65 if( QGraphicsScene* aScene = theViewPort->scene() )
66 aScene->addItem( this );
69 //================================================================
70 // Function : removeFrom
72 //================================================================
73 void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort )
75 if( QGraphicsScene* aScene = theViewPort->scene() )
76 aScene->removeItem( this );
79 //================================================================
82 //================================================================
83 void GraphicsView_Object::setName( const QString& theName )
88 //================================================================
91 //================================================================
92 QRectF GraphicsView_Object::getRect() const
94 return sceneBoundingRect();
97 //================================================================
98 // Function : checkHighlight
100 //================================================================
101 bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& theCursor ) const
103 return !getRect().isNull() && getRect().contains( theX, theY );
106 //================================================================
107 // Function : highlight
109 //================================================================
110 bool GraphicsView_Object::highlight( double theX, double theY )
113 if( myIsHighlighted = isVisible() )
114 myIsHighlighted = checkHighlight( theX, theY, aCursor );
115 return myIsHighlighted;
118 //================================================================
119 // Function : unhighlight
121 //================================================================
122 void GraphicsView_Object::unhighlight()
124 myIsHighlighted = false;
127 //================================================================
130 //================================================================
131 bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
134 if( myIsSelected = isVisible() )
136 if( !theRect.isNull() )
137 myIsSelected = theRect.contains( getRect() );
139 myIsSelected = checkHighlight( theX, theY, aCursor );
144 //================================================================
145 // Function : unselect
147 //================================================================
148 void GraphicsView_Object::unselect()
150 myIsSelected = false;
153 //================================================================
156 //================================================================
157 void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
166 moveBy( theDX, theDY );
169 //================================================================
170 // Function : finishMove
172 //================================================================
173 bool GraphicsView_Object::finishMove( bool theStatus )
177 if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
178 aScene->processRectChanged();
182 //================================================================
183 // Function : setViewTransform
185 //================================================================
186 void GraphicsView_Object::setViewTransform( const QTransform& theTransform )
188 myViewTransform = theTransform;