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