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);
103 bool x11EventFilter(XEvent * ev);
107 /// Create the main window with given geometry settings.
108 /// \param geometry_arg: only for Windows platform.
109 /// \param optional id identifier.
110 void createView(QString const & geometry_arg = QString(),
111 bool autoShow = true, int id = 0);
112 /// FIXME: this method and the one above are quite ugly.
113 void createView(int id);
115 GuiView const * currentView() const { return current_view_; }
117 GuiView * currentView() { return current_view_; }
119 void setCurrentView(GuiView * view) { current_view_ = view; }
121 QList<int> viewIds() const;
123 /// Clear all session information.
127 ColorCache & colorCache();
129 QAbstractItemModel * languageModel();
131 /// return a suitable serif font name.
132 QString const romanFontName();
134 /// return a suitable sans serif font name.
135 QString const sansFontName();
137 /// return a suitable monospaced font name.
138 QString const typewriterFontName();
140 void unregisterView(GuiView * gv);
142 GuiView & view(int id) const;
144 /// Current ratio between physical pixels and device-independent pixels
145 double pixelRatio() const;
147 /// How to load image files
148 support::search_mode imageSearchMode() const {
149 #if QT_VERSION >= 0x050000
150 return support::check_hidpi;
152 return support::must_exist;
156 void processKeySym(KeySymbol const & key, KeyModifier state);
157 /// return the status bar state string
158 docstring viewStatusMessage();
160 /// \name Methods to process FuncRequests
162 /// process the func request
163 void processFuncRequest(FuncRequest const &);
164 /// add a func request to the queue and process it asynchronously
165 /// \note As a side-effect this will also process the
166 /// func requests that were added to the queue before.
167 void processFuncRequestAsync(FuncRequest const &);
168 /// process the func requests in the queue
169 void processFuncRequestQueue();
170 /// process the func requests in the queue asynchronously
171 void processFuncRequestQueueAsync();
172 /// add a func request to the queue for later processing
173 void addToFuncRequestQueue(FuncRequest const &);
177 /// openFile: whether or not open a file if the file is not opened
178 /// switchToBuffer: whether or not switch to buffer if the buffer is
179 /// not the current buffer
180 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
182 /// Start a long operation with some cancel possibility (button or ESC)
183 void startLongOperation();
184 /// This needs to be periodically called to avoid freezing the GUI
185 bool longOperationCancelled();
186 /// Stop the long operation mode (i.e., release the GUI)
187 void stopLongOperation();
188 /// A started long operation is still in progress ?
189 bool longOperationStarted();
192 void execBatchCommands();
194 void socketDataReceived(int fd);
195 /// events to be triggered by Private::general_timer_ should go here
196 void handleRegularEvents();
198 void onLastWindowClosed();
200 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
204 void validateCurrentView();
206 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
208 bool closeAllViews();
209 /// read the given ui (menu/toolbar) file
210 bool readUIFile(QString const & name, bool include = false);
218 ReturnValues readUIFile(support::FileName);
220 void setGuiLanguage();
222 void reconfigure(std::string const & option);
224 /// This GuiView is the one receiving Clipboard and Selection
226 GuiView * current_view_;
233 extern GuiApplication * guiApp;
235 /// \return the icon file name for the given action.
236 QString iconName(FuncRequest const & f, bool unknown);
238 /// \return the pixmap for the given path, name and extension.
239 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
241 /// \return an icon for the given action.
242 QIcon getIcon(FuncRequest const & f, bool unknown);
245 GuiApplication * theGuiApp();
247 } // namespace frontend
250 #endif // GUIAPPLICATION_H