]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Do not close LyX in the commitData process (#9277)
[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 #include "support/filetools.h"
18
19 #include <QApplication>
20 #include <QList>
21
22 class QAbstractItemModel;
23 class QIcon;
24 class QSessionManager;
25
26 namespace lyx {
27
28 class BufferView;
29 class ColorCache;
30 class KeySymbol;
31
32 namespace support {
33 class FileName;
34 }
35
36 namespace frontend {
37
38 class GuiView;
39 class GuiWorkArea;
40 class Menus;
41 class SocketNotifier;
42 class Toolbars;
43
44 /// The Qt main application class
45 /**
46 There should be only one instance of this class. No Qt object
47 initialisation should be done before the instantiation of this class.
48 */
49 class GuiApplication : public QApplication, public Application
50 {
51         Q_OBJECT
52
53 public:
54         GuiApplication(int & argc, char ** argv);
55         ~GuiApplication();
56
57         /// \name Methods inherited from Application class
58         //@{
59         void dispatch(FuncRequest const &);
60         void dispatch(FuncRequest const &, DispatchResult & dr);
61         FuncStatus getStatus(FuncRequest const & cmd) const;
62         void restoreGuiSession();
63         Buffer const * updateInset(Inset const * inset) const;
64         int exec();
65         void exit(int status);
66         bool event(QEvent * e);
67         bool getRgbColor(ColorCode col, RGBColor & rgbcol);
68         std::string const hexName(ColorCode col);
69         void registerSocketCallback(int fd, SocketCallback func);
70         void unregisterSocketCallback(int fd);
71         bool searchMenu(FuncRequest const & func, docstring_list & names) const;
72         void handleKeyFunc(FuncCode action);
73         //@}
74
75         ///
76         bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
77         ///
78         void hideDialogs(std::string const & name, Inset * inset) const;
79         ///
80         void resetGui();
81
82         ///
83         Clipboard & clipboard();
84         ///
85         Selection & selection();
86         ///
87         FontLoader & fontLoader();
88
89         ///
90         Toolbars const & toolbars() const;
91         ///
92         Toolbars & toolbars();
93         ///
94         Menus const & menus() const;
95         ///
96         Menus & menus();
97
98         /// \name Methods inherited from QApplication class
99         //@{
100         bool notify(QObject * receiver, QEvent * event);
101         void commitData(QSessionManager & sm);
102         // FIXME QT5
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         /// Current ratio between physical pixels and device-independent pixels
146         double pixelRatio() const;
147
148         /// How to load image files
149         support::search_mode imageSearchMode() const {
150 #if QT_VERSION >= 0x050000
151                 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
152 #else
153                 return support::must_exist;
154 #endif
155         }
156
157         void processKeySym(KeySymbol const & key, KeyModifier state);
158         /// return the status bar state string
159         docstring viewStatusMessage();
160
161         /// \name Methods to process FuncRequests
162         //@{
163         /// process the func request
164         void processFuncRequest(FuncRequest const &);
165         /// add a func request to the queue and process it asynchronously
166         /// \note As a side-effect this will also process the
167         /// func requests that were added to the queue before.
168         void processFuncRequestAsync(FuncRequest const &);
169         /// process the func requests in the queue
170         void processFuncRequestQueue();
171         /// process the func requests in the queue asynchronously
172         void processFuncRequestQueueAsync();
173         /// add a func request to the queue for later processing
174         void addToFuncRequestQueue(FuncRequest const &);
175         //@}
176
177         /// goto a bookmark
178         /// openFile: whether or not open a file if the file is not opened
179         /// switchToBuffer: whether or not switch to buffer if the buffer is
180         ///             not the current buffer
181         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
182
183         /// Start a long operation with some cancel possibility (button or ESC)
184         void startLongOperation();
185         /// This needs to be periodically called to avoid freezing the GUI
186         bool longOperationCancelled();
187         /// Stop the long operation mode (i.e., release the GUI)
188         void stopLongOperation();
189         /// A started long operation is still in progress ?
190         bool longOperationStarted();
191 private Q_SLOTS:
192         ///
193         void execBatchCommands();
194         ///
195         void socketDataReceived(int fd);
196         /// events to be triggered by Private::general_timer_ should go here
197         void handleRegularEvents();
198         ///
199         void onLastWindowClosed();
200         ///
201         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
202
203 private:
204         ///
205         void validateCurrentView();
206         ///
207         void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
208         ///
209         bool closeAllViews();
210         /// Things that need to be done when the OSes session manager
211         /// requests a log out.
212         bool prepareAllViewsForLogout();
213         /// read the given ui (menu/toolbar) file
214         bool readUIFile(QString const & name, bool include = false);
215         ///
216         enum ReturnValues {
217                 ReadOK,
218                 ReadError,
219                 FormatMismatch
220         };
221         ///
222         ReturnValues readUIFile(support::FileName);
223         ///
224         void setGuiLanguage();
225         ///
226         void reconfigure(std::string const & option);
227
228         /// This GuiView is the one receiving Clipboard and Selection
229         /// events
230         GuiView * current_view_;
231
232         ///
233         struct Private;
234         Private * const d;
235 }; // GuiApplication
236
237 extern GuiApplication * guiApp;
238
239 /// \return the icon file name for the given action.
240 QString iconName(FuncRequest const & f, bool unknown);
241
242 /// \return the pixmap for the given path, name and extension.
243 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
244
245 /// \return an icon for the given action.
246 QIcon getIcon(FuncRequest const & f, bool unknown);
247
248 ///
249 GuiApplication * theGuiApp();
250
251 } // namespace frontend
252 } // namespace lyx
253
254 #endif // GUIAPPLICATION_H