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