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