]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
consolidate showDialog() incarnations
[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         /// called on timeout
98         void autoSave();
99         ///
100         void updateEmbeddedFiles();
101
102         /// \return the current buffer view.
103         BufferView * view();
104
105         /// load a buffer into the current workarea.
106         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
107                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
108
109         /** redraw \c inset in all the BufferViews in which it is currently
110          *  visible. If successful return a pointer to the owning Buffer.
111          */
112         Buffer const * updateInset(Inset const *);
113         ///
114         void restartCursor();
115
116         /// \return the \c Workarea associated to \p  Buffer
117         /// \retval 0 if no \c WorkArea is found.
118         GuiWorkArea * workArea(Buffer & buffer);
119
120         /// Add a \c WorkArea 
121         /// \return the \c Workarea associated to \p  Buffer
122         /// \retval 0 if no \c WorkArea is found.
123         GuiWorkArea * addWorkArea(Buffer & buffer);
124         ///
125         void setCurrentWorkArea(GuiWorkArea * work_area);
126         ///
127         void removeWorkArea(GuiWorkArea * work_area);
128         /// return the current WorkArea (the one that has the focus).
129         GuiWorkArea const * currentWorkArea() const;
130
131 Q_SIGNALS:
132         void closing(int);
133
134 public Q_SLOTS:
135         /// idle timeout.
136         /// clear any temporary message and replace with current status.
137         void clearMessage();
138
139 private Q_SLOTS:
140         ///
141         void updateWindowTitle(GuiWorkArea * wa);
142
143         ///
144         void on_currentWorkAreaChanged(GuiWorkArea *);
145
146         /// slots to change the icon size
147         void smallSizedIcons();
148         void normalSizedIcons();
149         void bigSizedIcons();
150
151 private:
152         ///
153         void addTabWorkArea();
154
155         /// connect to signals in the given BufferView
156         void connectBufferView(BufferView & bv);
157         /// disconnect from signals in the given BufferView
158         void disconnectBufferView();
159         /// connect to signals in the given buffer
160         void connectBuffer(Buffer & buf);
161         /// disconnect from signals in the given buffer
162         void disconnectBuffer();
163         ///
164         void updateToc();
165         ///
166         void dragEnterEvent(QDragEnterEvent * ev);
167         ///
168         void dropEvent(QDropEvent * ev);
169         /// make sure we quit cleanly
170         void closeEvent(QCloseEvent * e);
171         ///
172         void showEvent(QShowEvent *);
173
174         /// in order to catch Tab key press.
175         bool event(QEvent * e);
176         bool focusNextPrevChild(bool);
177
178         ///
179         struct GuiViewPrivate;
180         GuiViewPrivate & d;
181
182         ///
183         QTimer statusbar_timer_;
184
185         /// are we quitting by the menu?
186         bool quitting_by_menu_;
187
188         struct ToolbarSize {
189                 int top_width;
190                 int bottom_width;
191                 int left_height;
192                 int right_height;
193         };
194
195         ToolbarSize toolbarSize_;
196
197         /// auto-saving of buffers
198         Timeout * const autosave_timeout_;
199
200 public:
201         ///
202         /// dialogs for this view
203         ///
204
205         /** Check the status of all visible dialogs and disable or reenable
206          *  them as appropriate.
207          *
208          *  Disabling is needed for example when a dialog is open and the
209          *  cursor moves to a position where the corresponding inset is not
210          *  allowed.
211          */
212         void checkStatus();
213
214         /// Are the tooltips on or off?
215         bool tooltipsEnabled();
216
217         /// Hide all visible dialogs
218         void hideAll() const;
219         /// Hide any dialogs that require a buffer for them to operate
220         void hideBufferDependent() const;
221         /** Update visible, buffer-dependent dialogs
222             If the bool is true then a buffer change has occurred
223             else it is still the same buffer.
224          */
225         void updateBufferDependent(bool) const;
226
227         /** \param name == "bibtex", "citation" etc; an identifier used to
228             launch a particular dialog.
229             \param data is a string representation of the Inset contents.
230             It is often little more than the output from Inset::write.
231             It is passed to, and parsed by, the frontend dialog.
232             Several of these dialogs do not need any data,
233             so it defaults to string().
234             \param inset ownership is _not_ passed to the frontend dialog.
235             It is stored internally and used by the kernel to ascertain
236             what to do with the FuncRequest dispatched from the frontend
237             dialog on 'Apply'; should it be used to create a new inset at
238             the current cursor position or modify an existing, 'open' inset?
239         */
240         void showDialog(std::string const & name,
241                 std::string const & data, Inset * inset = 0);
242
243         /** \param name == "citation", "bibtex" etc; an identifier used
244             to update the contents of a particular dialog with \param data.
245             See the comments to 'show', above.
246         */
247         void updateDialog(std::string const & name, std::string const & data);
248
249         /// Is the dialog currently visible?
250         bool isDialogVisible(std::string const & name) const;
251
252         /** All Dialogs of the given \param name will be closed if they are
253             connected to the given \param inset.
254         */
255         void hideDialog(std::string const & name, Inset * inset);
256         ///
257         void disconnectDialog(std::string const & name);
258         ///
259         Inset * getOpenInset(std::string const & name) const;
260
261 private:
262         ///
263         void redrawDialog() const;
264         ///
265         bool isValidName(std::string const & name) const;
266         ///
267         Dialog * find_or_build(std::string const & name);
268         ///
269         Dialog * build(std::string const & name);
270
271         ///
272         /// flag against a race condition due to multiclicks in Qt frontend,
273         /// see bug #1119
274         bool in_show_;
275 };
276
277 } // namespace frontend
278 } // namespace lyx
279
280 #endif // GUIVIEW_H