Version: 8.3.0
YACS::HMI::GraphicsView Class Reference

#include <GraphicsView.hxx>

Inheritance diagram for YACS::HMI::GraphicsView:
Collaboration diagram for YACS::HMI::GraphicsView:

Public Slots

virtual void onViewFitAll ()
 
virtual void onViewFitArea ()
 
virtual void onViewZoom ()
 
virtual void onViewPan ()
 
virtual void onViewGlobalPan ()
 
virtual void onViewReset ()
 
virtual void onZoomToBloc ()
 
virtual void onCenterOnNode ()
 
- Public Slots inherited from YACS::HMI::WrapGraphicsView
virtual void onViewFitAll ()
 
virtual void onViewFitArea ()
 
virtual void onViewZoom ()
 
virtual void onViewPan ()
 
virtual void onViewGlobalPan ()
 
virtual void onViewReset ()
 

Public Member Functions

 GraphicsView (QWidget *parent=0)
 
virtual ~GraphicsView ()
 
- Public Member Functions inherited from YACS::HMI::WrapGraphicsView
 WrapGraphicsView (QWidget *parent=0)
 
virtual ~WrapGraphicsView ()
 

Protected Member Functions

void contextMenuEvent (QContextMenuEvent *event)
 
void mouseMoveEvent (QMouseEvent *e)
 
void mousePressEvent (QMouseEvent *e)
 
void mouseReleaseEvent (QMouseEvent *e)
 
virtual void wheelEvent (QWheelEvent *e)
 

Protected Attributes

bool _zooming
 
bool _fittingArea
 
bool _panning
 
int _prevX
 
int _prevY
 
qreal _scale
 
QPoint _prevPos
 
QGraphicsRectItem * _rect
 

Detailed Description

Definition at line 33 of file GraphicsView.hxx.

Constructor & Destructor Documentation

GraphicsView::GraphicsView ( QWidget parent = 0)

Definition at line 41 of file GraphicsView.cxx.

References _fittingArea, _panning, _rect, and _zooming.

42  : WrapGraphicsView(parent)
43 {
44  _zooming = false;
45  _fittingArea = false;
46  _panning = false;
47  _rect = 0;
48  setTransformationAnchor(QGraphicsView::AnchorViewCenter);
49 }
GraphicsView::~GraphicsView ( )
virtual

Definition at line 51 of file GraphicsView.cxx.

52 {
53 }

Member Function Documentation

void GraphicsView::contextMenuEvent ( QContextMenuEvent *  event)
protected

Definition at line 103 of file GraphicsView.cxx.

References YACS::HMI::SceneTextItem::popupMenu(), YACS::HMI::SceneItem::popupMenu(), YACS::HMI::SceneTextItem::setEventPos(), and YACS::HMI::SceneItem::setEventPos().

104 {
105  QGraphicsItem *qgitem = itemAt(event->pos());
106  if (qgitem)
107  {
108  SceneItem *item = dynamic_cast<SceneItem*>(qgitem);
109  if (item)
110  {
111  QPointF point = mapToScene(event->pos());
112  item->setEventPos(point);
113  item->popupMenu(this, event->globalPos());
114  }
115  else
116  {
117  SceneTextItem *item = dynamic_cast<SceneTextItem*>(qgitem);
118  if (item)
119  {
120  QPointF point = mapToScene(event->pos());
121  item->setEventPos(point);
122  item->popupMenu(this, event->globalPos());
123  }
124  }
125  }
126 }
void GraphicsView::mouseMoveEvent ( QMouseEvent *  e)
protected

Definition at line 128 of file GraphicsView.cxx.

References _fittingArea, _panning, _prevPos, _prevX, _prevY, _rect, _scale, and _zooming.

129 {
130  WrapGraphicsView::mouseMoveEvent(e);
131  if (e->buttons()==Qt::LeftButton)
132  {
133  QPoint current = e->pos();
134  if (_zooming)
135  {
136  qreal currentX = e->globalX();
137  qreal currentY = e->globalY();
138  qreal delta = sqrt((currentX - _prevX)*(currentX - _prevX) + (currentY - _prevY)*(currentY - _prevY));
139  if ((currentX*currentX + currentY*currentY) < (_prevX*_prevX + _prevY*_prevY))
140  delta = -delta;
141  _prevX = currentX;
142  _prevY = currentY;
143  // if (delta < -30) delta = -30;
144  // if (delta > 30) delta = 30;
145  double deltax = delta/900.;
146  double zoom = exp(deltax);
147  _scale = _scale*zoom;
148  scale(zoom,zoom);
149  //DEBTRACE("move zooming " << delta << " " << deltax << " " << zoom);
150  }
151  else if (_panning)
152  {
153  translate(current.x() - _prevPos.x(), current.y() - _prevPos.y());
154  //DEBTRACE(current.x()<<"-"<<_prevPos.x()<<" "<<current.y()<<"-"<<_prevPos.y());
155  _prevPos = current;
156  }
157  else if (_fittingArea)
158  {
159  if (!_rect)
160  {
161  _rect = scene()->addRect(QGraphicsView::mapToScene(QRect(_prevPos, current)).boundingRect());
162  _rect->setZValue(100000);
163  _rect->setParentItem(0);
164  }
165  else
166  {
167  _rect->setRect(QGraphicsView::mapToScene(QRect(_prevPos, current)).boundingRect());
168  _rect->show();
169  }
170  }
171  }
172 }
void GraphicsView::mousePressEvent ( QMouseEvent *  e)
protected

Definition at line 174 of file GraphicsView.cxx.

References _fittingArea, _panning, _prevPos, _prevX, _prevY, _zooming, DEBTRACE, YACS::HMI::QtGuiContext::getGMain(), YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::GenericGui::switchContext().

175 {
176  DEBTRACE("GraphicsView::mousePressEvent");
177  if (QtGuiContext::getQtCurrent()->getView() != this)
178  {
179  DEBTRACE("Switch context before selection");
180  QtGuiContext::getQtCurrent()->getGMain()->switchContext(this->parentWidget());
181  }
182  WrapGraphicsView::mousePressEvent(e);
183  if (_zooming)
184  {
185  _prevX = e->globalX();
186  _prevY = e->globalY();
187  }
188  else if (_fittingArea)
189  {
190  _prevPos = e->pos();
191  }
192  else if (_panning)
193  {
194  _prevPos = e->pos();
195  //setDragMode(QGraphicsView::ScrollHandDrag);
196  }
197 }
void GraphicsView::mouseReleaseEvent ( QMouseEvent *  e)
protected

Definition at line 199 of file GraphicsView.cxx.

References _fittingArea, _panning, _prevPos, _rect, _zooming, and DEBTRACE.

200 {
201  _zooming = false;
202  _panning = false;
203  setDragMode(QGraphicsView::NoDrag);
204  setTransformationAnchor(QGraphicsView::AnchorViewCenter);
205  if( _fittingArea)
206  {
207  _fittingArea = false;
208  QPoint current = e->pos();
209  fitInView(QGraphicsView::mapToScene(QRect(_prevPos, current)).boundingRect(), Qt::KeepAspectRatio);
210  if (_rect)
211  _rect->hide();
212  }
213 
214  QTransform q = transform();
215  DEBTRACE(q.m11()<<" "<<q.m12()<<" "<<q.m21()<<" "<<q.m22()<<" "<<q.dx()<<" "<<q.dy());
216  WrapGraphicsView::mouseReleaseEvent(e);
217 }
void GraphicsView::onCenterOnNode ( )
virtualslot

Definition at line 244 of file GraphicsView.cxx.

References YACS::HMI::QtGuiContext::_mapOfSceneItem, YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::QtGuiContext::getSelectedSubject().

245 {
247  SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
248  if (!snode)
249  return;
251  centerOn(item);
252 }
void GraphicsView::onViewFitAll ( )
virtualslot

Definition at line 55 of file GraphicsView.cxx.

References YACS::HMI::QtGuiContext::_mapOfSceneItem, YACS::HMI::SceneItem::boundingRect(), DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::GuiContext::getSubjectProc().

56 {
57  DEBTRACE("GraphicsView::onViewFitAll");
60  //SceneProcItem *procItem = dynamic_cast<SceneProcItem*>(item);
61  fitInView(item->boundingRect(), Qt::KeepAspectRatio);
62 }
void GraphicsView::onViewFitArea ( )
virtualslot

Definition at line 64 of file GraphicsView.cxx.

References _fittingArea, DEBTRACE, and YACS::HMI::Scene::setZoom().

65 {
66  DEBTRACE("GraphicsView::onViewFitArea");
67  Scene* myScene = dynamic_cast<Scene*>(scene());
68  myScene->setZoom(true);
69  _fittingArea = true;
70 }
void GraphicsView::onViewGlobalPan ( )
virtualslot

Definition at line 91 of file GraphicsView.cxx.

References DEBTRACE.

92 {
93  DEBTRACE("GraphicsView::onViewGlobalPan");
94 }
void GraphicsView::onViewPan ( )
virtualslot

Definition at line 81 of file GraphicsView.cxx.

References _panning, DEBTRACE, and YACS::HMI::Scene::setZoom().

82 {
83  DEBTRACE("GraphicsView::onViewPan");
84  Scene* myScene = dynamic_cast<Scene*>(scene());
85  myScene->setZoom(true);
86  _panning = true;
87  //setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
88  setTransformationAnchor(QGraphicsView::NoAnchor);
89 }
void GraphicsView::onViewReset ( )
virtualslot

Definition at line 96 of file GraphicsView.cxx.

References DEBTRACE.

97 {
98  DEBTRACE("GraphicsView::onViewReset");
99  resetTransform();
100 }
void GraphicsView::onViewZoom ( )
virtualslot

Definition at line 72 of file GraphicsView.cxx.

References _scale, _zooming, DEBTRACE, and YACS::HMI::Scene::setZoom().

73 {
74  DEBTRACE("GraphicsView::onViewZoom");
75  Scene* myScene = dynamic_cast<Scene*>(scene());
76  myScene->setZoom(true);
77  _zooming =true;
78  _scale = 1;
79 }
void GraphicsView::onZoomToBloc ( )
virtualslot

Definition at line 228 of file GraphicsView.cxx.

References YACS::HMI::QtGuiContext::_mapOfSceneItem, YACS::HMI::SceneItem::boundingRect(), YACS::HMI::Subject::getParent(), YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::getSelectedSubject(), and YASSERT.

229 {
231  SubjectNode *snode = dynamic_cast<SubjectNode*>(sub);
232  if (!snode)
233  return;
234  SubjectComposedNode *scnode = dynamic_cast<SubjectComposedNode*>(sub);
235  if (!scnode)
236  scnode = dynamic_cast<SubjectComposedNode*>(snode->getParent());
237  YASSERT(scnode);
239  YASSERT(item);
240  QRectF rect = item->mapToScene(item->boundingRect().toRect()).boundingRect();
241  fitInView(rect.toRect(), Qt::KeepAspectRatio);
242 }
void GraphicsView::wheelEvent ( QWheelEvent *  e)
protectedvirtual

Definition at line 219 of file GraphicsView.cxx.

References _scale, and DEBTRACE.

220 {
221  DEBTRACE("GraphicsView::wheelEvent " << e->delta());
222  double zoom = exp(0.1*e->delta()/120);
223  _scale = _scale*zoom;
224  setTransformationAnchor(QGraphicsView::AnchorUnderMouse);
225  scale(zoom,zoom);
226 }

Member Data Documentation

bool YACS::HMI::GraphicsView::_fittingArea
protected
bool YACS::HMI::GraphicsView::_panning
protected
QPoint YACS::HMI::GraphicsView::_prevPos
protected

Definition at line 65 of file GraphicsView.hxx.

Referenced by mouseMoveEvent(), mousePressEvent(), and mouseReleaseEvent().

int YACS::HMI::GraphicsView::_prevX
protected

Definition at line 62 of file GraphicsView.hxx.

Referenced by mouseMoveEvent(), and mousePressEvent().

int YACS::HMI::GraphicsView::_prevY
protected

Definition at line 63 of file GraphicsView.hxx.

Referenced by mouseMoveEvent(), and mousePressEvent().

QGraphicsRectItem* YACS::HMI::GraphicsView::_rect
protected

Definition at line 66 of file GraphicsView.hxx.

Referenced by GraphicsView(), mouseMoveEvent(), and mouseReleaseEvent().

qreal YACS::HMI::GraphicsView::_scale
protected

Definition at line 64 of file GraphicsView.hxx.

Referenced by mouseMoveEvent(), onViewZoom(), and wheelEvent().

bool YACS::HMI::GraphicsView::_zooming
protected

The documentation for this class was generated from the following files: