Salome HOME
mergefrom branch BR_V511_PR tag mergeto_trunk_03feb09
[modules/yacs.git] / src / genericgui / SceneItem.hxx
1 //  Copyright (C) 2006-2008  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 #ifndef _SCENEITEM_HXX_
20 #define _SCENEITEM_HXX_
21
22 #include <QGraphicsItem>
23 #include <QGraphicsTextItem>
24 #include <QGraphicsScene>
25 #include <QString>
26 #include <QPainter>
27 #include <QEvent>
28
29 #include "guiObservers.hxx"
30
31 namespace YACS
32 {
33   namespace HMI
34   {
35     class Scene;
36
37     class RootSceneItem: public GuiObserver
38     {
39     public:
40       RootSceneItem(YACS::HMI::Subject *context);
41       virtual ~RootSceneItem();
42       virtual void update(GuiEvent event, int type, Subject* son);
43     protected:
44       void setNewRoot(YACS::HMI::Subject *root);
45       Subject *_context;
46       Subject *_root;
47     };
48
49     // ----------------------------------------------------------------------------
50
51     class SceneItem;
52     /*!
53      * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
54      * nor from GuiObserver. not instantiable. See derived classes.
55      */
56     class AbstractSceneItem
57     {
58     public:
59       AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
60                         QString label);
61       virtual ~AbstractSceneItem();
62       
63       virtual QRectF boundingRect() const = 0;
64       virtual void paint(QPainter *painter,
65                          const QStyleOptionGraphicsItem *option,
66                          QWidget *widget) = 0;
67
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; };
88
89     protected:
90       virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
91
92       SceneItem *_parent;
93       YACS::HMI::Scene *_scene;
94       QString _label;
95       int _level;
96       qreal _margin;
97       qreal _nml;
98       qreal _width;
99       qreal _height;
100       QColor _penColor;
101       QColor _brushColor;
102       QColor _hiPenColor;
103       QColor _hiBrushColor;
104       bool _hasHeader;
105       bool _hasNml;
106       bool _optimize;
107       bool _dragable;
108       enum Qt::MouseButton _dragButton;
109     };
110
111     // ----------------------------------------------------------------------------
112
113     /*!
114      * Generic class for 2D graphics item, inherits QGraphicsItem,
115      * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
116      */
117     class SceneItem: public QGraphicsItem, public AbstractSceneItem
118     {
119     public:
120       SceneItem(QGraphicsScene *scene, SceneItem *parent,
121                 QString label);
122       virtual ~SceneItem();
123       
124       virtual QRectF boundingRect() const;
125       virtual QRectF childrenBoundingRect () const;
126       virtual void paint(QPainter *painter,
127                          const QStyleOptionGraphicsItem *option,
128                          QWidget *widget);
129       virtual void setTopLeft(QPointF topLeft);
130       virtual void checkGeometryChange();
131       virtual void popupMenu(QWidget *caller, const QPoint &globalPos);
132       void setParent(SceneItem* parent);
133
134     protected:
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);
143       bool _hover;
144     };
145
146   }
147 }
148
149 #endif