]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
make frontend::Application a bit slimmer
[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
29 class QSessionManager;
30
31 namespace lyx {
32
33 class BufferView;
34
35 namespace frontend {
36
37 class GuiView;
38 class LyXView;
39 class GuiWorkArea;
40 class SocketNotifier;
41
42 /// The Qt main application class
43 /**
44 There should be only one instance of this class. No Qt object
45 initialisation should be done before the instanciation of this class.
46 */
47 class GuiApplication : public QApplication, public Application
48 {
49         Q_OBJECT
50
51 public:
52         GuiApplication(int & argc, char ** argv);
53         ///
54         virtual ~GuiApplication();
55
56         /// Method inherited from \c Application class
57         //@{
58         virtual Clipboard & clipboard();
59         virtual Selection & selection();
60         virtual FontLoader & fontLoader() { return font_loader_; }
61         virtual int exec();
62         virtual void exit(int status);
63         virtual bool event(QEvent * e);
64         void syncEvents();
65         virtual std::string const romanFontName();
66         virtual std::string const sansFontName();
67         virtual std::string const typewriterFontName();
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         LyXView & createView(std::string const & geometry_arg);
74         //@}
75
76         /// Methods inherited from \c QApplication class
77         //@{
78         bool notify(QObject * receiver, QEvent * event);
79         void commitData(QSessionManager & sm);
80         //@}
81
82         ///
83         ColorCache & colorCache() { return color_cache_; }
84         ///
85         GuiFontLoader & guiFontLoader() { return font_loader_; }
86
87
88         virtual int createRegisteredView();
89         virtual bool closeAllViews();
90         virtual bool unregisterView(int id);
91
92         virtual LyXView & view(int id) const;
93         ///
94         virtual void hideDialogs(std::string const & name, Inset * inset) const;
95         ///
96         virtual Buffer const * updateInset(Inset const * inset) const;
97
98 private Q_SLOTS:
99         ///
100         void execBatchCommands();
101         ///
102         void socketDataReceived(int fd);
103
104 private:
105         ///
106         GuiClipboard clipboard_;
107         ///
108         GuiSelection selection_;
109         ///
110         GuiFontLoader font_loader_;
111         ///
112         ColorCache color_cache_;
113         ///
114         QTranslator qt_trans_;
115         ///
116         std::map<int, SocketNotifier *> socket_notifiers_;
117
118 #ifdef Q_WS_X11
119 public:
120         bool x11EventFilter(XEvent * ev);
121 #endif
122         /// A translator suitable for the entries in the LyX menu.
123         /// Only needed with Qt/Mac.
124         void addMenuTranslator();
125
126         /// Multiple views container.
127         /**
128         * Warning: This must not be a smart pointer as the destruction of the
129         * object is handled by Qt when the view is closed
130         * \sa Qt::WA_DeleteOnClose attribute.
131         */
132         std::map<int, GuiView *> views_;
133 }; // GuiApplication
134
135 extern GuiApplication * guiApp;
136
137 } // namespace frontend
138 } // namespace lyx
139
140 #endif // GUIAPPLICATION_H