Salome HOME
Updated copyright comment
[modules/gui.git] / src / GraphicsView / GraphicsView_Scene.cxx
1 // Copyright (C) 2013-2024  CEA, EDF, 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   (void)theRect; // unused in debug mode
80 #ifdef VIEWER_DEBUG
81   mySceneRectItem->setRect( theRect );
82 #endif
83 }
84
85 //================================================================
86 // Function : keyPressEvent
87 // Purpose  : 
88 //================================================================
89 void GraphicsView_Scene::keyPressEvent( QKeyEvent* e )
90 {
91   emit gsKeyEvent( e );
92   QGraphicsScene::keyPressEvent( e );
93 }
94
95 //================================================================
96 // Function : keyReleaseEvent
97 // Purpose  : 
98 //================================================================
99 void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e )
100 {
101   emit gsKeyEvent( e );
102   QGraphicsScene::keyReleaseEvent( e );
103 }
104
105 //================================================================
106 // Function : mousePressEvent
107 // Purpose  : 
108 //================================================================
109 void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
110 {
111   emit gsMouseEvent( e );
112   QGraphicsScene::mousePressEvent( e );
113 }
114
115 //================================================================
116 // Function : mouseMoveEvent
117 // Purpose  : 
118 //================================================================
119 void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
120 {
121   emit gsMouseEvent( e );
122   QGraphicsScene::mouseMoveEvent( e );
123 }
124
125 //================================================================
126 // Function : mouseReleaseEvent
127 // Purpose  : 
128 //================================================================
129 void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
130 {
131   emit gsMouseEvent( e );
132   QGraphicsScene::mouseReleaseEvent( e );
133 }
134
135 //================================================================
136 // Function : mouseDoubleClickEvent
137 // Purpose  : 
138 //================================================================
139 void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
140 {
141   emit gsMouseEvent( e );
142   QGraphicsScene::mouseDoubleClickEvent( e );
143 }
144
145 //================================================================
146 // Function : wheelEvent
147 // Purpose  : 
148 //================================================================
149 void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
150 {
151   emit gsWheelEvent( e );
152
153   // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
154   // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
155   e->accept();
156
157   //QGraphicsScene::wheelEvent( e ); // don't uncomment
158 }
159
160 //================================================================
161 // Function : contextMenuEvent
162 // Purpose  : 
163 //================================================================
164 void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
165 {
166   emit gsContextMenuEvent( e );
167   QGraphicsScene::contextMenuEvent( e );
168 }
169
170 //================================================================
171 // Function : dragEnterEvent
172 // Purpose  : 
173 //================================================================
174 void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
175 {
176   //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
177 }
178
179 //================================================================
180 // Function : dragLeaveEvent
181 // Purpose  : 
182 //================================================================
183 void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
184 {
185   //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
186 }
187
188 //================================================================
189 // Function : dragMoveEvent
190 // Purpose  : 
191 //================================================================
192 void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
193 {
194   //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
195 }
196
197 //================================================================
198 // Function : dropEvent
199 // Purpose  : 
200 //================================================================
201 void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
202 {
203   //QGraphicsScene::dropEvent( e ); // don't uncomment
204 }