]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiApplication.h
Today is a sad day, LyXView has passed over... long live GuiView!
[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 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         /// \name Methods inherited from Application class
59         //@{
60         void dispatch(FuncRequest const &);
61         void dispatch(FuncRequest const &, DispatchResult & dr);
62         FuncStatus getStatus(FuncRequest const & cmd) 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         void handleKeyFunc(FuncCode action);
81         //@}
82
83         Toolbars const & toolbars() const;
84         Toolbars & toolbars();
85         Menus const & menus() const;
86         Menus & menus();
87
88         /// \name Methods inherited from 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         /// goto a bookmark
136         /// openFile: whether or not open a file if the file is not opened
137         /// switchToBuffer: whether or not switch to buffer if the buffer is
138         ///             not the current buffer
139         void gotoBookmark(unsigned int idx, bool openFile, bool switchToBuffer);
140
141 private Q_SLOTS:
142         ///
143         void execBatchCommands();
144         ///
145         void socketDataReceived(int fd);
146         /// events to be triggered by general_timer_ should go here
147         void handleRegularEvents();
148         ///
149         void onLastWindowClosed();
150
151         ///
152         void processFuncRequestQueue();
153
154 private:
155         ///
156         bool closeAllViews();
157         /// read the given ui (menu/toolbar) file
158         bool readUIFile(QString const & name, bool include = false);
159         ///
160         void setGuiLanguage();
161
162         /// This GuiView is the one receiving Clipboard and Selection
163         /// events
164         GuiView * current_view_;
165
166         ///
167         struct Private;
168         Private * const d;
169 }; // GuiApplication
170
171 extern GuiApplication * guiApp;
172
173 /// \return the icon file name for the given action.
174 QString iconName(FuncRequest const & f, bool unknown);
175
176
177 /// \return the pixmap for the given path, name and extension.
178 QPixmap getPixmap(QString const & path, QString const & name, QString const & ext);
179
180 /// \return an icon for the given action.
181 QIcon getIcon(FuncRequest const & f, bool unknown);
182
183 GuiApplication * theGuiApp();
184
185 } // namespace frontend
186 } // namespace lyx
187
188 #endif // GUIAPPLICATION_H