]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
- Cleanup and simplify the layout list GUI handling.
[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
53 {
54         Q_OBJECT
55 public:
56         /// create a main window of the given dimensions
57         GuiView(int id);
58
59         ~GuiView();
60
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         /** Check the status of all visible dialogs and disable or reenable
185          *  them as appropriate.
186          *
187          *  Disabling is needed for example when a dialog is open and the
188          *  cursor moves to a position where the corresponding inset is not
189          *  allowed.
190          */
191         void checkStatus();
192
193         /// Hide all visible dialogs
194         void hideAll() const;
195         /// Hide any dialogs that require a buffer for them to operate
196         void hideBufferDependent() const;
197         /** Update visible, buffer-dependent dialogs
198             If the bool is true then a buffer change has occurred
199             else it is still the same buffer.
200          */
201         void updateBufferDependent(bool) const;
202
203         /** \param name == "bibtex", "citation" etc; an identifier used to
204             launch a particular dialog.
205             \param data is a string representation of the Inset contents.
206             It is often little more than the output from Inset::write.
207             It is passed to, and parsed by, the frontend dialog.
208             Several of these dialogs do not need any data,
209             so it defaults to string().
210             \param inset ownership is _not_ passed to the frontend dialog.
211             It is stored internally and used by the kernel to ascertain
212             what to do with the FuncRequest dispatched from the frontend
213             dialog on 'Apply'; should it be used to create a new inset at
214             the current cursor position or modify an existing, 'open' inset?
215         */
216         void showDialog(std::string const & name,
217                 std::string const & data, Inset * inset = 0);
218
219         /** \param name == "citation", "bibtex" etc; an identifier used
220             to update the contents of a particular dialog with \param data.
221             See the comments to 'show', above.
222         */
223         void updateDialog(std::string const & name, std::string const & data);
224
225         /** All Dialogs of the given \param name will be closed if they are
226             connected to the given \param inset.
227         */
228         void hideDialog(std::string const & name, Inset * inset);
229         ///
230         void disconnectDialog(std::string const & name);
231         ///
232         Inset * getOpenInset(std::string const & name) const;
233
234 private:
235         /// Is the dialog currently visible?
236         bool isDialogVisible(std::string const & name) const;
237         ///
238         Dialog * find_or_build(std::string const & name);
239         ///
240         Dialog * build(std::string const & name);
241
242         /// This view ID.
243         int id_;
244 };
245
246 } // namespace frontend
247 } // namespace lyx
248
249 #endif // GUIVIEW_H