1 // Copyright (C) 2013-2023 CEA, EDF, 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, or (at your option) any later version.
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 ),
40 //=======================================================================
41 // Name : GraphicsView_Object
42 // Purpose : Destructor
43 //=======================================================================
44 GraphicsView_Object::~GraphicsView_Object()
46 QListIterator<QGraphicsItem*> aChildIter( childItems() );
47 while( aChildIter.hasNext() )
49 if( QGraphicsItem* aChild = aChildIter.next() )
51 removeFromGroup( aChild );
52 if( QGraphicsScene* aScene = aChild->scene() )
53 aScene->removeItem( aChild );
60 //================================================================
63 //================================================================
64 void GraphicsView_Object::addTo( GraphicsView_ViewPort* theViewPort )
66 if( QGraphicsScene* aScene = theViewPort->scene() )
67 aScene->addItem( this );
70 //================================================================
71 // Function : removeFrom
73 //================================================================
74 void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort )
76 if( QGraphicsScene* aScene = theViewPort->scene() )
77 aScene->removeItem( this );
80 //================================================================
83 //================================================================
84 void GraphicsView_Object::setName( const QString& theName )
89 //================================================================
92 //================================================================
93 QRectF GraphicsView_Object::getRect() const
95 return sceneBoundingRect();
98 //================================================================
99 // Function : checkHighlight
101 //================================================================
102 bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& /*theCursor*/ ) const
104 return !getRect().isNull() && getRect().contains( theX, theY );
107 //================================================================
108 // Function : highlight
110 //================================================================
111 bool GraphicsView_Object::highlight( double theX, double theY )
114 if( (myIsHighlighted = isVisible()) )
115 myIsHighlighted = checkHighlight( theX, theY, aCursor );
116 return myIsHighlighted;
119 //================================================================
120 // Function : unhighlight
122 //================================================================
123 void GraphicsView_Object::unhighlight()
125 myIsHighlighted = false;
128 //================================================================
131 //================================================================
132 bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
135 if( (myIsSelected = isVisible()) )
137 if( !theRect.isNull() )
138 myIsSelected = theRect.contains( getRect() );
140 myIsSelected = checkHighlight( theX, theY, aCursor );
145 //================================================================
146 // Function : unselect
148 //================================================================
149 void GraphicsView_Object::unselect()
151 myIsSelected = false;
154 //================================================================
157 //================================================================
158 void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
170 moveBy( theDX, theDY );
173 //================================================================
174 // Function : finishMove
176 //================================================================
177 bool GraphicsView_Object::finishMove( bool theStatus )
181 if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
182 aScene->processRectChanged();
186 //================================================================
187 // Function : setViewTransform
189 //================================================================
190 void GraphicsView_Object::setViewTransform( const QTransform& theTransform )
192 myViewTransform = theTransform;