]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Put LFUN_UI_TOGGLE in its own method and add FIXMEs WRT multple workareas.
[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         /// load a document into the current workarea.
93         Buffer * loadDocument(support::FileName const &  name, ///< File to load.
94                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
95         ///
96         void openDocument(std::string const & filename);
97         ///
98         void importDocument(std::string const &);
99         ///
100         void newDocument(std::string const & filename, bool fromTemplate);
101         /// write all buffers, asking the user, returns false if cancelled
102         bool quitWriteAll();
103
104         /// GuiBufferDelegate.
105         ///@{
106         void resetAutosaveTimers();
107         void errors(std::string const &);
108         void structureChanged() { updateToc(); }
109         ///@}
110         
111         /// called on timeout
112         void autoSave();
113         ///
114         void updateEmbeddedFiles();
115
116         /// \return the current buffer view.
117         BufferView * view();
118
119         /** redraw \c inset in all the BufferViews in which it is currently
120          *  visible. If successful return a pointer to the owning Buffer.
121          */
122         Buffer const * updateInset(Inset const *);
123         ///
124         void restartCursor();
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         ///
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
141 Q_SIGNALS:
142         void closing(int);
143
144 public Q_SLOTS:
145         /// idle timeout.
146         /// clear any temporary message and replace with current status.
147         void clearMessage();
148
149 private Q_SLOTS:
150         ///
151         void updateWindowTitle(GuiWorkArea * wa);
152
153         ///
154         void on_currentWorkAreaChanged(GuiWorkArea *);
155
156         /// slots to change the icon size
157         void smallSizedIcons();
158         void normalSizedIcons();
159         void bigSizedIcons();
160
161 private:
162         ///
163         void addTabWorkArea();
164
165         /// connect to signals in the given BufferView
166         void connectBufferView(BufferView & bv);
167         /// disconnect from signals in the given BufferView
168         void disconnectBufferView();
169         /// connect to signals in the given buffer
170         void connectBuffer(Buffer & buf);
171         /// disconnect from signals in the given buffer
172         void disconnectBuffer();
173         ///
174         void updateToc();
175         ///
176         void dragEnterEvent(QDragEnterEvent * ev);
177         ///
178         void dropEvent(QDropEvent * ev);
179         /// make sure we quit cleanly
180         void closeEvent(QCloseEvent * e);
181         ///
182         void showEvent(QShowEvent *);
183
184         /// in order to catch Tab key press.
185         bool event(QEvent * e);
186         bool focusNextPrevChild(bool);
187
188         ///
189         struct GuiViewPrivate;
190         GuiViewPrivate & d;
191
192 public:
193         ///
194         /// dialogs for this view
195         ///
196
197         ///
198         void resetDialogs();
199
200         /** Check the status of all visible dialogs and disable or reenable
201          *  them as appropriate.
202          *
203          *  Disabling is needed for example when a dialog is open and the
204          *  cursor moves to a position where the corresponding inset is not
205          *  allowed.
206          */
207         void checkStatus();
208
209         /// Hide all visible dialogs
210         void hideAll() const;
211         /// Hide any dialogs that require a buffer for them to operate
212         void hideBufferDependent() const;
213         /** Update visible, buffer-dependent dialogs
214             If the bool is true then a buffer change has occurred
215             else it is still the same buffer.
216          */
217         void updateBufferDependent(bool) const;
218
219         /** \param name == "bibtex", "citation" etc; an identifier used to
220             launch a particular dialog.
221             \param data is a string representation of the Inset contents.
222             It is often little more than the output from Inset::write.
223             It is passed to, and parsed by, the frontend dialog.
224             Several of these dialogs do not need any data,
225             so it defaults to string().
226             \param inset ownership is _not_ passed to the frontend dialog.
227             It is stored internally and used by the kernel to ascertain
228             what to do with the FuncRequest dispatched from the frontend
229             dialog on 'Apply'; should it be used to create a new inset at
230             the current cursor position or modify an existing, 'open' inset?
231         */
232         void showDialog(std::string const & name,
233                 std::string const & data, Inset * inset = 0);
234
235         /** \param name == "citation", "bibtex" etc; an identifier used
236             to update the contents of a particular dialog with \param data.
237             See the comments to 'show', above.
238         */
239         void updateDialog(std::string const & name, std::string const & data);
240
241         /** All Dialogs of the given \param name will be closed if they are
242             connected to the given \param inset.
243         */
244         void hideDialog(std::string const & name, Inset * inset);
245         ///
246         void disconnectDialog(std::string const & name);
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);
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