]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
If we are in a closeEvent, we don't want to close all buffers, because these may...
[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 "frontends/Application.h"
17
18 #include <QApplication>
19 #include <QList>
20
21 class QAbstractItemModel;
22 class QIcon;
23 class QObject;
24 class QSessionManager;
25 class QSortFilterProxyModel;
26
27 namespace lyx {
28
29 class BufferView;
30 class ColorCache;
31
32 namespace frontend {
33
34 class GuiView;
35 class LyXView;
36 class GlobalMenuBar;
37 class GuiWorkArea;
38 class Menus;
39 class SocketNotifier;
40 class Toolbars;
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 class GuiApplication : public QApplication, public Application
48 {
49         Q_OBJECT
50
51 public:
52         GuiApplication(int & argc, char ** argv);
53         ~GuiApplication();
54
55         /// Clear all session information.
56         void clearSession();
57
58         /// Method inherited from \c Application class
59         //@{
60         bool getStatus(FuncRequest const & cmd, FuncStatus & flag) const;
61         bool dispatch(FuncRequest const &);
62         void dispatchDelayed(FuncRequest const &);
63         void resetGui();
64         void restoreGuiSession();
65         Clipboard & clipboard();
66         Selection & selection();
67         FontLoader & fontLoader();
68         int exec();
69         void exit(int status);
70         bool event(QEvent * e);
71         bool getRgbColor(ColorCode col, RGBColor & rgbcol);
72         std::string const hexName(ColorCode col);
73         void registerSocketCallback(int fd, SocketCallback func);
74         void unregisterSocketCallback(int fd);
75         bool searchMenu(FuncRequest const & func, docstring_list & names) const;
76         docstring iconName(FuncRequest const & f, bool unknown);
77         void hideDialogs(std::string const & name, Inset * inset) const;
78         Buffer const * updateInset(Inset const * inset) const;
79         //@}
80
81         Toolbars const & toolbars() const;
82         Toolbars & toolbars();
83         Menus const & menus() const;
84         Menus & menus();
85         /// Methods inherited from \c QApplication class
86         //@{
87         bool notify(QObject * receiver, QEvent * event);
88         void commitData(QSessionManager & sm);
89 #ifdef Q_WS_X11
90         bool x11EventFilter(XEvent * ev);
91 #endif
92         //@}
93
94         /// Create the main window with given geometry settings.
95         /// \param geometry_arg: only for Windows platform.
96         /// \param optional id identifier.
97         void createView(QString const & geometry_arg = QString(),
98                 bool autoShow = true, int id = 0);
99         /// FIXME: this method and the one above are quite ugly.
100         void createView(int id);
101         ///
102         GuiView const * currentView() const { return current_view_; }
103         ///
104         GuiView * currentView() { return current_view_; }
105         ///
106         void setCurrentView(GuiView * view) { current_view_ = view; }
107         ///
108         QList<int> viewIds() const;
109
110         ///
111         ColorCache & colorCache();
112
113         QAbstractItemModel * languageModel();
114
115         /// return a suitable serif font name.
116         QString const romanFontName();
117
118         /// return a suitable sans serif font name.
119         QString const sansFontName();
120
121         /// return a suitable monospaced font name.
122         QString const typewriterFontName();
123         ///
124         void unregisterView(GuiView * gv);
125         ///
126         GuiView & view(int id) const;
127
128 private Q_SLOTS:
129         ///
130         void execBatchCommands();
131         ///
132         void socketDataReceived(int fd);
133         /// events to be triggered by general_timer_ should go here
134         void handleRegularEvents();
135         ///
136         void onLastWindowClosed();
137
138         ///
139         void processFuncRequestQueue();
140
141 private:
142         ///
143         bool closeAllViews();
144         /// read the given ui (menu/toolbar) file
145         bool readUIFile(QString const & name, bool include = false);
146         ///
147         void setGuiLanguage();
148
149         /// This LyXView is the one receiving Clipboard and Selection
150         /// events
151         GuiView * current_view_;
152         ///
153         struct Private;
154         Private * const d;
155 }; // GuiApplication
156
157 extern GuiApplication * guiApp;
158
159 /// \return the icon file name for the given action.
160 QString iconName(FuncRequest const & f, bool unknown);
161
162
163 /// \return the pixmap for the given path, name and extension.
164 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
165
166 /// \return an icon for the given action.
167 QIcon getIcon(FuncRequest const & f, bool unknown);
168
169 GuiApplication * theGuiApp();
170
171 } // namespace frontend
172 } // namespace lyx
173
174 #endif // GUIAPPLICATION_H