]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Also display the info about BibTeX databases in the TeX info panel.
[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 support {
34 class FileName;
35 }
36
37 namespace frontend {
38
39 class GuiView;
40 class GlobalMenuBar;
41 class GuiWorkArea;
42 class Menus;
43 class SocketNotifier;
44 class Toolbars;
45
46 /// The Qt main application class
47 /**
48 There should be only one instance of this class. No Qt object
49 initialisation should be done before the instantiation of this class.
50 */
51 class GuiApplication : public QApplication, public Application
52 {
53         Q_OBJECT
54
55 public:
56         GuiApplication(int & argc, char ** argv);
57         ~GuiApplication();
58
59         /// \name Methods inherited from Application class
60         //@{
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;
66         int exec();
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);
75         //@}
76
77         ///
78         bool getStatus(FuncRequest const & cmd, FuncStatus & status) const;
79         ///
80         void hideDialogs(std::string const & name, Inset * inset) const;
81         ///
82         void resetGui();
83
84         ///
85         Clipboard & clipboard();
86         ///
87         Selection & selection();
88         ///
89         FontLoader & fontLoader();
90
91         ///
92         Toolbars const & toolbars() const;
93         ///
94         Toolbars & toolbars();
95         ///
96         Menus const & menus() const;
97         ///
98         Menus & menus();
99
100         /// \name Methods inherited from QApplication class
101         //@{
102         bool notify(QObject * receiver, QEvent * event);
103         void commitData(QSessionManager & sm);
104 #ifdef Q_WS_X11
105         bool x11EventFilter(XEvent * ev);
106 #endif
107         //@}
108
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);
116         ///
117         GuiView const * currentView() const { return current_view_; }
118         ///
119         GuiView * currentView() { return current_view_; }
120         ///
121         void setCurrentView(GuiView * view) { current_view_ = view; }
122         ///
123         QList<int> viewIds() const;
124
125         /// Clear all session information.
126         void clearSession();
127
128         ///
129         ColorCache & colorCache();
130         ///
131         QAbstractItemModel * languageModel();
132
133         /// return a suitable serif font name.
134         QString const romanFontName();
135
136         /// return a suitable sans serif font name.
137         QString const sansFontName();
138
139         /// return a suitable monospaced font name.
140         QString const typewriterFontName();
141         ///
142         void unregisterView(GuiView * gv);
143         ///
144         GuiView & view(int id) const;
145         ///
146         void processKeySym(KeySymbol const & key, KeyModifier state);
147         /// return the status bar state string
148         docstring viewStatusMessage();
149
150         /// \name Methods to process FuncRequests
151         //@{
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 &);
164         //@}
165
166         /// goto a bookmark
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);
171
172 private Q_SLOTS:
173         ///
174         void execBatchCommands();
175         ///
176         void socketDataReceived(int fd);
177         /// events to be triggered by Private::general_timer_ should go here
178         void handleRegularEvents();
179         ///
180         void onLastWindowClosed();
181         ///
182         void slotProcessFuncRequestQueue() { processFuncRequestQueue(); }
183
184 private:
185         ///
186         void validateCurrentView();
187         ///
188         bool closeAllViews();
189         /// read the given ui (menu/toolbar) file
190         bool readUIFile(QString const & name, bool include = false);
191         ///
192         enum ReturnValues {
193                 ReadOK,
194                 ReadError,
195                 FormatMismatch
196         };
197         ///
198         ReturnValues readUIFile(support::FileName);
199         ///
200         void setGuiLanguage();
201         ///
202         void reconfigure(std::string const & option);
203
204         /// This GuiView is the one receiving Clipboard and Selection
205         /// events
206         GuiView * current_view_;
207
208         ///
209         struct Private;
210         Private * const d;
211 }; // GuiApplication
212
213 extern GuiApplication * guiApp;
214
215 /// \return the icon file name for the given action.
216 QString iconName(FuncRequest const & f, bool unknown);
217
218 /// \return the pixmap for the given path, name and extension.
219 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
220
221 /// \return an icon for the given action.
222 QIcon getIcon(FuncRequest const & f, bool unknown);
223
224 ///
225 GuiApplication * theGuiApp();
226
227 } // namespace frontend
228 } // namespace lyx
229
230 #endif // GUIAPPLICATION_H