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;
47 * GuiView - Qt4 implementation of LyXView
49 * qt4-private implementation of the main LyX window.
51 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
52 * is deleted. This might be useful for closing other dialogs
53 * depending on a given GuiView.
55 class GuiView : public QMainWindow, public LyXView, public GuiBufferViewDelegate,
56 public GuiBufferDelegate
60 /// create a main window of the given dimensions
65 /// LyXView inherited methods.
67 int id() const { return id_; };
69 BufferView * currentBufferView();
70 BufferView const * currentBufferView() const;
71 BufferView * documentBufferView();
72 BufferView const * documentBufferView() const;
73 void setBuffer(Buffer * b);
74 Buffer * loadDocument(support::FileName const & name,
75 bool tolastfiles = true);
76 void newDocument(std::string const & filename,
78 void message(docstring const &);
79 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
80 bool dispatch(FuncRequest const & cmd);
82 void updateCompletion(Cursor & cur, bool start, bool keep);
86 /// add toolbar, if newline==true, add a toolbar break before the toolbar
87 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
88 void updateStatusBar();
90 /// updates the possible layouts selectable
91 void updateLayoutList();
92 void updateToolbars();
93 QMenu * createPopupMenu();
96 LayoutBox * getLayoutDialog() const;
98 /// hides the workarea and makes sure it is clean
99 bool hideWorkArea(GuiWorkArea * wa);
100 /// closes the workarea
101 bool closeWorkArea(GuiWorkArea * wa);
103 void openDocument(std::string const & filename);
105 void importDocument(std::string const &);
107 /// GuiBufferDelegate.
109 void resetAutosaveTimers();
110 void errors(std::string const &, bool from_master = false);
111 void structureChanged();
112 void updateTocItem(std::string const &, DocIterator const &);
116 TocModels & tocModels();
118 /// called on timeout
121 /** redraw \c inset in all the BufferViews in which it is currently
122 * visible. If successful return a pointer to the owning Buffer.
124 Buffer const * updateInset(Inset const *);
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);
134 /// \param work_area The current \c WorkArea, or \c NULL
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;
140 /// return the current WorkArea (the one that has the focus).
141 GuiWorkArea * currentWorkArea();
143 /// return the current document WorkArea (it may not have the focus).
144 GuiWorkArea const * currentMainWorkArea() const;
145 /// return the current document WorkArea (it may not have the focus).
146 GuiWorkArea * currentMainWorkArea();
153 /// clear any temporary message and replace with current status.
158 void updateWindowTitle(GuiWorkArea * wa);
160 void resetWindowTitleAndIconText();
163 void on_currentWorkAreaChanged(GuiWorkArea *);
165 void on_lastWorkAreaRemoved();
167 /// slots to change the icon size
168 void smallSizedIcons();
169 void normalSizedIcons();
170 void bigSizedIcons();
173 /// Open given child document in current buffer directory.
174 void openChildDocument(std::string const & filename);
175 /// Close current document buffer.
177 /// Close all document buffers.
178 bool closeBufferAll();
180 TabWorkArea * addTabWorkArea();
182 /// connect to signals in the given BufferView
183 void connectBufferView(BufferView & bv);
184 /// disconnect from signals in the given BufferView
185 void disconnectBufferView();
186 /// connect to signals in the given buffer
187 void connectBuffer(Buffer & buf);
188 /// disconnect from signals in the given buffer
189 void disconnectBuffer();
191 void dragEnterEvent(QDragEnterEvent * ev);
193 void dropEvent(QDropEvent * ev);
194 /// make sure we quit cleanly
195 void closeEvent(QCloseEvent * e);
197 void showEvent(QShowEvent *);
199 /// in order to catch Tab key press.
200 bool event(QEvent * e);
201 bool focusNextPrevChild(bool);
204 bool goToFileRow(std::string const & argument);
207 struct GuiViewPrivate;
212 /// dialogs for this view
218 /// Hide all visible dialogs
219 void hideAll() const;
221 /// Update all visible dialogs.
223 * Check the status of all visible dialogs and disable or reenable
224 * them as appropriate.
226 * Disabling is needed for example when a dialog is open and the
227 * cursor moves to a position where the corresponding inset is not
230 void updateDialogs();
232 /** \param name == "bibtex", "citation" etc; an identifier used to
233 launch a particular dialog.
234 \param data is a string representation of the Inset contents.
235 It is often little more than the output from Inset::write.
236 It is passed to, and parsed by, the frontend dialog.
237 Several of these dialogs do not need any data,
238 so it defaults to string().
239 \param inset ownership is _not_ passed to the frontend dialog.
240 It is stored internally and used by the kernel to ascertain
241 what to do with the FuncRequest dispatched from the frontend
242 dialog on 'Apply'; should it be used to create a new inset at
243 the current cursor position or modify an existing, 'open' inset?
245 void showDialog(std::string const & name,
246 std::string const & data, Inset * inset = 0);
248 /** \param name == "citation", "bibtex" etc; an identifier used
249 to reset the contents of a particular dialog with \param data.
250 See the comments to 'show', above.
252 void updateDialog(std::string const & name, std::string const & data);
254 /** All Dialogs of the given \param name will be closed if they are
255 connected to the given \param inset.
257 void hideDialog(std::string const & name, Inset * inset);
259 void disconnectDialog(std::string const & name);
263 void saveLayout() const;
265 bool restoreLayout();
267 GuiToolbar * toolbar(std::string const & name);
269 void constructToolbars();
273 void lfunUiToggle(FuncRequest const & cmd);
275 void toggleFullScreen();
277 void insertLyXFile(docstring const & fname);
279 void insertPlaintextFile(docstring const & fname,
282 /// Save a buffer as a new file.
284 Write a buffer to a new file name and rename the buffer
285 according to the new file name.
287 This function is e.g. used by menu callbacks and
288 LFUN_BUFFER_WRITE_AS.
290 If 'newname' is empty, the user is asked via a
291 dialog for the buffer's new name and location.
293 If 'newname' is non-empty and has an absolute path, that is used.
294 Otherwise the base directory of the buffer is used as the base
295 for any relative path in 'newname'.
297 bool renameBuffer(Buffer & b, docstring const & newname);
299 bool saveBuffer(Buffer & b);
300 /// closes a workarea, if close_buffer is true the buffer will
301 /// also be released, otherwise the buffer will be hidden.
302 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
303 /// closes the tabworkarea and all tabs. If we are in a close event,
304 /// all buffers will be closed, otherwise they will be hidden.
305 bool closeTabWorkArea(TabWorkArea * twa);
306 /// gives the user the possibility to save his work
307 /// or to discard the changes. If hiding is true, the
308 /// document will be reloaded.
309 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
310 /// closes all workareas
311 bool closeWorkAreaAll();
312 /// write all open workareas into the session file
313 void writeSession() const;
314 /// is the buffer in this workarea also shown in another tab ?
315 /// This tab can either be in the same view or in another one.
316 bool inMultiTabs(GuiWorkArea * wa);
317 /// is the buffer in this workarea also shown in another view ?
318 bool inMultiViews(GuiWorkArea * wa);
320 enum NextOrPrevious {
325 void gotoNextOrPreviousBuffer(NextOrPrevious np);
327 /// Is the dialog currently visible?
328 bool isDialogVisible(std::string const & name) const;
330 Dialog * findOrBuild(std::string const & name, bool hide_it);
332 Dialog * build(std::string const & name);
336 void dispatchVC(FuncRequest const & cmd);
341 /// flag to avoid two concurrent close events.
345 } // namespace frontend