]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Remove special GlobalMenuBar class. As Patrick De Visschere pointed out it is not...
[lyx.git] / src / frontends / qt4 / GuiApplication.h
1 /**
2  * \file GuiApplication.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUIAPPLICATION_H
14 #define GUIAPPLICATION_H
15
16 #include "frontends/Application.h"
17
18 #include <QApplication>
19 #include <QList>
20
21 class QAbstractItemModel;
22 class QIcon;
23 class QObject;
24 class QSessionManager;
25 class QSortFilterProxyModel;
26
27 namespace lyx {
28
29 class BufferView;
30 class ColorCache;
31 class KeySymbol;
32
33 namespace support {
34 class FileName;
35 }
36
37 namespace frontend {
38
39 class GuiView;
40 class GuiWorkArea;
41 class Menus;
42 class SocketNotifier;
43 class Toolbars;
44
45 /// The Qt main application class
46 /**
47 There should be only one instance of this class. No Qt object
48 initialisation should be done before the instantiation of this class.
49 */
50 class GuiApplication : public QApplication, public Application
51 {
52         Q_OBJECT
53
54 public:
55         GuiApplication(int & argc, char ** argv);
56         ~GuiApplication();
57
58         /// \name Methods inherited from Application class
59         //@{
60         void dispatch(FuncRequest const &);
61         void dispatch(FuncRequest const &, DispatchResult & dr);
62         FuncStatus getStatus(FuncRequest const & cmd) const;
63         void restoreGuiSession();
64         Buffer const * updateInset(Inset const * inset) const;
65         int exec();
66         void exit(int status);
67         bool event(QEvent * e);
68         bool getRgbColor(ColorCode col, RGBColor & rgbcol);
69         std::string const hexName(ColorCode col);
70         void registerSocketCallback(int fd, SocketCallback func);
71         void unregisterSocketCallback(int fd);
72         bool searchMenu(FuncRequest const & func, docstring_list & names) const;
73         void handleKeyFunc(FuncCode action);
74         //@}
75
76         ///
77         bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
78         ///
79         void hideDialogs(std::string const & name, Inset * inset) const;
80         ///
81         void resetGui();
82
83         ///
84         Clipboard & clipboard();
85         ///
86         Selection & selection();
87         ///
88         FontLoader & fontLoader();
89
90         ///
91         Toolbars const & toolbars() const;
92         ///
93         Toolbars & toolbars();
94         ///
95         Menus const & menus() const;
96         ///
97         Menus & menus();
98
99         /// \name Methods inherited from QApplication class
100         //@{
101         bool notify(QObject * receiver, QEvent * event);
102         void commitData(QSessionManager & sm);
103 #ifdef Q_WS_X11
104         bool x11EventFilter(XEvent * ev);
105 #endif
106         //@}
107
108         /// Create the main window with given geometry settings.
109         /// \param geometry_arg: only for Windows platform.
110         /// \param optional id identifier.
111         void createView(QString const & geometry_arg = QString(),
112                 bool autoShow = true, int id = 0);
113         /// FIXME: this method and the one above are quite ugly.
114         void createView(int id);
115         ///
116         GuiView const * currentView() const { return current_view_; }
117         ///
118         GuiView * currentView() { return current_view_; }
119         ///
120         void setCurrentView(GuiView * view) { current_view_ = view; }
121         ///
122         QList<int> viewIds() const;
123
124         /// Clear all session information.
125         void clearSession();
126
127         ///
128         ColorCache & colorCache();
129         ///
130         QAbstractItemModel * languageModel();
131
132         /// return a suitable serif font name.
133         QString const romanFontName();
134
135         /// return a suitable sans serif font name.
136         QString const sansFontName();
137
138         /// return a suitable monospaced font name.
139         QString const typewriterFontName();
140         ///
141         void unregisterView(GuiView * gv);
142         ///
143         GuiView & view(int id) const;
144         ///
145         void processKeySym(KeySymbol const & key, KeyModifier state);
146         /// return the status bar state string
147         docstring viewStatusMessage();
148
149         /// \name Methods to process FuncRequests
150         //@{
151         /// process the func request
152         void processFuncRequest(FuncRequest const &);
153         /// add a func request to the queue and process it asynchronously
154         /// \note As a side-effect this will also process the
155         /// func requests that were added to the queue before.
156         void processFuncRequestAsync(FuncRequest const &);
157         /// process the func requests in the queue
158         void processFuncRequestQueue();
159         /// process the func requests in the queue asynchronously
160         void processFuncRequestQueueAsync();
161         /// add a func request to the queue for later processing
162         void addToFuncRequestQueue(FuncRequest const &);
163         //@}
164
165         /// goto a bookmark
166         /// openFile: whether or not open a file if the file is not opened
167         /// switchToBuffer: whether or not switch to buffer if the buffer is
168         ///             not the current buffer
169         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
170
171         /// Start a long operation with some cancel possibility (button or ESC)
172         void startLongOperation();
173         /// This needs to be periodically called to avoid freezing the GUI
174         bool longOperationCancelled();
175         /// Stop the long operation mode (i.e., release the GUI)
176         void stopLongOperation();
177         /// A started long operation is still in progress ?
178         bool longOperationStarted();
179 private Q_SLOTS:
180         ///
181         void execBatchCommands();
182         ///
183         void socketDataReceived(int fd);
184         /// events to be triggered by Private::general_timer_ should go here
185         void handleRegularEvents();
186         ///
187         void onLastWindowClosed();
188         ///
189         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
190
191 private:
192         ///
193         void validateCurrentView();
194         ///
195         void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
196         ///
197         bool closeAllViews();
198         /// read the given ui (menu/toolbar) file
199         bool readUIFile(QString const & name, bool include = false);
200         ///
201         enum ReturnValues {
202                 ReadOK,
203                 ReadError,
204                 FormatMismatch
205         };
206         ///
207         ReturnValues readUIFile(support::FileName);
208         ///
209         void setGuiLanguage();
210         ///
211         void reconfigure(std::string const & option);
212
213         /// This GuiView is the one receiving Clipboard and Selection
214         /// events
215         GuiView * current_view_;
216
217         ///
218         struct Private;
219         Private * const d;
220 }; // GuiApplication
221
222 extern GuiApplication * guiApp;
223
224 /// \return the icon file name for the given action.
225 QString iconName(FuncRequest const & f, bool unknown);
226
227 /// \return the pixmap for the given path, name and extension.
228 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
229
230 /// \return an icon for the given action.
231 QIcon getIcon(FuncRequest const & f, bool unknown);
232
233 ///
234 GuiApplication * theGuiApp();
235
236 } // namespace frontend
237 } // namespace lyx
238
239 #endif // GUIAPPLICATION_H