1 // Copyright (C) 2013-2022 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, 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_Scene.h"
22 #include <QGraphicsLineItem>
23 #include <QGraphicsRectItem>
24 #include <QGraphicsSceneWheelEvent>
26 //#define VIEWER_DEBUG
28 //=======================================================================
29 // Name : GraphicsView_Scene
30 // Purpose : Constructor
31 //=======================================================================
32 GraphicsView_Scene::GraphicsView_Scene( QObject* theParent )
33 : QGraphicsScene( theParent )
36 mySceneRectItem = new QGraphicsRectItem();
37 mySceneRectItem->setPen( QPen( Qt::red, 0.0 ) );
39 addItem( mySceneRectItem );
41 connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ),
42 this, SLOT( onSceneRectChanged( const QRectF& ) ) );
44 setSceneRect( -2000, -2000, 4000, 4000 );
46 QGraphicsLineItem* aHorLineItem = new QGraphicsLineItem( -2000, 0, 2000, 0 );
47 aHorLineItem->setPen( QPen( Qt::red ) );
48 addItem( aHorLineItem );
50 QGraphicsLineItem* aVerLineItem = new QGraphicsLineItem( 0, -2000, 0, 2000 );
51 aVerLineItem->setPen( QPen( Qt::red ) );
52 addItem( aVerLineItem );
56 //=======================================================================
57 // Name : GraphicsView_Scene
58 // Purpose : Destructor
59 //=======================================================================
60 GraphicsView_Scene::~GraphicsView_Scene()
64 //================================================================
65 // Function : processRectChanged
67 //================================================================
68 void GraphicsView_Scene::processRectChanged()
70 emit gsBoundingRectChanged();
73 //================================================================
74 // Function : onSceneRectChanged
76 //================================================================
77 void GraphicsView_Scene::onSceneRectChanged( const QRectF& theRect )
79 (void)theRect; // unused in debug mode
81 mySceneRectItem->setRect( theRect );
85 //================================================================
86 // Function : keyPressEvent
88 //================================================================
89 void GraphicsView_Scene::keyPressEvent( QKeyEvent* e )
92 QGraphicsScene::keyPressEvent( e );
95 //================================================================
96 // Function : keyReleaseEvent
98 //================================================================
99 void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e )
101 emit gsKeyEvent( e );
102 QGraphicsScene::keyReleaseEvent( e );
105 //================================================================
106 // Function : mousePressEvent
108 //================================================================
109 void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
111 emit gsMouseEvent( e );
112 QGraphicsScene::mousePressEvent( e );
115 //================================================================
116 // Function : mouseMoveEvent
118 //================================================================
119 void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
121 emit gsMouseEvent( e );
122 QGraphicsScene::mouseMoveEvent( e );
125 //================================================================
126 // Function : mouseReleaseEvent
128 //================================================================
129 void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
131 emit gsMouseEvent( e );
132 QGraphicsScene::mouseReleaseEvent( e );
135 //================================================================
136 // Function : mouseDoubleClickEvent
138 //================================================================
139 void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
141 emit gsMouseEvent( e );
142 QGraphicsScene::mouseDoubleClickEvent( e );
145 //================================================================
146 // Function : wheelEvent
148 //================================================================
149 void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
151 emit gsWheelEvent( e );
153 // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
154 // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
157 //QGraphicsScene::wheelEvent( e ); // don't uncomment
160 //================================================================
161 // Function : contextMenuEvent
163 //================================================================
164 void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
166 emit gsContextMenuEvent( e );
167 QGraphicsScene::contextMenuEvent( e );
170 //================================================================
171 // Function : dragEnterEvent
173 //================================================================
174 void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
176 //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
179 //================================================================
180 // Function : dragLeaveEvent
182 //================================================================
183 void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
185 //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
188 //================================================================
189 // Function : dragMoveEvent
191 //================================================================
192 void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
194 //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
197 //================================================================
198 // Function : dropEvent
200 //================================================================
201 void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* /*e*/ ) //!< TODO: unused variable
203 //QGraphicsScene::dropEvent( e ); // don't uncomment