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