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