]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Transfer LFUN_INSET_APPLY from GuiView to BufferView.
[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         Buffer * loadDocument(support::FileName const &  name,
75                 bool tolastfiles = true);
76         void newDocument(std::string const & filename,
77                 bool fromTemplate);
78         void message(docstring const &);
79         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
80         bool dispatch(FuncRequest const & cmd);
81         void restartCursor();
82         void updateCompletion(Cursor & cur, bool start, bool keep);
83         void setFocus();
84         ///@}
85
86         /// add toolbar, if newline==true, add a toolbar break before the toolbar
87         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
88         void updateStatusBar();
89
90         /// updates the possible layouts selectable
91         void updateLayoutList();
92         void updateToolbars();
93         QMenu * createPopupMenu();
94
95         ///
96         LayoutBox * getLayoutDialog() const;
97
98         /// hides the workarea and makes sure it is clean
99         bool hideWorkArea(GuiWorkArea * wa);
100         /// closes the workarea
101         bool closeWorkArea(GuiWorkArea * wa);
102         ///
103         void openDocument(std::string const & filename);
104         ///
105         void importDocument(std::string const &);
106
107         /// GuiBufferDelegate.
108         ///@{
109         void resetAutosaveTimers();
110         void errors(std::string const &, bool from_master = false);
111         void structureChanged();
112         void updateTocItem(std::string const &, DocIterator const &);
113         ///@}
114
115         ///
116         TocModels & tocModels();
117         
118         /// called on timeout
119         void autoSave();
120
121         /** redraw \c inset in all the BufferViews in which it is currently
122          *  visible. If successful return a pointer to the owning Buffer.
123          */
124         Buffer const * updateInset(Inset const *);
125
126         /// \return the \c Workarea associated to \p  Buffer
127         /// \retval 0 if no \c WorkArea is found.
128         GuiWorkArea * workArea(Buffer & buffer);
129
130         /// Add a \c WorkArea 
131         /// \return the \c Workarea associated to \p  Buffer
132         /// \retval 0 if no \c WorkArea is found.
133         GuiWorkArea * addWorkArea(Buffer & buffer);
134         /// \param work_area The current \c WorkArea, or \c NULL
135         void setCurrentWorkArea(GuiWorkArea * work_area);
136         ///
137         void removeWorkArea(GuiWorkArea * work_area);
138         /// return the current WorkArea (the one that has the focus).
139         GuiWorkArea const * currentWorkArea() const;
140         /// return the current WorkArea (the one that has the focus).
141         GuiWorkArea * currentWorkArea();
142
143         /// return the current document WorkArea (it may not have the focus).
144         GuiWorkArea const * currentMainWorkArea() const;
145         /// return the current document WorkArea (it may not have the focus).
146         GuiWorkArea * currentMainWorkArea();
147
148 Q_SIGNALS:
149         void closing(int);
150
151 public Q_SLOTS:
152         /// idle timeout.
153         /// clear any temporary message and replace with current status.
154         void clearMessage();
155
156 private Q_SLOTS:
157         ///
158         void updateWindowTitle(GuiWorkArea * wa);
159         ///
160         void resetWindowTitleAndIconText();
161
162         ///
163         void on_currentWorkAreaChanged(GuiWorkArea *);
164         ///
165         void on_lastWorkAreaRemoved();
166
167         /// slots to change the icon size
168         void smallSizedIcons();
169         void normalSizedIcons();
170         void bigSizedIcons();
171
172 private:
173         /// Open given child document in current buffer directory.
174         void openChildDocument(std::string const & filename);
175         /// Close current document buffer.
176         bool closeBuffer();
177         /// Close all document buffers.
178         bool closeBufferAll();
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         bool goToFileRow(std::string const & argument);
205
206         ///
207         struct GuiViewPrivate;
208         GuiViewPrivate & d;
209
210 public:
211         ///
212         /// dialogs for this view
213         ///
214
215         ///
216         void resetDialogs();
217
218         /// Hide all visible dialogs
219         void hideAll() const;
220
221         /// Update all visible dialogs.
222         /** 
223          *  Check the status of all visible dialogs and disable or reenable
224          *  them as appropriate.
225          *
226          *  Disabling is needed for example when a dialog is open and the
227          *  cursor moves to a position where the corresponding inset is not
228          *  allowed.
229          */
230         void updateDialogs();
231
232         /** \param name == "bibtex", "citation" etc; an identifier used to
233             launch a particular dialog.
234             \param data is a string representation of the Inset contents.
235             It is often little more than the output from Inset::write.
236             It is passed to, and parsed by, the frontend dialog.
237             Several of these dialogs do not need any data,
238             so it defaults to string().
239             \param inset ownership is _not_ passed to the frontend dialog.
240             It is stored internally and used by the kernel to ascertain
241             what to do with the FuncRequest dispatched from the frontend
242             dialog on 'Apply'; should it be used to create a new inset at
243             the current cursor position or modify an existing, 'open' inset?
244         */
245         void showDialog(std::string const & name,
246                 std::string const & data, Inset * inset = 0);
247
248         /** \param name == "citation", "bibtex" etc; an identifier used
249             to reset the contents of a particular dialog with \param data.
250             See the comments to 'show', above.
251         */
252         void updateDialog(std::string const & name, std::string const & data);
253
254         /** All Dialogs of the given \param name will be closed if they are
255             connected to the given \param inset.
256         */
257         void hideDialog(std::string const & name, Inset * inset);
258         ///
259         void disconnectDialog(std::string const & name);
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         /// closes a workarea, if close_buffer is true the buffer will
301         /// also be released, otherwise the buffer will be hidden.
302         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
303         /// closes the tabworkarea and all tabs. If we are in a close event,
304         /// all buffers will be closed, otherwise they will be hidden.
305         bool closeTabWorkArea(TabWorkArea * twa);
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         /// closes all workareas
311         bool closeWorkAreaAll();
312         /// write all open workareas into the session file
313         void writeSession() const;
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         /// Is the dialog currently visible?
328         bool isDialogVisible(std::string const & name) const;
329         ///
330         Dialog * findOrBuild(std::string const & name, bool hide_it);
331         ///
332         Dialog * build(std::string const & name);
333         ///
334         void reloadBuffer();
335         ///
336         void dispatchVC(FuncRequest const & cmd);
337
338         /// This view ID.
339         int id_;
340
341         /// flag to avoid two concurrent close events.
342         bool closing_;
343 };
344
345 } // namespace frontend
346 } // namespace lyx
347
348 #endif // GUIVIEW_H