Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / Scene.cxx
1 //  Copyright (C) 2006-2008  CEA/DEN, EDF R&D
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 #include "Scene.hxx"
20 #include "SceneItem.hxx"
21 #include "QtGuiContext.hxx"
22
23 #include <QGraphicsSceneMouseEvent>
24
25 #include <cassert>
26 #include <cmath>
27
28 //#define _DEVDEBUG_
29 #include "YacsTrace.hxx"
30
31 using namespace std;
32 using namespace YACS::HMI;
33
34 bool Scene::_autoComputeLinks = true;
35 bool Scene::_simplifyLinks = true;
36 bool Scene::_force2NodesLink = true;
37
38 Scene::Scene(QObject *parent): QGraphicsScene(parent)
39 {
40   _zooming = false;
41 }
42
43 Scene::~Scene()
44 {
45 }
46
47 /*! to notify scene when mouse actions must not be used for selection
48  *  or node displacement, typically when mouse is used to adjust the view,
49  *  like zoom or recenter of the view.
50  */
51 void Scene::setZoom(bool zooming)
52 {
53   _zooming = zooming;
54 }
55
56 /*! check if mouse move event can be used for selection or node
57  *  displacement. @see setZoom()
58  */
59 bool Scene::isZooming()
60 {
61   return _zooming;
62 }
63
64 void Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
65 {
66   //DEBTRACE("Scene::mousePressEvent");
67   QGraphicsScene::mousePressEvent(mouseEvent);
68   QGraphicsItem *qit  = mouseGrabberItem();
69   if (qit)
70     {
71       //DEBTRACE(qit);
72       SceneItem *item = dynamic_cast<SceneItem*>(qit);
73       if (item)
74         DEBTRACE("mouseGrabberItem " <<item->handlesChildEvents()
75                  << " " << item->getLabel().toStdString());
76     }
77 //   QList<QGraphicsItem*> selItems = items(mouseEvent->scenePos());
78 }
79
80 void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)
81 {
82   _zooming = false;
83   QGraphicsScene::mouseReleaseEvent(mouseEvent);
84 }
85
86 void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent)
87 {
88   //QGraphicsScene::mouseMoveEvent(mouseEvent);
89   QGraphicsScene::mouseMoveEvent(mouseEvent);
90    
91 }