]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
#9130 Text in main work area isn't rendered with high resolution
[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         void 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, long * result);
112 #endif
113         //@}
114
115         /// Create the main window with given geometry settings.
116         /// \param geometry_arg: only for Windows platform.
117         /// \param optional id identifier.
118         void createView(QString const & geometry_arg = QString(),
119                 bool autoShow = true, int id = 0);
120         /// FIXME: this method and the one above are quite ugly.
121         void createView(int id);
122         ///
123         GuiView const * currentView() const { return current_view_; }
124         ///
125         GuiView * currentView() { return current_view_; }
126         ///
127         void setCurrentView(GuiView * view) { current_view_ = view; }
128         ///
129         QList<int> viewIds() const;
130
131         /// Clear all session information.
132         void clearSession();
133
134         ///
135         ColorCache & colorCache();
136         ///
137         QAbstractItemModel * languageModel();
138
139         /// return a suitable serif font name.
140         QString const romanFontName();
141
142         /// return a suitable sans serif font name.
143         QString const sansFontName();
144
145         /// return a suitable monospaced font name.
146         QString const typewriterFontName();
147         ///
148         void unregisterView(GuiView * gv);
149         ///
150         GuiView & view(int id) const;
151
152         /// Current ratio between physical pixels and device-independent pixels
153         double pixelRatio() const;
154
155         /// How to load image files
156         support::search_mode imageSearchMode() const {
157 #if QT_VERSION >= 0x050000
158                 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
159 #else
160                 return support::must_exist;
161 #endif
162         }
163
164         void processKeySym(KeySymbol const & key, KeyModifier state);
165         /// return the status bar state string
166         docstring viewStatusMessage();
167
168         /// \name Methods to process FuncRequests
169         //@{
170         /// process the func request
171         void processFuncRequest(FuncRequest const &);
172         /// add a func request to the queue and process it asynchronously
173         /// \note As a side-effect this will also process the
174         /// func requests that were added to the queue before.
175         void processFuncRequestAsync(FuncRequest const &);
176         /// process the func requests in the queue
177         void processFuncRequestQueue();
178         /// process the func requests in the queue asynchronously
179         void processFuncRequestQueueAsync();
180         /// add a func request to the queue for later processing
181         void addToFuncRequestQueue(FuncRequest const &);
182         //@}
183
184         /// goto a bookmark
185         /// openFile: whether or not open a file if the file is not opened
186         /// switchToBuffer: whether or not switch to buffer if the buffer is
187         ///             not the current buffer
188         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
189
190         /// Start a long operation with some cancel possibility (button or ESC)
191         void startLongOperation();
192         /// This needs to be periodically called to avoid freezing the GUI
193         bool longOperationCancelled();
194         /// Stop the long operation mode (i.e., release the GUI)
195         void stopLongOperation();
196         /// A started long operation is still in progress ?
197         bool longOperationStarted();
198 private Q_SLOTS:
199         ///
200         void execBatchCommands();
201         ///
202         void socketDataReceived(int fd);
203         /// events to be triggered by Private::general_timer_ should go here
204         void handleRegularEvents();
205         ///
206         void onLastWindowClosed();
207         ///
208         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
209
210 private:
211         ///
212         void validateCurrentView();
213         ///
214         void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
215         ///
216         bool closeAllViews();
217         /// Things that need to be done when the OSes session manager
218         /// requests a log out.
219         bool prepareAllViewsForLogout();
220         /// read the given ui (menu/toolbar) file
221         bool readUIFile(QString const & name, bool include = false);
222         ///
223         enum ReturnValues {
224                 ReadOK,
225                 ReadError,
226                 FormatMismatch
227         };
228         ///
229         ReturnValues readUIFile(support::FileName);
230         ///
231         void setGuiLanguage();
232         ///
233         void reconfigure(std::string const & option);
234
235         /// This GuiView is the one receiving Clipboard and Selection
236         /// events
237         GuiView * current_view_;
238
239         ///
240         struct Private;
241         Private * const d;
242 }; // GuiApplication
243
244 extern GuiApplication * guiApp;
245
246 /// \return the icon file name for the given action.
247 QString iconName(FuncRequest const & f, bool unknown);
248
249 /// \return the pixmap for the given path, name and extension.
250 /// in case of errors a warning is produced and an empty pixmap is returned.
251 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
252 /// Load the file at \param path and convert it to a pixmap.
253 /// \return true on success otherwise invalidate the pixmap and return false.
254 /// The caller is responsible for error reporting.
255 bool getPixmap(QPixmap & pixmap, QString const & path);
256
257 /// \return an icon for the given action.
258 QIcon getIcon(FuncRequest const & f, bool unknown);
259
260 ///
261 GuiApplication * theGuiApp();
262
263 } // namespace frontend
264 } // namespace lyx
265
266 #endif // GUIAPPLICATION_H