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