]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
- Move as much platform specific stuff as possible to GuiApplication.cpp
[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         ~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 #ifdef Q_WS_X11
90         bool x11EventFilter(XEvent * ev);
91 #endif
92         //@}
93
94         /// Create the main window with given geometry settings.
95         /// \param geometry_arg: only for Windows platform.
96         void createView(QString const & geometry_arg = QString(),
97                 bool autoShow = true);
98         ///
99         GuiView const * currentView() const { return current_view_; }
100         ///
101         GuiView * currentView() { return current_view_; }
102         ///
103         void setCurrentView(GuiView * view) { current_view_ = view; }
104         ///
105         virtual size_t viewCount() const { return view_ids_.size(); }
106         ///
107         std::vector<int> const & viewIds() { return view_ids_; }
108
109         ///
110         ColorCache & colorCache() { return color_cache_; }
111
112         QAbstractItemModel * languageModel();
113
114         /// return a suitable serif font name.
115         virtual QString const romanFontName();
116
117         /// return a suitable sans serif font name.
118         virtual QString const sansFontName();
119
120         /// return a suitable monospaced font name.
121         virtual QString const typewriterFontName();
122         ///
123         virtual bool unregisterView(int id);
124         ///
125         virtual GuiView & view(int id) const;
126         ///
127         virtual void hideDialogs(std::string const & name, Inset * inset) const;
128         ///
129         virtual Buffer const * updateInset(Inset const * inset) const;
130
131 private Q_SLOTS:
132         ///
133         void execBatchCommands();
134         ///
135         void socketDataReceived(int fd);
136         /// events to be triggered by general_timer_ should go here
137         void handleRegularEvents();
138         ///
139         void onLastWindowClosed();
140         
141 private:
142         ///
143         bool closeAllViews();
144         ///
145         GuiClipboard clipboard_;
146         ///
147         GuiSelection selection_;
148         ///
149         FontLoader font_loader_;
150         ///
151         ColorCache color_cache_;
152         ///
153         QSortFilterProxyModel * language_model_;
154         ///
155         QTranslator qt_trans_;
156         ///
157         std::map<int, SocketNotifier *> socket_notifiers_;
158         ///
159         Menus menus_;
160         /// this timer is used for any regular events one wants to
161         /// perform. at present it is used to check if forked processes
162         /// are done.
163         QTimer general_timer_;
164
165         /// Multiple views container.
166         /**
167         * Warning: This must not be a smart pointer as the destruction of the
168         * object is handled by Qt when the view is closed
169         * \sa Qt::WA_DeleteOnClose attribute.
170         */
171         std::map<int, GuiView *> views_;
172         ///
173         std::vector<int> view_ids_;
174         /// This LyXView is the one receiving Clipboard and Selection
175         /// events
176         GuiView * current_view_;
177         ///
178         struct Private;
179         Private * const d;
180 }; // GuiApplication
181
182 extern GuiApplication * guiApp;
183
184 } // namespace frontend
185 } // namespace lyx
186
187 #endif // GUIAPPLICATION_H