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 newDocument(std::string const & filename,
76 /// could be called from any thread
77 void message(docstring const &);
78 /// must be called from GUI thread
79 void updateMessage(QString const & str);
81 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
82 bool dispatch(FuncRequest const & cmd);
84 void updateCompletion(Cursor & cur, bool start, bool keep);
88 /// set a buffer to the current workarea.
89 void setBuffer(Buffer * b); ///< \c Buffer to set.
91 /// load a document into the current workarea.
92 Buffer * loadDocument(
93 support::FileName const & name, ///< File to load.
94 bool tolastfiles = true ///< append to the "Open recent" menu?
97 /// add toolbar, if newline==true, add a toolbar break before the toolbar
98 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
99 void updateStatusBar();
101 /// updates the possible layouts selectable
102 void updateLayoutList();
103 void updateToolbars();
104 QMenu * createPopupMenu();
107 LayoutBox * getLayoutDialog() const;
109 /// hides the workarea and makes sure it is clean
110 bool hideWorkArea(GuiWorkArea * wa);
111 /// closes the workarea
112 bool closeWorkArea(GuiWorkArea * wa);
113 /// closes the buffer
114 bool closeBuffer(Buffer & buf);
116 void openDocument(std::string const & filename);
118 void importDocument(std::string const &);
120 /// GuiBufferDelegate.
122 void resetAutosaveTimers();
123 void errors(std::string const &, bool from_master = false);
124 void structureChanged();
125 void updateTocItem(std::string const &, DocIterator const &);
129 TocModels & tocModels();
131 /// called on timeout
134 /// check for external change of any opened buffer, mainly for svn usage
135 void checkExternallyModifiedBuffers();
137 /** redraw \c inset in all the BufferViews in which it is currently
138 * visible. If successful return a pointer to the owning Buffer.
140 Buffer const * updateInset(Inset const *);
142 /// \return the \c Workarea associated to \p Buffer
143 /// \retval 0 if no \c WorkArea is found.
144 GuiWorkArea * workArea(Buffer & buffer);
146 /// Add a \c WorkArea
147 /// \return the \c Workarea associated to \p Buffer
148 /// \retval 0 if no \c WorkArea is found.
149 GuiWorkArea * addWorkArea(Buffer & buffer);
150 /// \param work_area The current \c WorkArea, or \c NULL
151 void setCurrentWorkArea(GuiWorkArea * work_area);
153 void removeWorkArea(GuiWorkArea * work_area);
154 /// return the current WorkArea (the one that has the focus).
155 GuiWorkArea const * currentWorkArea() const;
156 /// return the current WorkArea (the one that has the focus).
157 GuiWorkArea * currentWorkArea();
159 /// return the current document WorkArea (it may not have the focus).
160 GuiWorkArea const * currentMainWorkArea() const;
161 /// return the current document WorkArea (it may not have the focus).
162 GuiWorkArea * currentMainWorkArea();
166 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
170 /// clear any temporary message and replace with current status.
175 void updateWindowTitle(GuiWorkArea * wa);
177 void resetWindowTitleAndIconText();
180 void on_currentWorkAreaChanged(GuiWorkArea *);
182 void on_lastWorkAreaRemoved();
184 /// slots to change the icon size
185 void smallSizedIcons();
186 void normalSizedIcons();
187 void bigSizedIcons();
189 /// For completion of autosave or exporrt threads.
190 void threadFinished();
192 /// must be called in GUI thread
193 void doShowDialog(QString const & qname, QString const & qdata,
197 /// Open given child document in current buffer directory.
198 void openChildDocument(std::string const & filename);
199 /// Close current document buffer.
201 /// Close all document buffers.
202 bool closeBufferAll();
204 TabWorkArea * addTabWorkArea();
206 /// connect to signals in the given BufferView
207 void connectBufferView(BufferView & bv);
208 /// disconnect from signals in the given BufferView
209 void disconnectBufferView();
210 /// connect to signals in the given buffer
211 void connectBuffer(Buffer & buf);
212 /// disconnect from signals in the given buffer
213 void disconnectBuffer();
215 void dragEnterEvent(QDragEnterEvent * ev);
217 void dropEvent(QDropEvent * ev);
218 /// make sure we quit cleanly
219 void closeEvent(QCloseEvent * e);
221 void showEvent(QShowEvent *);
223 /// in order to catch Tab key press.
224 bool event(QEvent * e);
225 bool focusNextPrevChild(bool);
228 bool goToFileRow(std::string const & argument);
231 struct GuiViewPrivate;
236 /// dialogs for this view
242 /// Hide all visible dialogs
243 void hideAll() const;
245 /// Update all visible dialogs.
247 * Check the status of all visible dialogs and disable or reenable
248 * them as appropriate.
250 * Disabling is needed for example when a dialog is open and the
251 * cursor moves to a position where the corresponding inset is not
254 void updateDialogs();
256 /** Show dialog could be called from arbitrary threads.
257 \param name == "bibtex", "citation" etc; an identifier used to
258 launch a particular dialog.
259 \param data is a string representation of the Inset contents.
260 It is often little more than the output from Inset::write.
261 It is passed to, and parsed by, the frontend dialog.
262 Several of these dialogs do not need any data,
263 so it defaults to string().
264 \param inset ownership is _not_ passed to the frontend dialog.
265 It is stored internally and used by the kernel to ascertain
266 what to do with the FuncRequest dispatched from the frontend
267 dialog on 'Apply'; should it be used to create a new inset at
268 the current cursor position or modify an existing, 'open' inset?
270 void showDialog(std::string const & name,
271 std::string const & data, Inset * inset = 0);
273 /** \param name == "citation", "bibtex" etc; an identifier used
274 to reset the contents of a particular dialog with \param data.
275 See the comments to 'show', above.
277 void updateDialog(std::string const & name, std::string const & data);
279 /** All Dialogs of the given \param name will be closed if they are
280 connected to the given \param inset.
282 void hideDialog(std::string const & name, Inset * inset);
284 void disconnectDialog(std::string const & name);
286 /// Find or create buffer view and WorkArea for supplied document
287 /// buffer and make it current.
288 void selectDocumentBuffer(Buffer const * p_buf);
292 void saveLayout() const;
294 bool restoreLayout();
296 GuiToolbar * toolbar(std::string const & name);
298 void constructToolbars();
302 void lfunUiToggle(FuncRequest const & cmd);
304 void toggleFullScreen();
306 void insertLyXFile(docstring const & fname);
308 void insertPlaintextFile(docstring const & fname,
311 /// Save a buffer as a new file.
313 Write a buffer to a new file name and rename the buffer
314 according to the new file name.
316 This function is e.g. used by menu callbacks and
317 LFUN_BUFFER_WRITE_AS.
319 If 'newname' is empty, the user is asked via a
320 dialog for the buffer's new name and location.
322 If 'newname' is non-empty and has an absolute path, that is used.
323 Otherwise the base directory of the buffer is used as the base
324 for any relative path in 'newname'.
326 bool renameBuffer(Buffer & b, docstring const & newname);
328 bool saveBuffer(Buffer & b);
329 /// closes a workarea, if close_buffer is true the buffer will
330 /// also be released, otherwise the buffer will be hidden.
331 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
332 /// closes the tabworkarea and all tabs. If we are in a close event,
333 /// all buffers will be closed, otherwise they will be hidden.
334 bool closeTabWorkArea(TabWorkArea * twa);
335 /// gives the user the possibility to save his work
336 /// or to discard the changes. If hiding is true, the
337 /// document will be reloaded.
338 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
339 /// closes all workareas
340 bool closeWorkAreaAll();
341 /// write all open workareas into the session file
342 void writeSession() const;
343 /// is the buffer in this workarea also shown in another tab ?
344 /// This tab can either be in the same view or in another one.
345 bool inMultiTabs(GuiWorkArea * wa);
346 /// is the buffer in this workarea also shown in another view ?
347 bool inMultiViews(GuiWorkArea * wa);
349 enum NextOrPrevious {
354 void gotoNextOrPreviousBuffer(NextOrPrevious np);
356 /// Is the dialog currently visible?
357 bool isDialogVisible(std::string const & name) const;
359 Dialog * findOrBuild(std::string const & name, bool hide_it);
361 Dialog * build(std::string const & name);
364 void reloadBuffer(Buffer * buf);
366 void dispatchVC(FuncRequest const & cmd);
373 /// flag to avoid two concurrent close events.
377 } // namespace frontend