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