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