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