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.
92 /// load a document into the current workarea.
93 Buffer * loadDocument(support::FileName const & name, ///< File to load.
94 bool tolastfiles = true); ///< append to the "Open recent" menu?
96 void openDocument(std::string const & filename);
98 void importDocument(std::string const &);
100 void newDocument(std::string const & filename, bool fromTemplate);
101 /// write all buffers, asking the user, returns false if cancelled
104 /// GuiBufferDelegate.
106 void resetAutosaveTimers();
107 void errors(std::string const &);
108 void structureChanged() { updateToc(); }
111 /// called on timeout
114 void updateEmbeddedFiles();
116 /// \return the current buffer view.
119 /** redraw \c inset in all the BufferViews in which it is currently
120 * visible. If successful return a pointer to the owning Buffer.
122 Buffer const * updateInset(Inset const *);
124 void restartCursor();
126 /// \return the \c Workarea associated to \p Buffer
127 /// \retval 0 if no \c WorkArea is found.
128 GuiWorkArea * workArea(Buffer & buffer);
130 /// Add a \c WorkArea
131 /// \return the \c Workarea associated to \p Buffer
132 /// \retval 0 if no \c WorkArea is found.
133 GuiWorkArea * addWorkArea(Buffer & buffer);
135 void setCurrentWorkArea(GuiWorkArea * work_area);
137 void removeWorkArea(GuiWorkArea * work_area);
138 /// return the current WorkArea (the one that has the focus).
139 GuiWorkArea const * currentWorkArea() const;
146 /// clear any temporary message and replace with current status.
151 void updateWindowTitle(GuiWorkArea * wa);
154 void on_currentWorkAreaChanged(GuiWorkArea *);
156 /// slots to change the icon size
157 void smallSizedIcons();
158 void normalSizedIcons();
159 void bigSizedIcons();
163 void addTabWorkArea();
165 /// connect to signals in the given BufferView
166 void connectBufferView(BufferView & bv);
167 /// disconnect from signals in the given BufferView
168 void disconnectBufferView();
169 /// connect to signals in the given buffer
170 void connectBuffer(Buffer & buf);
171 /// disconnect from signals in the given buffer
172 void disconnectBuffer();
176 void dragEnterEvent(QDragEnterEvent * ev);
178 void dropEvent(QDropEvent * ev);
179 /// make sure we quit cleanly
180 void closeEvent(QCloseEvent * e);
182 void showEvent(QShowEvent *);
184 /// in order to catch Tab key press.
185 bool event(QEvent * e);
186 bool focusNextPrevChild(bool);
189 struct GuiViewPrivate;
194 /// dialogs for this view
200 /** Check the status of all visible dialogs and disable or reenable
201 * them as appropriate.
203 * Disabling is needed for example when a dialog is open and the
204 * cursor moves to a position where the corresponding inset is not
209 /// Hide all visible dialogs
210 void hideAll() const;
211 /// Hide any dialogs that require a buffer for them to operate
212 void hideBufferDependent() const;
213 /** Update visible, buffer-dependent dialogs
214 If the bool is true then a buffer change has occurred
215 else it is still the same buffer.
217 void updateBufferDependent(bool) const;
219 /** \param name == "bibtex", "citation" etc; an identifier used to
220 launch a particular dialog.
221 \param data is a string representation of the Inset contents.
222 It is often little more than the output from Inset::write.
223 It is passed to, and parsed by, the frontend dialog.
224 Several of these dialogs do not need any data,
225 so it defaults to string().
226 \param inset ownership is _not_ passed to the frontend dialog.
227 It is stored internally and used by the kernel to ascertain
228 what to do with the FuncRequest dispatched from the frontend
229 dialog on 'Apply'; should it be used to create a new inset at
230 the current cursor position or modify an existing, 'open' inset?
232 void showDialog(std::string const & name,
233 std::string const & data, Inset * inset = 0);
235 /** \param name == "citation", "bibtex" etc; an identifier used
236 to update the contents of a particular dialog with \param data.
237 See the comments to 'show', above.
239 void updateDialog(std::string const & name, std::string const & data);
241 /** All Dialogs of the given \param name will be closed if they are
242 connected to the given \param inset.
244 void hideDialog(std::string const & name, Inset * inset);
246 void disconnectDialog(std::string const & name);
250 void insertLyXFile(docstring const & fname);
252 void insertPlaintextFile(docstring const & fname,
255 /// Save a buffer as a new file.
257 Write a buffer to a new file name and rename the buffer
258 according to the new file name.
260 This function is e.g. used by menu callbacks and
261 LFUN_BUFFER_WRITE_AS.
263 If 'newname' is empty, the user is asked via a
264 dialog for the buffer's new name and location.
266 If 'newname' is non-empty and has an absolute path, that is used.
267 Otherwise the base directory of the buffer is used as the base
268 for any relative path in 'newname'.
270 bool renameBuffer(Buffer & b, docstring const & newname);
272 bool saveBuffer(Buffer & b);
274 bool closeBuffer(Buffer & buf);
277 Inset * getOpenInset(std::string const & name) const;
279 /// Is the dialog currently visible?
280 bool isDialogVisible(std::string const & name) const;
282 Dialog * find_or_build(std::string const & name);
284 Dialog * build(std::string const & name);
290 } // namespace frontend