1 // Copyright (C) 2006-2008 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
19 #ifndef _SCENEITEM_HXX_
20 #define _SCENEITEM_HXX_
22 #include <QGraphicsItem>
23 #include <QGraphicsTextItem>
24 #include <QGraphicsScene>
29 #include "guiObservers.hxx"
37 class RootSceneItem: public GuiObserver
40 RootSceneItem(YACS::HMI::Subject *context);
41 virtual ~RootSceneItem();
42 virtual void update(GuiEvent event, int type, Subject* son);
44 void setNewRoot(YACS::HMI::Subject *root);
49 // ----------------------------------------------------------------------------
53 * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
54 * nor from GuiObserver. not instantiable. See derived classes.
56 class AbstractSceneItem
59 AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
61 virtual ~AbstractSceneItem();
63 virtual QRectF boundingRect() const = 0;
64 virtual void paint(QPainter *painter,
65 const QStyleOptionGraphicsItem *option,
68 virtual void setTopLeft(QPointF topLeft) = 0;
69 virtual int getLevel();
70 virtual qreal getMargin();
71 virtual void checkGeometryChange() = 0;
72 virtual void reorganize();
73 virtual QString getLabel();
74 virtual void addHeader();
75 virtual qreal getHeaderBottom();
76 virtual qreal getWidth();
77 virtual qreal getHeight();
78 virtual void setWidth(qreal width);
79 virtual void setHeight(qreal height);
80 virtual qreal getInternWidth();
81 virtual qreal getInternHeight();
82 virtual void popupMenu(QWidget *caller, const QPoint &globalPos) = 0;
83 virtual void activateSelection(bool selected);
84 virtual void setGeometryOptimization(bool optimize);
85 inline bool hasNml() { return _hasNml; };
86 inline qreal getNml() { return _hasNml*_nml; };
87 inline SceneItem* getParent() { return _parent; };
90 virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
93 YACS::HMI::Scene *_scene;
103 QColor _hiBrushColor;
108 enum Qt::MouseButton _dragButton;
111 // ----------------------------------------------------------------------------
114 * Generic class for 2D graphics item, inherits QGraphicsItem,
115 * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
117 class SceneItem: public QGraphicsItem, public AbstractSceneItem
120 SceneItem(QGraphicsScene *scene, SceneItem *parent,
122 virtual ~SceneItem();
124 virtual QRectF boundingRect() const;
125 virtual QRectF childrenBoundingRect () const;
126 virtual void paint(QPainter *painter,
127 const QStyleOptionGraphicsItem *option,
129 virtual void setTopLeft(QPointF topLeft);
130 virtual void checkGeometryChange();
131 virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
132 void setParent(SceneItem* parent);
135 // virtual bool sceneEvent(QEvent *event);
136 virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
137 virtual void hoverEnterEvent(QGraphicsSceneHoverEvent * event);
138 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent * event);
139 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent * event);
140 virtual QColor getPenColor();
141 virtual QColor getBrushColor();
142 QColor hoverColor(QColor origColor);