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