1 // Copyright (C) 2006-2014 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, or (at your option) any later version.
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"
45 class RootSceneItem: public GuiObserver
48 RootSceneItem(YACS::HMI::Subject *context);
49 virtual ~RootSceneItem();
50 virtual void update(GuiEvent event, int type, Subject* son);
52 void setNewRoot(YACS::HMI::Subject *root);
57 // ----------------------------------------------------------------------------
61 * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
62 * nor from GuiObserver. not instantiable. See derived classes.
64 class AbstractSceneItem
67 AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
69 virtual ~AbstractSceneItem();
71 virtual QRectF boundingRect() const = 0;
72 virtual void paint(QPainter *painter,
73 const QStyleOptionGraphicsItem *option,
76 virtual void setTopLeft(QPointF topLeft) = 0;
79 virtual void checkGeometryChange() = 0;
80 virtual void reorganize();
81 virtual QString getLabel();
82 virtual void addHeader();
83 virtual void addProgressItem();
84 virtual qreal getHeaderBottom();
87 virtual void setWidth(qreal width);
88 virtual void setHeight(qreal height);
89 virtual void popupMenu(QWidget *caller, const QPoint &globalPos) = 0;
90 virtual void activateSelection(bool selected);
91 virtual void setGeometryOptimization(bool optimize);
92 inline SceneItem* getParent() { return _parent; };
95 virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
98 YACS::HMI::Scene *_scene;
107 QColor _hiBrushColor;
111 enum Qt::MouseButton _dragButton;
114 // ----------------------------------------------------------------------------
117 * Generic class for 2D graphics item, inherits QGraphicsItem,
118 * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
120 class SceneItem: public QGraphicsItem, public AbstractSceneItem
123 SceneItem(QGraphicsScene *scene, SceneItem *parent,
125 virtual ~SceneItem();
127 virtual QRectF boundingRect() const;
128 virtual QRectF childrenBoundingRect () const;
129 virtual void paint(QPainter *painter,
130 const QStyleOptionGraphicsItem *option,
132 virtual void setTopLeft(QPointF topLeft);
133 virtual void checkGeometryChange();
134 virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
135 void setParent(SceneItem* parent);
136 virtual QString getToolTip();
137 void setEventPos(QPointF point);
138 virtual void updateChildItems();
139 virtual void updateLinks();
140 virtual void shrinkExpandLink(bool se);
141 virtual void shrinkExpandRecursive(bool isExpanding, bool fromHere, ShrinkMode theShrinkMode);
142 bool isAncestorShrinked() { return _ancestorShrinked; };
147 // virtual bool sceneEvent(QEvent *event);
148 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
149 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
150 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event);
151 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
152 virtual QColor getPenColor();
153 virtual QColor getBrushColor();
154 QColor hoverColor(QColor origColor);
156 bool _ancestorShrinked;