]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Don't pretend we have multiple menu backends: transfer the singleton to GuiApplication.
[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
21 #include "frontends/Application.h"
22
23 #include "MenuBackend.h"
24
25 #include <QObject>
26 #include <QApplication>
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 menu_backend_; }
68         MenuBackend & menuBackend() { return menu_backend_; }
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         /// Methods inherited from \c QApplication class
80         //@{
81         bool notify(QObject * receiver, QEvent * event);
82         void commitData(QSessionManager & sm);
83         //@}
84
85         /// Create the main window with given geometry settings.
86         /// \param geometry_arg: only for Windows platform.
87         void createView(QString const & geometry_arg);
88         ///
89         GuiView const * currentView() const { return current_view_; }
90         ///
91         GuiView * currentView() { return current_view_; }
92         ///
93         void setCurrentView(GuiView & view) { current_view_ = &view; }
94         ///
95         virtual size_t viewCount() const { return view_ids_.size(); }
96         ///
97         std::vector<int> const & viewIds() { return view_ids_; }
98
99         ///
100         ColorCache & colorCache() { return color_cache_; }
101         ///
102         GuiFontLoader & guiFontLoader() { return font_loader_; }
103
104         /// return a suitable serif font name.
105         virtual QString const romanFontName();
106
107         /// return a suitable sans serif font name.
108         virtual QString const sansFontName();
109
110         /// return a suitable monospaced font name.
111         virtual QString const typewriterFontName();
112         ///
113         virtual bool unregisterView(int id);
114         ///
115         virtual GuiView & view(int id) const;
116         ///
117         virtual void hideDialogs(std::string const & name, Inset * inset) const;
118         ///
119         virtual Buffer const * updateInset(Inset const * inset) const;
120
121 private Q_SLOTS:
122         ///
123         void execBatchCommands();
124         ///
125         void socketDataReceived(int fd);
126
127 private:
128         ///
129         bool closeAllViews();
130         ///
131         GuiClipboard clipboard_;
132         ///
133         GuiSelection selection_;
134         ///
135         GuiFontLoader font_loader_;
136         ///
137         ColorCache color_cache_;
138         ///
139         QTranslator qt_trans_;
140         ///
141         std::map<int, SocketNotifier *> socket_notifiers_;
142         ///
143         MenuBackend menu_backend_;
144
145 #ifdef Q_WS_X11
146 public:
147         bool x11EventFilter(XEvent * ev);
148 #endif
149         /// A translator suitable for the entries in the LyX menu.
150         /// Only needed with Qt/Mac.
151         void addMenuTranslator();
152
153         /// Multiple views container.
154         /**
155         * Warning: This must not be a smart pointer as the destruction of the
156         * object is handled by Qt when the view is closed
157         * \sa Qt::WA_DeleteOnClose attribute.
158         */
159         std::map<int, GuiView *> views_;
160         ///
161         std::vector<int> view_ids_;
162         /// This LyXView is the one receiving Clipboard and Selection
163         /// events
164         GuiView * current_view_;
165 }; // GuiApplication
166
167 extern GuiApplication * guiApp;
168
169 } // namespace frontend
170 } // namespace lyx
171
172 #endif // GUIAPPLICATION_H