]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Cleanup app quitting and window closing now that there is a clean separation between...
[lyx.git] / src / frontends / qt4 / GuiView.h
1 // -*- C++ -*-
2 /**
3  * \file GuiView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjornes
8  * \author John Levon
9  * \author Abdelrazak Younes
10  * \author Peter Kümmel
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef GUI_VIEW_H
16 #define GUI_VIEW_H
17
18 #include "frontends/Delegates.h"
19 #include "frontends/LyXView.h"
20
21 #include "support/strfwd.h"
22
23 #include <QMainWindow>
24
25 class QCloseEvent;
26 class QDragEnterEvent;
27 class QDropEvent;
28 class QMenu;
29 class QShowEvent;
30
31
32 namespace lyx {
33
34 class ToolbarInfo;
35
36 namespace frontend {
37
38 class Dialog;
39 class GuiLayoutBox;
40 class GuiToolbar;
41 class GuiWorkArea;
42 class TabWorkArea;
43
44 /**
45  * GuiView - Qt4 implementation of LyXView
46  *
47  * qt4-private implementation of the main LyX window.
48  *
49  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
50  * is deleted. This might be useful for closing other dialogs
51  * depending on a given GuiView.
52  */
53 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
54         public GuiBufferDelegate
55 {
56         Q_OBJECT
57 public:
58         /// create a main window of the given dimensions
59         GuiView(int id);
60
61         ~GuiView();
62
63         ///
64         int id() const { return id_; }
65         void setFocus();
66         void setBusy(bool);
67         /// returns true if this view has the focus.
68         bool hasFocus() const;
69
70         /// add toolbar, if newline==true, add a toolbar break before the toolbar
71         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
72         virtual void updateStatusBar();
73         virtual void message(docstring const & str);
74
75         /// updates the possible layouts selectable
76         void updateLayoutList();
77         void updateToolbars();
78         QMenu * createPopupMenu();
79         FuncStatus getStatus(FuncRequest const & cmd);
80         bool dispatch(FuncRequest const & cmd);
81
82         ///
83         void setLayoutDialog(GuiLayoutBox *);
84
85         /// \return the buffer currently shown in this window
86         Buffer * buffer();
87         Buffer const * buffer() const;
88         /// set a buffer to the current workarea.
89         void setBuffer(Buffer * b); ///< \c Buffer to set.
90         ///
91         bool closeBuffer();
92         /// load a document into the current workarea.
93         Buffer * loadDocument(support::FileName const &  name, ///< File to load.
94                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
95         ///
96         void openDocument(std::string const & filename);
97         ///
98         void importDocument(std::string const &);
99         ///
100         void newDocument(std::string const & filename, bool fromTemplate);
101
102         /// GuiBufferDelegate.
103         ///@{
104         void resetAutosaveTimers();
105         void errors(std::string const &);
106         void structureChanged() { updateToc(); }
107         ///@}
108         
109         /// called on timeout
110         void autoSave();
111         ///
112         void updateEmbeddedFiles();
113
114         /// \return the current buffer view.
115         BufferView * view();
116
117         /** redraw \c inset in all the BufferViews in which it is currently
118          *  visible. If successful return a pointer to the owning Buffer.
119          */
120         Buffer const * updateInset(Inset const *);
121         ///
122         void restartCursor();
123
124         /// \return the \c Workarea associated to \p  Buffer
125         /// \retval 0 if no \c WorkArea is found.
126         GuiWorkArea * workArea(Buffer & buffer);
127
128         /// Add a \c WorkArea 
129         /// \return the \c Workarea associated to \p  Buffer
130         /// \retval 0 if no \c WorkArea is found.
131         GuiWorkArea * addWorkArea(Buffer & buffer);
132         ///
133         void setCurrentWorkArea(GuiWorkArea * work_area);
134         ///
135         void removeWorkArea(GuiWorkArea * work_area);
136         /// return the current WorkArea (the one that has the focus).
137         GuiWorkArea const * currentWorkArea() const;
138
139 Q_SIGNALS:
140         void closing(int);
141
142 public Q_SLOTS:
143         /// idle timeout.
144         /// clear any temporary message and replace with current status.
145         void clearMessage();
146
147 private Q_SLOTS:
148         ///
149         void updateWindowTitle(GuiWorkArea * wa);
150
151         ///
152         void on_currentWorkAreaChanged(GuiWorkArea *);
153
154         /// slots to change the icon size
155         void smallSizedIcons();
156         void normalSizedIcons();
157         void bigSizedIcons();
158
159 private:
160         ///
161         TabWorkArea * addTabWorkArea();
162
163         /// connect to signals in the given BufferView
164         void connectBufferView(BufferView & bv);
165         /// disconnect from signals in the given BufferView
166         void disconnectBufferView();
167         /// connect to signals in the given buffer
168         void connectBuffer(Buffer & buf);
169         /// disconnect from signals in the given buffer
170         void disconnectBuffer();
171         ///
172         void updateToc();
173         ///
174         void dragEnterEvent(QDragEnterEvent * ev);
175         ///
176         void dropEvent(QDropEvent * ev);
177         /// make sure we quit cleanly
178         void closeEvent(QCloseEvent * e);
179         ///
180         void showEvent(QShowEvent *);
181
182         /// in order to catch Tab key press.
183         bool event(QEvent * e);
184         bool focusNextPrevChild(bool);
185
186         ///
187         struct GuiViewPrivate;
188         GuiViewPrivate & d;
189
190 public:
191         ///
192         /// dialogs for this view
193         ///
194
195         ///
196         void resetDialogs();
197
198         /** Check the status of all visible dialogs and disable or reenable
199          *  them as appropriate.
200          *
201          *  Disabling is needed for example when a dialog is open and the
202          *  cursor moves to a position where the corresponding inset is not
203          *  allowed.
204          */
205         void checkStatus();
206
207         /// Hide all visible dialogs
208         void hideAll() const;
209         /// Hide any dialogs that require a buffer for them to operate
210         void hideBufferDependent() const;
211         /** Update visible, buffer-dependent dialogs
212             If the bool is true then a buffer change has occurred
213             else it is still the same buffer.
214          */
215         void updateBufferDependent(bool) const;
216
217         /** \param name == "bibtex", "citation" etc; an identifier used to
218             launch a particular dialog.
219             \param data is a string representation of the Inset contents.
220             It is often little more than the output from Inset::write.
221             It is passed to, and parsed by, the frontend dialog.
222             Several of these dialogs do not need any data,
223             so it defaults to string().
224             \param inset ownership is _not_ passed to the frontend dialog.
225             It is stored internally and used by the kernel to ascertain
226             what to do with the FuncRequest dispatched from the frontend
227             dialog on 'Apply'; should it be used to create a new inset at
228             the current cursor position or modify an existing, 'open' inset?
229         */
230         void showDialog(std::string const & name,
231                 std::string const & data, Inset * inset = 0);
232
233         /** \param name == "citation", "bibtex" etc; an identifier used
234             to update the contents of a particular dialog with \param data.
235             See the comments to 'show', above.
236         */
237         void updateDialog(std::string const & name, std::string const & data);
238
239         /** All Dialogs of the given \param name will be closed if they are
240             connected to the given \param inset.
241         */
242         void hideDialog(std::string const & name, Inset * inset);
243         ///
244         void disconnectDialog(std::string const & name);
245
246         ///
247         void updateCompletion(bool start, bool keep);
248
249 private:
250         ///
251         void lfunUiToggle(FuncRequest const & cmd);
252
253         ///
254         void insertLyXFile(docstring const & fname);
255         ///
256         void insertPlaintextFile(docstring const & fname,
257                 bool asParagraph);
258
259         /// Save a buffer as a new file. 
260         /**
261         Write a buffer to a new file name and rename the buffer
262     according to the new file name.
263
264     This function is e.g. used by menu callbacks and
265     LFUN_BUFFER_WRITE_AS.
266
267     If 'newname' is empty, the user is asked via a
268     dialog for the buffer's new name and location.
269
270     If 'newname' is non-empty and has an absolute path, that is used.
271     Otherwise the base directory of the buffer is used as the base
272     for any relative path in 'newname'.
273         */
274         bool renameBuffer(Buffer & b, docstring const & newname);
275         ///
276         bool saveBuffer(Buffer & b);
277         ///
278         bool closeBuffer(Buffer & buf);
279
280         ///
281         Inset * getOpenInset(std::string const & name) const;
282
283         /// Is the dialog currently visible?
284         bool isDialogVisible(std::string const & name) const;
285         ///
286         Dialog * find_or_build(std::string const & name);
287         ///
288         Dialog * build(std::string const & name);
289
290         /// This view ID.
291         int id_;
292 };
293
294 } // namespace frontend
295 } // namespace lyx
296
297 #endif // GUIVIEW_H