Salome HOME
Synchronize adm files
[modules/yacs.git] / src / genericgui / SceneItem.hxx
1 // Copyright (C) 2006-2014  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, or (at your option) any later version.
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 void addProgressItem();
77       virtual qreal getHeaderBottom();
78       qreal getWidth();
79       qreal getHeight();
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; };
86
87     protected:
88       virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
89
90       SceneItem *_parent;
91       YACS::HMI::Scene *_scene;
92       QString _label;
93       int _level;
94       qreal _width;
95       qreal _height;
96       qreal _incHeight;
97       QColor _penColor;
98       QColor _brushColor;
99       QColor _hiPenColor;
100       QColor _hiBrushColor;
101       bool _hasHeader;
102       bool _optimize;
103       bool _dragable;
104       enum Qt::MouseButton _dragButton;
105     };
106
107     // ----------------------------------------------------------------------------
108
109     /*!
110      * Generic class for 2D graphics item, inherits QGraphicsItem,
111      * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
112      */
113     class SceneItem: public QGraphicsItem, public AbstractSceneItem
114     {
115     public:
116       SceneItem(QGraphicsScene *scene, SceneItem *parent,
117                 QString label);
118       virtual ~SceneItem();
119       
120       virtual QRectF boundingRect() const;
121       virtual QRectF childrenBoundingRect () const;
122       virtual void paint(QPainter *painter,
123                          const QStyleOptionGraphicsItem *option,
124                          QWidget *widget);
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; };
136       bool _blocX;
137       bool _blocY;
138
139     protected:
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);
148       bool _hover;
149       bool _ancestorShrinked;
150       QPointF _eventPos;
151     };
152
153   }
154 }
155
156 #endif