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