]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Transfer forked process checking from GuiWorkArea to GuiApplication. I got rid of...
[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 "ColorCache.h"
17 #include "GuiFontLoader.h"
18 #include "GuiClipboard.h"
19 #include "GuiSelection.h"
20 #include "Menus.h"
21
22 #include "frontends/Application.h"
23
24 #include <QObject>
25 #include <QApplication>
26 #include <QTimer>
27 #include <QTranslator>
28
29 #include <map>
30 #include <vector>
31
32 class QSessionManager;
33
34 namespace lyx {
35
36 class BufferView;
37
38 namespace frontend {
39
40 class GuiView;
41 class LyXView;
42 class GuiWorkArea;
43 class SocketNotifier;
44
45 /// The Qt main application class
46 /**
47 There should be only one instance of this class. No Qt object
48 initialisation should be done before the instanciation of this class.
49 */
50 class GuiApplication : public QApplication, public Application
51 {
52         Q_OBJECT
53
54 public:
55         GuiApplication(int & argc, char ** argv);
56         ///
57         virtual ~GuiApplication();
58
59         /// Method inherited from \c Application class
60         //@{
61         virtual FuncStatus getStatus(FuncRequest const &);
62         virtual bool dispatch(FuncRequest const &);
63         virtual void resetGui();
64         virtual Clipboard & clipboard();
65         virtual Selection & selection();
66         virtual FontLoader & fontLoader() { return font_loader_; }
67         MenuBackend const & menuBackend() const { return menus_; }
68         MenuBackend & menuBackend() { return menus_; }
69         virtual int exec();
70         virtual void exit(int status);
71         virtual bool event(QEvent * e);
72         virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
73         virtual std::string const hexName(ColorCode col);
74         virtual void updateColor(ColorCode col);
75         virtual void registerSocketCallback(int fd, SocketCallback func);
76         void unregisterSocketCallback(int fd);
77         //@}
78
79         Menus const & menus() const { return menus_; }
80         Menus & menus() { return menus_; }
81         /// Methods inherited from \c QApplication class
82         //@{
83         bool notify(QObject * receiver, QEvent * event);
84         void commitData(QSessionManager & sm);
85         //@}
86
87         /// Create the main window with given geometry settings.
88         /// \param geometry_arg: only for Windows platform.
89         void createView(QString const & geometry_arg);
90         ///
91         GuiView const * currentView() const { return current_view_; }
92         ///
93         GuiView * currentView() { return current_view_; }
94         ///
95         void setCurrentView(GuiView & view) { current_view_ = &view; }
96         ///
97         virtual size_t viewCount() const { return view_ids_.size(); }
98         ///
99         std::vector<int> const & viewIds() { return view_ids_; }
100
101         ///
102         ColorCache & colorCache() { return color_cache_; }
103         ///
104         GuiFontLoader & guiFontLoader() { return font_loader_; }
105
106         /// return a suitable serif font name.
107         virtual QString const romanFontName();
108
109         /// return a suitable sans serif font name.
110         virtual QString const sansFontName();
111
112         /// return a suitable monospaced font name.
113         virtual QString const typewriterFontName();
114         ///
115         virtual bool unregisterView(int id);
116         ///
117         virtual GuiView & view(int id) const;
118         ///
119         virtual void hideDialogs(std::string const & name, Inset * inset) const;
120         ///
121         virtual Buffer const * updateInset(Inset const * inset) const;
122
123 private Q_SLOTS:
124         ///
125         void execBatchCommands();
126         ///
127         void socketDataReceived(int fd);
128         /// events to be triggered by general_timer_ should go here
129         void handleRegularEvents();
130
131 private:
132         ///
133         bool closeAllViews();
134         ///
135         GuiClipboard clipboard_;
136         ///
137         GuiSelection selection_;
138         ///
139         GuiFontLoader font_loader_;
140         ///
141         ColorCache color_cache_;
142         ///
143         QTranslator qt_trans_;
144         ///
145         std::map<int, SocketNotifier *> socket_notifiers_;
146         ///
147         Menus menus_;
148         /// this timer is used for any regular events one wants to
149         /// perform. at present it is used to check if forked processes
150         /// are done.
151         QTimer general_timer_;
152
153 #ifdef Q_WS_X11
154 public:
155         bool x11EventFilter(XEvent * ev);
156 #endif
157         /// A translator suitable for the entries in the LyX menu.
158         /// Only needed with Qt/Mac.
159         void addMenuTranslator();
160
161         /// Multiple views container.
162         /**
163         * Warning: This must not be a smart pointer as the destruction of the
164         * object is handled by Qt when the view is closed
165         * \sa Qt::WA_DeleteOnClose attribute.
166         */
167         std::map<int, GuiView *> views_;
168         ///
169         std::vector<int> view_ids_;
170         /// This LyXView is the one receiving Clipboard and Selection
171         /// events
172         GuiView * current_view_;
173 }; // GuiApplication
174
175 extern GuiApplication * guiApp;
176
177 } // namespace frontend
178 } // namespace lyx
179
180 #endif // GUIAPPLICATION_H