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;
48 /// The Qt main application class
50 There should be only one instance of this class. No Qt object
51 initialisation should be done before the instantiation of this class.
53 class GuiApplication : public QApplication, public Application
55 , public QAbstractNativeEventFilter
61 GuiApplication(int & argc, char ** argv);
64 /// \name Methods inherited from Application class
66 DispatchResult const & dispatch(FuncRequest const &);
67 void dispatch(FuncRequest const &, DispatchResult & dr);
68 FuncStatus getStatus(FuncRequest const & cmd) const;
69 void restoreGuiSession();
70 Buffer const * updateInset(Inset const * inset) const;
72 void exit(int status);
73 bool event(QEvent * e);
74 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
75 std::string const hexName(ColorCode col);
76 void registerSocketCallback(int fd, SocketCallback func);
77 void unregisterSocketCallback(int fd);
78 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
79 void handleKeyFunc(FuncCode action);
83 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
85 void hideDialogs(std::string const & name, Inset * inset) const;
90 Clipboard & clipboard();
92 Selection & selection();
94 FontLoader & fontLoader();
97 Toolbars const & toolbars() const;
99 Toolbars & toolbars();
101 Menus const & menus() const;
105 /// \name Methods inherited from QApplication class
107 bool notify(QObject * receiver, QEvent * event);
108 void commitData(QSessionManager & sm);
110 bool x11EventFilter(XEvent * ev);
111 #elif defined(QPA_XCB)
112 virtual bool nativeEventFilter(const QByteArray & eventType, void * message,
113 long * result) Q_DECL_OVERRIDE;
117 /// Create the main window with given geometry settings.
118 /// \param geometry_arg: only for Windows platform.
119 /// \param optional id identifier.
120 void createView(QString const & geometry_arg = QString(),
121 bool autoShow = true, int id = 0);
122 /// FIXME: this method and the one above are quite ugly.
123 void createView(int id);
125 GuiView const * currentView() const { return current_view_; }
127 GuiView * currentView() { return current_view_; }
129 void setCurrentView(GuiView * view) { current_view_ = view; }
131 QList<int> viewIds() const;
133 /// Clear all session information.
137 ColorCache & colorCache();
139 QAbstractItemModel * languageModel();
141 /// return a suitable serif font name.
142 QString const romanFontName();
144 /// return a suitable sans serif font name.
145 QString const sansFontName();
147 /// return a suitable monospaced font name.
148 QString const typewriterFontName();
149 QFont const typewriterSystemFont();
152 void unregisterView(GuiView * gv);
154 GuiView & view(int id) const;
156 /// Current ratio between physical pixels and device-independent pixels
157 double pixelRatio() const;
159 /// How to load image files
160 support::search_mode imageSearchMode() const {
161 #if QT_VERSION >= 0x050000
162 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
164 return support::must_exist;
168 void processKeySym(KeySymbol const & key, KeyModifier state);
169 /// return the status bar state string
170 docstring viewStatusMessage();
172 /// \name Methods to process FuncRequests
174 /// process the func request
175 void processFuncRequest(FuncRequest const &);
176 /// add a func request to the queue and process it asynchronously
177 /// \note As a side-effect this will also process the
178 /// func requests that were added to the queue before.
179 void processFuncRequestAsync(FuncRequest const &);
180 /// process the func requests in the queue
181 void processFuncRequestQueue();
182 /// process the func requests in the queue asynchronously
183 void processFuncRequestQueueAsync();
184 /// add a func request to the queue for later processing
185 void addToFuncRequestQueue(FuncRequest const &);
189 /// openFile: whether or not open a file if the file is not opened
190 /// switchToBuffer: whether or not switch to buffer if the buffer is
191 /// not the current buffer
192 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
194 /// Start a long operation with some cancel possibility (button or ESC)
195 void startLongOperation();
196 /// This needs to be periodically called to avoid freezing the GUI
197 bool longOperationCancelled();
198 /// Stop the long operation mode (i.e., release the GUI)
199 void stopLongOperation();
200 /// A started long operation is still in progress ?
201 bool longOperationStarted();
204 void execBatchCommands();
206 void socketDataReceived(int fd);
207 /// events to be triggered by Private::general_timer_ should go here
208 void handleRegularEvents();
210 void onLastWindowClosed();
212 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
216 void validateCurrentView();
218 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
220 bool closeAllViews();
221 /// Things that need to be done when the OSes session manager
222 /// requests a log out.
223 bool prepareAllViewsForLogout();
224 /// read the given ui (menu/toolbar) file
225 bool readUIFile(QString const & name, bool include = false);
233 ReturnValues readUIFile(support::FileName);
235 void setGuiLanguage();
237 void reconfigure(std::string const & option);
239 /// This GuiView is the one receiving Clipboard and Selection
241 GuiView * current_view_;
248 extern GuiApplication * guiApp;
250 /// \return the icon file name for the given action.
251 QString iconName(FuncRequest const & f, bool unknown);
253 /// \return the pixmap for the given path, name and extension.
254 /// in case of errors a warning is produced and an empty pixmap is returned.
255 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
256 /// Load the file at \param path and convert it to a pixmap.
257 /// \return true on success otherwise invalidate the pixmap and return false.
258 /// The caller is responsible for error reporting.
259 bool getPixmap(QPixmap & pixmap, QString const & path);
261 /// \return an icon for the given action.
262 QIcon getIcon(FuncRequest const & f, bool unknown);
265 GuiApplication * theGuiApp();
267 } // namespace frontend
270 #endif // GUIAPPLICATION_H