Salome HOME
9126290a63fb5ecda6f2dff52e6294e5c3821233
[modules/gui.git] / src / SUIT / SUIT_ViewManager.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef SUIT_VIEWMANAGER_H
23 #define SUIT_VIEWMANAGER_H
24
25 #include "SUIT.h"
26
27 #include "SUIT_PopupClient.h"
28
29 #include <QObject>
30 #include <QPixmap>
31 #include <QVector>
32 #include <QPointer>
33
34 class QMenu;
35 class QMouseEvent;
36 class QWheelEvent;
37 class QKeyEvent;
38
39 class SUIT_Study;
40 class SUIT_Desktop;
41 class SUIT_ViewModel;
42 class SUIT_ViewWindow;
43
44 #ifdef WIN32
45 #pragma warning( disable:4251 )
46 #endif
47
48 class SUIT_EXPORT SUIT_ViewManager : public QObject, public SUIT_PopupClient
49 {
50   Q_OBJECT
51 public:
52   SUIT_ViewManager( SUIT_Study*,
53                     SUIT_Desktop*,
54                     SUIT_ViewModel* = 0 );
55   virtual ~SUIT_ViewManager();
56
57   virtual QString  popupClientType() const { return getType(); }
58   virtual void     contextMenuPopup( QMenu* );
59
60   void             setViewModel(SUIT_ViewModel* theViewModel);
61   SUIT_ViewModel*  getViewModel() { return myViewModel; }
62
63   SUIT_Study*      study() const;
64
65   QString          getType() const;
66   SUIT_ViewWindow* getActiveView() { return myActiveView; }
67
68   int              getViewsCount() { return myViews.count(); }
69   QVector<SUIT_ViewWindow*> getViews() const;
70
71   QString          getTitle() const { return myTitle; }
72   virtual void     setTitle( const QString& );
73
74   QPixmap          getIcon() const { return myIcon; }
75   virtual void     setIcon( const QPixmap& );
76
77   SUIT_ViewWindow* createViewWindow();
78
79   bool             isVisible() const;
80   virtual void     setShown( const bool );
81   virtual void     setDestructiveClose( const bool );
82
83   int              getId() const;
84
85 public slots:
86   void             createView();
87   void             closeAllViews();
88
89 signals:
90   void             lastViewClosed(SUIT_ViewManager*);
91   void             deleteView(SUIT_ViewWindow*);
92   void             viewCreated(SUIT_ViewWindow*);
93   void             mousePress(SUIT_ViewWindow*, QMouseEvent*);
94   void             mouseRelease(SUIT_ViewWindow*, QMouseEvent*);
95   void             mouseDoubleClick(SUIT_ViewWindow*, QMouseEvent*);
96   void             mouseMove(SUIT_ViewWindow*, QMouseEvent*);
97   void             wheel(SUIT_ViewWindow*, QWheelEvent*);
98   void             keyPress(SUIT_ViewWindow*, QKeyEvent*);
99   void             keyRelease(SUIT_ViewWindow*, QKeyEvent*);
100   void             activated(SUIT_ViewManager*);
101
102 protected slots:
103   void             onWindowActivated(SUIT_ViewWindow*);
104   void             onClosingView( SUIT_ViewWindow* );
105   void             onMousePressed(SUIT_ViewWindow*, QMouseEvent* );
106   void             onDeleteStudy();
107
108 private slots:
109   void             onContextMenuRequested( QContextMenuEvent* e );
110
111 protected:
112   /*! Inserts the View into internal Views Vector.\n
113    *  Returns true if view has been added successfully
114    */
115   virtual bool     insertView(SUIT_ViewWindow* theView);
116
117   /*! Removes the View from internal Views Vector.*/
118   virtual void     removeView(SUIT_ViewWindow* theView);
119
120   /*! Close the specified View.*/
121   virtual void     closeView(SUIT_ViewWindow* theView);
122
123   /*! Used to set unique name for the view.*/
124   virtual void     setViewName(SUIT_ViewWindow* theView );
125   QString          prepareTitle( const QString&, const int, const int );
126
127   static int       useNewId( const QString& );
128
129 protected:
130   typedef QPointer<SUIT_ViewWindow> ViewWindow;
131
132 protected:
133   SUIT_Desktop*               myDesktop;
134   SUIT_ViewModel*             myViewModel;
135   QVector<ViewWindow>         myViews;
136   SUIT_ViewWindow*            myActiveView;
137
138   int                         myId;
139   QPixmap                     myIcon;
140   QString                     myTitle;
141   SUIT_Study*                 myStudy;
142
143   static QMap<QString, int>   _ViewMgrId;
144 };
145
146 #ifdef WIN32
147 #pragma warning( default:4251 )
148 #endif
149
150 #endif