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