1 // Copyright (C) 2006-2013 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 void addProgressItem();
77 virtual qreal getHeaderBottom();
80 virtual void setWidth(qreal width);
81 virtual void setHeight(qreal height);
82 virtual void popupMenu(QWidget *caller, const QPoint &globalPos) = 0;
83 virtual void activateSelection(bool selected);
84 virtual void setGeometryOptimization(bool optimize);
85 inline SceneItem* getParent() { return _parent; };
88 virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
91 YACS::HMI::Scene *_scene;
100 QColor _hiBrushColor;
104 enum Qt::MouseButton _dragButton;
107 // ----------------------------------------------------------------------------
110 * Generic class for 2D graphics item, inherits QGraphicsItem,
111 * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
113 class SceneItem: public QGraphicsItem, public AbstractSceneItem
116 SceneItem(QGraphicsScene *scene, SceneItem *parent,
118 virtual ~SceneItem();
120 virtual QRectF boundingRect() const;
121 virtual QRectF childrenBoundingRect () const;
122 virtual void paint(QPainter *painter,
123 const QStyleOptionGraphicsItem *option,
125 virtual void setTopLeft(QPointF topLeft);
126 virtual void checkGeometryChange();
127 virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
128 void setParent(SceneItem* parent);
129 virtual QString getToolTip();
130 void setEventPos(QPointF point);
131 virtual void updateChildItems();
132 virtual void updateLinks();
133 virtual void shrinkExpandLink(bool se);
134 virtual void shrinkExpandRecursive(bool isExpanding, bool fromHere);
135 bool isAncestorShrinked() { return _ancestorShrinked; };
140 // virtual bool sceneEvent(QEvent *event);
141 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
142 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
143 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event);
144 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
145 virtual QColor getPenColor();
146 virtual QColor getBrushColor();
147 QColor hoverColor(QColor origColor);
149 bool _ancestorShrinked;