Salome HOME
sources v1.2
[modules/kernel.git] / src / SALOMEGUI / QAD_Application.h
1 //  SALOME SALOMEGUI : implementation of desktop and GUI kernel
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : QAD_Application.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef QAD_Application_H
30 #define QAD_Application_H
31
32 #include "QAD.h"
33 #include "QAD_Popup.h"
34 #include "QAD_Study.h"
35 #include "QAD_Action.h"
36
37 #include "SALOME_NamingService.hxx"
38
39 // QT Includes
40 #include <qlist.h>
41 #include <qpixmap.h>
42 #include <qstringlist.h>
43 #include <qtranslator.h>
44 #include <qtoolbar.h>
45 #include <qmap.h>
46
47 class QAD_Operation;
48 class QAD_Desktop;
49 class QAD_EXPORT QAD_Application : public QObject, public QAD_PopupServer
50 {
51   Q_OBJECT
52     enum { EditUndoId, EditRedoId, EditCopyId, EditPasteId };
53
54 friend class QAD_Desktop;
55
56 public:
57   QAD_Application ( const QString& format, const QString& description, 
58                     const QString& filter); 
59   ~QAD_Application();
60
61 public:
62     static void         run();
63     static bool         addToDesktop( QAD_Application* app, SALOME_NamingService* name_service );    
64     static QAD_Desktop* getDesktop();    
65
66     static QPalette     getPalette(bool alternative = false);
67
68     const QString&               getApplicationName() const;
69     const QPixmap&               getApplicationIcon() const;
70
71     /* studies management */
72     const QString&  getStudyFormat() const;     
73     const QString&  getStudyExtension() const;
74     const QString&  getStudyDescription() const;    
75
76     /* studies */
77     bool              isStudyOpened( const QString& studyname );
78     QAD_Study*        getStudyByName( const QString& studyname );    
79     QAD_Study*        getActiveStudy() const;
80     QList<QAD_Study>& getStudies();
81     
82     QAD_Study*      newStudy();
83     QAD_Study*      loadStudy( const QString& fileName);
84     QAD_Study*      openStudy( const QString& fileName);
85     bool            saveStudy( QAD_Study* study );
86     bool            saveAsStudy( QAD_Study* study, const QString& fileName );
87     bool            closeStudy( QAD_Study* study, bool permanently = false );
88     
89     /* customization */
90     void            updateFilePopup( QPopupMenu* menu, bool add, int index = -1 );
91     void            updateEditPopup( QPopupMenu* menu, bool add, int index = -1 );
92     void            updateViewPopup( QPopupMenu* menu, bool add, int index = -1 );
93     void            updateHelpPopup( QPopupMenu* menu, bool add, int index = -1 );
94     void            updateMainMenu( QMenuBar* menu, bool add, int index = -1 );
95     void            updateStatusBar( QStatusBar*, bool add );
96     void            updateToolBars( bool add );
97   
98     /* toolbars */ 
99     QToolBar*       createToolBar( int id,
100                                    const QString& label,  Dock dock = DockTop, 
101                                    bool  dockTop       = true, bool dockBottom   = true, 
102                                    bool  dockLeft      = true, bool dockRight    = true,
103                                    bool  dockMinimized = true, bool dockTornOff  = true );
104     void            removeToolBar( int id );
105     QToolBar*       getToolBar( int id );
106     QList<QToolBar> getToolBars();
107
108     virtual void    onStudyActivated( QAD_Study* );
109     virtual void    onStudyDeactivated( QAD_Study* );
110     virtual void    startOperation( QAD_Operation* op );    
111
112     virtual void    helpAbout();    
113     virtual void    helpSearch();
114     virtual void    helpContents();
115
116 public slots:
117     void    updateActions();
118
119 signals:
120     void            appActivated ( QAD_Application* );
121     void            appDeactivated ( QAD_Application* );
122     void            desktopCreated();
123
124 protected slots:
125     virtual bool    onUndo();
126     virtual bool    onRedo();
127     virtual bool    onCopy();
128     virtual bool    onPaste();
129     virtual void    onOperationTerminated( bool );
130
131 private slots:
132     void            onDesktopCreated();
133
134 protected:    
135     /* menu */
136     virtual int     onUpdateMainMenuItems ( QMenuBar*, bool add, int index );    
137     virtual int     onUpdateFileActions ( QPopupMenu*, bool add, int index );
138     virtual int     onUpdateEditActions ( QPopupMenu*, bool add, int index );
139     virtual int     onUpdateViewActions ( QPopupMenu*, bool add, int index );
140     virtual int     onUpdateHelpActions ( QPopupMenu*, bool add, int index );          
141     virtual void    onUpdateStatusBar( QStatusBar*, bool activate );
142     virtual void    onUpdateToolBars( bool activate );
143
144     /* study */
145     virtual void    onStudyCreated( QAD_Study* );
146     virtual void    onStudyOpened( QAD_Study* );
147     virtual void    onStudyClosed( QAD_Study* );
148     virtual void    onStudyShown( QAD_Study* );
149     virtual void    onActiveStudyChanged( QAD_Study* oldActiveStudy, 
150                                           QAD_Study* newActiveStudy );
151     /* specific initialization ( CAF etc. ) */
152     virtual bool    initApp(SALOME_NamingService* name_service) = 0;    
153     virtual bool    createDesktop(SALOME_NamingService* name_service); 
154
155     /* undo/redo */
156     virtual bool    undo( QAD_Study* study );
157     virtual bool    redo( QAD_Study* study );
158     /* copy/paste */
159     bool            canCopy();
160     bool            canPaste();
161  
162     /* popup */
163     void            onCreatePopup();
164
165 protected:
166
167     SALOMEDS::StudyManager_var     myStudyMgr;
168
169     QAD_Study*                     myActiveStudy;
170     QList<QAD_Study>               myStudies;
171     QPixmap                        myIcon;
172     QString                        myName; 
173     
174     QString                        myStudyFormat;
175     QString                        myStudyExtension;
176     QString                        myStudyDescription;    
177
178 #if defined SOLARIS          
179 /*  SUN C++ v4.1 compiler BUG ? 
180     Error when using protected 'desktop' in subclasses. 
181     */   
182 public: 
183 #endif
184     static QAD_Desktop* desktop;        /* the only QAD desktop */    
185
186 private:
187     void                createActions();
188
189     void                addStudy( QAD_Study* study );
190     void                removeStudy( QAD_Study* study );    
191
192 private :
193     ActionMap            myEditActions;
194     ActionMap            myViewActions;
195     ActionMap            myHelpActions;
196     QMap<int, QToolBar*> myToolBars;
197 };
198
199 #endif
200