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 "FontLoader.h"
18 #include "GuiClipboard.h"
19 #include "GuiSelection.h"
22 #include "frontends/Application.h"
25 #include <QApplication>
27 #include <QTranslator>
32 class QSessionManager;
33 class QAbstractItemModel;
47 /// The Qt main application class
49 There should be only one instance of this class. No Qt object
50 initialisation should be done before the instanciation of this class.
52 class GuiApplication : public QApplication, public Application
57 GuiApplication(int & argc, char ** argv);
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_; }
69 virtual void exit(int status);
70 virtual bool event(QEvent * e);
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 readMenus(Lexer & lex);
75 virtual void initGlobalMenu();
76 virtual void registerSocketCallback(int fd, SocketCallback func);
77 void unregisterSocketCallback(int fd);
78 bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
81 Menus const & menus() const { return menus_; }
82 Menus & menus() { return menus_; }
83 /// Methods inherited from \c QApplication class
85 bool notify(QObject * receiver, QEvent * event);
86 void commitData(QSessionManager & sm);
89 /// Create the main window with given geometry settings.
90 /// \param geometry_arg: only for Windows platform.
91 void createView(QString const & geometry_arg = QString(),
92 bool autoShow = true);
94 GuiView const * currentView() const { return current_view_; }
96 GuiView * currentView() { return current_view_; }
98 void setCurrentView(GuiView * view) { current_view_ = view; }
100 virtual size_t viewCount() const { return view_ids_.size(); }
102 std::vector<int> const & viewIds() { return view_ids_; }
105 ColorCache & colorCache() { return color_cache_; }
107 QAbstractItemModel * languageModel();
109 /// return a suitable serif font name.
110 virtual QString const romanFontName();
112 /// return a suitable sans serif font name.
113 virtual QString const sansFontName();
115 /// return a suitable monospaced font name.
116 virtual QString const typewriterFontName();
118 virtual bool unregisterView(int id);
120 virtual GuiView & view(int id) const;
122 virtual void hideDialogs(std::string const & name, Inset * inset) const;
124 virtual Buffer const * updateInset(Inset const * inset) const;
128 void execBatchCommands();
130 void socketDataReceived(int fd);
131 /// events to be triggered by general_timer_ should go here
132 void handleRegularEvents();
134 void onLastWindowClosed();
138 bool closeAllViews();
140 GuiClipboard clipboard_;
142 GuiSelection selection_;
144 FontLoader font_loader_;
146 ColorCache color_cache_;
148 QSortFilterProxyModel * language_model_;
150 QTranslator qt_trans_;
152 std::map<int, SocketNotifier *> socket_notifiers_;
155 /// this timer is used for any regular events one wants to
156 /// perform. at present it is used to check if forked processes
158 QTimer general_timer_;
162 bool x11EventFilter(XEvent * ev);
164 /// A translator suitable for the entries in the LyX menu.
165 /// Only needed with Qt/Mac.
166 void addMenuTranslator();
168 /// Multiple views container.
170 * Warning: This must not be a smart pointer as the destruction of the
171 * object is handled by Qt when the view is closed
172 * \sa Qt::WA_DeleteOnClose attribute.
174 std::map<int, GuiView *> views_;
176 std::vector<int> view_ids_;
177 /// This LyXView is the one receiving Clipboard and Selection
179 GuiView * current_view_;
181 GlobalMenuBar * global_menubar_;
184 extern GuiApplication * guiApp;
186 } // namespace frontend
189 #endif // GUIAPPLICATION_H