]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Spoiling some fun from Andre': put Application on a diet and remove unnecessary strin...
[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 Clipboard & clipboard();
60         virtual Selection & selection();
61         virtual FontLoader & fontLoader() { return font_loader_; }
62         virtual int exec();
63         virtual void exit(int status);
64         virtual bool event(QEvent * e);
65         virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
66         virtual std::string const hexName(ColorCode col);
67         virtual void updateColor(ColorCode col);
68         virtual void registerSocketCallback(int fd, SocketCallback func);
69         void unregisterSocketCallback(int fd);
70         LyXView & createView(std::string const & geometry_arg);
71         //@}
72
73         /// Methods inherited from \c QApplication class
74         //@{
75         bool notify(QObject * receiver, QEvent * event);
76         void commitData(QSessionManager & sm);
77         //@}
78
79         ///
80         GuiView const * currentView() const { return current_view_; }
81         ///
82         GuiView * currentView() { return current_view_; }
83         ///
84         void setCurrentView(GuiView & view) { current_view_ = &view; }
85         ///
86         virtual size_t viewCount() const { return view_ids_.size(); }
87         ///
88         std::vector<int> const & viewIds() { return view_ids_; }
89
90         ///
91         ColorCache & colorCache() { return color_cache_; }
92         ///
93         GuiFontLoader & guiFontLoader() { return font_loader_; }
94
95         /// return a suitable serif font name.
96         virtual QString const romanFontName();
97
98         /// return a suitable sans serif font name.
99         virtual QString const sansFontName();
100
101         /// return a suitable monospaced font name.
102         virtual QString const typewriterFontName();
103         ///
104         virtual bool closeAllViews();
105         ///
106         virtual bool unregisterView(int id);
107         ///
108         virtual LyXView & view(int id) const;
109         ///
110         virtual void hideDialogs(std::string const & name, Inset * inset) const;
111         ///
112         virtual Buffer const * updateInset(Inset const * inset) const;
113
114 private Q_SLOTS:
115         ///
116         void execBatchCommands();
117         ///
118         void socketDataReceived(int fd);
119
120 private:
121         ///
122         GuiClipboard clipboard_;
123         ///
124         GuiSelection selection_;
125         ///
126         GuiFontLoader font_loader_;
127         ///
128         ColorCache color_cache_;
129         ///
130         QTranslator qt_trans_;
131         ///
132         std::map<int, SocketNotifier *> socket_notifiers_;
133
134 #ifdef Q_WS_X11
135 public:
136         bool x11EventFilter(XEvent * ev);
137 #endif
138         /// A translator suitable for the entries in the LyX menu.
139         /// Only needed with Qt/Mac.
140         void addMenuTranslator();
141
142         /// Multiple views container.
143         /**
144         * Warning: This must not be a smart pointer as the destruction of the
145         * object is handled by Qt when the view is closed
146         * \sa Qt::WA_DeleteOnClose attribute.
147         */
148         std::map<int, GuiView *> views_;
149         ///
150         std::vector<int> view_ids_;
151         /// This LyXView is the one receiving Clipboard and Selection
152         /// events
153         GuiView * current_view_;
154 }; // GuiApplication
155
156 extern GuiApplication * guiApp;
157
158 } // namespace frontend
159 } // namespace lyx
160
161 #endif // GUIAPPLICATION_H