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