]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
If we are in a closeEvent, we don't want to close all buffers, because these may...
[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 Cursor;
35
36 namespace frontend {
37
38 class Dialog;
39 class LayoutBox;
40 class GuiToolbar;
41 class GuiWorkArea;
42 class TabWorkArea;
43 class TocModels;
44 class ToolbarInfo;
45
46 /**
47  * GuiView - Qt4 implementation of LyXView
48  *
49  * qt4-private implementation of the main LyX window.
50  *
51  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
52  * is deleted. This might be useful for closing other dialogs
53  * depending on a given GuiView.
54  */
55 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
56         public GuiBufferDelegate
57 {
58         Q_OBJECT
59 public:
60         /// create a main window of the given dimensions
61         GuiView(int id);
62
63         ~GuiView();
64
65         ///
66         int id() const { return id_; }
67         void setFocus();
68         void setBusy(bool);
69         /// returns true if this view has the focus.
70         bool hasFocus() const;
71
72         /// add toolbar, if newline==true, add a toolbar break before the toolbar
73         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
74         virtual void updateStatusBar();
75         virtual void message(docstring const & str);
76
77         /// updates the possible layouts selectable
78         void updateLayoutList();
79         void updateToolbars();
80         QMenu * createPopupMenu();
81         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
82         bool dispatch(FuncRequest const & cmd);
83
84         ///
85         LayoutBox * getLayoutDialog() const;
86
87         /// \return the buffer currently shown in this window
88         Buffer * buffer();
89         Buffer const * buffer() const;
90         /// set a buffer to the current workarea.
91         void setBuffer(Buffer * b); ///< \c Buffer to set.
92         ///
93         bool closeBuffer();
94         /// hides the workarea and makes sure it is clean
95         bool hideWorkArea(GuiWorkArea * wa);
96         /// closes the workarea
97         bool closeWorkArea(GuiWorkArea * wa);
98         /// load a document into the current workarea.
99         Buffer * loadDocument(support::FileName const &  name, ///< File to load.
100                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
101         ///
102         void openDocument(std::string const & filename);
103         ///
104         void importDocument(std::string const &);
105         ///
106         void newDocument(std::string const & filename, bool fromTemplate);
107
108         /// GuiBufferDelegate.
109         ///@{
110         void resetAutosaveTimers();
111         void errors(std::string const &, bool from_master = false);
112         void structureChanged();
113         void updateTocItem(std::string const &, DocIterator const &);
114         ///@}
115
116         ///
117         TocModels & tocModels();
118         
119         /// called on timeout
120         void autoSave();
121
122         /// \return the current buffer view.
123         BufferView * view();
124
125         /** redraw \c inset in all the BufferViews in which it is currently
126          *  visible. If successful return a pointer to the owning Buffer.
127          */
128         Buffer const * updateInset(Inset const *);
129         ///
130         void restartCursor();
131
132         /// \return the \c Workarea associated to \p  Buffer
133         /// \retval 0 if no \c WorkArea is found.
134         GuiWorkArea * workArea(Buffer & buffer);
135
136         /// Add a \c WorkArea 
137         /// \return the \c Workarea associated to \p  Buffer
138         /// \retval 0 if no \c WorkArea is found.
139         GuiWorkArea * addWorkArea(Buffer & buffer);
140         ///
141         void setCurrentWorkArea(GuiWorkArea * work_area);
142         ///
143         void removeWorkArea(GuiWorkArea * work_area);
144         /// return the current WorkArea (the one that has the focus).
145         GuiWorkArea const * currentWorkArea() const;
146         /// return the current WorkArea (the one that has the focus).
147         GuiWorkArea * currentWorkArea();
148
149         /// return the current document WorkArea (it may not have the focus).
150         GuiWorkArea const * currentMainWorkArea() const;
151         /// return the current document WorkArea (it may not have the focus).
152         GuiWorkArea * currentMainWorkArea();
153
154 Q_SIGNALS:
155         void closing(int);
156
157 public Q_SLOTS:
158         /// idle timeout.
159         /// clear any temporary message and replace with current status.
160         void clearMessage();
161
162 private Q_SLOTS:
163         ///
164         void updateWindowTitle(GuiWorkArea * wa);
165         ///
166         void resetWindowTitleAndIconText();
167
168         ///
169         void on_currentWorkAreaChanged(GuiWorkArea *);
170         ///
171         void on_lastWorkAreaRemoved();
172
173         /// slots to change the icon size
174         void smallSizedIcons();
175         void normalSizedIcons();
176         void bigSizedIcons();
177
178 private:
179         ///
180         TabWorkArea * addTabWorkArea();
181
182         /// connect to signals in the given BufferView
183         void connectBufferView(BufferView & bv);
184         /// disconnect from signals in the given BufferView
185         void disconnectBufferView();
186         /// connect to signals in the given buffer
187         void connectBuffer(Buffer & buf);
188         /// disconnect from signals in the given buffer
189         void disconnectBuffer();
190         ///
191         void dragEnterEvent(QDragEnterEvent * ev);
192         ///
193         void dropEvent(QDropEvent * ev);
194         /// make sure we quit cleanly
195         void closeEvent(QCloseEvent * e);
196         ///
197         void showEvent(QShowEvent *);
198
199         /// in order to catch Tab key press.
200         bool event(QEvent * e);
201         bool focusNextPrevChild(bool);
202
203         ///
204         struct GuiViewPrivate;
205         GuiViewPrivate & d;
206
207 public:
208         ///
209         /// dialogs for this view
210         ///
211
212         ///
213         void resetDialogs();
214
215         /// Hide all visible dialogs
216         void hideAll() const;
217
218         /// Update all visible dialogs.
219         /** 
220          *  Check the status of all visible dialogs and disable or reenable
221          *  them as appropriate.
222          *
223          *  Disabling is needed for example when a dialog is open and the
224          *  cursor moves to a position where the corresponding inset is not
225          *  allowed.
226          */
227         void updateDialogs();
228
229         /** \param name == "bibtex", "citation" etc; an identifier used to
230             launch a particular dialog.
231             \param data is a string representation of the Inset contents.
232             It is often little more than the output from Inset::write.
233             It is passed to, and parsed by, the frontend dialog.
234             Several of these dialogs do not need any data,
235             so it defaults to string().
236             \param inset ownership is _not_ passed to the frontend dialog.
237             It is stored internally and used by the kernel to ascertain
238             what to do with the FuncRequest dispatched from the frontend
239             dialog on 'Apply'; should it be used to create a new inset at
240             the current cursor position or modify an existing, 'open' inset?
241         */
242         void showDialog(std::string const & name,
243                 std::string const & data, Inset * inset = 0);
244
245         /** \param name == "citation", "bibtex" etc; an identifier used
246             to reset the contents of a particular dialog with \param data.
247             See the comments to 'show', above.
248         */
249         void updateDialog(std::string const & name, std::string const & data);
250
251         /** All Dialogs of the given \param name will be closed if they are
252             connected to the given \param inset.
253         */
254         void hideDialog(std::string const & name, Inset * inset);
255         ///
256         void disconnectDialog(std::string const & name);
257
258         ///
259         void updateCompletion(Cursor & cur, bool start, bool keep);
260
261 private:
262         ///
263         void saveLayout() const;
264         ///
265         bool restoreLayout();
266         ///
267         GuiToolbar * toolbar(std::string const & name);
268         ///
269         void constructToolbars();
270         ///
271         void initToolbars();
272         ///
273         void lfunUiToggle(FuncRequest const & cmd);
274         ///
275         void toggleFullScreen();
276         ///
277         void insertLyXFile(docstring const & fname);
278         ///
279         void insertPlaintextFile(docstring const & fname,
280                 bool asParagraph);
281
282         /// Save a buffer as a new file. 
283         /**
284         Write a buffer to a new file name and rename the buffer
285     according to the new file name.
286
287     This function is e.g. used by menu callbacks and
288     LFUN_BUFFER_WRITE_AS.
289
290     If 'newname' is empty, the user is asked via a
291     dialog for the buffer's new name and location.
292
293     If 'newname' is non-empty and has an absolute path, that is used.
294     Otherwise the base directory of the buffer is used as the base
295     for any relative path in 'newname'.
296         */
297         bool renameBuffer(Buffer & b, docstring const & newname);
298         ///
299         bool saveBuffer(Buffer & b);
300         ///
301         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer,
302                 bool in_close_event = false, bool mark_active = false);
303         /// closes the tabworkarea and all tabs.
304         bool closeTabWorkArea(TabWorkArea * twa, bool in_close_event = false,
305                 GuiWorkArea * main_work_area = 0);
306         /// gives the user the possibility to save his work 
307         /// or to discard the changes. If hiding is true, the
308         /// document will be reloaded.
309         bool saveBufferIfNeeded(Buffer & buf, bool hiding);
310         ///
311         bool closeBufferAll(bool in_close_event = false);
312         ///
313         bool closeWorkAreaAll(bool in_close_event = false);
314         /// is the buffer in this workarea also shown in another tab ?
315         /// This tab can either be in the same view or in another one.
316         bool inMultiTabs(GuiWorkArea * wa);
317         /// is the buffer in this workarea also shown in another view ?
318         bool inMultiViews(GuiWorkArea * wa);
319         ///
320         enum NextOrPrevious {
321                 NEXTBUFFER,
322                 PREVBUFFER
323         };
324         ///
325         void gotoNextOrPreviousBuffer(NextOrPrevious np);
326
327         ///
328         Inset * getOpenInset(std::string const & name) const;
329
330         /// Is the dialog currently visible?
331         bool isDialogVisible(std::string const & name) const;
332         ///
333         Dialog * findOrBuild(std::string const & name, bool hide_it);
334         ///
335         Dialog * build(std::string const & name);
336
337         /// This view ID.
338         int id_;
339
340         /// flag to avoid two concurrent close events.
341         bool closing_;
342 };
343
344 } // namespace frontend
345 } // namespace lyx
346
347 #endif // GUIVIEW_H