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
66 int id() const { return id_; }
69 /// returns true if this view has the focus.
70 bool hasFocus() const;
72 /// add toolbar, if newline==true, add a toolbar break before the toolbar
73 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
74 virtual void updateStatusBar();
75 virtual void message(docstring const & str);
77 /// updates the possible layouts selectable
78 void updateLayoutList();
79 void updateToolbars();
80 QMenu * createPopupMenu();
81 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
82 bool dispatch(FuncRequest const & cmd);
85 LayoutBox * getLayoutDialog() const;
87 /// \return the buffer currently shown in this window
89 Buffer const * buffer() const;
90 /// set a buffer to the current workarea.
91 void setBuffer(Buffer * b); ///< \c Buffer to set.
92 /// closes the current active buffer
94 /// hides the workarea and makes sure it is clean
95 bool hideWorkArea(GuiWorkArea * wa);
96 /// closes the workarea
97 bool closeWorkArea(GuiWorkArea * wa);
98 /// load a document into the current workarea.
99 Buffer * loadDocument(support::FileName const & name, ///< File to load.
100 bool tolastfiles = true); ///< append to the "Open recent" menu?
102 void openDocument(std::string const & filename);
104 void importDocument(std::string const &);
106 void newDocument(std::string const & filename, bool fromTemplate);
108 /// GuiBufferDelegate.
110 void resetAutosaveTimers();
111 void errors(std::string const &, bool from_master = false);
112 void structureChanged();
113 void updateTocItem(std::string const &, DocIterator const &);
117 TocModels & tocModels();
119 /// called on timeout
122 /// \return the current buffer view.
125 /** redraw \c inset in all the BufferViews in which it is currently
126 * visible. If successful return a pointer to the owning Buffer.
128 Buffer const * updateInset(Inset const *);
130 void restartCursor();
132 /// \return the \c Workarea associated to \p Buffer
133 /// \retval 0 if no \c WorkArea is found.
134 GuiWorkArea * workArea(Buffer & buffer);
136 /// Add a \c WorkArea
137 /// \return the \c Workarea associated to \p Buffer
138 /// \retval 0 if no \c WorkArea is found.
139 GuiWorkArea * addWorkArea(Buffer & buffer);
141 void setCurrentWorkArea(GuiWorkArea * work_area);
143 void removeWorkArea(GuiWorkArea * work_area);
144 /// return the current WorkArea (the one that has the focus).
145 GuiWorkArea const * currentWorkArea() const;
146 /// return the current WorkArea (the one that has the focus).
147 GuiWorkArea * currentWorkArea();
149 /// return the current document WorkArea (it may not have the focus).
150 GuiWorkArea const * currentMainWorkArea() const;
151 /// return the current document WorkArea (it may not have the focus).
152 GuiWorkArea * currentMainWorkArea();
159 /// clear any temporary message and replace with current status.
164 void updateWindowTitle(GuiWorkArea * wa);
166 void resetWindowTitleAndIconText();
169 void on_currentWorkAreaChanged(GuiWorkArea *);
171 void on_lastWorkAreaRemoved();
173 /// slots to change the icon size
174 void smallSizedIcons();
175 void normalSizedIcons();
176 void bigSizedIcons();
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 struct GuiViewPrivate;
209 /// dialogs for this view
215 /// Hide all visible dialogs
216 void hideAll() const;
218 /// Update all visible dialogs.
220 * Check the status of all visible dialogs and disable or reenable
221 * them as appropriate.
223 * Disabling is needed for example when a dialog is open and the
224 * cursor moves to a position where the corresponding inset is not
227 void updateDialogs();
229 /** \param name == "bibtex", "citation" etc; an identifier used to
230 launch a particular dialog.
231 \param data is a string representation of the Inset contents.
232 It is often little more than the output from Inset::write.
233 It is passed to, and parsed by, the frontend dialog.
234 Several of these dialogs do not need any data,
235 so it defaults to string().
236 \param inset ownership is _not_ passed to the frontend dialog.
237 It is stored internally and used by the kernel to ascertain
238 what to do with the FuncRequest dispatched from the frontend
239 dialog on 'Apply'; should it be used to create a new inset at
240 the current cursor position or modify an existing, 'open' inset?
242 void showDialog(std::string const & name,
243 std::string const & data, Inset * inset = 0);
245 /** \param name == "citation", "bibtex" etc; an identifier used
246 to reset the contents of a particular dialog with \param data.
247 See the comments to 'show', above.
249 void updateDialog(std::string const & name, std::string const & data);
251 /** All Dialogs of the given \param name will be closed if they are
252 connected to the given \param inset.
254 void hideDialog(std::string const & name, Inset * inset);
256 void disconnectDialog(std::string const & name);
259 void updateCompletion(Cursor & cur, bool start, bool keep);
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 /// main_work_area is the workarea marked in the session file as active.
306 bool closeTabWorkArea(TabWorkArea * twa);
307 /// gives the user the possibility to save his work
308 /// or to discard the changes. If hiding is true, the
309 /// document will be reloaded.
310 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
311 /// closes all workareas and all hidden buffers
312 bool closeBufferAll();
313 /// closes all workareas
314 bool closeWorkAreaAll();
315 /// write all open workareas into the session file
316 void writeSession() const;
317 /// is the buffer in this workarea also shown in another tab ?
318 /// This tab can either be in the same view or in another one.
319 bool inMultiTabs(GuiWorkArea * wa);
320 /// is the buffer in this workarea also shown in another view ?
321 bool inMultiViews(GuiWorkArea * wa);
323 enum NextOrPrevious {
328 void gotoNextOrPreviousBuffer(NextOrPrevious np);
331 Inset * getOpenInset(std::string const & name) const;
333 /// Is the dialog currently visible?
334 bool isDialogVisible(std::string const & name) const;
336 Dialog * findOrBuild(std::string const & name, bool hide_it);
338 Dialog * build(std::string const & name);
343 /// flag to avoid two concurrent close events.
347 } // namespace frontend