]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
merge frontend::Gui and frontend::Application
[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 \todo The work areas handling could be moved to a base virtual class
48 comon to all frontends.
49 */
50 class GuiApplication : public QApplication, public Application
51 {
52         Q_OBJECT
53
54 public:
55         GuiApplication(int & argc, char ** argv);
56         ///
57         virtual ~GuiApplication();
58
59         /// Method inherited from \c Application class
60         //@{
61         virtual Clipboard & clipboard();
62         virtual Selection & selection();
63         virtual FontLoader & fontLoader() { return font_loader_; }
64         virtual int exec();
65         virtual void exit(int status);
66         virtual bool event(QEvent * e);
67         void syncEvents();
68         virtual std::string const romanFontName();
69         virtual std::string const sansFontName();
70         virtual std::string const typewriterFontName();
71         virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
72         virtual std::string const hexName(ColorCode col);
73         virtual void updateColor(ColorCode col);
74         virtual void registerSocketCallback(int fd, SocketCallback func);
75         void unregisterSocketCallback(int fd);
76         LyXView & createView(std::string const & geometry_arg);
77         //@}
78
79         /// Methods inherited from \c QApplication class
80         //@{
81         bool notify(QObject * receiver, QEvent * event);
82         void commitData(QSessionManager & sm);
83         //@}
84
85         ///
86         ColorCache & colorCache() { return color_cache_; }
87         ///
88         GuiFontLoader & guiFontLoader() { return font_loader_; }
89
90
91         virtual int createRegisteredView();
92         virtual bool closeAllViews();
93         virtual bool unregisterView(int id);
94
95         virtual LyXView & view(int id) const;
96         ///
97         virtual void hideDialogs(std::string const & name, Inset * inset) const;
98         ///
99         virtual Buffer const * updateInset(Inset const * inset) const;
100
101 private Q_SLOTS:
102         ///
103         void execBatchCommands();
104         ///
105         void socketDataReceived(int fd);
106
107 private:
108         ///
109         GuiClipboard clipboard_;
110         ///
111         GuiSelection selection_;
112         ///
113         GuiFontLoader font_loader_;
114         ///
115         ColorCache color_cache_;
116         ///
117         QTranslator qt_trans_;
118         ///
119         std::map<int, SocketNotifier *> socket_notifiers_;
120
121 #ifdef Q_WS_X11
122 public:
123         bool x11EventFilter(XEvent * ev);
124 #endif
125         /// A translator suitable for the entries in the LyX menu.
126         /// Only needed with Qt/Mac.
127         void addMenuTranslator();
128
129         /// Multiple views container.
130         /**
131         * Warning: This must not be a smart pointer as the destruction of the
132         * object is handled by Qt when the view is closed
133         * \sa Qt::WA_DeleteOnClose attribute.
134         */
135         std::map<int, GuiView *> views_;
136 }; // GuiApplication
137
138 extern GuiApplication * guiApp;
139
140 } // namespace frontend
141 } // namespace lyx
142
143 #endif // GUIAPPLICATION_H