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