4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjornes
9 * \author Abdelrazak Younes
10 * \author Peter Kümmel
12 * Full author contact details are available in file CREDITS.
18 #include "frontends/Delegates.h"
19 #include "frontends/LyXView.h"
21 #include "support/strfwd.h"
23 #include <QMainWindow>
26 class QDragEnterEvent;
44 * GuiView - Qt4 implementation of LyXView
46 * qt4-private implementation of the main LyX window.
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.
52 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
53 public GuiBufferDelegate
57 /// create a main window of the given dimensions
63 int id() const { return id_; }
67 /// returns true if this view has the focus.
68 bool hasFocus() const;
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);
75 /// updates the possible layouts selectable
76 void updateLayoutList();
77 void updateToolbars();
78 QMenu * createPopupMenu();
79 FuncStatus getStatus(FuncRequest const & cmd);
80 bool dispatch(FuncRequest const & cmd);
83 void setLayoutDialog(GuiLayoutBox *);
85 /// \return the buffer currently shown in this window
87 Buffer const * buffer() const;
88 /// set a buffer to the current workarea.
89 void setBuffer(Buffer * b); ///< \c Buffer to set.
93 void newDocument(std::string const & filename, bool fromTemplate);
94 /// write all buffers, asking the user, returns false if cancelled
97 /// GuiBufferDelegate.
99 void resetAutosaveTimers();
100 void errors(std::string const &);
101 void structureChanged() { updateToc(); }
104 /// called on timeout
107 void updateEmbeddedFiles();
109 /// \return the current buffer view.
112 /** redraw \c inset in all the BufferViews in which it is currently
113 * visible. If successful return a pointer to the owning Buffer.
115 Buffer const * updateInset(Inset const *);
117 void restartCursor();
119 /// \return the \c Workarea associated to \p Buffer
120 /// \retval 0 if no \c WorkArea is found.
121 GuiWorkArea * workArea(Buffer & buffer);
123 /// Add a \c WorkArea
124 /// \return the \c Workarea associated to \p Buffer
125 /// \retval 0 if no \c WorkArea is found.
126 GuiWorkArea * addWorkArea(Buffer & buffer);
128 void setCurrentWorkArea(GuiWorkArea * work_area);
130 void removeWorkArea(GuiWorkArea * work_area);
131 /// return the current WorkArea (the one that has the focus).
132 GuiWorkArea const * currentWorkArea() const;
139 /// clear any temporary message and replace with current status.
144 void updateWindowTitle(GuiWorkArea * wa);
147 void on_currentWorkAreaChanged(GuiWorkArea *);
149 /// slots to change the icon size
150 void smallSizedIcons();
151 void normalSizedIcons();
152 void bigSizedIcons();
156 void addTabWorkArea();
158 /// connect to signals in the given BufferView
159 void connectBufferView(BufferView & bv);
160 /// disconnect from signals in the given BufferView
161 void disconnectBufferView();
162 /// connect to signals in the given buffer
163 void connectBuffer(Buffer & buf);
164 /// disconnect from signals in the given buffer
165 void disconnectBuffer();
169 void dragEnterEvent(QDragEnterEvent * ev);
171 void dropEvent(QDropEvent * ev);
172 /// make sure we quit cleanly
173 void closeEvent(QCloseEvent * e);
175 void showEvent(QShowEvent *);
177 /// in order to catch Tab key press.
178 bool event(QEvent * e);
179 bool focusNextPrevChild(bool);
182 struct GuiViewPrivate;
187 /// dialogs for this view
193 /** Check the status of all visible dialogs and disable or reenable
194 * them as appropriate.
196 * Disabling is needed for example when a dialog is open and the
197 * cursor moves to a position where the corresponding inset is not
202 /// Hide all visible dialogs
203 void hideAll() const;
204 /// Hide any dialogs that require a buffer for them to operate
205 void hideBufferDependent() const;
206 /** Update visible, buffer-dependent dialogs
207 If the bool is true then a buffer change has occurred
208 else it is still the same buffer.
210 void updateBufferDependent(bool) const;
212 /** \param name == "bibtex", "citation" etc; an identifier used to
213 launch a particular dialog.
214 \param data is a string representation of the Inset contents.
215 It is often little more than the output from Inset::write.
216 It is passed to, and parsed by, the frontend dialog.
217 Several of these dialogs do not need any data,
218 so it defaults to string().
219 \param inset ownership is _not_ passed to the frontend dialog.
220 It is stored internally and used by the kernel to ascertain
221 what to do with the FuncRequest dispatched from the frontend
222 dialog on 'Apply'; should it be used to create a new inset at
223 the current cursor position or modify an existing, 'open' inset?
225 void showDialog(std::string const & name,
226 std::string const & data, Inset * inset = 0);
228 /** \param name == "citation", "bibtex" etc; an identifier used
229 to update the contents of a particular dialog with \param data.
230 See the comments to 'show', above.
232 void updateDialog(std::string const & name, std::string const & data);
234 /** All Dialogs of the given \param name will be closed if they are
235 connected to the given \param inset.
237 void hideDialog(std::string const & name, Inset * inset);
239 void disconnectDialog(std::string const & name);
243 void insertLyXFile(docstring const & fname);
245 void insertPlaintextFile(docstring const & fname,
248 /// Save a buffer as a new file.
250 Write a buffer to a new file name and rename the buffer
251 according to the new file name.
253 This function is e.g. used by menu callbacks and
254 LFUN_BUFFER_WRITE_AS.
256 If 'newname' is empty, the user is asked via a
257 dialog for the buffer's new name and location.
259 If 'newname' is non-empty and has an absolute path, that is used.
260 Otherwise the base directory of the buffer is used as the base
261 for any relative path in 'newname'.
263 bool renameBuffer(Buffer & b, docstring const & newname);
265 bool saveBuffer(Buffer & b);
267 bool closeBuffer(Buffer & buf);
270 Inset * getOpenInset(std::string const & name) const;
272 /// Is the dialog currently visible?
273 bool isDialogVisible(std::string const & name) const;
275 Dialog * find_or_build(std::string const & name);
277 Dialog * build(std::string const & name);
283 } // namespace frontend