]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
* on Mac close GuiView when the last tab was closed
[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 class ToolbarInfo;
36
37 namespace frontend {
38
39 class Dialog;
40 class GuiLayoutBox;
41 class GuiToolbar;
42 class GuiWorkArea;
43 class TabWorkArea;
44
45 /**
46  * GuiView - Qt4 implementation of LyXView
47  *
48  * qt4-private implementation of the main LyX window.
49  *
50  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
51  * is deleted. This might be useful for closing other dialogs
52  * depending on a given GuiView.
53  */
54 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
55         public GuiBufferDelegate
56 {
57         Q_OBJECT
58 public:
59         /// create a main window of the given dimensions
60         GuiView(int id);
61
62         ~GuiView();
63
64         ///
65         int id() const { return id_; }
66         void setFocus();
67         void setBusy(bool);
68         /// returns true if this view has the focus.
69         bool hasFocus() const;
70
71         /// add toolbar, if newline==true, add a toolbar break before the toolbar
72         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
73         virtual void updateStatusBar();
74         virtual void message(docstring const & str);
75
76         /// updates the possible layouts selectable
77         void updateLayoutList();
78         void updateToolbars();
79         QMenu * createPopupMenu();
80         FuncStatus getStatus(FuncRequest const & cmd);
81         bool dispatch(FuncRequest const & cmd);
82
83         ///
84         void setLayoutDialog(GuiLayoutBox *);
85
86         /// \return the buffer currently shown in this window
87         Buffer * buffer();
88         Buffer const * buffer() const;
89         /// set a buffer to the current workarea.
90         void setBuffer(Buffer * b); ///< \c Buffer to set.
91         ///
92         bool closeBuffer();
93         /// load a document into the current workarea.
94         Buffer * loadDocument(support::FileName const &  name, ///< File to load.
95                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
96         ///
97         void openDocument(std::string const & filename);
98         ///
99         void importDocument(std::string const &);
100         ///
101         void newDocument(std::string const & filename, bool fromTemplate);
102
103         /// GuiBufferDelegate.
104         ///@{
105         void resetAutosaveTimers();
106         void errors(std::string const &);
107         void structureChanged() { updateToc(); }
108         ///@}
109         
110         /// called on timeout
111         void autoSave();
112         ///
113         void updateEmbeddedFiles();
114
115         /// \return the current buffer view.
116         BufferView * view();
117
118         /** redraw \c inset in all the BufferViews in which it is currently
119          *  visible. If successful return a pointer to the owning Buffer.
120          */
121         Buffer const * updateInset(Inset const *);
122         ///
123         void restartCursor();
124
125         /// \return the \c Workarea associated to \p  Buffer
126         /// \retval 0 if no \c WorkArea is found.
127         GuiWorkArea * workArea(Buffer & buffer);
128
129         /// Add a \c WorkArea 
130         /// \return the \c Workarea associated to \p  Buffer
131         /// \retval 0 if no \c WorkArea is found.
132         GuiWorkArea * addWorkArea(Buffer & buffer);
133         ///
134         void setCurrentWorkArea(GuiWorkArea * work_area);
135         ///
136         void removeWorkArea(GuiWorkArea * work_area);
137         /// return the current WorkArea (the one that has the focus).
138         GuiWorkArea const * currentWorkArea() const;
139
140 Q_SIGNALS:
141         void closing(int);
142
143 public Q_SLOTS:
144         /// idle timeout.
145         /// clear any temporary message and replace with current status.
146         void clearMessage();
147
148 private Q_SLOTS:
149         ///
150         void updateWindowTitle(GuiWorkArea * wa);
151
152         ///
153         void on_currentWorkAreaChanged(GuiWorkArea *);
154         ///
155         void on_lastWorkAreaRemoved();
156
157         /// slots to change the icon size
158         void smallSizedIcons();
159         void normalSizedIcons();
160         void bigSizedIcons();
161
162 private:
163         ///
164         TabWorkArea * addTabWorkArea();
165
166         /// connect to signals in the given BufferView
167         void connectBufferView(BufferView & bv);
168         /// disconnect from signals in the given BufferView
169         void disconnectBufferView();
170         /// connect to signals in the given buffer
171         void connectBuffer(Buffer & buf);
172         /// disconnect from signals in the given buffer
173         void disconnectBuffer();
174         ///
175         void updateToc();
176         ///
177         void dragEnterEvent(QDragEnterEvent * ev);
178         ///
179         void dropEvent(QDropEvent * ev);
180         /// make sure we quit cleanly
181         void closeEvent(QCloseEvent * e);
182         ///
183         void showEvent(QShowEvent *);
184
185         /// in order to catch Tab key press.
186         bool event(QEvent * e);
187         bool focusNextPrevChild(bool);
188
189         ///
190         struct GuiViewPrivate;
191         GuiViewPrivate & d;
192
193 public:
194         ///
195         /// dialogs for this view
196         ///
197
198         ///
199         void resetDialogs();
200
201         /** Check the status of all visible dialogs and disable or reenable
202          *  them as appropriate.
203          *
204          *  Disabling is needed for example when a dialog is open and the
205          *  cursor moves to a position where the corresponding inset is not
206          *  allowed.
207          */
208         void checkStatus();
209
210         /// Hide all visible dialogs
211         void hideAll() const;
212         /// Hide any dialogs that require a buffer for them to operate
213         void hideBufferDependent() const;
214         /** Update visible, buffer-dependent dialogs
215             If the bool is true then a buffer change has occurred
216             else it is still the same buffer.
217          */
218         void updateBufferDependent(bool) const;
219
220         /** \param name == "bibtex", "citation" etc; an identifier used to
221             launch a particular dialog.
222             \param data is a string representation of the Inset contents.
223             It is often little more than the output from Inset::write.
224             It is passed to, and parsed by, the frontend dialog.
225             Several of these dialogs do not need any data,
226             so it defaults to string().
227             \param inset ownership is _not_ passed to the frontend dialog.
228             It is stored internally and used by the kernel to ascertain
229             what to do with the FuncRequest dispatched from the frontend
230             dialog on 'Apply'; should it be used to create a new inset at
231             the current cursor position or modify an existing, 'open' inset?
232         */
233         void showDialog(std::string const & name,
234                 std::string const & data, Inset * inset = 0);
235
236         /** \param name == "citation", "bibtex" etc; an identifier used
237             to update the contents of a particular dialog with \param data.
238             See the comments to 'show', above.
239         */
240         void updateDialog(std::string const & name, std::string const & data);
241
242         /** All Dialogs of the given \param name will be closed if they are
243             connected to the given \param inset.
244         */
245         void hideDialog(std::string const & name, Inset * inset);
246         ///
247         void disconnectDialog(std::string const & name);
248
249         ///
250         void updateCompletion(Cursor & cur, bool start, bool keep);
251
252 private:
253         ///
254         void lfunUiToggle(FuncRequest const & cmd);
255
256         ///
257         void insertLyXFile(docstring const & fname);
258         ///
259         void insertPlaintextFile(docstring const & fname,
260                 bool asParagraph);
261
262         /// Save a buffer as a new file. 
263         /**
264         Write a buffer to a new file name and rename the buffer
265     according to the new file name.
266
267     This function is e.g. used by menu callbacks and
268     LFUN_BUFFER_WRITE_AS.
269
270     If 'newname' is empty, the user is asked via a
271     dialog for the buffer's new name and location.
272
273     If 'newname' is non-empty and has an absolute path, that is used.
274     Otherwise the base directory of the buffer is used as the base
275     for any relative path in 'newname'.
276         */
277         bool renameBuffer(Buffer & b, docstring const & newname);
278         ///
279         bool saveBuffer(Buffer & b);
280         ///
281         bool closeBuffer(Buffer & buf);
282
283         ///
284         Inset * getOpenInset(std::string const & name) const;
285
286         /// Is the dialog currently visible?
287         bool isDialogVisible(std::string const & name) const;
288         ///
289         Dialog * find_or_build(std::string const & name);
290         ///
291         Dialog * build(std::string const & name);
292
293         /// This view ID.
294         int id_;
295 };
296
297 } // namespace frontend
298 } // namespace lyx
299
300 #endif // GUIVIEW_H