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;
86 bool isBufferBusy(Buffer const * b) override;
90 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
92 void hideDialogs(std::string const & name, Inset * inset) const;
95 /// Return true if current position is RTL of if no document is open and interface if RTL
96 bool rtlContext() const;
98 /// Scale Pixmaps properly (also for HiDPI)
99 QPixmap getScaledPixmap(QString imagedir, QString name) const;
102 Clipboard & clipboard();
104 Selection & selection();
106 FontLoader & fontLoader();
109 Toolbars const & toolbars() const;
111 Toolbars & toolbars();
113 Menus const & menus() const;
117 /// \returns true if painting the workarea requires a backing store.
118 bool needsBackingStore() const;
120 /// \name Methods inherited from QApplication class
122 bool notify(QObject * receiver, QEvent * event) override;
123 void commitData(QSessionManager & sm);
125 #if (QT_VERSION < 0x060000)
128 #define QINTPTR qintptr
130 virtual bool nativeEventFilter(const QByteArray & eventType, void * message,
131 QINTPTR * result) override;
135 /// Create the main window with given geometry settings.
136 /// \param geometry_arg: only for Windows platform.
137 /// \param optional id identifier.
138 void createView(QString const & geometry_arg = QString(),
139 bool autoShow = true, int id = 0);
140 /// FIXME: this method and the one above are quite ugly.
141 void createView(int id);
143 GuiView const * currentView() const { return current_view_; }
145 GuiView * currentView() { return current_view_; }
147 void setCurrentView(GuiView * view) { current_view_ = view; }
149 QList<int> viewIds() const;
151 /// Clear all session information.
155 ColorCache & colorCache();
157 QAbstractItemModel * languageModel();
159 /// return a suitable serif font name.
160 QString const romanFontName();
162 /// return a suitable sans serif font name.
163 QString const sansFontName();
165 /// return a suitable monospaced font name.
166 QString const typewriterFontName();
167 QFont const typewriterSystemFont();
170 void unregisterView(GuiView * gv);
172 GuiView & view(int id) const;
174 /// Current ratio between physical pixels and device-independent pixels
175 double pixelRatio() const;
177 /// How to load image files
178 support::search_mode imageSearchMode() const {
179 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
182 /// return true if the key is part of a shortcut
183 bool queryKeySym(KeySymbol const & key, KeyModifier state) const;
185 void processKeySym(KeySymbol const & key, KeyModifier state);
186 /// return the status bar state string
187 docstring viewStatusMessage();
189 /// \name Methods to process FuncRequests
191 /// process the func request
192 void processFuncRequest(FuncRequest const &);
193 /// add a func request to the queue and process it asynchronously
194 /// \note As a side-effect this will also process the
195 /// func requests that were added to the queue before.
196 void processFuncRequestAsync(FuncRequest const &);
197 /// process the func requests in the queue
198 void processFuncRequestQueue();
199 /// process the func requests in the queue asynchronously
200 void processFuncRequestQueueAsync();
201 /// add a func request to the queue for later processing
202 void addToFuncRequestQueue(FuncRequest const &);
206 /// openFile: whether or not open a file if the file is not opened
207 /// switchToBuffer: whether or not switch to buffer if the buffer is
208 /// not the current buffer
209 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
211 /// Start a long operation with some cancel possibility (button or ESC)
212 void startLongOperation() override;
213 /// This needs to be periodically called to avoid freezing the GUI
214 bool longOperationCancelled() override;
215 /// Stop the long operation mode (i.e., release the GUI)
216 void stopLongOperation() override;
217 /// A started long operation is still in progress ?
218 bool longOperationStarted() override;
221 void execBatchCommands();
223 void socketDataReceived(int fd);
224 /// events to be triggered by Private::general_timer_ should go here
225 void handleRegularEvents();
227 void onLastWindowClosed();
229 void onLocaleChanged();
231 void onPaletteChanged();
233 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
235 void onApplicationStateChanged(Qt::ApplicationState state);
239 void validateCurrentView();
241 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
243 bool closeAllViews();
244 /// Things that need to be done when the OSes session manager
245 /// requests a log out.
246 bool prepareAllViewsForLogout();
247 /// read the given ui (menu/toolbar) file
248 bool readUIFile(QString const & name, bool include = false);
256 ReturnValues readUIFile(support::FileName const & ui_path);
258 void setGuiLanguage();
260 void reconfigure(std::string const & option);
262 /// This GuiView is the one receiving Clipboard and Selection
264 GuiView * current_view_;
271 extern GuiApplication * guiApp;
274 /// Absolute path to icon file
276 /// Swap the icon in RTL mode
278 /// Invert the icon in dark mode
282 /// \return the pixmap for the given path, name and extension.
283 /// in case of errors a warning is produced and an empty pixmap is returned.
284 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
286 /// \return an icon for the given action.
287 QIcon getIcon(FuncRequest const & f, bool unknown, bool rtl = false);
290 GuiApplication * theGuiApp();
292 } // namespace frontend
295 #endif // GUIAPPLICATION_H