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