1 // Copyright (C) 2013-2015 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 )
80 mySceneRectItem->setRect( theRect );
84 //================================================================
85 // Function : keyPressEvent
87 //================================================================
88 void GraphicsView_Scene::keyPressEvent( QKeyEvent* e )
91 QGraphicsScene::keyPressEvent( e );
94 //================================================================
95 // Function : keyReleaseEvent
97 //================================================================
98 void GraphicsView_Scene::keyReleaseEvent( QKeyEvent* e )
100 emit gsKeyEvent( e );
101 QGraphicsScene::keyReleaseEvent( e );
104 //================================================================
105 // Function : mousePressEvent
107 //================================================================
108 void GraphicsView_Scene::mousePressEvent( QGraphicsSceneMouseEvent* e )
110 emit gsMouseEvent( e );
111 QGraphicsScene::mousePressEvent( e );
114 //================================================================
115 // Function : mouseMoveEvent
117 //================================================================
118 void GraphicsView_Scene::mouseMoveEvent( QGraphicsSceneMouseEvent* e )
120 emit gsMouseEvent( e );
121 QGraphicsScene::mouseMoveEvent( e );
124 //================================================================
125 // Function : mouseReleaseEvent
127 //================================================================
128 void GraphicsView_Scene::mouseReleaseEvent( QGraphicsSceneMouseEvent* e )
130 emit gsMouseEvent( e );
131 QGraphicsScene::mouseReleaseEvent( e );
134 //================================================================
135 // Function : mouseDoubleClickEvent
137 //================================================================
138 void GraphicsView_Scene::mouseDoubleClickEvent( QGraphicsSceneMouseEvent* e )
140 emit gsMouseEvent( e );
141 QGraphicsScene::mouseDoubleClickEvent( e );
144 //================================================================
145 // Function : wheelEvent
147 //================================================================
148 void GraphicsView_Scene::wheelEvent( QGraphicsSceneWheelEvent* e )
150 emit gsWheelEvent( e );
152 // accept the event to prevent calling QAbstractScrollArea::wheelEvent()
153 // from QGraphicsView::wheelEvent(), which will change values of scroll-bars
156 //QGraphicsScene::wheelEvent( e ); // don't uncomment
159 //================================================================
160 // Function : contextMenuEvent
162 //================================================================
163 void GraphicsView_Scene::contextMenuEvent( QGraphicsSceneContextMenuEvent* e )
165 emit gsContextMenuEvent( e );
166 QGraphicsScene::contextMenuEvent( e );
169 //================================================================
170 // Function : dragEnterEvent
172 //================================================================
173 void GraphicsView_Scene::dragEnterEvent( QGraphicsSceneDragDropEvent* e )
175 //QGraphicsScene::dragEnterEvent( e ); // don't uncomment
178 //================================================================
179 // Function : dragLeaveEvent
181 //================================================================
182 void GraphicsView_Scene::dragLeaveEvent( QGraphicsSceneDragDropEvent* e )
184 //QGraphicsScene::dragLeaveEvent( e ); // don't uncomment
187 //================================================================
188 // Function : dragMoveEvent
190 //================================================================
191 void GraphicsView_Scene::dragMoveEvent( QGraphicsSceneDragDropEvent* e )
193 //QGraphicsScene::dragMoveEvent( e ); // don't uncomment
196 //================================================================
197 // Function : dropEvent
199 //================================================================
200 void GraphicsView_Scene::dropEvent( QGraphicsSceneDragDropEvent* e )
202 //QGraphicsScene::dropEvent( e ); // don't uncomment