]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Restructure processFuncRequest* function family:
[lyx.git] / src / frontends / qt4 / GuiApplication.h
1 /**
2  * \file GuiApplication.h
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef GUIAPPLICATION_H
14 #define GUIAPPLICATION_H
15
16 #include "frontends/Application.h"
17
18 #include <QApplication>
19 #include <QList>
20
21 class QAbstractItemModel;
22 class QIcon;
23 class QObject;
24 class QSessionManager;
25 class QSortFilterProxyModel;
26
27 namespace lyx {
28
29 class BufferView;
30 class ColorCache;
31 class KeySymbol;
32
33 namespace frontend {
34
35 class GuiView;
36 class GlobalMenuBar;
37 class GuiWorkArea;
38 class Menus;
39 class SocketNotifier;
40 class Toolbars;
41
42 /// The Qt main application class
43 /**
44 There should be only one instance of this class. No Qt object
45 initialisation should be done before the instanciation of this class.
46 */
47 class GuiApplication : public QApplication, public Application
48 {
49         Q_OBJECT
50
51 public:
52         GuiApplication(int & argc, char ** argv);
53         ~GuiApplication();
54
55         /// \name Methods inherited from Application class
56         //@{
57         void dispatch(FuncRequest const &);
58         void dispatch(FuncRequest const &, DispatchResult & dr);
59         FuncStatus getStatus(FuncRequest const & cmd) const;
60         void restoreGuiSession();
61         Buffer const * updateInset(Inset const * inset) const;
62         int exec();
63         void exit(int status);
64         bool event(QEvent * e);
65         bool getRgbColor(ColorCode col, RGBColor & rgbcol);
66         std::string const hexName(ColorCode col);
67         void registerSocketCallback(int fd, SocketCallback func);
68         void unregisterSocketCallback(int fd);
69         bool searchMenu(FuncRequest const & func, docstring_list & names) const;
70         docstring iconName(FuncRequest const & f, bool unknown);
71         void handleKeyFunc(FuncCode action);
72         //@}
73
74         ///
75         bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
76         ///
77         void hideDialogs(std::string const & name, Inset * inset) const;
78         ///
79         void resetGui();
80
81         ///
82         Clipboard & clipboard();
83         ///
84         Selection & selection();
85         ///
86         FontLoader & fontLoader();
87
88         ///
89         Toolbars const & toolbars() const;
90         ///
91         Toolbars & toolbars();
92         ///
93         Menus const & menus() const;
94         ///
95         Menus & menus();
96
97         /// \name Methods inherited from QApplication class
98         //@{
99         bool notify(QObject * receiver, QEvent * event);
100         void commitData(QSessionManager & sm);
101 #ifdef Q_WS_X11
102         bool x11EventFilter(XEvent * ev);
103 #endif
104         //@}
105
106         /// Create the main window with given geometry settings.
107         /// \param geometry_arg: only for Windows platform.
108         /// \param optional id identifier.
109         void createView(QString const & geometry_arg = QString(),
110                 bool autoShow = true, int id = 0);
111         /// FIXME: this method and the one above are quite ugly.
112         void createView(int id);
113         ///
114         GuiView const * currentView() const { return current_view_; }
115         ///
116         GuiView * currentView() { return current_view_; }
117         ///
118         void setCurrentView(GuiView * view) { current_view_ = view; }
119         ///
120         QList<int> viewIds() const;
121         
122         /// Clear all session information.
123         void clearSession();
124
125         ///
126         ColorCache & colorCache();
127         ///
128         QAbstractItemModel * languageModel();
129
130         /// return a suitable serif font name.
131         QString const romanFontName();
132
133         /// return a suitable sans serif font name.
134         QString const sansFontName();
135
136         /// return a suitable monospaced font name.
137         QString const typewriterFontName();
138         ///
139         void unregisterView(GuiView * gv);
140         ///
141         GuiView & view(int id) const;
142         ///
143         void processKeySym(KeySymbol const & key, KeyModifier state);
144         /// return the status bar state string
145         docstring viewStatusMessage();
146
147         /// \name Methods to process FuncRequests
148         //@{
149         /// process the func request
150         void processFuncRequest(FuncRequest const &);
151         /// add a func request to the queue and process it asynchronously
152         /// \note As a side-effect this will also process the
153         /// func requests that were added to the queue before.
154         void processFuncRequestAsync(FuncRequest const &);
155         /// process the func requests in the queue
156         void processFuncRequestQueue();
157         /// process the func requests in the queue asynchronously
158         void processFuncRequestQueueAsync();
159         /// add a func request to the queue for later processing
160         void addToFuncRequestQueue(FuncRequest const &);
161         //@}
162
163         /// goto a bookmark
164         /// openFile: whether or not open a file if the file is not opened
165         /// switchToBuffer: whether or not switch to buffer if the buffer is
166         ///             not the current buffer
167         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
168
169 private Q_SLOTS:
170         ///
171         void execBatchCommands();
172         ///
173         void socketDataReceived(int fd);
174         /// events to be triggered by Private::general_timer_ should go here
175         void handleRegularEvents();
176         ///
177         void onLastWindowClosed();
178         ///
179         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
180
181 private:
182         ///
183         bool closeAllViews();
184         /// read the given ui (menu/toolbar) file
185         bool readUIFile(QString const & name, bool include = false);
186         ///
187         void setGuiLanguage();
188         ///
189         void reconfigure(std::string const & option);
190
191         /// This GuiView is the one receiving Clipboard and Selection
192         /// events
193         GuiView * current_view_;
194
195         ///
196         struct Private;
197         Private * const d;
198 }; // GuiApplication
199
200 extern GuiApplication * guiApp;
201
202 /// \return the icon file name for the given action.
203 QString iconName(FuncRequest const & f, bool unknown);
204
205 /// \return the pixmap for the given path, name and extension.
206 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
207
208 /// \return an icon for the given action.
209 QIcon getIcon(FuncRequest const & f, bool unknown);
210
211 ///
212 GuiApplication * theGuiApp();
213
214 } // namespace frontend
215 } // namespace lyx
216
217 #endif // GUIAPPLICATION_H