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 "frontends/Application.h"
17 #include "support/filetools.h"
19 #include <QApplication>
22 #include <QAbstractNativeEventFilter>
25 class QAbstractItemModel;
27 class QSessionManager;
47 /// The Qt main application class
49 There should be only one instance of this class. No Qt object
50 initialisation should be done before the instantiation of this class.
52 class GuiApplication : public QApplication, public Application
54 , public QAbstractNativeEventFilter
60 GuiApplication(int & argc, char ** argv);
63 /// \name Methods inherited from Application class
65 void dispatch(FuncRequest const &);
66 void dispatch(FuncRequest const &, DispatchResult & dr);
67 FuncStatus getStatus(FuncRequest const & cmd) const;
68 void restoreGuiSession();
69 Buffer const * updateInset(Inset const * inset) const;
71 void exit(int status);
72 bool event(QEvent * e);
73 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
74 std::string const hexName(ColorCode col);
75 void registerSocketCallback(int fd, SocketCallback func);
76 void unregisterSocketCallback(int fd);
77 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
78 void handleKeyFunc(FuncCode action);
82 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
84 void hideDialogs(std::string const & name, Inset * inset) const;
89 Clipboard & clipboard();
91 Selection & selection();
93 FontLoader & fontLoader();
96 Toolbars const & toolbars() const;
98 Toolbars & toolbars();
100 Menus const & menus() const;
104 /// \name Methods inherited from QApplication class
106 bool notify(QObject * receiver, QEvent * event);
107 void commitData(QSessionManager & sm);
109 bool x11EventFilter(XEvent * ev);
110 #elif defined(QPA_XCB)
111 virtual bool nativeEventFilter(const QByteArray & eventType, void * message, long * result);
115 /// Create the main window with given geometry settings.
116 /// \param geometry_arg: only for Windows platform.
117 /// \param optional id identifier.
118 void createView(QString const & geometry_arg = QString(),
119 bool autoShow = true, int id = 0);
120 /// FIXME: this method and the one above are quite ugly.
121 void createView(int id);
123 GuiView const * currentView() const { return current_view_; }
125 GuiView * currentView() { return current_view_; }
127 void setCurrentView(GuiView * view) { current_view_ = view; }
129 QList<int> viewIds() const;
131 /// Clear all session information.
135 ColorCache & colorCache();
137 QAbstractItemModel * languageModel();
139 /// return a suitable serif font name.
140 QString const romanFontName();
142 /// return a suitable sans serif font name.
143 QString const sansFontName();
145 /// return a suitable monospaced font name.
146 QString const typewriterFontName();
148 void unregisterView(GuiView * gv);
150 GuiView & view(int id) const;
152 /// Current ratio between physical pixels and device-independent pixels
153 double pixelRatio() const;
155 /// How to load image files
156 support::search_mode imageSearchMode() const {
157 #if QT_VERSION >= 0x050000
158 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
160 return support::must_exist;
164 void processKeySym(KeySymbol const & key, KeyModifier state);
165 /// return the status bar state string
166 docstring viewStatusMessage();
168 /// \name Methods to process FuncRequests
170 /// process the func request
171 void processFuncRequest(FuncRequest const &);
172 /// add a func request to the queue and process it asynchronously
173 /// \note As a side-effect this will also process the
174 /// func requests that were added to the queue before.
175 void processFuncRequestAsync(FuncRequest const &);
176 /// process the func requests in the queue
177 void processFuncRequestQueue();
178 /// process the func requests in the queue asynchronously
179 void processFuncRequestQueueAsync();
180 /// add a func request to the queue for later processing
181 void addToFuncRequestQueue(FuncRequest const &);
185 /// openFile: whether or not open a file if the file is not opened
186 /// switchToBuffer: whether or not switch to buffer if the buffer is
187 /// not the current buffer
188 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
190 /// Start a long operation with some cancel possibility (button or ESC)
191 void startLongOperation();
192 /// This needs to be periodically called to avoid freezing the GUI
193 bool longOperationCancelled();
194 /// Stop the long operation mode (i.e., release the GUI)
195 void stopLongOperation();
196 /// A started long operation is still in progress ?
197 bool longOperationStarted();
200 void execBatchCommands();
202 void socketDataReceived(int fd);
203 /// events to be triggered by Private::general_timer_ should go here
204 void handleRegularEvents();
206 void onLastWindowClosed();
208 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
212 void validateCurrentView();
214 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
216 bool closeAllViews();
217 /// Things that need to be done when the OSes session manager
218 /// requests a log out.
219 bool prepareAllViewsForLogout();
220 /// read the given ui (menu/toolbar) file
221 bool readUIFile(QString const & name, bool include = false);
229 ReturnValues readUIFile(support::FileName);
231 void setGuiLanguage();
233 void reconfigure(std::string const & option);
235 /// This GuiView is the one receiving Clipboard and Selection
237 GuiView * current_view_;
244 extern GuiApplication * guiApp;
246 /// \return the icon file name for the given action.
247 QString iconName(FuncRequest const & f, bool unknown);
249 /// \return the pixmap for the given path, name and extension.
250 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
252 /// \return an icon for the given action.
253 QIcon getIcon(FuncRequest const & f, bool unknown);
256 GuiApplication * theGuiApp();
258 } // namespace frontend
261 #endif // GUIAPPLICATION_H