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