]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Cleanup Toc dialog and GuiView interaction. The toc models are now part of GuiView...
[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 class TocModels;
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         FuncStatus getStatus(FuncRequest const & cmd);
82         bool dispatch(FuncRequest const & cmd);
83
84         ///
85         void setLayoutDialog(GuiLayoutBox *);
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         /// load a document into the current workarea.
95         Buffer * loadDocument(support::FileName const &  name, ///< File to load.
96                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
97         ///
98         void openDocument(std::string const & filename);
99         ///
100         void importDocument(std::string const &);
101         ///
102         void newDocument(std::string const & filename, bool fromTemplate);
103
104         /// GuiBufferDelegate.
105         ///@{
106         void resetAutosaveTimers();
107         void errors(std::string const &);
108         void structureChanged();
109         ///@}
110
111         ///
112         TocModels & tocModels();
113         
114         /// called on timeout
115         void autoSave();
116
117         /// \return the current buffer view.
118         BufferView * view();
119
120         /** redraw \c inset in all the BufferViews in which it is currently
121          *  visible. If successful return a pointer to the owning Buffer.
122          */
123         Buffer const * updateInset(Inset const *);
124         ///
125         void restartCursor();
126
127         /// \return the \c Workarea associated to \p  Buffer
128         /// \retval 0 if no \c WorkArea is found.
129         GuiWorkArea * workArea(Buffer & buffer);
130
131         /// Add a \c WorkArea 
132         /// \return the \c Workarea associated to \p  Buffer
133         /// \retval 0 if no \c WorkArea is found.
134         GuiWorkArea * addWorkArea(Buffer & buffer);
135         ///
136         void setCurrentWorkArea(GuiWorkArea * work_area);
137         ///
138         void removeWorkArea(GuiWorkArea * work_area);
139         /// return the current WorkArea (the one that has the focus).
140         GuiWorkArea const * currentWorkArea() const;
141
142 Q_SIGNALS:
143         void closing(int);
144
145 public Q_SLOTS:
146         /// idle timeout.
147         /// clear any temporary message and replace with current status.
148         void clearMessage();
149
150 private Q_SLOTS:
151         ///
152         void updateWindowTitle(GuiWorkArea * wa);
153
154         ///
155         void on_currentWorkAreaChanged(GuiWorkArea *);
156         ///
157         void on_lastWorkAreaRemoved();
158
159         /// slots to change the icon size
160         void smallSizedIcons();
161         void normalSizedIcons();
162         void bigSizedIcons();
163
164 private:
165         ///
166         TabWorkArea * addTabWorkArea();
167
168         /// connect to signals in the given BufferView
169         void connectBufferView(BufferView & bv);
170         /// disconnect from signals in the given BufferView
171         void disconnectBufferView();
172         /// connect to signals in the given buffer
173         void connectBuffer(Buffer & buf);
174         /// disconnect from signals in the given buffer
175         void disconnectBuffer();
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
213         // Update all visible dialogs.
214         void updateDialogs();
215
216         /** \param name == "bibtex", "citation" etc; an identifier used to
217             launch a particular dialog.
218             \param data is a string representation of the Inset contents.
219             It is often little more than the output from Inset::write.
220             It is passed to, and parsed by, the frontend dialog.
221             Several of these dialogs do not need any data,
222             so it defaults to string().
223             \param inset ownership is _not_ passed to the frontend dialog.
224             It is stored internally and used by the kernel to ascertain
225             what to do with the FuncRequest dispatched from the frontend
226             dialog on 'Apply'; should it be used to create a new inset at
227             the current cursor position or modify an existing, 'open' inset?
228         */
229         void showDialog(std::string const & name,
230                 std::string const & data, Inset * inset = 0);
231
232         /** \param name == "citation", "bibtex" etc; an identifier used
233             to update the contents of a particular dialog with \param data.
234             See the comments to 'show', above.
235         */
236         void updateDialog(std::string const & name, std::string const & data);
237
238         /** All Dialogs of the given \param name will be closed if they are
239             connected to the given \param inset.
240         */
241         void hideDialog(std::string const & name, Inset * inset);
242         ///
243         void disconnectDialog(std::string const & name);
244
245         ///
246         void updateCompletion(Cursor & cur, bool start, bool keep);
247
248 private:
249         ///
250         void lfunUiToggle(FuncRequest const & cmd);
251
252         ///
253         void insertLyXFile(docstring const & fname);
254         ///
255         void insertPlaintextFile(docstring const & fname,
256                 bool asParagraph);
257
258         /// Save a buffer as a new file. 
259         /**
260         Write a buffer to a new file name and rename the buffer
261     according to the new file name.
262
263     This function is e.g. used by menu callbacks and
264     LFUN_BUFFER_WRITE_AS.
265
266     If 'newname' is empty, the user is asked via a
267     dialog for the buffer's new name and location.
268
269     If 'newname' is non-empty and has an absolute path, that is used.
270     Otherwise the base directory of the buffer is used as the base
271     for any relative path in 'newname'.
272         */
273         bool renameBuffer(Buffer & b, docstring const & newname);
274         ///
275         bool saveBuffer(Buffer & b);
276         ///
277         bool closeBuffer(Buffer & buf, bool tolastopened = false);
278
279         ///
280         Inset * getOpenInset(std::string const & name) const;
281
282         /// Is the dialog currently visible?
283         bool isDialogVisible(std::string const & name) const;
284         ///
285         Dialog * find_or_build(std::string const & name);
286         ///
287         Dialog * build(std::string const & name);
288
289         /// This view ID.
290         int id_;
291 };
292
293 } // namespace frontend
294 } // namespace lyx
295
296 #endif // GUIVIEW_H