Salome HOME
Copyrights update 2015.
[modules/yacs.git] / src / genericgui / Scene.cxx
1 // Copyright (C) 2006-2015  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, 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 "Scene.hxx"
21 #include "SceneItem.hxx"
22 #include "SceneTextItem.hxx"
23 #include "QtGuiContext.hxx"
24
25 #include <QGraphicsSceneMouseEvent>
26 #include <QToolTip>
27
28 #include <cassert>
29 #include <cmath>
30
31 //#define _DEVDEBUG_
32 #include "YacsTrace.hxx"
33
34 using namespace std;
35 using namespace YACS::HMI;
36
37 bool Scene::_straightLinks = false;
38 bool Scene::_autoComputeLinks = true;
39 bool Scene::_simplifyLinks = true;
40 bool Scene::_force2NodesLink = true;
41 bool Scene::_addRowCols = true;
42
43 Scene::Scene(QObject *parent): QGraphicsScene(parent)
44 {
45   _zooming = false;
46 }
47
48 Scene::~Scene()
49 {
50 }
51
52 /*! to notify scene when mouse actions must not be used for selection
53  *  or node displacement, typically when mouse is used to adjust the view,
54  *  like zoom or recenter of the view.
55  */
56 void Scene::setZoom(bool zooming)
57 {
58   _zooming = zooming;
59 }
60
61 /*! check if mouse move event can be used for selection or node
62  *  displacement. @see setZoom()
63  */
64 bool Scene::isZooming()
65 {
66   return _zooming;
67 }
68  
69 void Scene::helpEvent(QGraphicsSceneHelpEvent *event)
70 {
71   DEBTRACE("Scene::helpEvent");
72   QGraphicsItem *qit = itemAt(event->scenePos());
73   SceneItem * item = dynamic_cast<SceneItem*>(qit);
74   if (item)
75     {
76       QToolTip::showText(event->screenPos(), item->getToolTip());
77       return;
78     }
79   SceneTextItem * itemt = dynamic_cast<SceneTextItem*>(qit);
80   if (itemt)
81     {
82       QToolTip::showText(event->screenPos(), itemt->getToolTip());
83       return;
84     }
85   QToolTip::hideText();
86 }
87
88 void Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
89 {
90   //DEBTRACE("Scene::mousePressEvent");
91   QGraphicsScene::mousePressEvent(mouseEvent);
92   QGraphicsItem *qit  = mouseGrabberItem();
93   if (qit)
94     {
95       //DEBTRACE(qit);
96       SceneItem *item = dynamic_cast<SceneItem*>(qit);
97       if (item)
98         DEBTRACE("mouseGrabberItem " <<item->handlesChildEvents()
99                  << " " << item->getLabel().toStdString());
100     }
101 //   QList<QGraphicsItem*> selItems = items(mouseEvent->scenePos());
102 }
103
104 void Scene::mouseReleaseEvent(QGraphicsSceneMouseEvent* mouseEvent)
105 {
106   _zooming = false;
107   QGraphicsScene::mouseReleaseEvent(mouseEvent);
108 }
109
110 void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* mouseEvent)
111 {
112   //QGraphicsScene::mouseMoveEvent(mouseEvent);
113   QGraphicsScene::mouseMoveEvent(mouseEvent);
114    
115 }