2 * \file GuiApplication.h
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
13 #ifndef GUIAPPLICATION_H
14 #define GUIAPPLICATION_H
16 #include "ColorCache.h"
17 #include "GuiFontLoader.h"
18 #include "GuiClipboard.h"
19 #include "GuiSelection.h"
22 #include "frontends/Application.h"
25 #include <QApplication>
27 #include <QTranslator>
32 class QSessionManager;
45 /// The Qt main application class
47 There should be only one instance of this class. No Qt object
48 initialisation should be done before the instanciation of this class.
50 class GuiApplication : public QApplication, public Application
55 GuiApplication(int & argc, char ** argv);
57 virtual ~GuiApplication();
59 /// Method inherited from \c Application class
61 virtual FuncStatus getStatus(FuncRequest const &);
62 virtual bool dispatch(FuncRequest const &);
63 virtual void resetGui();
64 virtual Clipboard & clipboard();
65 virtual Selection & selection();
66 virtual FontLoader & fontLoader() { return font_loader_; }
67 MenuBackend const & menuBackend() const { return menus_; }
68 MenuBackend & menuBackend() { return menus_; }
70 virtual void exit(int status);
71 virtual bool event(QEvent * e);
72 virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
73 virtual std::string const hexName(ColorCode col);
74 virtual void updateColor(ColorCode col);
75 virtual void registerSocketCallback(int fd, SocketCallback func);
76 void unregisterSocketCallback(int fd);
79 Menus const & menus() const { return menus_; }
80 Menus & menus() { return menus_; }
81 /// Methods inherited from \c QApplication class
83 bool notify(QObject * receiver, QEvent * event);
84 void commitData(QSessionManager & sm);
87 /// Create the main window with given geometry settings.
88 /// \param geometry_arg: only for Windows platform.
89 void createView(QString const & geometry_arg);
91 GuiView const * currentView() const { return current_view_; }
93 GuiView * currentView() { return current_view_; }
95 void setCurrentView(GuiView & view) { current_view_ = &view; }
97 virtual size_t viewCount() const { return view_ids_.size(); }
99 std::vector<int> const & viewIds() { return view_ids_; }
102 ColorCache & colorCache() { return color_cache_; }
104 GuiFontLoader & guiFontLoader() { return font_loader_; }
106 /// return a suitable serif font name.
107 virtual QString const romanFontName();
109 /// return a suitable sans serif font name.
110 virtual QString const sansFontName();
112 /// return a suitable monospaced font name.
113 virtual QString const typewriterFontName();
115 virtual bool unregisterView(int id);
117 virtual GuiView & view(int id) const;
119 virtual void hideDialogs(std::string const & name, Inset * inset) const;
121 virtual Buffer const * updateInset(Inset const * inset) const;
125 void execBatchCommands();
127 void socketDataReceived(int fd);
128 /// events to be triggered by general_timer_ should go here
129 void handleRegularEvents();
133 bool closeAllViews();
135 GuiClipboard clipboard_;
137 GuiSelection selection_;
139 GuiFontLoader font_loader_;
141 ColorCache color_cache_;
143 QTranslator qt_trans_;
145 std::map<int, SocketNotifier *> socket_notifiers_;
148 /// this timer is used for any regular events one wants to
149 /// perform. at present it is used to check if forked processes
151 QTimer general_timer_;
155 bool x11EventFilter(XEvent * ev);
157 /// A translator suitable for the entries in the LyX menu.
158 /// Only needed with Qt/Mac.
159 void addMenuTranslator();
161 /// Multiple views container.
163 * Warning: This must not be a smart pointer as the destruction of the
164 * object is handled by Qt when the view is closed
165 * \sa Qt::WA_DeleteOnClose attribute.
167 std::map<int, GuiView *> views_;
169 std::vector<int> view_ids_;
170 /// This LyXView is the one receiving Clipboard and Selection
172 GuiView * current_view_;
175 extern GuiApplication * guiApp;
177 } // namespace frontend
180 #endif // GUIAPPLICATION_H