Salome HOME
no message
[modules/gui.git] / src / SUIT / SUIT_Application.h
1 #ifndef SUIT_APPLICATION_H
2 #define SUIT_APPLICATION_H
3
4 #include "SUIT.h"
5 #include "SUIT_Study.h"
6
7 #include <qobject.h>
8 #include <qwidget.h>
9
10 class QAction;
11 class SUIT_Desktop;
12 class SUIT_Convertor;
13 class SUIT_ViewModel;
14 class SUIT_ResourceMgr;
15 class QString;
16 class QIconSet;
17 /*! \class QObject
18  * \brief For more information see <a href="http://doc.trolltech.com">QT documentation</a>.
19  */
20 /*!
21   An <b>Application</b> is a class which defines application configuration and behaviour.
22   For example Application object defines what Viewers are used in this application, what auxilliary windows
23   are present, how user can dial with them. Also Application object defines an sertain type of data structure by 
24   holding of pointer on an instance of SUIT_Study class (which represents Document data structure). In other words
25   Application defines type of sata structure, type of used Viewers, type of main GUI widget (Desktop),
26   and other auxilliary tools.
27 */
28
29 class SUIT_EXPORT SUIT_Application : public QObject
30 {
31   Q_OBJECT
32
33 public:
34   SUIT_Application();
35   virtual ~SUIT_Application();
36
37   //! Returns main widget (Desktop) of the application (if it exists)
38   virtual SUIT_Desktop* desktop();
39
40   /*! Returns FALSE if applic ation can not be closed (because of non saved data for example). 
41       This method called by SUIT_Session whin closing of application was requested. */
42   virtual bool          isPossibleToClose();
43
44   virtual void          closeApplication();
45
46   //! Returns active Study. If Application supports wirking with several studies this method should be redefined
47   virtual SUIT_Study*   activeStudy() const;
48
49   //! Returns Name of application. Using is not defined.
50   virtual QString       applicationName() const = 0;
51
52   virtual QString       applicationVersion() const;
53
54   //! Shows the application's main widget. For non GUI application must be redefined.
55   virtual void          start();
56
57   //! Opens document <theFileName> into active Study. If Study is empty - creates it.
58   virtual bool          useFile( const QString& theFileName);
59
60   //! Loads document <theName> into active Study. If Study is empty - creates it.
61   virtual bool          useStudy( const QString& theName);
62
63   //! Creates new empty Study if active Study = 0
64   virtual void          createEmptyStudy();
65
66   /*! Returns number of Studies. 
67    *  Must be redefined in Applications which support several studies for one Application instance. */
68   virtual int           getNbStudies() const;
69
70   SUIT_ResourceMgr*     resourceMgr() const;
71
72   /*! Returns instance of data object Convertor class according to given Viewer. 
73       If convertation is not supported returns 0. */
74   virtual SUIT_Convertor* getConvertor(const SUIT_ViewModel* theViewer) { return 0; }
75
76   //! Puts the message to the status bar  
77   void putInfo ( const QString&, const int = 0 );
78
79   //! Invokes application-specific "Open/Save File" dialog and returns the selected file name.
80   virtual QString getFileName( bool open, const QString& initial, const QString& filters, 
81                                const QString& caption, QWidget* parent ) = 0;
82
83   //! Invokes application-specific "Select Directory" dialog and returns the selected directory name.
84   virtual QString getDirectory( const QString& initial, const QString& caption, QWidget* parent ) = 0;
85
86 signals:
87   void                  applicationClosed( SUIT_Application* );
88   void                  activated( SUIT_Application* );
89
90 protected:
91   SUIT_Application*     startApplication( int, char** ) const;
92   SUIT_Application*     startApplication( const QString&, int, char** ) const;
93
94   virtual void          setDesktop( SUIT_Desktop* );
95
96   //! Creates a new Study instance. Must be redefined in new application according to its Study type.
97   virtual SUIT_Study*   createNewStudy();
98   virtual void          setActiveStudy( SUIT_Study* );
99   
100   /** @name Create tool functions*/ //@{
101   int                   createTool( const QString& );
102   int                   createTool( const int, const int, const int = -1 );
103   int                   createTool( const int, const QString&, const int = -1 );
104   int                   createTool( QAction*, const int, const int = -1, const int = -1 );
105   int                   createTool( QAction*, const QString&, const int = -1, const int = -1 );//@}
106
107   /** @name Create menu functions*/ //@{
108   int                   createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 );
109   int                   createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 );
110   int                   createMenu( const int, const int, const int = -1, const int = -1 );
111   int                   createMenu( const int, const QString&, const int = -1, const int = -1 );
112   int                   createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 );
113   int                   createMenu( QAction*, const QString&, const int = -1, const int = -1, const int = -1 );//@}
114
115   /** @name Set menu shown functions*/ //@{
116   void                  setMenuShown( QAction*, const bool );
117   void                  setMenuShown( const int, const bool );//@}
118   /** @name Set tool shown functions*/ //@{
119   void                  setToolShown( QAction*, const bool );
120   void                  setToolShown( const int, const bool );//@}
121
122   static QAction*       separator();
123   QAction*              action( const int ) const;
124   int                   actionId( const QAction* ) const;
125   void                  registerAction( const int, QAction* );
126   QAction*              createAction( const int, const QString&, const QIconSet&, const QString&,
127                                       const QString&, const int, QObject* = 0,
128                                       const bool = false, QObject* = 0, const char* = 0 );
129
130 protected slots:
131   virtual void          onDesktopActivated();
132
133 private:
134   SUIT_Study*           myStudy;
135   SUIT_Desktop*         myDesktop;
136 };
137
138 //! This function must return a new application instance.
139 extern "C"
140 {
141   //jfa 22.06.2005:typedef SUIT_Application* (*APP_CREATE_FUNC)( int, char** );
142   typedef SUIT_Application* (*APP_CREATE_FUNC)();
143 }
144
145 #define APP_CREATE_NAME "createApplication"
146
147 #endif