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 void restoreGuiSession();
65 virtual Clipboard & clipboard();
66 virtual Selection & selection();
67 virtual FontLoader & fontLoader() { return font_loader_; }
68 MenuBackend const & menuBackend() const { return menus_; }
69 MenuBackend & menuBackend() { return menus_; }
71 virtual void exit(int status);
72 virtual bool event(QEvent * e);
73 virtual bool getRgbColor(ColorCode col, RGBColor & rgbcol);
74 virtual std::string const hexName(ColorCode col);
75 virtual void updateColor(ColorCode col);
76 virtual void registerSocketCallback(int fd, SocketCallback func);
77 void unregisterSocketCallback(int fd);
80 Menus const & menus() const { return menus_; }
81 Menus & menus() { return menus_; }
82 /// Methods inherited from \c QApplication class
84 bool notify(QObject * receiver, QEvent * event);
85 void commitData(QSessionManager & sm);
88 /// Create the main window with given geometry settings.
89 /// \param geometry_arg: only for Windows platform.
90 void createView(QString const & geometry_arg);
92 GuiView const * currentView() const { return current_view_; }
94 GuiView * currentView() { return current_view_; }
96 void setCurrentView(GuiView & view) { current_view_ = &view; }
98 virtual size_t viewCount() const { return view_ids_.size(); }
100 std::vector<int> const & viewIds() { return view_ids_; }
103 ColorCache & colorCache() { return color_cache_; }
105 GuiFontLoader & guiFontLoader() { return font_loader_; }
107 /// return a suitable serif font name.
108 virtual QString const romanFontName();
110 /// return a suitable sans serif font name.
111 virtual QString const sansFontName();
113 /// return a suitable monospaced font name.
114 virtual QString const typewriterFontName();
116 virtual bool unregisterView(int id);
118 virtual GuiView & view(int id) const;
120 virtual void hideDialogs(std::string const & name, Inset * inset) const;
122 virtual Buffer const * updateInset(Inset const * inset) const;
126 void execBatchCommands();
128 void socketDataReceived(int fd);
129 /// events to be triggered by general_timer_ should go here
130 void handleRegularEvents();
134 bool closeAllViews();
136 GuiClipboard clipboard_;
138 GuiSelection selection_;
140 GuiFontLoader font_loader_;
142 ColorCache color_cache_;
144 QTranslator qt_trans_;
146 std::map<int, SocketNotifier *> socket_notifiers_;
149 /// this timer is used for any regular events one wants to
150 /// perform. at present it is used to check if forked processes
152 QTimer general_timer_;
156 bool x11EventFilter(XEvent * ev);
158 /// A translator suitable for the entries in the LyX menu.
159 /// Only needed with Qt/Mac.
160 void addMenuTranslator();
162 /// Multiple views container.
164 * Warning: This must not be a smart pointer as the destruction of the
165 * object is handled by Qt when the view is closed
166 * \sa Qt::WA_DeleteOnClose attribute.
168 std::map<int, GuiView *> views_;
170 std::vector<int> view_ids_;
171 /// This LyXView is the one receiving Clipboard and Selection
173 GuiView * current_view_;
176 extern GuiApplication * guiApp;
178 } // namespace frontend
181 #endif // GUIAPPLICATION_H