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