]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Transfer LyXfunc code to GuiApplication::dispatch() and getStatus(). Now
[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 class KeySymbol;
32
33 namespace frontend {
34
35 class GuiView;
36 class LyXView;
37 class GlobalMenuBar;
38 class GuiWorkArea;
39 class Menus;
40 class SocketNotifier;
41 class Toolbars;
42
43 /// The Qt main application class
44 /**
45 There should be only one instance of this class. No Qt object
46 initialisation should be done before the instanciation of this class.
47 */
48 class GuiApplication : public QApplication, public Application
49 {
50         Q_OBJECT
51
52 public:
53         GuiApplication(int & argc, char ** argv);
54         ~GuiApplication();
55
56         /// Clear all session information.
57         void clearSession();
58
59         /// \name Methods inherited from Application class
60         //@{
61         void dispatch(FuncRequest const &);
62         void dispatch(FuncRequest const &, DispatchResult & dr);
63         FuncStatus getStatus(FuncRequest const & cmd) const;
64         LyXView * currentWindow();
65         void dispatchDelayed(FuncRequest const &);
66         void resetGui();
67         void restoreGuiSession();
68         Clipboard & clipboard();
69         Selection & selection();
70         FontLoader & fontLoader();
71         int exec();
72         void exit(int status);
73         bool event(QEvent * e);
74         bool getRgbColor(ColorCode col, RGBColor & rgbcol);
75         std::string const hexName(ColorCode col);
76         void registerSocketCallback(int fd, SocketCallback func);
77         void unregisterSocketCallback(int fd);
78         bool searchMenu(FuncRequest const & func, docstring_list & names) const;
79         docstring iconName(FuncRequest const & f, bool unknown);
80         void hideDialogs(std::string const & name, Inset * inset) const;
81         Buffer const * updateInset(Inset const * inset) const;
82         void handleKeyFunc(FuncCode action);
83         //@}
84
85         Toolbars const & toolbars() const;
86         Toolbars & toolbars();
87         Menus const & menus() const;
88         Menus & menus();
89
90         /// \name Methods inherited from QApplication class
91         //@{
92         bool notify(QObject * receiver, QEvent * event);
93         void commitData(QSessionManager & sm);
94 #ifdef Q_WS_X11
95         bool x11EventFilter(XEvent * ev);
96 #endif
97         //@}
98
99         /// Create the main window with given geometry settings.
100         /// \param geometry_arg: only for Windows platform.
101         /// \param optional id identifier.
102         void createView(QString const & geometry_arg = QString(),
103                 bool autoShow = true, int id = 0);
104         /// FIXME: this method and the one above are quite ugly.
105         void createView(int id);
106         ///
107         GuiView const * currentView() const { return current_view_; }
108         ///
109         GuiView * currentView() { return current_view_; }
110         ///
111         void setCurrentView(GuiView * view) { current_view_ = view; }
112         ///
113         QList<int> viewIds() const;
114
115         ///
116         ColorCache & colorCache();
117
118         QAbstractItemModel * languageModel();
119
120         /// return a suitable serif font name.
121         QString const romanFontName();
122
123         /// return a suitable sans serif font name.
124         QString const sansFontName();
125
126         /// return a suitable monospaced font name.
127         QString const typewriterFontName();
128         ///
129         void unregisterView(GuiView * gv);
130         ///
131         GuiView & view(int id) const;
132         ///
133         void processKeySym(KeySymbol const & key, KeyModifier state);
134         /// return the status bar state string
135         docstring viewStatusMessage();
136
137         /// goto a bookmark
138         /// openFile: whether or not open a file if the file is not opened
139         /// switchToBuffer: whether or not switch to buffer if the buffer is
140         ///             not the current buffer
141         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
142
143 private Q_SLOTS:
144         ///
145         void execBatchCommands();
146         ///
147         void socketDataReceived(int fd);
148         /// events to be triggered by general_timer_ should go here
149         void handleRegularEvents();
150         ///
151         void onLastWindowClosed();
152
153         ///
154         void processFuncRequestQueue();
155
156 private:
157         ///
158         bool closeAllViews();
159         /// read the given ui (menu/toolbar) file
160         bool readUIFile(QString const & name, bool include = false);
161         ///
162         void setGuiLanguage();
163
164         /// This LyXView is the one receiving Clipboard and Selection
165         /// events
166         GuiView * current_view_;
167
168         ///
169         struct Private;
170         Private * const d;
171 }; // GuiApplication
172
173 extern GuiApplication * guiApp;
174
175 /// \return the icon file name for the given action.
176 QString iconName(FuncRequest const & f, bool unknown);
177
178
179 /// \return the pixmap for the given path, name and extension.
180 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
181
182 /// \return an icon for the given action.
183 QIcon getIcon(FuncRequest const & f, bool unknown);
184
185 GuiApplication * theGuiApp();
186
187 } // namespace frontend
188 } // namespace lyx
189
190 #endif // GUIAPPLICATION_H