]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
ae85894e5f0b416fea138e062809703080e4afa6
[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         ///
109         void openDocument(std::string const & filename);
110         ///
111         void importDocument(std::string const &);
112
113         /// GuiBufferDelegate.
114         ///@{
115         void resetAutosaveTimers();
116         void errors(std::string const &, bool from_master = false);
117         void structureChanged();
118         void updateTocItem(std::string const &, DocIterator const &);
119         ///@}
120
121         ///
122         TocModels & tocModels();
123         
124         /// called on timeout
125         void autoSave();
126
127         /** redraw \c inset in all the BufferViews in which it is currently
128          *  visible. If successful return a pointer to the owning Buffer.
129          */
130         Buffer const * updateInset(Inset const *);
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         /// \param work_area The current \c WorkArea, or \c NULL
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         /// Open given child document in current buffer directory.
180         void openChildDocument(std::string const & filename);
181         /// Close current document buffer.
182         bool closeBuffer();
183         /// Close all document buffers.
184         bool closeBufferAll();
185         ///
186         TabWorkArea * addTabWorkArea();
187
188         /// connect to signals in the given BufferView
189         void connectBufferView(BufferView & bv);
190         /// disconnect from signals in the given BufferView
191         void disconnectBufferView();
192         /// connect to signals in the given buffer
193         void connectBuffer(Buffer & buf);
194         /// disconnect from signals in the given buffer
195         void disconnectBuffer();
196         ///
197         void dragEnterEvent(QDragEnterEvent * ev);
198         ///
199         void dropEvent(QDropEvent * ev);
200         /// make sure we quit cleanly
201         void closeEvent(QCloseEvent * e);
202         ///
203         void showEvent(QShowEvent *);
204
205         /// in order to catch Tab key press.
206         bool event(QEvent * e);
207         bool focusNextPrevChild(bool);
208
209         ///
210         bool goToFileRow(std::string const & argument);
211
212         ///
213         struct GuiViewPrivate;
214         GuiViewPrivate & d;
215
216 public:
217         ///
218         /// dialogs for this view
219         ///
220
221         ///
222         void resetDialogs();
223
224         /// Hide all visible dialogs
225         void hideAll() const;
226
227         /// Update all visible dialogs.
228         /** 
229          *  Check the status of all visible dialogs and disable or reenable
230          *  them as appropriate.
231          *
232          *  Disabling is needed for example when a dialog is open and the
233          *  cursor moves to a position where the corresponding inset is not
234          *  allowed.
235          */
236         void updateDialogs();
237
238         /** \param name == "bibtex", "citation" etc; an identifier used to
239             launch a particular dialog.
240             \param data is a string representation of the Inset contents.
241             It is often little more than the output from Inset::write.
242             It is passed to, and parsed by, the frontend dialog.
243             Several of these dialogs do not need any data,
244             so it defaults to string().
245             \param inset ownership is _not_ passed to the frontend dialog.
246             It is stored internally and used by the kernel to ascertain
247             what to do with the FuncRequest dispatched from the frontend
248             dialog on 'Apply'; should it be used to create a new inset at
249             the current cursor position or modify an existing, 'open' inset?
250         */
251         void showDialog(std::string const & name,
252                 std::string const & data, Inset * inset = 0);
253
254         /** \param name == "citation", "bibtex" etc; an identifier used
255             to reset the contents of a particular dialog with \param data.
256             See the comments to 'show', above.
257         */
258         void updateDialog(std::string const & name, std::string const & data);
259
260         /** All Dialogs of the given \param name will be closed if they are
261             connected to the given \param inset.
262         */
263         void hideDialog(std::string const & name, Inset * inset);
264         ///
265         void disconnectDialog(std::string const & name);
266
267 private:
268         ///
269         void saveLayout() const;
270         ///
271         bool restoreLayout();
272         ///
273         GuiToolbar * toolbar(std::string const & name);
274         ///
275         void constructToolbars();
276         ///
277         void initToolbars();
278         ///
279         void lfunUiToggle(FuncRequest const & cmd);
280         ///
281         void toggleFullScreen();
282         ///
283         void insertLyXFile(docstring const & fname);
284         ///
285         void insertPlaintextFile(docstring const & fname,
286                 bool asParagraph);
287
288         /// Save a buffer as a new file. 
289         /**
290         Write a buffer to a new file name and rename the buffer
291     according to the new file name.
292
293     This function is e.g. used by menu callbacks and
294     LFUN_BUFFER_WRITE_AS.
295
296     If 'newname' is empty, the user is asked via a
297     dialog for the buffer's new name and location.
298
299     If 'newname' is non-empty and has an absolute path, that is used.
300     Otherwise the base directory of the buffer is used as the base
301     for any relative path in 'newname'.
302         */
303         bool renameBuffer(Buffer & b, docstring const & newname);
304         ///
305         bool saveBuffer(Buffer & b);
306         /// closes a workarea, if close_buffer is true the buffer will
307         /// also be released, otherwise the buffer will be hidden.
308         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
309         /// closes the tabworkarea and all tabs. If we are in a close event,
310         /// all buffers will be closed, otherwise they will be hidden.
311         bool closeTabWorkArea(TabWorkArea * twa);
312         /// gives the user the possibility to save his work 
313         /// or to discard the changes. If hiding is true, the
314         /// document will be reloaded.
315         bool saveBufferIfNeeded(Buffer & buf, bool hiding);
316         /// closes all workareas
317         bool closeWorkAreaAll();
318         /// write all open workareas into the session file
319         void writeSession() const;
320         /// is the buffer in this workarea also shown in another tab ?
321         /// This tab can either be in the same view or in another one.
322         bool inMultiTabs(GuiWorkArea * wa);
323         /// is the buffer in this workarea also shown in another view ?
324         bool inMultiViews(GuiWorkArea * wa);
325         ///
326         enum NextOrPrevious {
327                 NEXTBUFFER,
328                 PREVBUFFER
329         };
330         ///
331         void gotoNextOrPreviousBuffer(NextOrPrevious np);
332
333         /// Is the dialog currently visible?
334         bool isDialogVisible(std::string const & name) const;
335         ///
336         Dialog * findOrBuild(std::string const & name, bool hide_it);
337         ///
338         Dialog * build(std::string const & name);
339         ///
340         void reloadBuffer();
341         ///
342         void dispatchVC(FuncRequest const & cmd);
343         ///
344         void showMessage();
345
346         /// This view ID.
347         int id_;
348
349         /// flag to avoid two concurrent close events.
350         bool closing_;
351 };
352
353 } // namespace frontend
354 } // namespace lyx
355
356 #endif // GUIVIEW_H