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);
288 void saveLayout() const;
290 bool restoreLayout();
292 GuiToolbar * toolbar(std::string const & name);
294 void constructToolbars();
298 void lfunUiToggle(FuncRequest const & cmd);
300 void toggleFullScreen();
302 void insertLyXFile(docstring const & fname);
304 void insertPlaintextFile(docstring const & fname,
307 /// Save a buffer as a new file.
309 Write a buffer to a new file name and rename the buffer
310 according to the new file name.
312 This function is e.g. used by menu callbacks and
313 LFUN_BUFFER_WRITE_AS.
315 If 'newname' is empty, the user is asked via a
316 dialog for the buffer's new name and location.
318 If 'newname' is non-empty and has an absolute path, that is used.
319 Otherwise the base directory of the buffer is used as the base
320 for any relative path in 'newname'.
322 bool renameBuffer(Buffer & b, docstring const & newname);
324 bool saveBuffer(Buffer & b);
325 /// closes a workarea, if close_buffer is true the buffer will
326 /// also be released, otherwise the buffer will be hidden.
327 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
328 /// closes the tabworkarea and all tabs. If we are in a close event,
329 /// all buffers will be closed, otherwise they will be hidden.
330 bool closeTabWorkArea(TabWorkArea * twa);
331 /// gives the user the possibility to save his work
332 /// or to discard the changes. If hiding is true, the
333 /// document will be reloaded.
334 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
335 /// closes all workareas
336 bool closeWorkAreaAll();
337 /// write all open workareas into the session file
338 void writeSession() const;
339 /// is the buffer in this workarea also shown in another tab ?
340 /// This tab can either be in the same view or in another one.
341 bool inMultiTabs(GuiWorkArea * wa);
342 /// is the buffer in this workarea also shown in another view ?
343 bool inMultiViews(GuiWorkArea * wa);
345 enum NextOrPrevious {
350 void gotoNextOrPreviousBuffer(NextOrPrevious np);
352 /// Is the dialog currently visible?
353 bool isDialogVisible(std::string const & name) const;
355 Dialog * findOrBuild(std::string const & name, bool hide_it);
357 Dialog * build(std::string const & name);
361 void dispatchVC(FuncRequest const & cmd);
368 /// flag to avoid two concurrent close events.
372 } // namespace frontend