Version: 8.3.0
YACS::HMI::SceneItem Class Reference

#include <SceneItem.hxx>

Inheritance diagram for YACS::HMI::SceneItem:
Collaboration diagram for YACS::HMI::SceneItem:

Public Member Functions

 SceneItem (QGraphicsScene *scene, SceneItem *parent, QString label)
 
virtual ~SceneItem ()
 
virtual QRectF boundingRect () const
 
virtual QRectF childrenBoundingRect () const
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
 
virtual void setTopLeft (QPointF topLeft)
 
virtual void checkGeometryChange ()
 
virtual void popupMenu (QWidget *caller, const QPoint &globalPos)
 
void setParent (SceneItem *parent)
 
virtual QString getToolTip ()
 
void setEventPos (QPointF point)
 
virtual void updateChildItems ()
 
virtual void updateLinks ()
 
virtual void shrinkExpandLink (bool se)
 
virtual void shrinkExpandRecursive (bool isExpanding, bool fromHere, ShrinkMode theShrinkMode)
 
bool isAncestorShrinked ()
 
- Public Member Functions inherited from YACS::HMI::AbstractSceneItem
 AbstractSceneItem (QGraphicsScene *scene, SceneItem *parent, QString label)
 
virtual ~AbstractSceneItem ()
 
int getLevel ()
 
void setLevel ()
 
virtual void reorganize ()
 
virtual QString getLabel ()
 
virtual void addHeader ()
 
virtual void addProgressItem ()
 
virtual qreal getHeaderBottom ()
 
qreal getWidth ()
 
qreal getHeight ()
 
virtual void setWidth (qreal width)
 AbstractSceneItem cannot be resized (only ComposedNodeItem can) More...
 
virtual void setHeight (qreal height)
 AbstractSceneItem cannot be resized (only ComposedNodeItem can) More...
 
virtual void activateSelection (bool selected)
 
virtual void setGeometryOptimization (bool optimize)
 
SceneItemgetParent ()
 

Public Attributes

bool _blocX
 
bool _blocY
 

Protected Member Functions

virtual void mousePressEvent (QGraphicsSceneMouseEvent *event)
 
virtual void hoverEnterEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverMoveEvent (QGraphicsSceneHoverEvent *event)
 
virtual void hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
 
virtual QColor getPenColor ()
 
virtual QColor getBrushColor ()
 
QColor hoverColor (QColor origColor)
 
- Protected Member Functions inherited from YACS::HMI::AbstractSceneItem
virtual QRectF childBoundingRect (AbstractSceneItem *child) const
 

Protected Attributes

bool _hover
 
bool _ancestorShrinked
 
QPointF _eventPos
 
- Protected Attributes inherited from YACS::HMI::AbstractSceneItem
SceneItem_parent
 
YACS::HMI::Scene_scene
 
QString _label
 
int _level
 
qreal _width
 
qreal _height
 
qreal _incHeight
 
QColor _penColor
 
QColor _brushColor
 
QColor _hiPenColor
 
QColor _hiBrushColor
 
bool _hasHeader
 
bool _optimize
 
bool _dragable
 
enum Qt::MouseButton _dragButton
 

Detailed Description

Generic class for 2D graphics item, inherits QGraphicsItem, specialised in 2 kind of classes, with or without inheritance from GuiObserver.

Definition at line 120 of file SceneItem.hxx.

Constructor & Destructor Documentation

SceneItem::SceneItem ( QGraphicsScene scene,
SceneItem parent,
QString  label 
)

Definition at line 191 of file SceneItem.cxx.

References _ancestorShrinked, _hover, YACS::HMI::AbstractSceneItem::_label, YACS::HMI::AbstractSceneItem::_level, YACS::HMI::AbstractSceneItem::_parent, and DEBTRACE.

193  : QGraphicsItem(parent), AbstractSceneItem(scene, parent, label)
194 {
195  _hover = false;
196  _ancestorShrinked = false;
197  setToolTip(_label);
198  DEBTRACE("SceneItem::SceneItem "<<label.toStdString()<<" "<<this<<" "<<_parent<<" "<< _level);
199  setFlag(QGraphicsItem::ItemIsSelectable);
200  setAcceptHoverEvents(true);
201 }
SceneItem::~SceneItem ( )
virtual

Definition at line 203 of file SceneItem.cxx.

204 {
205 }

Member Function Documentation

QRectF SceneItem::boundingRect ( ) const
virtual

Implements YACS::HMI::AbstractSceneItem.

Reimplemented in YACS::HMI::SceneLinkItem.

Definition at line 215 of file SceneItem.cxx.

References YACS::HMI::AbstractSceneItem::_height, and YACS::HMI::AbstractSceneItem::_width.

Referenced by YACS::HMI::SceneBlocItem::arrangeCanvasNodes(), YACS::HMI::SceneComposedNodeItem::autoPosNewChild(), YACS::HMI::LinkMatrix::cellFrom(), YACS::HMI::LinkMatrix::cellTo(), YACS::HMI::SceneComposedNodeItem::collisionResolv(), YACS::HMI::LinkMatrix::getBoundingBox(), YACS::HMI::GraphicsView::onViewFitAll(), and YACS::HMI::GraphicsView::onZoomToBloc().

216 {
217 // DEBTRACE("SceneItem::boundingRect " <<_label.toStdString()
218 // <<" "<<_width<<" "<< _height);
219  qreal penWidth = 1;
220  return QRectF(- penWidth/2, - penWidth/2,
221  _width + penWidth/2, _height + penWidth/2);
222 }
void SceneItem::checkGeometryChange ( )
virtual

Implements YACS::HMI::AbstractSceneItem.

Definition at line 248 of file SceneItem.cxx.

References YACS::HMI::AbstractSceneItem::_height, YACS::HMI::AbstractSceneItem::_incHeight, YACS::HMI::AbstractSceneItem::_label, YACS::HMI::AbstractSceneItem::_optimize, YACS::HMI::AbstractSceneItem::_parent, YACS::HMI::AbstractSceneItem::_width, YACS::HMI::SceneNodeItem::adjustHeader(), checkGeometryChange(), childrenBoundingRect(), DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::isLoadingPresentation(), YACS::HMI::SceneNodeItem::setExpandedWH(), and YACS::HMI::SceneNodeItem::updateLinks().

Referenced by YACS::HMI::SceneNodeItem::addHeader(), YACS::HMI::SceneNodeItem::addProgressItem(), YACS::HMI::SceneBlocItem::arrangeCanvasNodes(), checkGeometryChange(), YACS::HMI::GuiEditor::PutGraphInBloc(), YACS::HMI::SceneNodeItem::setTopLeft(), and setTopLeft().

249 {
250  DEBTRACE("SceneItem::checkGeometryChange: enter : " << _label.toStdString() << " width= " << _width << " height= " << _height);
251  qreal newWidth;
252  qreal newHeight;
253  bool resize = false;
254  SceneElementaryNodeItem* aElemNode = dynamic_cast<SceneElementaryNodeItem*>(this);
256  {
257  newWidth = _width;
258  newHeight = _height;
259  resize = true;
260  }
261  else
262  {
263  if (aElemNode)
264  {
265  newWidth = _width;
266  newHeight = _height;
267  resize = true;
268  DEBTRACE("elementaryNode resize true");
269  }
270  else
271  {
272  QRectF childrenBox = childrenBoundingRect();
273  newWidth = childrenBox.width();
274  newHeight = childrenBox.height();
275  DEBTRACE("composedNode newWidth= " << newWidth << " newHeight=" << newHeight);
276  }
277  }
278  bool wider = (newWidth > _width + 0.5);
279  qreal deltaW = 0;
280  bool higher = (newHeight > _height + 0.5);
281  qreal deltaH = 0;
282  bool changeWidth = (fabs(newWidth - _width) > 0.5);
283 
284  if (wider || (_optimize && (newWidth < _width)))
285  {
286  deltaW = newWidth - _width;
287  resize = true;
288  }
289  if (higher || (_optimize && (newHeight < _height)))
290  {
291  deltaH = newHeight - _height;
292  resize = true;
293  }
294  if (_incHeight >0) //when a port has been added in an elementaryNode, force the collision resolv
295  {
296  higher = true;
297  deltaH = _incHeight;
298  resize = true;
299  }
300  _incHeight = 0;
301  DEBTRACE("SceneItem::checkGeometryChange "<<_label.toStdString() <<
302  " " << wider << " " << higher << " " << changeWidth << " " << resize);
303 
304  if (resize)
305  {
306  prepareGeometryChange();
307  _width = newWidth;
308  _height = newHeight;
309  }
310  SceneNodeItem *aNode = dynamic_cast<SceneNodeItem*>(this);
311  if (aNode)
312  {
313  if (changeWidth) aNode->adjustHeader();
314  if (wider || higher)
315  {
316  QPointF oldPos(pos().x() - deltaW, pos().y() - deltaH);
317  if (SceneComposedNodeItem *bloc = dynamic_cast<SceneComposedNodeItem*>(_parent))
318  bloc->collisionResolv(aNode, oldPos);
319  }
320  if (changeWidth) aNode->updateLinks();
321  }
322  if (resize)
323  {
324  update();
325  if (_parent)
327  }
328  if(resize && aNode)
329  aNode->setExpandedWH();
330 }
QRectF SceneItem::childrenBoundingRect ( ) const
virtual

Reimplemented in YACS::HMI::SceneComposedNodeItem.

Definition at line 224 of file SceneItem.cxx.

Referenced by checkGeometryChange().

225 {
226  return QGraphicsItem::childrenBoundingRect();
227 }
QColor SceneItem::getBrushColor ( )
protectedvirtual
QString SceneItem::getToolTip ( )
virtual

generic behaviour for headers: obtain the tooltip from parent. Method to be redefined in derived classes.

Reimplemented in YACS::HMI::SceneProgressItem, and YACS::HMI::SceneObserverItem.

Definition at line 336 of file SceneItem.cxx.

References YACS::HMI::AbstractSceneItem::_label, YACS::HMI::AbstractSceneItem::getParent(), and getToolTip().

Referenced by YACS::HMI::SceneTextItem::getToolTip(), and getToolTip().

337 {
338  QString tooltip = _label;
339  SceneItem *parent = getParent();
340  if (parent)
341  tooltip = parent->getToolTip();
342  return tooltip;
343 }
QColor SceneItem::hoverColor ( QColor  origColor)
protected

Definition at line 372 of file SceneItem.cxx.

References gui.CONNECTOR::a, and gui.CONNECTOR::b.

Referenced by YACS::HMI::SceneInPortItem::getBrushColor(), YACS::HMI::SceneObserverItem::getBrushColor(), YACS::HMI::SceneHeaderItem::getBrushColor(), YACS::HMI::SceneProgressItem::getBrushColor(), YACS::HMI::SceneComposedNodeItem::getBrushColor(), and getBrushColor().

373 {
374  qreal r, g, b, a;
375  origColor.getRgbF(&r, &g, &b, &a);
376  r = 0.96*r;
377  g = 0.96*g;
378  b = 0.96*b;
379  return QColor::fromRgbF(r, g, b, a);
380 
381  // qreal h, s, v, a;
382  // origColor.getHsvF(&h, &s, &v, &a);
383  // s = 1.05*s;
384  // if (s>254.0) s=255.0;
385  // return QColor::fromHsvF(h, s, v, a);
386 }
void SceneItem::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

Definition at line 388 of file SceneItem.cxx.

References _hover.

389 {
390  _hover = true;
391  update();
392 }
void SceneItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

Definition at line 398 of file SceneItem.cxx.

References _hover.

399 {
400  _hover = false;
401  update();
402 }
void SceneItem::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

Definition at line 394 of file SceneItem.cxx.

395 {
396 }
bool YACS::HMI::SceneItem::isAncestorShrinked ( )
inline

Definition at line 142 of file SceneItem.hxx.

References _ancestorShrinked.

142 { return _ancestorShrinked; };
void SceneItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

When Zooming, filter all mouse events to items: do not work, scene do not receive...

Reimplemented in YACS::HMI::SceneNodeItem, YACS::HMI::SceneHeaderNodeItem, YACS::HMI::SceneCtrlPortItem, YACS::HMI::SceneProgressItem, YACS::HMI::SceneHeaderItem, and YACS::HMI::SceneObserverItem.

Definition at line 357 of file SceneItem.cxx.

References YACS::HMI::AbstractSceneItem::_label, YACS::HMI::AbstractSceneItem::_scene, YACS::HMI::AbstractSceneItem::activateSelection(), DEBTRACE, and YACS::HMI::Scene::isZooming().

358 {
359  DEBTRACE("SceneItem::mousePressEvent " << _label.toStdString()
360  << " " << acceptedMouseButtons () << " " << _scene->isZooming());
361  if (!_scene->isZooming()) activateSelection(true);
362 }
void SceneItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget widget 
)
virtual

Implements YACS::HMI::AbstractSceneItem.

Reimplemented in YACS::HMI::SceneLinkItem, YACS::HMI::SceneNodeItem, YACS::HMI::SceneCtrlPortItem, YACS::HMI::SceneHeaderNodeItem, YACS::HMI::SceneDataPortItem, YACS::HMI::SceneElementaryNodeItem, YACS::HMI::SceneHeaderItem, YACS::HMI::SceneProgressItem, and YACS::HMI::SceneComposedNodeItem.

Definition at line 229 of file SceneItem.cxx.

Referenced by YACS::HMI::SceneObserverItem::mouseMoveEvent().

232 {
233  //DEBTRACE("SceneItem::paint");
234 // painter->save();
235 // painter->setPen(getPenColor());
236 // painter->setBrush(getBrushColor());
237 // painter->drawRoundRect(QRectF(0, 0, _width, _height), 33*_height/_width, 33);
238 // painter->restore();
239 }
void SceneItem::setEventPos ( QPointF  point)

Definition at line 422 of file SceneItem.cxx.

References _eventPos, and YACS::HMI::AbstractSceneItem::getHeaderBottom().

Referenced by YACS::HMI::GraphicsView::contextMenuEvent(), and YACS::HMI::SceneComposedNodeItem::dropEvent().

423 {
424  QPointF localPoint = mapFromScene(point);
425  if (localPoint.y() <= getHeaderBottom())
426  localPoint.setY(getHeaderBottom()+1);
427  _eventPos = localPoint;
428 }
void SceneItem::setParent ( SceneItem parent)

Definition at line 207 of file SceneItem.cxx.

References YACS::HMI::AbstractSceneItem::_level, YACS::HMI::AbstractSceneItem::_parent, and YACS::HMI::AbstractSceneItem::getLevel().

Referenced by YACS::HMI::SceneComposedNodeItem::update().

208 {
209  setParentItem(parent);
210  _parent = parent;
211  if (_parent)
212  _level = _parent->getLevel() +1;
213 }
void SceneItem::setTopLeft ( QPointF  topLeft)
virtual
void SceneItem::shrinkExpandLink ( bool  se)
virtual
void SceneItem::shrinkExpandRecursive ( bool  isExpanding,
bool  fromHere,
ShrinkMode  theShrinkMode 
)
virtual
void SceneItem::updateChildItems ( )
virtual

Reimplemented in YACS::HMI::SceneNodeItem, YACS::HMI::SceneComposedNodeItem, and YACS::HMI::SceneDataPortItem.

Definition at line 430 of file SceneItem.cxx.

431 {
432 }
void SceneItem::updateLinks ( )
virtual

Reimplemented in YACS::HMI::SceneNodeItem, and YACS::HMI::SceneDataPortItem.

Definition at line 443 of file SceneItem.cxx.

444 {
445 }

Member Data Documentation

QPointF YACS::HMI::SceneItem::_eventPos
protected

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