]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
cleanup and reorder initialisation code of GuiView and GuiToolbars. Move some things...
[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         ///
65         ///
66         int id() const { return id_; }
67         void close();
68         void setFocus();
69         void setBusy(bool);
70
71         /// add toolbar, if newline==true, add a toolbar break before the toolbar
72         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
73         virtual void updateStatusBar();
74         virtual void message(docstring const & str);
75         virtual bool hasFocus() const;
76         void updateLayoutChoice(bool force);
77         bool isToolbarVisible(std::string const & id);
78         void updateToolbars();
79         ///
80         QMenu * createPopupMenu();
81
82         /// dispatch to current BufferView
83         void dispatch(FuncRequest const & cmd);
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         /// GuiBufferDelegate.
92         ///@{
93         void resetAutosaveTimers();
94         void errors(std::string const &);
95         void structureChanged() { updateToc(); }
96         ///@}
97         
98         /// called on timeout
99         void autoSave();
100         ///
101         void updateEmbeddedFiles();
102
103         /// \return the current buffer view.
104         BufferView * view();
105
106         /// load a buffer into the current workarea.
107         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
108                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
109
110         /** redraw \c inset in all the BufferViews in which it is currently
111          *  visible. If successful return a pointer to the owning Buffer.
112          */
113         Buffer const * updateInset(Inset const *);
114         ///
115         void restartCursor();
116
117         /// \return the \c Workarea associated to \p  Buffer
118         /// \retval 0 if no \c WorkArea is found.
119         GuiWorkArea * workArea(Buffer & buffer);
120
121         /// Add a \c WorkArea 
122         /// \return the \c Workarea associated to \p  Buffer
123         /// \retval 0 if no \c WorkArea is found.
124         GuiWorkArea * addWorkArea(Buffer & buffer);
125         ///
126         void setCurrentWorkArea(GuiWorkArea * work_area);
127         ///
128         void removeWorkArea(GuiWorkArea * work_area);
129         /// return the current WorkArea (the one that has the focus).
130         GuiWorkArea const * currentWorkArea() const;
131
132 Q_SIGNALS:
133         void closing(int);
134
135 public Q_SLOTS:
136         /// idle timeout.
137         /// clear any temporary message and replace with current status.
138         void clearMessage();
139
140 private Q_SLOTS:
141         ///
142         void updateWindowTitle(GuiWorkArea * wa);
143
144         ///
145         void on_currentWorkAreaChanged(GuiWorkArea *);
146
147         /// slots to change the icon size
148         void smallSizedIcons();
149         void normalSizedIcons();
150         void bigSizedIcons();
151
152 private:
153         ///
154         void addTabWorkArea();
155
156         /// connect to signals in the given BufferView
157         void connectBufferView(BufferView & bv);
158         /// disconnect from signals in the given BufferView
159         void disconnectBufferView();
160         /// connect to signals in the given buffer
161         void connectBuffer(Buffer & buf);
162         /// disconnect from signals in the given buffer
163         void disconnectBuffer();
164         ///
165         void updateToc();
166         ///
167         void dragEnterEvent(QDragEnterEvent * ev);
168         ///
169         void dropEvent(QDropEvent * ev);
170         /// make sure we quit cleanly
171         void closeEvent(QCloseEvent * e);
172         ///
173         void showEvent(QShowEvent *);
174
175         /// in order to catch Tab key press.
176         bool event(QEvent * e);
177         bool focusNextPrevChild(bool);
178
179         ///
180         struct GuiViewPrivate;
181         GuiViewPrivate & d;
182
183 public:
184         ///
185         /// dialogs for this view
186         ///
187
188         /** Check the status of all visible dialogs and disable or reenable
189          *  them as appropriate.
190          *
191          *  Disabling is needed for example when a dialog is open and the
192          *  cursor moves to a position where the corresponding inset is not
193          *  allowed.
194          */
195         void checkStatus();
196
197         /// Hide all visible dialogs
198         void hideAll() const;
199         /// Hide any dialogs that require a buffer for them to operate
200         void hideBufferDependent() const;
201         /** Update visible, buffer-dependent dialogs
202             If the bool is true then a buffer change has occurred
203             else it is still the same buffer.
204          */
205         void updateBufferDependent(bool) const;
206
207         /** \param name == "bibtex", "citation" etc; an identifier used to
208             launch a particular dialog.
209             \param data is a string representation of the Inset contents.
210             It is often little more than the output from Inset::write.
211             It is passed to, and parsed by, the frontend dialog.
212             Several of these dialogs do not need any data,
213             so it defaults to string().
214             \param inset ownership is _not_ passed to the frontend dialog.
215             It is stored internally and used by the kernel to ascertain
216             what to do with the FuncRequest dispatched from the frontend
217             dialog on 'Apply'; should it be used to create a new inset at
218             the current cursor position or modify an existing, 'open' inset?
219         */
220         void showDialog(std::string const & name,
221                 std::string const & data, Inset * inset = 0);
222
223         /** \param name == "citation", "bibtex" etc; an identifier used
224             to update the contents of a particular dialog with \param data.
225             See the comments to 'show', above.
226         */
227         void updateDialog(std::string const & name, std::string const & data);
228
229         /// Is the dialog currently visible?
230         bool isDialogVisible(std::string const & name) const;
231
232         /** All Dialogs of the given \param name will be closed if they are
233             connected to the given \param inset.
234         */
235         void hideDialog(std::string const & name, Inset * inset);
236         ///
237         void disconnectDialog(std::string const & name);
238         ///
239         Inset * getOpenInset(std::string const & name) const;
240
241 private:
242         ///
243         void redrawDialog() const;
244         ///
245         bool isValidName(std::string const & name) const;
246         ///
247         Dialog * find_or_build(std::string const & name);
248         ///
249         Dialog * build(std::string const & name);
250
251         /// This view ID.
252         int id_;
253 };
254
255 } // namespace frontend
256 } // namespace lyx
257
258 #endif // GUIVIEW_H