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