1 // Copyright (C) 2006-2008 CEA/DEN, EDF R&D
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.
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
19 #include "GraphicsView.hxx"
20 #include "SchemaModel.hxx"
21 #include "SceneItem.hxx"
23 #include "QtGuiContext.hxx"
27 #include <QGraphicsView>
30 #include "YacsTrace.hxx"
33 using namespace YACS::HMI;
35 GraphicsView::GraphicsView(QWidget *parent)
36 : WrapGraphicsView(parent)
41 setTransformationAnchor(QGraphicsView::AnchorViewCenter);
44 GraphicsView::~GraphicsView()
48 void GraphicsView::onViewFitAll()
50 DEBTRACE("GraphicsView::onViewFitAll");
51 SubjectProc *sProc = QtGuiContext::getQtCurrent()->getSubjectProc();
52 SceneItem *item = QtGuiContext::getQtCurrent()->_mapOfSceneItem[sProc];
53 //SceneProcItem *procItem = dynamic_cast<SceneProcItem*>(item);
54 fitInView(item->boundingRect(), Qt::KeepAspectRatio);
57 void GraphicsView::onViewFitArea()
59 DEBTRACE("GraphicsView::onViewFitArea");
60 Scene* myScene = dynamic_cast<Scene*>(scene());
61 myScene->setZoom(true);
65 void GraphicsView::onViewZoom()
67 DEBTRACE("GraphicsView::onViewZoom");
68 Scene* myScene = dynamic_cast<Scene*>(scene());
69 myScene->setZoom(true);
74 void GraphicsView::onViewPan()
76 DEBTRACE("GraphicsView::onViewPan");
77 Scene* myScene = dynamic_cast<Scene*>(scene());
78 myScene->setZoom(true);
80 //setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
81 setTransformationAnchor(QGraphicsView::NoAnchor);
84 void GraphicsView::onViewGlobalPan()
86 DEBTRACE("GraphicsView::onViewGlobalPan");
89 void GraphicsView::onViewReset()
91 DEBTRACE("GraphicsView::onViewReset");
96 void GraphicsView::contextMenuEvent(QContextMenuEvent *event)
98 QGraphicsItem *qgitem = itemAt(event->pos());
101 AbstractSceneItem *item = dynamic_cast<AbstractSceneItem*>(qgitem);
103 item->popupMenu(this, event->globalPos());
107 void GraphicsView::mouseMoveEvent(QMouseEvent *e)
109 WrapGraphicsView::mouseMoveEvent(e);
110 if (e->buttons()==Qt::LeftButton)
114 qreal currentX = e->globalX();
115 qreal delta = currentX - _prevX;
117 // if (delta < -30) delta = -30;
118 // if (delta > 30) delta = 30;
119 double deltax = delta/900.;
120 double zoom = exp(deltax);
121 _scale = _scale*zoom;
123 //DEBTRACE("move zooming " << delta << " " << deltax << " " << zoom);
127 QPoint current = e->pos();
128 translate(current.x() - _prevPos.x(), current.y() - _prevPos.y());
129 //DEBTRACE(current.x()<<"-"<<_prevPos.x()<<" "<<current.y()<<"-"<<_prevPos.y());
135 void GraphicsView::mousePressEvent(QMouseEvent *e)
137 WrapGraphicsView::mousePressEvent(e);
140 _prevX = e->globalX();
142 else if (_fittingArea)
149 //setDragMode(QGraphicsView::ScrollHandDrag);
153 void GraphicsView::mouseReleaseEvent(QMouseEvent *e)
157 setDragMode(QGraphicsView::NoDrag);
158 setTransformationAnchor(QGraphicsView::AnchorViewCenter);
161 _fittingArea = false;
162 QPoint current = e->pos();
163 fitInView(QRect(_prevPos, current), Qt::KeepAspectRatio);
166 QTransform q = transform();
167 DEBTRACE(q.m11()<<" "<<q.m12()<<" "<<q.m21()<<" "<<q.m22()<<" "<<q.dx()<<" "<<q.dy());
168 WrapGraphicsView::mouseReleaseEvent(e);