Salome HOME
Updated copyright comment
[modules/yacs.git] / src / genericgui / SceneItem.hxx
1 // Copyright (C) 2006-2024  CEA, EDF
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     typedef enum
37       {
38         CurrentNode,
39         ChildrenNodes,
40         ElementaryNodes
41       } ShrinkMode;
42     
43     class Scene;
44
45     class RootSceneItem: public GuiObserver
46     {
47     public:
48       RootSceneItem(YACS::HMI::Subject *context);
49       virtual ~RootSceneItem();
50       virtual void update(GuiEvent event, int type, Subject* son);
51     protected:
52       void setNewRoot(YACS::HMI::Subject *root);
53       Subject *_context;
54       Subject *_root;
55     };
56
57     // ----------------------------------------------------------------------------
58
59     class SceneItem;
60     /*!
61      * Base class for 2D graphics item, does not herit neither from QGraphicsItem,
62      * nor from GuiObserver. not instantiable. See derived classes.
63      */
64     class AbstractSceneItem
65     {
66     public:
67       AbstractSceneItem(QGraphicsScene *scene, SceneItem *parent,
68                         QString label);
69       virtual ~AbstractSceneItem();
70       
71       virtual QRectF boundingRect() const = 0;
72       virtual void paint(QPainter *painter,
73                          const QStyleOptionGraphicsItem *option,
74                          QWidget *widget) = 0;
75
76       virtual void setTopLeft(QPointF topLeft) = 0;
77       int getLevel();
78       void setLevel();
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();
85       qreal getWidth();
86       qreal getHeight();
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; };
93
94     protected:
95       virtual QRectF childBoundingRect(AbstractSceneItem *child) const;
96
97       SceneItem *_parent;
98       YACS::HMI::Scene *_scene;
99       QString _label;
100       int _level;
101       qreal _width;
102       qreal _height;
103       qreal _incHeight;
104       QColor _penColor;
105       QColor _brushColor;
106       QColor _hiPenColor;
107       QColor _hiBrushColor;
108       bool _hasHeader;
109       bool _optimize;
110       bool _dragable;
111       enum Qt::MouseButton _dragButton;
112     };
113
114     // ----------------------------------------------------------------------------
115
116     /*!
117      * Generic class for 2D graphics item, inherits QGraphicsItem,
118      * specialised in 2 kind of classes, with or without inheritance from GuiObserver.
119      */
120     class SceneItem: public QGraphicsItem, public AbstractSceneItem
121     {
122     public:
123       SceneItem(QGraphicsScene *scene, SceneItem *parent,
124                 QString label);
125       virtual ~SceneItem();
126       
127       virtual QRectF boundingRect() const;
128       virtual QRectF childrenBoundingRect () const;
129       virtual void paint(QPainter *painter,
130                          const QStyleOptionGraphicsItem *option,
131                          QWidget *widget);
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; };
143       bool _blocX;
144       bool _blocY;
145
146     protected:
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);
155       bool _hover;
156       bool _ancestorShrinked;
157       QPointF _eventPos;
158     };
159
160   }
161 }
162
163 #endif