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