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;
24 class QSessionManager;
25 class QSortFilterProxyModel;
45 /// The Qt main application class
47 There should be only one instance of this class. No Qt object
48 initialisation should be done before the instantiation of this class.
50 class GuiApplication : public QApplication, public Application
55 GuiApplication(int & argc, char ** argv);
58 /// \name Methods inherited from Application class
60 void dispatch(FuncRequest const &);
61 void dispatch(FuncRequest const &, DispatchResult & dr);
62 FuncStatus getStatus(FuncRequest const & cmd) const;
63 void restoreGuiSession();
64 Buffer const * updateInset(Inset const * inset) const;
66 void exit(int status);
67 bool event(QEvent * e);
68 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
69 std::string const hexName(ColorCode col);
70 void registerSocketCallback(int fd, SocketCallback func);
71 void unregisterSocketCallback(int fd);
72 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
73 void handleKeyFunc(FuncCode action);
77 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
79 void hideDialogs(std::string const & name, Inset * inset) const;
84 Clipboard & clipboard();
86 Selection & selection();
88 FontLoader & fontLoader();
91 Toolbars const & toolbars() const;
93 Toolbars & toolbars();
95 Menus const & menus() const;
99 /// \name Methods inherited from QApplication class
101 bool notify(QObject * receiver, QEvent * event);
102 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 void processKeySym(KeySymbol const & key, KeyModifier state);
146 /// return the status bar state string
147 docstring viewStatusMessage();
149 /// \name Methods to process FuncRequests
151 /// process the func request
152 void processFuncRequest(FuncRequest const &);
153 /// add a func request to the queue and process it asynchronously
154 /// \note As a side-effect this will also process the
155 /// func requests that were added to the queue before.
156 void processFuncRequestAsync(FuncRequest const &);
157 /// process the func requests in the queue
158 void processFuncRequestQueue();
159 /// process the func requests in the queue asynchronously
160 void processFuncRequestQueueAsync();
161 /// add a func request to the queue for later processing
162 void addToFuncRequestQueue(FuncRequest const &);
166 /// openFile: whether or not open a file if the file is not opened
167 /// switchToBuffer: whether or not switch to buffer if the buffer is
168 /// not the current buffer
169 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
171 /// Start a long operation with some cancel possibility (button or ESC)
172 void startLongOperation();
173 /// This needs to be periodically called to avoid freezing the GUI
174 bool longOperationCancelled();
175 /// Stop the long operation mode (i.e., release the GUI)
176 void stopLongOperation();
177 /// A started long operation is still in progress ?
178 bool longOperationStarted();
181 void execBatchCommands();
183 void socketDataReceived(int fd);
184 /// events to be triggered by Private::general_timer_ should go here
185 void handleRegularEvents();
187 void onLastWindowClosed();
189 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
193 void validateCurrentView();
195 void updateCurrentView(FuncRequest const & cmd, DispatchResult & dr);
197 bool closeAllViews();
198 /// read the given ui (menu/toolbar) file
199 bool readUIFile(QString const & name, bool include = false);
207 ReturnValues readUIFile(support::FileName);
209 void setGuiLanguage();
211 void reconfigure(std::string const & option);
213 /// This GuiView is the one receiving Clipboard and Selection
215 GuiView * current_view_;
222 extern GuiApplication * guiApp;
224 /// \return the icon file name for the given action.
225 QString iconName(FuncRequest const & f, bool unknown);
227 /// \return the pixmap for the given path, name and extension.
228 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
230 /// \return an icon for the given action.
231 QIcon getIcon(FuncRequest const & f, bool unknown);
234 GuiApplication * theGuiApp();
236 } // namespace frontend
239 #endif // GUIAPPLICATION_H