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 DispatchResult const & 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,
112 long * result) Q_DECL_OVERRIDE;
116 /// Create the main window with given geometry settings.
117 /// \param geometry_arg: only for Windows platform.
118 /// \param optional id identifier.
119 void createView(QString const & geometry_arg = QString(),
120 bool autoShow = true, int id = 0);
121 /// FIXME: this method and the one above are quite ugly.
122 void createView(int id);
124 GuiView const * currentView() const { return current_view_; }
126 GuiView * currentView() { return current_view_; }
128 void setCurrentView(GuiView * view) { current_view_ = view; }
130 QList<int> viewIds() const;
132 /// Clear all session information.
136 ColorCache & colorCache();
138 QAbstractItemModel * languageModel();
140 /// return a suitable serif font name.
141 QString const romanFontName();
143 /// return a suitable sans serif font name.
144 QString const sansFontName();
146 /// return a suitable monospaced font name.
147 QString const typewriterFontName();
149 void unregisterView(GuiView * gv);
151 GuiView & view(int id) const;
153 /// Current ratio between physical pixels and device-independent pixels
154 double pixelRatio() const;
156 /// How to load image files
157 support::search_mode imageSearchMode() const {
158 #if QT_VERSION >= 0x050000
159 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
161 return support::must_exist;
165 void processKeySym(KeySymbol const & key, KeyModifier state);
166 /// return the status bar state string
167 docstring viewStatusMessage();
169 /// \name Methods to process FuncRequests
171 /// process the func request
172 void processFuncRequest(FuncRequest const &);
173 /// add a func request to the queue and process it asynchronously
174 /// \note As a side-effect this will also process the
175 /// func requests that were added to the queue before.
176 void processFuncRequestAsync(FuncRequest const &);
177 /// process the func requests in the queue
178 void processFuncRequestQueue();
179 /// process the func requests in the queue asynchronously
180 void processFuncRequestQueueAsync();
181 /// add a func request to the queue for later processing
182 void addToFuncRequestQueue(FuncRequest const &);
186 /// openFile: whether or not open a file if the file is not opened
187 /// switchToBuffer: whether or not switch to buffer if the buffer is
188 /// not the current buffer
189 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
191 /// Start a long operation with some cancel possibility (button or ESC)
192 void startLongOperation();
193 /// This needs to be periodically called to avoid freezing the GUI
194 bool longOperationCancelled();
195 /// Stop the long operation mode (i.e., release the GUI)
196 void stopLongOperation();
197 /// A started long operation is still in progress ?
198 bool longOperationStarted();
201 void execBatchCommands();
203 void socketDataReceived(int fd);
204 /// events to be triggered by Private::general_timer_ should go here
205 void handleRegularEvents();
207 void onLastWindowClosed();
209 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
213 void validateCurrentView();
215 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
217 bool closeAllViews();
218 /// Things that need to be done when the OSes session manager
219 /// requests a log out.
220 bool prepareAllViewsForLogout();
221 /// read the given ui (menu/toolbar) file
222 bool readUIFile(QString const & name, bool include = false);
230 ReturnValues readUIFile(support::FileName);
232 void setGuiLanguage();
234 void reconfigure(std::string const & option);
236 /// This GuiView is the one receiving Clipboard and Selection
238 GuiView * current_view_;
245 extern GuiApplication * guiApp;
247 /// \return the icon file name for the given action.
248 QString iconName(FuncRequest const & f, bool unknown);
250 /// \return the pixmap for the given path, name and extension.
251 /// in case of errors a warning is produced and an empty pixmap is returned.
252 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
253 /// Load the file at \param path and convert it to a pixmap.
254 /// \return true on success otherwise invalidate the pixmap and return false.
255 /// The caller is responsible for error reporting.
256 bool getPixmap(QPixmap & pixmap, QString const & path);
258 /// \return an icon for the given action.
259 QIcon getIcon(FuncRequest const & f, bool unknown);
262 GuiApplication * theGuiApp();
264 } // namespace frontend
267 #endif // GUIAPPLICATION_H