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"
18 #include <QApplication>
21 class QAbstractItemModel;
41 /// The Qt main application class
43 There should be only one instance of this class. No Qt object
44 initialisation should be done before the instantiation of this class.
46 class GuiApplication : public QApplication, public Application
51 GuiApplication(int & argc, char ** argv);
54 /// \name Methods inherited from Application class
56 void dispatch(FuncRequest const &);
57 void dispatch(FuncRequest const &, DispatchResult & dr);
58 FuncStatus getStatus(FuncRequest const & cmd) const;
59 void restoreGuiSession();
60 Buffer const * updateInset(Inset const * inset) const;
62 void exit(int status);
63 bool event(QEvent * e);
64 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
65 std::string const hexName(ColorCode col);
66 void registerSocketCallback(int fd, SocketCallback func);
67 void unregisterSocketCallback(int fd);
68 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
69 void handleKeyFunc(FuncCode action);
73 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
75 void hideDialogs(std::string const & name, Inset * inset) const;
80 Clipboard & clipboard();
82 Selection & selection();
84 FontLoader & fontLoader();
87 Toolbars const & toolbars() const;
89 Toolbars & toolbars();
91 Menus const & menus() const;
95 /// \name Methods inherited from QApplication class
97 bool notify(QObject * receiver, QEvent * event);
98 void commitData(QSessionManager & sm);
100 bool x11EventFilter(XEvent * ev);
104 /// Create the main window with given geometry settings.
105 /// \param geometry_arg: only for Windows platform.
106 /// \param optional id identifier.
107 void createView(QString const & geometry_arg = QString(),
108 bool autoShow = true, int id = 0);
109 /// FIXME: this method and the one above are quite ugly.
110 void createView(int id);
112 GuiView const * currentView() const { return current_view_; }
114 GuiView * currentView() { return current_view_; }
116 void setCurrentView(GuiView * view) { current_view_ = view; }
118 QList<int> viewIds() const;
120 /// Clear all session information.
124 ColorCache & colorCache();
126 QAbstractItemModel * languageModel();
128 /// return a suitable serif font name.
129 QString const romanFontName();
131 /// return a suitable sans serif font name.
132 QString const sansFontName();
134 /// return a suitable monospaced font name.
135 QString const typewriterFontName();
137 void unregisterView(GuiView * gv);
139 GuiView & view(int id) const;
141 void processKeySym(KeySymbol const & key, KeyModifier state);
142 /// return the status bar state string
143 docstring viewStatusMessage();
145 /// \name Methods to process FuncRequests
147 /// process the func request
148 void processFuncRequest(FuncRequest const &);
149 /// add a func request to the queue and process it asynchronously
150 /// \note As a side-effect this will also process the
151 /// func requests that were added to the queue before.
152 void processFuncRequestAsync(FuncRequest const &);
153 /// process the func requests in the queue
154 void processFuncRequestQueue();
155 /// process the func requests in the queue asynchronously
156 void processFuncRequestQueueAsync();
157 /// add a func request to the queue for later processing
158 void addToFuncRequestQueue(FuncRequest const &);
162 /// openFile: whether or not open a file if the file is not opened
163 /// switchToBuffer: whether or not switch to buffer if the buffer is
164 /// not the current buffer
165 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
167 /// Start a long operation with some cancel possibility (button or ESC)
168 void startLongOperation();
169 /// This needs to be periodically called to avoid freezing the GUI
170 bool longOperationCancelled();
171 /// Stop the long operation mode (i.e., release the GUI)
172 void stopLongOperation();
173 /// A started long operation is still in progress ?
174 bool longOperationStarted();
177 void execBatchCommands();
179 void socketDataReceived(int fd);
180 /// events to be triggered by Private::general_timer_ should go here
181 void handleRegularEvents();
183 void onLastWindowClosed();
185 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
189 void validateCurrentView();
191 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
193 bool closeAllViews();
194 /// read the given ui (menu/toolbar) file
195 bool readUIFile(QString const & name, bool include = false);
203 ReturnValues readUIFile(support::FileName);
205 void setGuiLanguage();
207 void reconfigure(std::string const & option);
209 /// This GuiView is the one receiving Clipboard and Selection
211 GuiView * current_view_;
218 extern GuiApplication * guiApp;
220 /// \return the icon file name for the given action.
221 QString iconName(FuncRequest const & f, bool unknown);
223 /// \return the pixmap for the given path, name and extension.
224 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
226 /// \return an icon for the given action.
227 QIcon getIcon(FuncRequest const & f, bool unknown);
230 GuiApplication * theGuiApp();
232 } // namespace frontend
235 #endif // GUIAPPLICATION_H