Version: 8.3.0
YACS::HMI::SceneObserverItem Class Reference

#include <SceneObserverItem.hxx>

Inheritance diagram for YACS::HMI::SceneObserverItem:
Collaboration diagram for YACS::HMI::SceneObserverItem:

Public Member Functions

 SceneObserverItem (QGraphicsScene *scene, SceneItem *parent, QString label, Subject *subject)
 
virtual ~SceneObserverItem ()
 
virtual void update (GuiEvent event, int type, Subject *son)
 
virtual void select (bool isSelected)
 
virtual void activateSelection (bool selected)
 
virtual SubjectgetSubject ()
 
virtual QString getToolTip ()
 
- Public Member Functions inherited from YACS::HMI::SceneItem
 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)
 
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 setGeometryOptimization (bool optimize)
 
SceneItemgetParent ()
 
- Public Member Functions inherited from YACS::HMI::GuiObserver
 GuiObserver ()
 
virtual ~GuiObserver ()
 
virtual void incrementSubjects (Subject *subject)
 
virtual void decrementSubjects (Subject *subject)
 
int getNbSubjects ()
 
bool isDestructible ()
 

Protected Member Functions

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

Protected Attributes

Subject_subject
 
bool _draging
 
bool _dragModifier
 
bool _emphasized
 
- Protected Attributes inherited from YACS::HMI::SceneItem
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
 
- Protected Attributes inherited from YACS::HMI::GuiObserver
std::set< Subject * > _subjectSet
 
bool _destructible
 

Additional Inherited Members

- Static Public Member Functions inherited from YACS::HMI::GuiObserver
static std::string eventName (GuiEvent event)
 
static void setEventMap ()
 
- Public Attributes inherited from YACS::HMI::SceneItem
bool _blocX
 
bool _blocY
 
- Static Protected Attributes inherited from YACS::HMI::GuiObserver
static std::map< int, std::string > _eventNameMap
 

Detailed Description

Definition at line 31 of file SceneObserverItem.hxx.

Constructor & Destructor Documentation

SceneObserverItem::SceneObserverItem ( QGraphicsScene scene,
SceneItem parent,
QString  label,
Subject subject 
)

Definition at line 42 of file SceneObserverItem.cxx.

References _draging, _dragModifier, _emphasized, YACS::HMI::QtGuiContext::_mapOfSceneItem, _subject, YACS::HMI::Subject::attach(), and YACS::HMI::QtGuiContext::getQtCurrent().

44  : SceneItem(scene, parent, label), GuiObserver()
45 {
46  _subject = subject;
47  _draging = false;
48  _dragModifier = false;
49  _emphasized = false;
50  _subject->attach(this);
52 }
SceneObserverItem::~SceneObserverItem ( )
virtual

Member Function Documentation

void SceneObserverItem::activateSelection ( bool  selected)
virtual

Reimplemented from YACS::HMI::AbstractSceneItem.

Definition at line 190 of file SceneObserverItem.cxx.

References YACS::HMI::AbstractSceneItem::_label, _subject, DEBTRACE, and YACS::HMI::Subject::select().

191 {
192  DEBTRACE("SceneObserverItem::activateSelection " << _label.toStdString()<< " " << selected);
193  _subject->select(true);
194 }
QString SceneObserverItem::getMimeFormat ( )
protectedvirtual

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

Definition at line 201 of file SceneObserverItem.cxx.

Referenced by mouseMoveEvent().

202 {
203  return "yacs/subject";
204 }
QString SceneObserverItem::getToolTip ( )
virtual

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

Reimplemented from YACS::HMI::SceneItem.

Definition at line 89 of file SceneObserverItem.cxx.

References YACS::HMI::AbstractSceneItem::_label, YACS::HMI::QtGuiContext::_mapOfSchemaItem, _subject, YACS::HMI::SchemaItem::data(), DEBTRACE, and YACS::HMI::QtGuiContext::getQtCurrent().

90 {
91  DEBTRACE("SceneObserverItem::getToolTip");
92  if (!_subject)
93  return _label;
94  if ( !QtGuiContext::getQtCurrent() || !QtGuiContext::getQtCurrent()->_mapOfSchemaItem.count(_subject))
95  return _label;
96  QString val ="";
98  val = item->data(0, Qt::ToolTipRole).toString();
99  return val;
100 }
void SceneObserverItem::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

creation of mime data if drag detected. setData mime type must be coherent with SchemaModel::mimeTypes to allow drop on port item in tree view

Reimplemented in YACS::HMI::SceneNodeItem.

Definition at line 123 of file SceneObserverItem.cxx.

References YACS::HMI::AbstractSceneItem::_dragButton, _draging, _dragModifier, _subject, DEBTRACE, getMimeFormat(), YACS::HMI::SceneItem::paint(), and YACS::HMI::ItemMimeData::setSubject().

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

124 {
125  if (_draging)
126  {
127  //DEBTRACE("_draging");
128  if (QLineF(event->screenPos(),
129  event->buttonDownScreenPos(_dragButton)).length()
130  < QApplication::startDragDistance())
131  {
132  return;
133  }
134  DEBTRACE("in drag");
135  QDrag *drag = new QDrag(event->widget());
136  ItemMimeData *mime = new ItemMimeData;
137  drag->setMimeData(mime);
138  mime->setSubject(_subject);
139  mime->setData(getMimeFormat(), "_subject");
140  if(_dragModifier)
141  mime->setControl(false);
142  else
143  mime->setControl(true);
144 
145  QPixmap pixmap(34, 34);
146  pixmap.fill(Qt::white);
147 
148  QPainter painter(&pixmap);
149  painter.translate(15, 15);
150  painter.setRenderHint(QPainter::Antialiasing);
151  paint(&painter, 0, 0);
152  painter.end();
153 
154  pixmap.setMask(pixmap.createHeuristicMask());
155 
156  drag->setPixmap(pixmap);
157  drag->setHotSpot(QPoint(15, 20));
158 
159  drag->exec();
160  //restore non drag state
161  setCursor(Qt::ArrowCursor);
162  _draging = false;
163  _dragModifier = false;
164  }
165 }
void SceneObserverItem::mousePressEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

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

Reimplemented from YACS::HMI::SceneItem.

Reimplemented in YACS::HMI::SceneNodeItem.

Definition at line 102 of file SceneObserverItem.cxx.

References YACS::HMI::AbstractSceneItem::_dragable, YACS::HMI::AbstractSceneItem::_dragButton, _draging, _dragModifier, YACS::HMI::AbstractSceneItem::_label, YACS::HMI::AbstractSceneItem::_scene, _subject, DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), YACS::HMI::QtGuiContext::isEdition(), YACS::HMI::Scene::isZooming(), and YACS::HMI::Subject::select().

Referenced by YACS::HMI::SceneNodeItem::mousePressEvent().

103 {
104  DEBTRACE("SceneObserverItem::mousePressEvent " << _label.toStdString()
105  << " " << acceptedMouseButtons ());
106  if (!_scene->isZooming())
107  {
108  _subject->select(true);
109  if (_dragable && (event->button() == _dragButton) && QtGuiContext::getQtCurrent()->isEdition())
110  {
111  setCursor(Qt::ClosedHandCursor);
112  _draging = true;
113  _dragModifier= event->modifiers() & (Qt::ControlModifier | Qt::ShiftModifier);
114  }
115  }
116 }
void SceneObserverItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent *  event)
protectedvirtual

Reimplemented in YACS::HMI::SceneNodeItem.

Definition at line 167 of file SceneObserverItem.cxx.

References _draging, and _dragModifier.

Referenced by YACS::HMI::SceneNodeItem::mouseReleaseEvent().

168 {
169  if (_draging)
170  {
171  setCursor(Qt::ArrowCursor);
172  }
173  _draging = false;
174  _dragModifier = false;
175 }
void SceneObserverItem::select ( bool  isSelected)
virtual

Reimplemented from YACS::HMI::GuiObserver.

Reimplemented in YACS::HMI::SceneLinkItem.

Definition at line 77 of file SceneObserverItem.cxx.

References YACS::HMI::AbstractSceneItem::_label, _subject, DEBTRACE, YACS::HMI::QtGuiContext::getQtCurrent(), and YACS::HMI::QtGuiContext::setSelectedSubject().

Referenced by YACS::HMI::SceneLinkItem::select().

78 {
79  DEBTRACE("SceneObserverItem::select " << _label.toStdString() << " " << isSelected);
80  if (isSelected)
81  {
82 // _scene->clearSelection();
83  setSelected(true);
85  }
86  else setSelected(false);
87 }
void SceneObserverItem::update ( GuiEvent  event,
int  type,
Subject son 
)
virtual

Reimplemented from YACS::HMI::GuiObserver.

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

Definition at line 59 of file SceneObserverItem.cxx.

References _emphasized, DEBTRACE, YACS::HMI::EMPHASIZE, and YACS::HMI::GuiObserver::eventName().

Referenced by gui.graph.MyCanvas::customEvent(), YACS::HMI::SceneDataPortItem::update(), and YACS::HMI::SceneNodeItem::update().

60 {
61  DEBTRACE(" SceneObserverItem::update " << eventName(event)<< " " << type << " " << son);
62  switch (event)
63  {
65  DEBTRACE("SceneObserverItem::update EMPHASIZE " << type);
66  if (type)
67  _emphasized = true;
68  else
69  _emphasized = false;
70  QGraphicsItem::update();
71  break;
72  default:
73  ;
74  }
75 }

Member Data Documentation

bool YACS::HMI::SceneObserverItem::_draging
protected
bool YACS::HMI::SceneObserverItem::_dragModifier
protected

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