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;
34 class QSortFilterProxyModel;
48 /// The Qt main application class
50 There should be only one instance of this class. No Qt object
51 initialisation should be done before the instanciation of this class.
53 class GuiApplication : public QApplication, public Application
58 GuiApplication(int & argc, char ** argv);
61 /// Method inherited from \c Application class
63 virtual FuncStatus getStatus(FuncRequest const &);
64 virtual bool dispatch(FuncRequest const &);
65 virtual void resetGui();
66 void restoreGuiSession();
67 virtual Clipboard & clipboard();
68 virtual Selection & selection();
69 virtual FontLoader & fontLoader() { return font_loader_; }
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 readMenus(Lexer & lex);
77 virtual void initGlobalMenu();
78 virtual void registerSocketCallback(int fd, SocketCallback func);
79 void unregisterSocketCallback(int fd);
80 bool searchMenu(FuncRequest const & func, std::vector<docstring> & names) const;
83 Menus const & menus() const { return menus_; }
84 Menus & menus() { return menus_; }
85 /// Methods inherited from \c QApplication class
87 bool notify(QObject * receiver, QEvent * event);
88 void commitData(QSessionManager & sm);
90 bool x11EventFilter(XEvent * ev);
94 /// Create the main window with given geometry settings.
95 /// \param geometry_arg: only for Windows platform.
96 void createView(QString const & geometry_arg = QString(),
97 bool autoShow = true);
99 GuiView const * currentView() const { return current_view_; }
101 GuiView * currentView() { return current_view_; }
103 void setCurrentView(GuiView * view) { current_view_ = view; }
105 virtual size_t viewCount() const { return view_ids_.size(); }
107 std::vector<int> const & viewIds() { return view_ids_; }
110 ColorCache & colorCache() { return color_cache_; }
112 QAbstractItemModel * languageModel();
114 /// return a suitable serif font name.
115 virtual QString const romanFontName();
117 /// return a suitable sans serif font name.
118 virtual QString const sansFontName();
120 /// return a suitable monospaced font name.
121 virtual QString const typewriterFontName();
123 virtual bool unregisterView(int id);
125 virtual GuiView & view(int id) const;
127 virtual void hideDialogs(std::string const & name, Inset * inset) const;
129 virtual Buffer const * updateInset(Inset const * inset) const;
133 void execBatchCommands();
135 void socketDataReceived(int fd);
136 /// events to be triggered by general_timer_ should go here
137 void handleRegularEvents();
139 void onLastWindowClosed();
143 bool closeAllViews();
145 GuiClipboard clipboard_;
147 GuiSelection selection_;
149 FontLoader font_loader_;
151 ColorCache color_cache_;
153 QSortFilterProxyModel * language_model_;
155 QTranslator qt_trans_;
157 std::map<int, SocketNotifier *> socket_notifiers_;
160 /// this timer is used for any regular events one wants to
161 /// perform. at present it is used to check if forked processes
163 QTimer general_timer_;
165 /// Multiple views container.
167 * Warning: This must not be a smart pointer as the destruction of the
168 * object is handled by Qt when the view is closed
169 * \sa Qt::WA_DeleteOnClose attribute.
171 std::map<int, GuiView *> views_;
173 std::vector<int> view_ids_;
174 /// This LyXView is the one receiving Clipboard and Selection
176 GuiView * current_view_;
182 extern GuiApplication * guiApp;
184 } // namespace frontend
187 #endif // GUIAPPLICATION_H