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