2 * \file GuiApplication.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
13 #ifndef GUIAPPLICATION_H
14 #define GUIAPPLICATION_H
16 #include "KeyModifier.h"
18 #include "frontends/Application.h"
19 #include "support/filetools.h"
21 #include <QApplication>
24 #include <QAbstractNativeEventFilter>
27 class QAbstractItemModel;
29 class QSessionManager;
50 /// The Qt main application class
52 There should be only one instance of this class. No Qt object
53 initialisation should be done before the instantiation of this class.
55 class GuiApplication : public QApplication, public Application
57 , public QAbstractNativeEventFilter
63 GuiApplication(int & argc, char ** argv);
66 /// \name Methods inherited from Application class
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;
74 void exit(int status) override;
75 bool event(QEvent * e) override;
76 bool getRgbColor(ColorCode col, RGBColor & rgbcol) override;
77 bool isInDarkMode() override;
78 std::string const hexName(ColorCode col) override;
79 void registerSocketCallback(int fd, SocketCallback func) override;
80 void unregisterSocketCallback(int fd) override;
81 bool searchMenu(FuncRequest const & func, docstring_list & names) const override;
82 bool hasBufferView() const override;
83 std::string inputLanguageCode() const override;
84 void handleKeyFunc(FuncCode action) override;
85 bool unhide(Buffer * buf) override;
89 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
91 void hideDialogs(std::string const & name, Inset * inset) const;
94 /// Return true if current position is RTL of if no document is open and interface if RTL
95 bool rtlContext() const;
98 Clipboard & clipboard();
100 Selection & selection();
102 FontLoader & fontLoader();
105 Toolbars const & toolbars() const;
107 Toolbars & toolbars();
109 Menus const & menus() const;
113 /// \returns true if painting the workarea requires a backing store.
114 bool needsBackingStore() const;
116 /// \name Methods inherited from QApplication class
118 bool notify(QObject * receiver, QEvent * event) override;
119 void commitData(QSessionManager & sm);
121 virtual bool nativeEventFilter(const QByteArray & eventType, void * message,
122 long * result) override;
126 /// Create the main window with given geometry settings.
127 /// \param geometry_arg: only for Windows platform.
128 /// \param optional id identifier.
129 void createView(QString const & geometry_arg = QString(),
130 bool autoShow = true, int id = 0);
131 /// FIXME: this method and the one above are quite ugly.
132 void createView(int id);
134 GuiView const * currentView() const { return current_view_; }
136 GuiView * currentView() { return current_view_; }
138 void setCurrentView(GuiView * view) { current_view_ = view; }
140 QList<int> viewIds() const;
142 /// Clear all session information.
146 ColorCache & colorCache();
148 QAbstractItemModel * languageModel();
150 /// return a suitable serif font name.
151 QString const romanFontName();
153 /// return a suitable sans serif font name.
154 QString const sansFontName();
156 /// return a suitable monospaced font name.
157 QString const typewriterFontName();
158 QFont const typewriterSystemFont();
161 void unregisterView(GuiView * gv);
163 GuiView & view(int id) const;
165 /// Current ratio between physical pixels and device-independent pixels
166 double pixelRatio() const;
168 /// How to load image files
169 support::search_mode imageSearchMode() const {
170 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
173 /// return true if the key is part of a shortcut
174 bool queryKeySym(KeySymbol const & key, KeyModifier state) const;
176 void processKeySym(KeySymbol const & key, KeyModifier state);
177 /// return the status bar state string
178 docstring viewStatusMessage();
180 /// \name Methods to process FuncRequests
182 /// process the func request
183 void processFuncRequest(FuncRequest const &);
184 /// add a func request to the queue and process it asynchronously
185 /// \note As a side-effect this will also process the
186 /// func requests that were added to the queue before.
187 void processFuncRequestAsync(FuncRequest const &);
188 /// process the func requests in the queue
189 void processFuncRequestQueue();
190 /// process the func requests in the queue asynchronously
191 void processFuncRequestQueueAsync();
192 /// add a func request to the queue for later processing
193 void addToFuncRequestQueue(FuncRequest const &);
197 /// openFile: whether or not open a file if the file is not opened
198 /// switchToBuffer: whether or not switch to buffer if the buffer is
199 /// not the current buffer
200 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
202 /// Start a long operation with some cancel possibility (button or ESC)
203 void startLongOperation() override;
204 /// This needs to be periodically called to avoid freezing the GUI
205 bool longOperationCancelled() override;
206 /// Stop the long operation mode (i.e., release the GUI)
207 void stopLongOperation() override;
208 /// A started long operation is still in progress ?
209 bool longOperationStarted() override;
212 void execBatchCommands();
214 void socketDataReceived(int fd);
215 /// events to be triggered by Private::general_timer_ should go here
216 void handleRegularEvents();
218 void onLastWindowClosed();
220 void onLocaleChanged();
222 void onPaletteChanged();
224 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
226 #if (QT_VERSION >= 0x050100)
227 void onApplicationStateChanged(Qt::ApplicationState state);
232 void validateCurrentView();
234 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
236 bool closeAllViews();
237 /// Things that need to be done when the OSes session manager
238 /// requests a log out.
239 bool prepareAllViewsForLogout();
240 /// read the given ui (menu/toolbar) file
241 bool readUIFile(QString const & name, bool include = false);
249 ReturnValues readUIFile(support::FileName const & ui_path);
251 void setGuiLanguage();
253 void reconfigure(std::string const & option);
255 /// This GuiView is the one receiving Clipboard and Selection
257 GuiView * current_view_;
264 extern GuiApplication * guiApp;
267 /// Absolute path to icon file
269 /// Swap the icon in RTL mode
271 /// Invert the icon in dark mode
275 /// \return the pixmap for the given path, name and extension.
276 /// in case of errors a warning is produced and an empty pixmap is returned.
277 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
279 /// \return an icon for the given action.
280 QIcon getIcon(FuncRequest const & f, bool unknown, bool rtl = false);
283 GuiApplication * theGuiApp();
285 } // namespace frontend
288 #endif // GUIAPPLICATION_H