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;
74 Buffer const * buffer() const;
75 Buffer * documentBuffer();
76 Buffer const * documentBuffer() const;
77 void setBuffer(Buffer * b);
79 bool closeBufferAll();
80 bool hasFocus() const;
81 Buffer * loadDocument(support::FileName const & name,
82 bool tolastfiles = true);
83 void newDocument(std::string const & filename,
85 void message(docstring const &);
86 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
87 bool dispatch(FuncRequest const & cmd);
89 void updateCompletion(Cursor & cur, bool start, bool keep);
93 /// add toolbar, if newline==true, add a toolbar break before the toolbar
94 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
95 void updateStatusBar();
97 /// updates the possible layouts selectable
98 void updateLayoutList();
99 void updateToolbars();
100 QMenu * createPopupMenu();
103 LayoutBox * getLayoutDialog() const;
105 /// hides the workarea and makes sure it is clean
106 bool hideWorkArea(GuiWorkArea * wa);
107 /// closes the workarea
108 bool closeWorkArea(GuiWorkArea * wa);
110 void openDocument(std::string const & filename);
112 void importDocument(std::string const &);
114 /// GuiBufferDelegate.
116 void resetAutosaveTimers();
117 void errors(std::string const &, bool from_master = false);
118 void structureChanged();
119 void updateTocItem(std::string const &, DocIterator const &);
123 TocModels & tocModels();
125 /// called on timeout
128 /** redraw \c inset in all the BufferViews in which it is currently
129 * visible. If successful return a pointer to the owning Buffer.
131 Buffer const * updateInset(Inset const *);
133 /// \return the \c Workarea associated to \p Buffer
134 /// \retval 0 if no \c WorkArea is found.
135 GuiWorkArea * workArea(Buffer & buffer);
137 /// Add a \c WorkArea
138 /// \return the \c Workarea associated to \p Buffer
139 /// \retval 0 if no \c WorkArea is found.
140 GuiWorkArea * addWorkArea(Buffer & buffer);
141 /// \param work_area The current \c WorkArea, or \c NULL
142 void setCurrentWorkArea(GuiWorkArea * work_area);
144 void removeWorkArea(GuiWorkArea * work_area);
145 /// return the current WorkArea (the one that has the focus).
146 GuiWorkArea const * currentWorkArea() const;
147 /// return the current WorkArea (the one that has the focus).
148 GuiWorkArea * currentWorkArea();
150 /// return the current document WorkArea (it may not have the focus).
151 GuiWorkArea const * currentMainWorkArea() const;
152 /// return the current document WorkArea (it may not have the focus).
153 GuiWorkArea * currentMainWorkArea();
160 /// clear any temporary message and replace with current status.
165 void updateWindowTitle(GuiWorkArea * wa);
167 void resetWindowTitleAndIconText();
170 void on_currentWorkAreaChanged(GuiWorkArea *);
172 void on_lastWorkAreaRemoved();
174 /// slots to change the icon size
175 void smallSizedIcons();
176 void normalSizedIcons();
177 void bigSizedIcons();
181 TabWorkArea * addTabWorkArea();
183 /// connect to signals in the given BufferView
184 void connectBufferView(BufferView & bv);
185 /// disconnect from signals in the given BufferView
186 void disconnectBufferView();
187 /// connect to signals in the given buffer
188 void connectBuffer(Buffer & buf);
189 /// disconnect from signals in the given buffer
190 void disconnectBuffer();
192 void dragEnterEvent(QDragEnterEvent * ev);
194 void dropEvent(QDropEvent * ev);
195 /// make sure we quit cleanly
196 void closeEvent(QCloseEvent * e);
198 void showEvent(QShowEvent *);
200 /// in order to catch Tab key press.
201 bool event(QEvent * e);
202 bool focusNextPrevChild(bool);
205 struct GuiViewPrivate;
210 /// dialogs for this view
216 /// Hide all visible dialogs
217 void hideAll() const;
219 /// Update all visible dialogs.
221 * Check the status of all visible dialogs and disable or reenable
222 * them as appropriate.
224 * Disabling is needed for example when a dialog is open and the
225 * cursor moves to a position where the corresponding inset is not
228 void updateDialogs();
230 /** \param name == "bibtex", "citation" etc; an identifier used to
231 launch a particular dialog.
232 \param data is a string representation of the Inset contents.
233 It is often little more than the output from Inset::write.
234 It is passed to, and parsed by, the frontend dialog.
235 Several of these dialogs do not need any data,
236 so it defaults to string().
237 \param inset ownership is _not_ passed to the frontend dialog.
238 It is stored internally and used by the kernel to ascertain
239 what to do with the FuncRequest dispatched from the frontend
240 dialog on 'Apply'; should it be used to create a new inset at
241 the current cursor position or modify an existing, 'open' inset?
243 void showDialog(std::string const & name,
244 std::string const & data, Inset * inset = 0);
246 /** \param name == "citation", "bibtex" etc; an identifier used
247 to reset the contents of a particular dialog with \param data.
248 See the comments to 'show', above.
250 void updateDialog(std::string const & name, std::string const & data);
252 /** All Dialogs of the given \param name will be closed if they are
253 connected to the given \param inset.
255 void hideDialog(std::string const & name, Inset * inset);
257 void disconnectDialog(std::string const & name);
261 void saveLayout() const;
263 bool restoreLayout();
265 GuiToolbar * toolbar(std::string const & name);
267 void constructToolbars();
271 void lfunUiToggle(FuncRequest const & cmd);
273 void toggleFullScreen();
275 void insertLyXFile(docstring const & fname);
277 void insertPlaintextFile(docstring const & fname,
280 /// Save a buffer as a new file.
282 Write a buffer to a new file name and rename the buffer
283 according to the new file name.
285 This function is e.g. used by menu callbacks and
286 LFUN_BUFFER_WRITE_AS.
288 If 'newname' is empty, the user is asked via a
289 dialog for the buffer's new name and location.
291 If 'newname' is non-empty and has an absolute path, that is used.
292 Otherwise the base directory of the buffer is used as the base
293 for any relative path in 'newname'.
295 bool renameBuffer(Buffer & b, docstring const & newname);
297 bool saveBuffer(Buffer & b);
298 /// closes a workarea, if close_buffer is true the buffer will
299 /// also be released, otherwise the buffer will be hidden.
300 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
301 /// closes the tabworkarea and all tabs. If we are in a close event,
302 /// all buffers will be closed, otherwise they will be hidden.
303 bool closeTabWorkArea(TabWorkArea * twa);
304 /// gives the user the possibility to save his work
305 /// or to discard the changes. If hiding is true, the
306 /// document will be reloaded.
307 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
308 /// closes all workareas
309 bool closeWorkAreaAll();
310 /// write all open workareas into the session file
311 void writeSession() const;
312 /// is the buffer in this workarea also shown in another tab ?
313 /// This tab can either be in the same view or in another one.
314 bool inMultiTabs(GuiWorkArea * wa);
315 /// is the buffer in this workarea also shown in another view ?
316 bool inMultiViews(GuiWorkArea * wa);
318 enum NextOrPrevious {
323 void gotoNextOrPreviousBuffer(NextOrPrevious np);
326 Inset * getOpenInset(std::string const & name) const;
328 /// Is the dialog currently visible?
329 bool isDialogVisible(std::string const & name) const;
331 Dialog * findOrBuild(std::string const & name, bool hide_it);
333 Dialog * build(std::string const & name);
338 /// flag to avoid two concurrent close events.
342 } // namespace frontend