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