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 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;
88 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
90 void hideDialogs(std::string const & name, Inset * inset) const;
93 /// Return true if current position is RTL of if no document is open and interface if RTL
94 bool rtlContext() const;
97 Clipboard & clipboard();
99 Selection & selection();
101 FontLoader & fontLoader();
104 Toolbars const & toolbars() const;
106 Toolbars & toolbars();
108 Menus const & menus() const;
112 /// \name Methods inherited from QApplication class
114 bool notify(QObject * receiver, QEvent * event) override;
115 void commitData(QSessionManager & sm);
117 bool x11EventFilter(XEvent * ev) override;
118 #elif defined(QPA_XCB)
119 virtual bool nativeEventFilter(const QByteArray & eventType, void * message,
120 long * result) override;
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);
132 GuiView const * currentView() const { return current_view_; }
134 GuiView * currentView() { return current_view_; }
136 void setCurrentView(GuiView * view) { current_view_ = view; }
138 QList<int> viewIds() const;
140 /// Clear all session information.
144 ColorCache & colorCache();
146 QAbstractItemModel * languageModel();
148 /// return a suitable serif font name.
149 QString const romanFontName();
151 /// return a suitable sans serif font name.
152 QString const sansFontName();
154 /// return a suitable monospaced font name.
155 QString const typewriterFontName();
156 QFont const typewriterSystemFont();
159 void unregisterView(GuiView * gv);
161 GuiView & view(int id) const;
163 #if (QT_VERSION < 0x050000)
164 /// Emulate platformName() for Qt4
165 QString platformName() const;
168 /// Current ratio between physical pixels and device-independent pixels
169 double pixelRatio() const;
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;
176 return support::must_exist;
180 /// return true if the key is part of a shortcut
181 bool queryKeySym(KeySymbol const & key, KeyModifier state) const;
183 void processKeySym(KeySymbol const & key, KeyModifier state);
184 /// return the status bar state string
185 docstring viewStatusMessage();
187 /// \name Methods to process FuncRequests
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 &);
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);
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;
219 void execBatchCommands();
221 void socketDataReceived(int fd);
222 /// events to be triggered by Private::general_timer_ should go here
223 void handleRegularEvents();
225 void onLastWindowClosed();
227 void onLocaleChanged();
229 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
233 void validateCurrentView();
235 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
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);
250 ReturnValues readUIFile(support::FileName const & ui_path);
252 void setGuiLanguage();
254 void reconfigure(std::string const & option);
256 /// This GuiView is the one receiving Clipboard and Selection
258 GuiView * current_view_;
265 extern GuiApplication * guiApp;
267 /// \return the icon file name for the given action.
268 QString iconName(FuncRequest const & f, bool unknown,
269 QString const & suffix = QString());
271 /// \return the pixmap for the given path, name and extension.
272 /// in case of errors a warning is produced and an empty pixmap is returned.
273 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
275 /// \return an icon for the given action.
276 QIcon getIcon(FuncRequest const & f, bool unknown, bool rtl = false);
279 GuiApplication * theGuiApp();
281 } // namespace frontend
284 #endif // GUIAPPLICATION_H