]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Fix gcc compilation and warning.
[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 QAbstractItemModel;
34 class QSortFilterProxyModel;
35
36 namespace lyx {
37
38 class BufferView;
39
40 namespace frontend {
41
42 class GuiView;
43 class LyXView;
44 class GlobalMenuBar;
45 class GuiWorkArea;
46 class SocketNotifier;
47
48 /// The Qt main application class
49 /**
50 There should be only one instance of this class. No Qt object
51 initialisation should be done before the instanciation of this class.
52 */
53 class GuiApplication : public QApplication, public Application
54 {
55         Q_OBJECT
56
57 public:
58         GuiApplication(int & argc, char ** argv);
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                 bool autoShow = true);
94         ///
95         GuiView const * currentView() const { return current_view_; }
96         ///
97         GuiView * currentView() { return current_view_; }
98         ///
99         void setCurrentView(GuiView * view) { current_view_ = view; }
100         ///
101         virtual size_t viewCount() const { return view_ids_.size(); }
102         ///
103         std::vector<int> const & viewIds() { return view_ids_; }
104
105         ///
106         ColorCache & colorCache() { return color_cache_; }
107
108         QAbstractItemModel * languageModel();
109
110         /// return a suitable serif font name.
111         virtual QString const romanFontName();
112
113         /// return a suitable sans serif font name.
114         virtual QString const sansFontName();
115
116         /// return a suitable monospaced font name.
117         virtual QString const typewriterFontName();
118         ///
119         virtual bool unregisterView(int id);
120         ///
121         virtual GuiView & view(int id) const;
122         ///
123         virtual void hideDialogs(std::string const & name, Inset * inset) const;
124         ///
125         virtual Buffer const * updateInset(Inset const * inset) const;
126
127 private Q_SLOTS:
128         ///
129         void execBatchCommands();
130         ///
131         void socketDataReceived(int fd);
132         /// events to be triggered by general_timer_ should go here
133         void handleRegularEvents();
134         ///
135         void onLastWindowClosed();
136         
137 private:
138         ///
139         bool closeAllViews();
140         ///
141         GuiClipboard clipboard_;
142         ///
143         GuiSelection selection_;
144         ///
145         FontLoader font_loader_;
146         ///
147         ColorCache color_cache_;
148         ///
149         QSortFilterProxyModel * language_model_;
150         ///
151         QTranslator qt_trans_;
152         ///
153         std::map<int, SocketNotifier *> socket_notifiers_;
154         ///
155         Menus menus_;
156         /// this timer is used for any regular events one wants to
157         /// perform. at present it is used to check if forked processes
158         /// are done.
159         QTimer general_timer_;
160
161 #ifdef Q_WS_X11
162 public:
163         bool x11EventFilter(XEvent * ev);
164 #endif
165         /// A translator suitable for the entries in the LyX menu.
166         /// Only needed with Qt/Mac.
167         void addMenuTranslator();
168
169         /// Multiple views container.
170         /**
171         * Warning: This must not be a smart pointer as the destruction of the
172         * object is handled by Qt when the view is closed
173         * \sa Qt::WA_DeleteOnClose attribute.
174         */
175         std::map<int, GuiView *> views_;
176         ///
177         std::vector<int> view_ids_;
178         /// This LyXView is the one receiving Clipboard and Selection
179         /// events
180         GuiView * current_view_;
181         /// only used on mac
182         GlobalMenuBar * global_menubar_;
183 }; // GuiApplication
184
185 extern GuiApplication * guiApp;
186
187 } // namespace frontend
188 } // namespace lyx
189
190 #endif // GUIAPPLICATION_H