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