Salome HOME
Merge from BR_hydro 30/10/2013
[modules/gui.git] / src / GraphicsView / GraphicsView_Object.h
1 // Copyright (C) 2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef GRAPHICSVIEW_OBJECT_H
21 #define GRAPHICSVIEW_OBJECT_H
22
23 #include "GraphicsView.h"
24
25 #include "GraphicsView_Defs.h"
26
27 #include <QGraphicsItemGroup>
28
29 class GraphicsView_ViewPort;
30
31 /*
32   Class       : GraphicsView_Object
33   Description : Base class for all objects displayed at the scene
34 */
35 class GRAPHICSVIEW_API GraphicsView_Object : public QGraphicsItemGroup
36 {
37 public:
38   GraphicsView_Object( QGraphicsItem* theParent = 0 );
39   ~GraphicsView_Object();
40
41   virtual void               compute() = 0;
42
43   virtual void               addTo( GraphicsView_ViewPort* theViewPort );
44   virtual void               removeFrom( GraphicsView_ViewPort* theViewPort );
45
46   const QString&             getName() const { return myName; }
47   virtual void               setName( const QString& theName );
48
49   virtual int                getPriority() const { return myPriority; }
50
51   virtual bool               isOnTop() const { return myIsOnTop; }
52   virtual void               setIsOnTop( bool theIsOnTop ) { myIsOnTop = theIsOnTop; }
53
54   virtual bool               hasSpecificZValue() const { return false; }
55
56   virtual bool               isSelectable() const { return true; }
57   virtual bool               isMovable() const { return true; }
58
59   virtual QRectF             getRect() const;
60
61   virtual bool               checkHighlight( double theX, double theY, QCursor& theCursor ) const;
62
63   virtual bool               highlight( double theX, double theY );
64   virtual void               unhighlight();
65   virtual bool               isHighlighted() const { return myIsHighlighted; }
66
67   virtual bool               select( double theX, double theY, const QRectF& theRect );
68   virtual void               unselect();
69   virtual bool               isSelected() const { return myIsSelected; }
70   virtual void               setSelected( bool theState ) { myIsSelected = theState; }
71
72   virtual void               move( double theDX, double theDY, bool theIsAtOnce = false );
73   virtual bool               finishMove( bool theStatus );
74   virtual bool               isMoving() const { return myIsMoving; }
75   virtual bool               isMovingByXAllowed( double theDX ) { return true; }
76   virtual bool               isMovingByYAllowed( double theDY ) { return true; }
77
78   virtual bool               updateScale( bool theIsScaleUp, bool theIsCtrl ) { return false; }
79
80   virtual QRectF             getPullingRect() const { return getRect(); }
81   virtual bool               portContains( const QPointF& ) { return false; }
82   virtual bool               startPulling( const QPointF& ) { return false; }
83   virtual void               pull( const QPointF&,
84                                    GraphicsView_Object*,
85                                    const GraphicsView_ObjectList& ) {}
86   virtual void               finishPulling( bool, const GraphicsView_ObjectList& ) {}
87   virtual bool               isPulling() { return false; }
88
89   virtual bool               handleMousePress( QGraphicsSceneMouseEvent* ) { return false; }
90   virtual bool               handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; }
91   virtual bool               handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; }
92
93   virtual QTransform         getViewTransform() const { return myViewTransform; }
94   virtual void               setViewTransform( const QTransform& theTransform );
95
96 protected:
97   QString                    myName;
98
99   int                        myPriority;
100   bool                       myIsOnTop;
101
102   bool                       myIsHighlighted;
103   bool                       myIsSelected;
104
105   bool                       myIsMoving;
106
107   QTransform                 myViewTransform;
108 };
109
110 #endif