]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
merge GuiView/Dialogs
[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/LyXView.h"
19
20 #include <string>
21
22
23 #include <QMainWindow>
24 #include <QTimer>
25
26 class QCloseEvent;
27 class QDragEnterEvent;
28 class QDropEvent;
29 class QMenu;
30 class QShowEvent;
31
32
33 namespace lyx {
34
35 class Timeout;
36 class ToolbarInfo;
37
38 namespace frontend {
39
40 class GuiToolbar;
41 class GuiWorkArea;
42 class Dialog;
43
44 QWidget * mainWindow();
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
56 {
57         Q_OBJECT
58 public:
59         /// create a main window of the given dimensions
60         GuiView(int id);
61
62         ~GuiView();
63
64         virtual void init();
65         virtual void close();
66         virtual void setFocus();
67         virtual void setBusy(bool);
68
69         /// add toolbar, if newline==true, add a toolbar break before the toolbar
70         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
71         virtual void updateStatusBar();
72         virtual void message(docstring const & str);
73         virtual bool hasFocus() const;
74         void updateLayoutChoice(bool force);
75         bool isToolbarVisible(std::string const & id);
76         void updateToolbars();
77         ///
78         QMenu * createPopupMenu();
79
80         /// dispatch to current BufferView
81         void dispatch(FuncRequest const & cmd);
82
83         /// \return the buffer currently shown in this window
84         Buffer * buffer();
85         Buffer const * buffer() const;
86         /// set a buffer to the current workarea.
87         void setBuffer(Buffer * b); ///< \c Buffer to set.
88
89         /// GuiBufferDelegate.
90         ///@{
91         void resetAutosaveTimers();
92         void errors(std::string const &);
93         void structureChanged() { updateToc(); }
94         ///@}
95
96         ////
97         void showDialog(std::string const & name);
98         void showDialogWithData(std::string const & name,
99                 std::string const & data);
100         void showInsetDialog(std::string const & name,
101                 std::string const & data, Inset * inset);
102         
103         /// called on timeout
104         void autoSave();
105         ///
106         void updateEmbeddedFiles();
107
108         /// \return the current buffer view.
109         BufferView * view();
110
111         /// load a buffer into the current workarea.
112         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
113                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
114
115         /** redraw \c inset in all the BufferViews in which it is currently
116          *  visible. If successful return a pointer to the owning Buffer.
117          */
118         Buffer const * updateInset(Inset const *);
119         ///
120         void restartCursor();
121
122         /// \return the \c Workarea associated to \p  Buffer
123         /// \retval 0 if no \c WorkArea is found.
124         GuiWorkArea * workArea(Buffer & buffer);
125
126         /// Add a \c WorkArea 
127         /// \return the \c Workarea associated to \p  Buffer
128         /// \retval 0 if no \c WorkArea is found.
129         GuiWorkArea * addWorkArea(Buffer & buffer);
130         ///
131         void setCurrentWorkArea(GuiWorkArea * work_area);
132         ///
133         void removeWorkArea(GuiWorkArea * work_area);
134         /// return the current WorkArea (the one that has the focus).
135         GuiWorkArea const * currentWorkArea() const;
136
137 Q_SIGNALS:
138         void closing(int);
139
140 public Q_SLOTS:
141         /// idle timeout.
142         /// clear any temporary message and replace with current status.
143         void clearMessage();
144
145 private Q_SLOTS:
146         ///
147         void updateWindowTitle(GuiWorkArea * wa);
148
149         ///
150         void on_currentWorkAreaChanged(GuiWorkArea *);
151
152         /// slots to change the icon size
153         void smallSizedIcons();
154         void normalSizedIcons();
155         void bigSizedIcons();
156
157 private:
158         ///
159         void addTabWorkArea();
160
161         /// connect to signals in the given BufferView
162         void connectBufferView(BufferView & bv);
163         /// disconnect from signals in the given BufferView
164         void disconnectBufferView();
165         /// connect to signals in the given buffer
166         void connectBuffer(Buffer & buf);
167         /// disconnect from signals in the given buffer
168         void disconnectBuffer();
169         ///
170         void updateToc();
171         ///
172         void dragEnterEvent(QDragEnterEvent * ev);
173         ///
174         void dropEvent(QDropEvent * ev);
175         /// make sure we quit cleanly
176         void closeEvent(QCloseEvent * e);
177         ///
178         void showEvent(QShowEvent *);
179
180         /// in order to catch Tab key press.
181         bool event(QEvent * e);
182         bool focusNextPrevChild(bool);
183
184         ///
185         struct GuiViewPrivate;
186         GuiViewPrivate & d;
187
188         ///
189         QTimer statusbar_timer_;
190
191         /// are we quitting by the menu?
192         bool quitting_by_menu_;
193
194         struct ToolbarSize {
195                 int top_width;
196                 int bottom_width;
197                 int left_height;
198                 int right_height;
199         };
200
201         ToolbarSize toolbarSize_;
202
203         /// auto-saving of buffers
204         Timeout * const autosave_timeout_;
205
206 public:
207         ///
208         /// dialogs for this view
209         ///
210
211         /** Check the status of all visible dialogs and disable or reenable
212          *  them as appropriate.
213          *
214          *  Disabling is needed for example when a dialog is open and the
215          *  cursor moves to a position where the corresponding inset is not
216          *  allowed.
217          */
218         void checkStatus();
219
220         /// Are the tooltips on or off?
221         bool tooltipsEnabled();
222
223         /// Hide all visible dialogs
224         void hideAll() const;
225         /// Hide any dialogs that require a buffer for them to operate
226         void hideBufferDependent() const;
227         /** Update visible, buffer-dependent dialogs
228             If the bool is true then a buffer change has occurred
229             else it is still the same buffer.
230          */
231         void updateBufferDependent(bool) const;
232
233         /** \param name == "bibtex", "citation" etc; an identifier used to
234             launch a particular dialog.
235             \param data is a string representation of the Inset contents.
236             It is often little more than the output from Inset::write.
237             It is passed to, and parsed by, the frontend dialog.
238             Several of these dialogs do not need any data,
239             so it defaults to string().
240             \param inset ownership is _not_ passed to the frontend dialog.
241             It is stored internally and used by the kernel to ascertain
242             what to do with the FuncRequest dispatched from the frontend
243             dialog on 'Apply'; should it be used to create a new inset at
244             the current cursor position or modify an existing, 'open' inset?
245         */
246         void showDialog(std::string const & name,
247                 std::string const & data = std::string(), Inset * inset = 0);
248
249         /** \param name == "citation", "bibtex" etc; an identifier used
250             to update the contents of a particular dialog with \param data.
251             See the comments to 'show', above.
252         */
253         void updateDialog(std::string const & name, std::string const & data);
254
255         /// Is the dialog currently visible?
256         bool isDialogVisible(std::string const & name) const;
257
258         /** All Dialogs of the given \param name will be closed if they are
259             connected to the given \param inset.
260         */
261         void hideDialog(std::string const & name, Inset * inset);
262         ///
263         void disconnectDialog(std::string const & name);
264         ///
265         Inset * getOpenInset(std::string const & name) const;
266
267 private:
268         ///
269         void redrawDialog() const;
270         ///
271         bool isValidName(std::string const & name) const;
272         ///
273         Dialog * find_or_build(std::string const & name);
274         ///
275         Dialog * build(std::string const & name);
276
277         ///
278         /// flag against a race condition due to multiclicks in Qt frontend,
279         /// see bug #1119
280         bool in_show_;
281 };
282
283 } // namespace frontend
284 } // namespace lyx
285
286 #endif // GUIVIEW_H