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