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