Version: 9.16.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 ()
 
virtual QRectF boundingRect () const =0
 
virtual void paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)=0
 
virtual void setTopLeft (QPointF topLeft)=0
 
int getLevel ()
 
void setLevel ()
 
virtual void checkGeometryChange ()=0
 
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 popupMenu (QWidget *caller, const QPoint &globalPos)=0
 
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::SceneItem ( QGraphicsScene scene,
SceneItem parent,
QString  label 
)

Definition at line 191 of file SceneItem.cxx.

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}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent, QString label)
Definition: SceneItem.cxx:88

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

◆ ~SceneItem()

SceneItem::~SceneItem ( )
virtual

Definition at line 203 of file SceneItem.cxx.

204{
205}

Member Function Documentation

◆ boundingRect()

QRectF SceneItem::boundingRect ( ) const
virtual

◆ checkGeometryChange()

void SceneItem::checkGeometryChange ( )
virtual

Implements YACS::HMI::AbstractSceneItem.

Definition at line 248 of file SceneItem.cxx.

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}
static QtGuiContext * getQtCurrent()
virtual QRectF childrenBoundingRect() const
Definition: SceneItem.cxx:224
virtual void checkGeometryChange()
Definition: SceneItem.cxx:248

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(), setTopLeft(), and YACS::HMI::SceneNodeItem::setTopLeft().

◆ childrenBoundingRect()

QRectF SceneItem::childrenBoundingRect ( ) const
virtual

Reimplemented in YACS::HMI::SceneComposedNodeItem.

Definition at line 224 of file SceneItem.cxx.

225{
226 return QGraphicsItem::childrenBoundingRect();
227}

Referenced by checkGeometryChange().

◆ getBrushColor()

◆ getPenColor()

◆ getToolTip()

QString SceneItem::getToolTip ( )
virtual

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

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

Definition at line 336 of file SceneItem.cxx.

337{
338 QString tooltip = _label;
339 SceneItem *parent = getParent();
340 if (parent)
341 tooltip = parent->getToolTip();
342 return tooltip;
343}
virtual QString getToolTip()
Definition: SceneItem.cxx:336

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

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

◆ hoverColor()

◆ hoverEnterEvent()

virtual void YACS::HMI::SceneItem::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

◆ hoverLeaveEvent()

virtual void YACS::HMI::SceneItem::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

◆ hoverMoveEvent()

virtual void YACS::HMI::SceneItem::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)
protectedvirtual

◆ isAncestorShrinked()

bool YACS::HMI::SceneItem::isAncestorShrinked ( )
inline

Definition at line 142 of file SceneItem.hxx.

142{ return _ancestorShrinked; };

References _ancestorShrinked.

◆ mousePressEvent()

virtual void YACS::HMI::SceneItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

◆ paint()

void SceneItem::paint ( QPainter *  painter,
const QStyleOptionGraphicsItem *  option,
QWidget widget 
)
virtual

Implements YACS::HMI::AbstractSceneItem.

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

Definition at line 229 of file SceneItem.cxx.

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}

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

◆ popupMenu()

◆ setEventPos()

void YACS::HMI::SceneItem::setEventPos ( QPointF  point)

◆ setParent()

void SceneItem::setParent ( SceneItem parent)

◆ setTopLeft()

void SceneItem::setTopLeft ( QPointF  topLeft)
virtual

◆ shrinkExpandLink()

virtual void YACS::HMI::SceneItem::shrinkExpandLink ( bool  se)
virtual

◆ shrinkExpandRecursive()

virtual void YACS::HMI::SceneItem::shrinkExpandRecursive ( bool  isExpanding,
bool  fromHere,
ShrinkMode  theShrinkMode 
)
virtual

◆ updateChildItems()

virtual void YACS::HMI::SceneItem::updateChildItems ( )
virtual

◆ updateLinks()

virtual void YACS::HMI::SceneItem::updateLinks ( )
virtual

Member Data Documentation

◆ _ancestorShrinked

◆ _blocX

◆ _blocY

◆ _eventPos

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

Definition at line 157 of file SceneItem.hxx.

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

◆ _hover


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