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 class QAbstractItemModel;
24 class QSessionManager;
44 /// The Qt main application class
46 There should be only one instance of this class. No Qt object
47 initialisation should be done before the instantiation of this class.
49 class GuiApplication : public QApplication, public Application
54 GuiApplication(int & argc, char ** argv);
57 /// \name Methods inherited from Application class
59 void dispatch(FuncRequest const &);
60 void dispatch(FuncRequest const &, DispatchResult & dr);
61 FuncStatus getStatus(FuncRequest const & cmd) const;
62 void restoreGuiSession();
63 Buffer const * updateInset(Inset const * inset) const;
65 void exit(int status);
66 bool event(QEvent * e);
67 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
68 std::string const hexName(ColorCode col);
69 void registerSocketCallback(int fd, SocketCallback func);
70 void unregisterSocketCallback(int fd);
71 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
72 void handleKeyFunc(FuncCode action);
76 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
78 void hideDialogs(std::string const & name, Inset * inset) const;
83 Clipboard & clipboard();
85 Selection & selection();
87 FontLoader & fontLoader();
90 Toolbars const & toolbars() const;
92 Toolbars & toolbars();
94 Menus const & menus() const;
98 /// \name Methods inherited from QApplication class
100 bool notify(QObject * receiver, QEvent * event);
101 void commitData(QSessionManager & sm);
104 bool x11EventFilter(XEvent * ev);
108 /// Create the main window with given geometry settings.
109 /// \param geometry_arg: only for Windows platform.
110 /// \param optional id identifier.
111 void createView(QString const & geometry_arg = QString(),
112 bool autoShow = true, int id = 0);
113 /// FIXME: this method and the one above are quite ugly.
114 void createView(int id);
116 GuiView const * currentView() const { return current_view_; }
118 GuiView * currentView() { return current_view_; }
120 void setCurrentView(GuiView * view) { current_view_ = view; }
122 QList<int> viewIds() const;
124 /// Clear all session information.
128 ColorCache & colorCache();
130 QAbstractItemModel * languageModel();
132 /// return a suitable serif font name.
133 QString const romanFontName();
135 /// return a suitable sans serif font name.
136 QString const sansFontName();
138 /// return a suitable monospaced font name.
139 QString const typewriterFontName();
141 void unregisterView(GuiView * gv);
143 GuiView & view(int id) const;
145 /// Current ratio between physical pixels and device-independent pixels
146 double pixelRatio() const;
148 /// How to load image files
149 support::search_mode imageSearchMode() const {
150 #if QT_VERSION >= 0x050000
151 return pixelRatio() > 1 ? support::check_hidpi : support::must_exist;
153 return support::must_exist;
157 void processKeySym(KeySymbol const & key, KeyModifier state);
158 /// return the status bar state string
159 docstring viewStatusMessage();
161 /// \name Methods to process FuncRequests
163 /// process the func request
164 void processFuncRequest(FuncRequest const &);
165 /// add a func request to the queue and process it asynchronously
166 /// \note As a side-effect this will also process the
167 /// func requests that were added to the queue before.
168 void processFuncRequestAsync(FuncRequest const &);
169 /// process the func requests in the queue
170 void processFuncRequestQueue();
171 /// process the func requests in the queue asynchronously
172 void processFuncRequestQueueAsync();
173 /// add a func request to the queue for later processing
174 void addToFuncRequestQueue(FuncRequest const &);
178 /// openFile: whether or not open a file if the file is not opened
179 /// switchToBuffer: whether or not switch to buffer if the buffer is
180 /// not the current buffer
181 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
183 /// Start a long operation with some cancel possibility (button or ESC)
184 void startLongOperation();
185 /// This needs to be periodically called to avoid freezing the GUI
186 bool longOperationCancelled();
187 /// Stop the long operation mode (i.e., release the GUI)
188 void stopLongOperation();
189 /// A started long operation is still in progress ?
190 bool longOperationStarted();
193 void execBatchCommands();
195 void socketDataReceived(int fd);
196 /// events to be triggered by Private::general_timer_ should go here
197 void handleRegularEvents();
199 void onLastWindowClosed();
201 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
205 void validateCurrentView();
207 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
209 bool closeAllViews();
210 /// Things that need to be done when the OSes session manager
211 /// requests a log out.
212 bool prepareAllViewsForLogout();
213 /// read the given ui (menu/toolbar) file
214 bool readUIFile(QString const & name, bool include = false);
222 ReturnValues readUIFile(support::FileName);
224 void setGuiLanguage();
226 void reconfigure(std::string const & option);
228 /// This GuiView is the one receiving Clipboard and Selection
230 GuiView * current_view_;
237 extern GuiApplication * guiApp;
239 /// \return the icon file name for the given action.
240 QString iconName(FuncRequest const & f, bool unknown);
242 /// \return the pixmap for the given path, name and extension.
243 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
245 /// \return an icon for the given action.
246 QIcon getIcon(FuncRequest const & f, bool unknown);
249 GuiApplication * theGuiApp();
251 } // namespace frontend
254 #endif // GUIAPPLICATION_H