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