Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/yacs.git] / src / genericgui / SceneItem.hxx
1 // Copyright (C) 2006-2012  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef _SCENEITEM_HXX_
21 #define _SCENEITEM_HXX_
22
23 #include <QGraphicsItem>
24 #include <QGraphicsTextItem>
25 #include <QGraphicsScene>
26 #include <QString>
27 #include <QPainter>
28 #include <QEvent>
29
30 #include "guiObservers.hxx"
31
32 namespace YACS
33 {
34   namespace HMI
35   {
36     class Scene;
37
38     class RootSceneItem: public GuiObserver
39     {
40     public:
41       RootSceneItem(YACS::HMI::Subject *context);
42       virtual ~RootSceneItem();
43       virtual void update(GuiEvent event, int type, Subject* son);
44     protected:
45       void setNewRoot(YACS::HMI::Subject *root);
46       Subject *_context;
47       Subject *_root;
48     };
49
50     // ----------------------------------------------------------------------------
51
52     class SceneItem;
53     /*!
54      * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
55      * nor from GuiObserver. not instantiable. See derived classes.
56      */
57     class AbstractSceneItem
58     {
59     public:
60       AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
61                         QString label);
62       virtual ~AbstractSceneItem();
63       
64       virtual QRectF boundingRect() const = 0;
65       virtual void paint(QPainter *painter,
66                          const QStyleOptionGraphicsItem *option,
67                          QWidget *widget) = 0;
68
69       virtual void setTopLeft(QPointF topLeft) = 0;
70       int getLevel();
71       void setLevel();
72       virtual void checkGeometryChange() = 0;
73       virtual void reorganize();
74       virtual QString getLabel();
75       virtual void addHeader();
76       virtual qreal getHeaderBottom();
77       qreal getWidth();
78       qreal getHeight();
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; };
85
86     protected:
87       virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
88
89       SceneItem *_parent;
90       YACS::HMI::Scene *_scene;
91       QString _label;
92       int _level;
93       qreal _width;
94       qreal _height;
95       qreal _incHeight;
96       QColor _penColor;
97       QColor _brushColor;
98       QColor _hiPenColor;
99       QColor _hiBrushColor;
100       bool _hasHeader;
101       bool _optimize;
102       bool _dragable;
103       enum Qt::MouseButton _dragButton;
104     };
105
106     // ----------------------------------------------------------------------------
107
108     /*!
109      * Generic class for 2D graphics item, inherits QGraphicsItem,
110      * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
111      */
112     class SceneItem: public QGraphicsItem, public AbstractSceneItem
113     {
114     public:
115       SceneItem(QGraphicsScene *scene, SceneItem *parent,
116                 QString label);
117       virtual ~SceneItem();
118       
119       virtual QRectF boundingRect() const;
120       virtual QRectF childrenBoundingRect () const;
121       virtual void paint(QPainter *painter,
122                          const QStyleOptionGraphicsItem *option,
123                          QWidget *widget);
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; };
135
136     protected:
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);
145       bool _hover;
146       bool _ancestorShrinked;
147       QPointF _eventPos;
148     };
149
150   }
151 }
152
153 #endif