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;
46 * GuiView - Qt4 implementation of LyXView
48 * qt4-private implementation of the main LyX window.
50 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
51 * is deleted. This might be useful for closing other dialogs
52 * depending on a given GuiView.
54 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
55 public GuiBufferDelegate
59 /// create a main window of the given dimensions
65 int id() const { return id_; }
68 /// returns true if this view has the focus.
69 bool hasFocus() const;
71 /// add toolbar, if newline==true, add a toolbar break before the toolbar
72 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
73 virtual void updateStatusBar();
74 virtual void message(docstring const & str);
76 /// updates the possible layouts selectable
77 void updateLayoutList();
78 void updateToolbars();
79 QMenu * createPopupMenu();
80 FuncStatus getStatus(FuncRequest const & cmd);
81 bool dispatch(FuncRequest const & cmd);
84 void setLayoutDialog(GuiLayoutBox *);
86 /// \return the buffer currently shown in this window
88 Buffer const * buffer() const;
89 /// set a buffer to the current workarea.
90 void setBuffer(Buffer * b); ///< \c Buffer to set.
93 /// load a document into the current workarea.
94 Buffer * loadDocument(support::FileName const & name, ///< File to load.
95 bool tolastfiles = true); ///< append to the "Open recent" menu?
97 void openDocument(std::string const & filename);
99 void importDocument(std::string const &);
101 void newDocument(std::string const & filename, bool fromTemplate);
103 /// GuiBufferDelegate.
105 void resetAutosaveTimers();
106 void errors(std::string const &);
107 void structureChanged();
110 /// called on timeout
113 /// \return the current buffer view.
116 /** redraw \c inset in all the BufferViews in which it is currently
117 * visible. If successful return a pointer to the owning Buffer.
119 Buffer const * updateInset(Inset const *);
121 void restartCursor();
123 /// \return the \c Workarea associated to \p Buffer
124 /// \retval 0 if no \c WorkArea is found.
125 GuiWorkArea * workArea(Buffer & buffer);
127 /// Add a \c WorkArea
128 /// \return the \c Workarea associated to \p Buffer
129 /// \retval 0 if no \c WorkArea is found.
130 GuiWorkArea * addWorkArea(Buffer & buffer);
132 void setCurrentWorkArea(GuiWorkArea * work_area);
134 void removeWorkArea(GuiWorkArea * work_area);
135 /// return the current WorkArea (the one that has the focus).
136 GuiWorkArea const * currentWorkArea() const;
143 /// clear any temporary message and replace with current status.
148 void updateWindowTitle(GuiWorkArea * wa);
151 void on_currentWorkAreaChanged(GuiWorkArea *);
153 void on_lastWorkAreaRemoved();
155 /// slots to change the icon size
156 void smallSizedIcons();
157 void normalSizedIcons();
158 void bigSizedIcons();
162 TabWorkArea * addTabWorkArea();
164 /// connect to signals in the given BufferView
165 void connectBufferView(BufferView & bv);
166 /// disconnect from signals in the given BufferView
167 void disconnectBufferView();
168 /// connect to signals in the given buffer
169 void connectBuffer(Buffer & buf);
170 /// disconnect from signals in the given buffer
171 void disconnectBuffer();
173 void dragEnterEvent(QDragEnterEvent * ev);
175 void dropEvent(QDropEvent * ev);
176 /// make sure we quit cleanly
177 void closeEvent(QCloseEvent * e);
179 void showEvent(QShowEvent *);
181 /// in order to catch Tab key press.
182 bool event(QEvent * e);
183 bool focusNextPrevChild(bool);
186 struct GuiViewPrivate;
191 /// dialogs for this view
197 /** Check the status of all visible dialogs and disable or reenable
198 * them as appropriate.
200 * Disabling is needed for example when a dialog is open and the
201 * cursor moves to a position where the corresponding inset is not
206 /// Hide all visible dialogs
207 void hideAll() const;
209 // Update all visible dialogs.
210 void updateDialogs();
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);
242 void updateCompletion(Cursor & cur, bool start, bool keep);
246 void lfunUiToggle(FuncRequest const & cmd);
249 void insertLyXFile(docstring const & fname);
251 void insertPlaintextFile(docstring const & fname,
254 /// Save a buffer as a new file.
256 Write a buffer to a new file name and rename the buffer
257 according to the new file name.
259 This function is e.g. used by menu callbacks and
260 LFUN_BUFFER_WRITE_AS.
262 If 'newname' is empty, the user is asked via a
263 dialog for the buffer's new name and location.
265 If 'newname' is non-empty and has an absolute path, that is used.
266 Otherwise the base directory of the buffer is used as the base
267 for any relative path in 'newname'.
269 bool renameBuffer(Buffer & b, docstring const & newname);
271 bool saveBuffer(Buffer & b);
273 bool closeBuffer(Buffer & buf, bool tolastopened = false);
276 Inset * getOpenInset(std::string const & name) const;
278 /// Is the dialog currently visible?
279 bool isDialogVisible(std::string const & name) const;
281 Dialog * find_or_build(std::string const & name);
283 Dialog * build(std::string const & name);
289 } // namespace frontend