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;
46 /// The Qt main application class
48 There should be only one instance of this class. No Qt object
49 initialisation should be done before the instantiation of this class.
51 class GuiApplication : public QApplication, public Application
56 GuiApplication(int & argc, char ** argv);
59 /// \name Methods inherited from Application class
61 void dispatch(FuncRequest const &);
62 void dispatch(FuncRequest const &, DispatchResult & dr);
63 FuncStatus getStatus(FuncRequest const & cmd) const;
64 void restoreGuiSession();
65 Buffer const * updateInset(Inset const * inset) const;
67 void exit(int status);
68 bool event(QEvent * e);
69 bool getRgbColor(ColorCode col, RGBColor & rgbcol);
70 std::string const hexName(ColorCode col);
71 void registerSocketCallback(int fd, SocketCallback func);
72 void unregisterSocketCallback(int fd);
73 bool searchMenu(FuncRequest const & func, docstring_list & names) const;
74 void handleKeyFunc(FuncCode action);
78 bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
80 void hideDialogs(std::string const & name, Inset * inset) const;
85 Clipboard & clipboard();
87 Selection & selection();
89 FontLoader & fontLoader();
92 Toolbars const & toolbars() const;
94 Toolbars & toolbars();
96 Menus const & menus() const;
100 /// \name Methods inherited from QApplication class
102 bool notify(QObject * receiver, QEvent * event);
103 void commitData(QSessionManager & sm);
105 bool x11EventFilter(XEvent * ev);
109 /// Create the main window with given geometry settings.
110 /// \param geometry_arg: only for Windows platform.
111 /// \param optional id identifier.
112 void createView(QString const & geometry_arg = QString(),
113 bool autoShow = true, int id = 0);
114 /// FIXME: this method and the one above are quite ugly.
115 void createView(int id);
117 GuiView const * currentView() const { return current_view_; }
119 GuiView * currentView() { return current_view_; }
121 void setCurrentView(GuiView * view) { current_view_ = view; }
123 QList<int> viewIds() const;
125 /// Clear all session information.
129 ColorCache & colorCache();
131 QAbstractItemModel * languageModel();
133 /// return a suitable serif font name.
134 QString const romanFontName();
136 /// return a suitable sans serif font name.
137 QString const sansFontName();
139 /// return a suitable monospaced font name.
140 QString const typewriterFontName();
142 void unregisterView(GuiView * gv);
144 GuiView & view(int id) const;
146 void processKeySym(KeySymbol const & key, KeyModifier state);
147 /// return the status bar state string
148 docstring viewStatusMessage();
150 /// \name Methods to process FuncRequests
152 /// process the func request
153 void processFuncRequest(FuncRequest const &);
154 /// add a func request to the queue and process it asynchronously
155 /// \note As a side-effect this will also process the
156 /// func requests that were added to the queue before.
157 void processFuncRequestAsync(FuncRequest const &);
158 /// process the func requests in the queue
159 void processFuncRequestQueue();
160 /// process the func requests in the queue asynchronously
161 void processFuncRequestQueueAsync();
162 /// add a func request to the queue for later processing
163 void addToFuncRequestQueue(FuncRequest const &);
167 /// openFile: whether or not open a file if the file is not opened
168 /// switchToBuffer: whether or not switch to buffer if the buffer is
169 /// not the current buffer
170 void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
174 void execBatchCommands();
176 void socketDataReceived(int fd);
177 /// events to be triggered by Private::general_timer_ should go here
178 void handleRegularEvents();
180 void onLastWindowClosed();
182 void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
186 void validateCurrentView();
188 bool closeAllViews();
189 /// read the given ui (menu/toolbar) file
190 bool readUIFile(QString const & name, bool include = false);
198 ReturnValues readUIFile(support::FileName);
200 void setGuiLanguage();
202 void reconfigure(std::string const & option);
204 /// This GuiView is the one receiving Clipboard and Selection
206 GuiView * current_view_;
213 extern GuiApplication * guiApp;
215 /// \return the icon file name for the given action.
216 QString iconName(FuncRequest const & f, bool unknown);
218 /// \return the pixmap for the given path, name and extension.
219 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
221 /// \return an icon for the given action.
222 QIcon getIcon(FuncRequest const & f, bool unknown);
225 GuiApplication * theGuiApp();
227 } // namespace frontend
230 #endif // GUIAPPLICATION_H