]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
merge MenuBackend into frontend/Menus
[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         void restoreGuiSession();
65         virtual Clipboard & clipboard();
66         virtual Selection & selection();
67         virtual FontLoader & fontLoader() { return font_loader_; }
68         virtual int exec();
69         virtual void exit(int status);
70         virtual bool event(QEvent * e);
71         virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
72         virtual std::string const hexName(ColorCode col);
73         virtual void updateColor(ColorCode col);
74         virtual void readMenus(Lexer & lex);
75         virtual void registerSocketCallback(int fd, SocketCallback func);
76         void unregisterSocketCallback(int fd);
77         bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
78         //@}
79
80         Menus const & menus() const { return menus_; }
81         Menus & menus() { return menus_; }
82         /// Methods inherited from \c QApplication class
83         //@{
84         bool notify(QObject * receiver, QEvent * event);
85         void commitData(QSessionManager & sm);
86         //@}
87
88         /// Create the main window with given geometry settings.
89         /// \param geometry_arg: only for Windows platform.
90         void createView(QString const & geometry_arg);
91         ///
92         GuiView const * currentView() const { return current_view_; }
93         ///
94         GuiView * currentView() { return current_view_; }
95         ///
96         void setCurrentView(GuiView & view) { current_view_ = &view; }
97         ///
98         virtual size_t viewCount() const { return view_ids_.size(); }
99         ///
100         std::vector<int> const & viewIds() { return view_ids_; }
101
102         ///
103         ColorCache & colorCache() { return color_cache_; }
104         ///
105         GuiFontLoader & guiFontLoader() { return font_loader_; }
106
107         /// return a suitable serif font name.
108         virtual QString const romanFontName();
109
110         /// return a suitable sans serif font name.
111         virtual QString const sansFontName();
112
113         /// return a suitable monospaced font name.
114         virtual QString const typewriterFontName();
115         ///
116         virtual bool unregisterView(int id);
117         ///
118         virtual GuiView & view(int id) const;
119         ///
120         virtual void hideDialogs(std::string const & name, Inset * inset) const;
121         ///
122         virtual Buffer const * updateInset(Inset const * inset) const;
123
124 private Q_SLOTS:
125         ///
126         void execBatchCommands();
127         ///
128         void socketDataReceived(int fd);
129         /// events to be triggered by general_timer_ should go here
130         void handleRegularEvents();
131
132 private:
133         ///
134         bool closeAllViews();
135         ///
136         GuiClipboard clipboard_;
137         ///
138         GuiSelection selection_;
139         ///
140         GuiFontLoader font_loader_;
141         ///
142         ColorCache color_cache_;
143         ///
144         QTranslator qt_trans_;
145         ///
146         std::map<int, SocketNotifier *> socket_notifiers_;
147         ///
148         Menus menus_;
149         /// this timer is used for any regular events one wants to
150         /// perform. at present it is used to check if forked processes
151         /// are done.
152         QTimer general_timer_;
153
154 #ifdef Q_WS_X11
155 public:
156         bool x11EventFilter(XEvent * ev);
157 #endif
158         /// A translator suitable for the entries in the LyX menu.
159         /// Only needed with Qt/Mac.
160         void addMenuTranslator();
161
162         /// Multiple views container.
163         /**
164         * Warning: This must not be a smart pointer as the destruction of the
165         * object is handled by Qt when the view is closed
166         * \sa Qt::WA_DeleteOnClose attribute.
167         */
168         std::map<int, GuiView *> views_;
169         ///
170         std::vector<int> view_ids_;
171         /// This LyXView is the one receiving Clipboard and Selection
172         /// events
173         GuiView * current_view_;
174 }; // GuiApplication
175
176 extern GuiApplication * guiApp;
177
178 } // namespace frontend
179 } // namespace lyx
180
181 #endif // GUIAPPLICATION_H