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