]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Fix crash in lyx -e latex lib/doc/Shortcuts.lyx: theApp() is 0 in batch mode.
[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 instantiation 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         void handleKeyFunc(FuncCode action);
71         //@}
72
73         ///
74         bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
75         ///
76         void hideDialogs(std::string const & name, Inset * inset) const;
77         ///
78         void resetGui();
79
80         ///
81         Clipboard & clipboard();
82         ///
83         Selection & selection();
84         ///
85         FontLoader & fontLoader();
86
87         ///
88         Toolbars const & toolbars() const;
89         ///
90         Toolbars & toolbars();
91         ///
92         Menus const & menus() const;
93         ///
94         Menus & menus();
95
96         /// \name Methods inherited from QApplication class
97         //@{
98         bool notify(QObject * receiver, QEvent * event);
99         void commitData(QSessionManager & sm);
100 #ifdef Q_WS_X11
101         bool x11EventFilter(XEvent * ev);
102 #endif
103         //@}
104
105         /// Create the main window with given geometry settings.
106         /// \param geometry_arg: only for Windows platform.
107         /// \param optional id identifier.
108         void createView(QString const & geometry_arg = QString(),
109                 bool autoShow = true, int id = 0);
110         /// FIXME: this method and the one above are quite ugly.
111         void createView(int id);
112         ///
113         GuiView const * currentView() const { return current_view_; }
114         ///
115         GuiView * currentView() { return current_view_; }
116         ///
117         void setCurrentView(GuiView * view) { current_view_ = view; }
118         ///
119         QList<int> viewIds() const;
120         
121         /// Clear all session information.
122         void clearSession();
123
124         ///
125         ColorCache & colorCache();
126         ///
127         QAbstractItemModel * languageModel();
128
129         /// return a suitable serif font name.
130         QString const romanFontName();
131
132         /// return a suitable sans serif font name.
133         QString const sansFontName();
134
135         /// return a suitable monospaced font name.
136         QString const typewriterFontName();
137         ///
138         void unregisterView(GuiView * gv);
139         ///
140         GuiView & view(int id) const;
141         ///
142         void processKeySym(KeySymbol const & key, KeyModifier state);
143         /// return the status bar state string
144         docstring viewStatusMessage();
145
146         /// \name Methods to process FuncRequests
147         //@{
148         /// process the func request
149         void processFuncRequest(FuncRequest const &);
150         /// add a func request to the queue and process it asynchronously
151         /// \note As a side-effect this will also process the
152         /// func requests that were added to the queue before.
153         void processFuncRequestAsync(FuncRequest const &);
154         /// process the func requests in the queue
155         void processFuncRequestQueue();
156         /// process the func requests in the queue asynchronously
157         void processFuncRequestQueueAsync();
158         /// add a func request to the queue for later processing
159         void addToFuncRequestQueue(FuncRequest const &);
160         //@}
161
162         /// goto a bookmark
163         /// openFile: whether or not open a file if the file is not opened
164         /// switchToBuffer: whether or not switch to buffer if the buffer is
165         ///             not the current buffer
166         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
167
168 private Q_SLOTS:
169         ///
170         void execBatchCommands();
171         ///
172         void socketDataReceived(int fd);
173         /// events to be triggered by Private::general_timer_ should go here
174         void handleRegularEvents();
175         ///
176         void onLastWindowClosed();
177         ///
178         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
179
180 private:
181         ///
182         bool closeAllViews();
183         /// read the given ui (menu/toolbar) file
184         bool readUIFile(QString const & name, bool include = false);
185         ///
186         void setGuiLanguage();
187         ///
188         void reconfigure(std::string const & option);
189
190         /// This GuiView is the one receiving Clipboard and Selection
191         /// events
192         GuiView * current_view_;
193
194         ///
195         struct Private;
196         Private * const d;
197 }; // GuiApplication
198
199 extern GuiApplication * guiApp;
200
201 /// \return the icon file name for the given action.
202 QString iconName(FuncRequest const & f, bool unknown);
203
204 /// \return the pixmap for the given path, name and extension.
205 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
206
207 /// \return an icon for the given action.
208 QIcon getIcon(FuncRequest const & f, bool unknown);
209
210 ///
211 GuiApplication * theGuiApp();
212
213 } // namespace frontend
214 } // namespace lyx
215
216 #endif // GUIAPPLICATION_H