1 // Copyright (C) 2006-2012 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
20 #ifndef _SCENEITEM_HXX_
21 #define _SCENEITEM_HXX_
23 #include <QGraphicsItem>
24 #include <QGraphicsTextItem>
25 #include <QGraphicsScene>
30 #include "guiObservers.hxx"
38 class RootSceneItem: public GuiObserver
41 RootSceneItem(YACS::HMI::Subject *context);
42 virtual ~RootSceneItem();
43 virtual void update(GuiEvent event, int type, Subject* son);
45 void setNewRoot(YACS::HMI::Subject *root);
50 // ----------------------------------------------------------------------------
54 * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
55 * nor from GuiObserver. not instantiable. See derived classes.
57 class AbstractSceneItem
60 AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
62 virtual ~AbstractSceneItem();
64 virtual QRectF boundingRect() const = 0;
65 virtual void paint(QPainter *painter,
66 const QStyleOptionGraphicsItem *option,
69 virtual void setTopLeft(QPointF topLeft) = 0;
72 virtual void checkGeometryChange() = 0;
73 virtual void reorganize();
74 virtual QString getLabel();
75 virtual void addHeader();
76 virtual qreal getHeaderBottom();
79 virtual void setWidth(qreal width);
80 virtual void setHeight(qreal height);
81 virtual void popupMenu(QWidget *caller, const QPoint &globalPos) = 0;
82 virtual void activateSelection(bool selected);
83 virtual void setGeometryOptimization(bool optimize);
84 inline SceneItem* getParent() { return _parent; };
87 virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
90 YACS::HMI::Scene *_scene;
103 enum Qt::MouseButton _dragButton;
106 // ----------------------------------------------------------------------------
109 * Generic class for 2D graphics item, inherits QGraphicsItem,
110 * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
112 class SceneItem: public QGraphicsItem, public AbstractSceneItem
115 SceneItem(QGraphicsScene *scene, SceneItem *parent,
117 virtual ~SceneItem();
119 virtual QRectF boundingRect() const;
120 virtual QRectF childrenBoundingRect () const;
121 virtual void paint(QPainter *painter,
122 const QStyleOptionGraphicsItem *option,
124 virtual void setTopLeft(QPointF topLeft);
125 virtual void checkGeometryChange();
126 virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
127 void setParent(SceneItem* parent);
128 virtual QString getToolTip();
129 void setEventPos(QPointF point);
130 virtual void updateChildItems();
131 virtual void updateLinks();
132 virtual void shrinkExpandLink(bool se);
133 virtual void shrinkExpandRecursive(bool isExpanding, bool fromHere);
134 bool isAncestorShrinked() { return _ancestorShrinked; };
137 // virtual bool sceneEvent(QEvent *event);
138 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
139 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
140 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event);
141 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
142 virtual QColor getPenColor();
143 virtual QColor getBrushColor();
144 QColor hoverColor(QColor origColor);
146 bool _ancestorShrinked;