Salome HOME
Merge remote branch 'origin/hydro/imps_2015'
[modules/gui.git] / src / GraphicsView / GraphicsView_Scene.cxx
1 // Copyright (C) 2013-2016  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, or (at your option) any later version.
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 #include "GraphicsView_Scene.h"
21
22 #include <QGraphicsLineItem>
23 #include <QGraphicsRectItem>
24 #include <QGraphicsSceneWheelEvent>
25
26 //#define VIEWER_DEBUG
27
28 //=======================================================================
29 // Name    : GraphicsView_Scene
30 // Purpose : Constructor
31 //=======================================================================
32 GraphicsView_Scene::GraphicsView_Scene( QObject* theParent )
33 : QGraphicsScene( theParent )
34 {
35 #ifdef VIEWER_DEBUG
36   mySceneRectItem = new QGraphicsRectItem();
37   mySceneRectItem->setPen( QPen( Qt::red, 0.0 ) );
38
39   addItem( mySceneRectItem );
40
41   connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ),
42            this, SLOT( onSceneRectChanged( const QRectF& ) ) );
43
44   setSceneRect( -2000, -2000, 4000, 4000 );
45
46   QGraphicsLineItem* aHorLineItem = new QGraphicsLineItem( -2000, 0, 2000, 0 );
47   aHorLineItem->setPen( QPen( Qt::red ) );
48   addItem( aHorLineItem );
49
50   QGraphicsLineItem* aVerLineItem = new QGraphicsLineItem( 0, -2000, 0, 2000 );
51   aVerLineItem->setPen( QPen( Qt::red ) );
52   addItem( aVerLineItem );
53 #endif
54 }
55
56 //=======================================================================
57 // Name    : GraphicsView_Scene
58 // Purpose : Destructor
59 //=======================================================================
60 GraphicsView_Scene::~GraphicsView_Scene()
61 {
62 }
63
64 //================================================================
65 // Function : processRectChanged
66 // Purpose  : 
67 //================================================================
68 void GraphicsView_Scene::processRectChanged()
69 {
70   emit gsBoundingRectChanged();
71 }
72
73 //================================================================
74 // Function : onSceneRectChanged
75 // Purpose  : 
76 //================================================================
77 void GraphicsView_Scene::onSceneRectChanged( const QRectF& theRect )
78 {
79 #ifdef VIEWER_DEBUG
80   mySceneRectItem->setRect( theRect );
81 #endif
82 }
83
84 //================================================================
85 // Function : keyPressEvent
86 // Purpose  : 
87 //================================================================
88 void GraphicsView_Scene::keyPressEvent( QKeyEvent* e )
89 {
90   emit gsKeyEvent( e );
91   QGraphicsScene::keyPressEvent( e );
92 }
93
94 //================================================================
95 // Function : keyReleaseEvent
96 // Purpose  : 
97 //================================================================
98 void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e )
99 {
100   emit gsKeyEvent( e );
101   QGraphicsScene::keyReleaseEvent( e );
102 }
103
104 //================================================================
105 // Function : mousePressEvent
106 // Purpose  : 
107 //================================================================
108 void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
109 {
110   emit gsMouseEvent( e );
111   QGraphicsScene::mousePressEvent( e );
112 }
113
114 //================================================================
115 // Function : mouseMoveEvent
116 // Purpose  : 
117 //================================================================
118 void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
119 {
120   emit gsMouseEvent( e );
121   QGraphicsScene::mouseMoveEvent( e );
122 }
123
124 //================================================================
125 // Function : mouseReleaseEvent
126 // Purpose  : 
127 //================================================================
128 void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
129 {
130   emit gsMouseEvent( e );
131   QGraphicsScene::mouseReleaseEvent( e );
132 }
133
134 //================================================================
135 // Function : mouseDoubleClickEvent
136 // Purpose  : 
137 //================================================================
138 void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
139 {
140   emit gsMouseEvent( e );
141   QGraphicsScene::mouseDoubleClickEvent( e );
142 }
143
144 //================================================================
145 // Function : wheelEvent
146 // Purpose  : 
147 //================================================================
148 void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
149 {
150   emit gsWheelEvent( e );
151
152   // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
153   // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
154   e->accept();
155
156   //QGraphicsScene::wheelEvent( e ); // don't uncomment
157 }
158
159 //================================================================
160 // Function : contextMenuEvent
161 // Purpose  : 
162 //================================================================
163 void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
164 {
165   emit gsContextMenuEvent( e );
166   QGraphicsScene::contextMenuEvent( e );
167 }
168
169 //================================================================
170 // Function : dragEnterEvent
171 // Purpose  : 
172 //================================================================
173 void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* e )
174 {
175   //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
176 }
177
178 //================================================================
179 // Function : dragLeaveEvent
180 // Purpose  : 
181 //================================================================
182 void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* e )
183 {
184   //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
185 }
186
187 //================================================================
188 // Function : dragMoveEvent
189 // Purpose  : 
190 //================================================================
191 void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* e )
192 {
193   //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
194 }
195
196 //================================================================
197 // Function : dropEvent
198 // Purpose  : 
199 //================================================================
200 void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* e )
201 {
202   //QGraphicsScene::dropEvent( e ); // don't uncomment
203 }