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"
20 #include "support/strfwd.h"
22 #include <QMainWindow>
25 class QDragEnterEvent;
33 namespace support { class FileName; }
54 * GuiView - Qt4 main LyX window
56 * This class represents the main LyX window and provides
57 * accessor functions to its content.
59 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
60 * is deleted. This might be useful for closing other dialogs
61 * depending on a given GuiView.
63 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
64 public GuiBufferDelegate
68 /// create a main window of the given dimensions
73 int id() const { return id_; }
77 /// \name Generic accessor functions
79 /// The current BufferView refers to the BufferView that has the focus,
80 /// including for example the one that is created when you use the
81 /// advanced search and replace pane.
82 /// \return the currently selected buffer view.
83 BufferView * currentBufferView();
84 BufferView const * currentBufferView() const;
86 /// The document BufferView always refers to the view's main document
87 /// BufferView. So, even if the BufferView in e.g., the advanced
88 /// search and replace pane has the focus.
89 /// \return the current document buffer view.
90 BufferView * documentBufferView();
91 BufferView const * documentBufferView() const;
93 void newDocument(std::string const & filename,
96 /// display a message in the view
97 /// could be called from any thread
98 void message(docstring const &);
99 /// must be called from GUI thread
100 void updateMessage(QString const & str);
102 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
103 /// dispatch command.
104 /// \return true if the \c FuncRequest has been dispatched.
105 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
107 void restartCursor();
108 /// Update the completion popup and the inline completion state.
109 /// If \c start is true, then a new completion might be started.
110 /// If \c keep is true, an active completion will be kept active
111 /// even though the cursor moved. The update flags of \c cur might
113 void updateCompletion(Cursor & cur, bool start, bool keep);
119 void focusInEvent(QFocusEvent * e);
120 /// set a buffer to the current workarea.
121 void setBuffer(Buffer * b); ///< \c Buffer to set.
123 /// load a document into the current workarea.
124 Buffer * loadDocument(
125 support::FileName const & name, ///< File to load.
126 bool tolastfiles = true ///< append to the "Open recent" menu?
129 /// add toolbar, if newline==true, add a toolbar break before the toolbar
130 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
131 void updateStatusBar();
133 /// updates the possible layouts selectable
134 void updateLayoutList();
135 void updateToolbars();
136 QMenu * createPopupMenu();
139 LayoutBox * getLayoutDialog() const;
141 /// hides the workarea and makes sure it is clean
142 bool hideWorkArea(GuiWorkArea * wa);
143 /// closes the workarea
144 bool closeWorkArea(GuiWorkArea * wa);
145 /// closes the buffer
146 bool closeBuffer(Buffer & buf);
148 void openDocument(std::string const & filename);
150 void importDocument(std::string const &);
152 /// \name GuiBufferDelegate.
154 void resetAutosaveTimers();
155 void errors(std::string const &, bool from_master = false);
156 void structureChanged();
157 void updateTocItem(std::string const &, DocIterator const &);
161 TocModels & tocModels();
163 /// called on timeout
166 /// check for external change of any opened buffer, mainly for svn usage
167 void checkExternallyModifiedBuffers();
169 /** redraw \c inset in all the BufferViews in which it is currently
170 * visible. If successful return a pointer to the owning Buffer.
172 Buffer const * updateInset(Inset const *);
174 /// \return the \c Workarea associated to \p Buffer
175 /// \retval 0 if no \c WorkArea is found.
176 GuiWorkArea * workArea(Buffer & buffer);
178 /// Add a \c WorkArea
179 /// \return the \c Workarea associated to \p Buffer
180 /// \retval 0 if no \c WorkArea is found.
181 GuiWorkArea * addWorkArea(Buffer & buffer);
182 /// \param work_area The current \c WorkArea, or \c NULL
183 void setCurrentWorkArea(GuiWorkArea * work_area);
185 void removeWorkArea(GuiWorkArea * work_area);
186 /// return the current WorkArea (the one that has the focus).
187 GuiWorkArea const * currentWorkArea() const;
188 /// return the current WorkArea (the one that has the focus).
189 GuiWorkArea * currentWorkArea();
191 /// return the current document WorkArea (it may not have the focus).
192 GuiWorkArea const * currentMainWorkArea() const;
193 /// return the current document WorkArea (it may not have the focus).
194 GuiWorkArea * currentMainWorkArea();
198 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
202 /// clear any temporary message and replace with current status.
207 void updateWindowTitle(GuiWorkArea * wa);
209 void resetWindowTitleAndIconText();
212 void on_currentWorkAreaChanged(GuiWorkArea *);
214 void on_lastWorkAreaRemoved();
216 /// slots to change the icon size
217 void smallSizedIcons();
218 void normalSizedIcons();
219 void bigSizedIcons();
221 /// For completion of autosave or exporrt threads.
222 void threadFinished();
224 /// must be called in GUI thread
225 void doShowDialog(QString const & qname, QString const & qdata,
229 /// Open given child document in current buffer directory.
230 void openChildDocument(std::string const & filename);
231 /// Close current document buffer.
233 /// Close all document buffers.
234 bool closeBufferAll();
236 TabWorkArea * addTabWorkArea();
238 /// connect to signals in the given BufferView
239 void connectBufferView(BufferView & bv);
240 /// disconnect from signals in the given BufferView
241 void disconnectBufferView();
242 /// connect to signals in the given buffer
243 void connectBuffer(Buffer & buf);
244 /// disconnect from signals in the given buffer
245 void disconnectBuffer();
247 void dragEnterEvent(QDragEnterEvent * ev);
249 void dropEvent(QDropEvent * ev);
250 /// make sure we quit cleanly
251 void closeEvent(QCloseEvent * e);
253 void showEvent(QShowEvent *);
255 /// in order to catch Tab key press.
256 bool event(QEvent * e);
257 bool focusNextPrevChild(bool);
260 bool goToFileRow(std::string const & argument);
263 struct GuiViewPrivate;
268 /// dialogs for this view
274 /// Hide all visible dialogs
275 void hideAll() const;
277 /// Update all visible dialogs.
279 * Check the status of all visible dialogs and disable or reenable
280 * them as appropriate.
282 * Disabling is needed for example when a dialog is open and the
283 * cursor moves to a position where the corresponding inset is not
286 void updateDialogs();
288 /** Show dialog could be called from arbitrary threads.
289 \param name == "bibtex", "citation" etc; an identifier used to
290 launch a particular dialog.
291 \param data is a string representation of the Inset contents.
292 It is often little more than the output from Inset::write.
293 It is passed to, and parsed by, the frontend dialog.
294 Several of these dialogs do not need any data,
295 so it defaults to string().
296 \param inset ownership is _not_ passed to the frontend dialog.
297 It is stored internally and used by the kernel to ascertain
298 what to do with the FuncRequest dispatched from the frontend
299 dialog on 'Apply'; should it be used to create a new inset at
300 the current cursor position or modify an existing, 'open' inset?
302 void showDialog(std::string const & name,
303 std::string const & data, Inset * inset = 0);
305 /** \param name == "citation", "bibtex" etc; an identifier used
306 to reset the contents of a particular dialog with \param data.
307 See the comments to 'show', above.
309 void updateDialog(std::string const & name, std::string const & data);
311 /** All Dialogs of the given \param name will be closed if they are
312 connected to the given \param inset.
314 void hideDialog(std::string const & name, Inset * inset);
316 void disconnectDialog(std::string const & name);
320 void saveLayout() const;
322 bool restoreLayout();
324 GuiToolbar * toolbar(std::string const & name);
326 void constructToolbars();
330 bool lfunUiToggle(std::string const & ui_component);
332 void toggleFullScreen();
334 void insertLyXFile(docstring const & fname);
336 void insertPlaintextFile(docstring const & fname,
339 /// Save a buffer as a new file.
341 Write a buffer to a new file name and rename the buffer
342 according to the new file name.
344 This function is e.g. used by menu callbacks and
345 LFUN_BUFFER_WRITE_AS.
347 If 'newname' is empty, the user is asked via a
348 dialog for the buffer's new name and location.
350 If 'newname' is non-empty and has an absolute path, that is used.
351 Otherwise the base directory of the buffer is used as the base
352 for any relative path in 'newname'.
354 bool renameBuffer(Buffer & b, docstring const & newname);
356 bool saveBuffer(Buffer & b);
357 /// closes a workarea, if close_buffer is true the buffer will
358 /// also be released, otherwise the buffer will be hidden.
359 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
360 /// closes the tabworkarea and all tabs. If we are in a close event,
361 /// all buffers will be closed, otherwise they will be hidden.
362 bool closeTabWorkArea(TabWorkArea * twa);
363 /// gives the user the possibility to save his work
364 /// or to discard the changes. If hiding is true, the
365 /// document will be reloaded.
366 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
367 /// closes all workareas
368 bool closeWorkAreaAll();
369 /// write all open workareas into the session file
370 void writeSession() const;
371 /// is the buffer in this workarea also shown in another tab ?
372 /// This tab can either be in the same view or in another one.
373 bool inMultiTabs(GuiWorkArea * wa);
374 /// is the buffer in this workarea also shown in another view ?
375 bool inMultiViews(GuiWorkArea * wa);
377 enum NextOrPrevious {
382 void gotoNextOrPreviousBuffer(NextOrPrevious np);
384 /// Is the dialog currently visible?
385 bool isDialogVisible(std::string const & name) const;
387 Dialog * findOrBuild(std::string const & name, bool hide_it);
389 Dialog * build(std::string const & name);
393 void dispatchVC(FuncRequest const & cmd);
400 /// flag to avoid two concurrent close events.
404 } // namespace frontend