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 /// \name 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);
89 void focusInEvent(QFocusEvent * e);
90 /// set a buffer to the current workarea.
91 void setBuffer(Buffer * b); ///< \c Buffer to set.
93 /// load a document into the current workarea.
94 Buffer * loadDocument(
95 support::FileName const & name, ///< File to load.
96 bool tolastfiles = true ///< append to the "Open recent" menu?
99 /// add toolbar, if newline==true, add a toolbar break before the toolbar
100 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
101 void updateStatusBar();
103 /// updates the possible layouts selectable
104 void updateLayoutList();
105 void updateToolbars();
106 QMenu * createPopupMenu();
109 LayoutBox * getLayoutDialog() const;
111 /// hides the workarea and makes sure it is clean
112 bool hideWorkArea(GuiWorkArea * wa);
113 /// closes the workarea
114 bool closeWorkArea(GuiWorkArea * wa);
115 /// closes the buffer
116 bool closeBuffer(Buffer & buf);
118 void openDocument(std::string const & filename);
120 void importDocument(std::string const &);
122 /// \name GuiBufferDelegate.
124 void resetAutosaveTimers();
125 void errors(std::string const &, bool from_master = false);
126 void structureChanged();
127 void updateTocItem(std::string const &, DocIterator const &);
131 TocModels & tocModels();
133 /// called on timeout
136 /// check for external change of any opened buffer, mainly for svn usage
137 void checkExternallyModifiedBuffers();
139 /** redraw \c inset in all the BufferViews in which it is currently
140 * visible. If successful return a pointer to the owning Buffer.
142 Buffer const * updateInset(Inset const *);
144 /// \return the \c Workarea associated to \p Buffer
145 /// \retval 0 if no \c WorkArea is found.
146 GuiWorkArea * workArea(Buffer & buffer);
148 /// Add a \c WorkArea
149 /// \return the \c Workarea associated to \p Buffer
150 /// \retval 0 if no \c WorkArea is found.
151 GuiWorkArea * addWorkArea(Buffer & buffer);
152 /// \param work_area The current \c WorkArea, or \c NULL
153 void setCurrentWorkArea(GuiWorkArea * work_area);
155 void removeWorkArea(GuiWorkArea * work_area);
156 /// return the current WorkArea (the one that has the focus).
157 GuiWorkArea const * currentWorkArea() const;
158 /// return the current WorkArea (the one that has the focus).
159 GuiWorkArea * currentWorkArea();
161 /// return the current document WorkArea (it may not have the focus).
162 GuiWorkArea const * currentMainWorkArea() const;
163 /// return the current document WorkArea (it may not have the focus).
164 GuiWorkArea * currentMainWorkArea();
168 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
172 /// clear any temporary message and replace with current status.
177 void updateWindowTitle(GuiWorkArea * wa);
179 void resetWindowTitleAndIconText();
182 void on_currentWorkAreaChanged(GuiWorkArea *);
184 void on_lastWorkAreaRemoved();
186 /// slots to change the icon size
187 void smallSizedIcons();
188 void normalSizedIcons();
189 void bigSizedIcons();
191 /// For completion of autosave or exporrt threads.
192 void threadFinished();
194 /// must be called in GUI thread
195 void doShowDialog(QString const & qname, QString const & qdata,
199 /// Open given child document in current buffer directory.
200 void openChildDocument(std::string const & filename);
201 /// Close current document buffer.
203 /// Close all document buffers.
204 bool closeBufferAll();
206 TabWorkArea * addTabWorkArea();
208 /// connect to signals in the given BufferView
209 void connectBufferView(BufferView & bv);
210 /// disconnect from signals in the given BufferView
211 void disconnectBufferView();
212 /// connect to signals in the given buffer
213 void connectBuffer(Buffer & buf);
214 /// disconnect from signals in the given buffer
215 void disconnectBuffer();
217 void dragEnterEvent(QDragEnterEvent * ev);
219 void dropEvent(QDropEvent * ev);
220 /// make sure we quit cleanly
221 void closeEvent(QCloseEvent * e);
223 void showEvent(QShowEvent *);
225 /// in order to catch Tab key press.
226 bool event(QEvent * e);
227 bool focusNextPrevChild(bool);
230 bool goToFileRow(std::string const & argument);
233 struct GuiViewPrivate;
238 /// dialogs for this view
244 /// Hide all visible dialogs
245 void hideAll() const;
247 /// Update all visible dialogs.
249 * Check the status of all visible dialogs and disable or reenable
250 * them as appropriate.
252 * Disabling is needed for example when a dialog is open and the
253 * cursor moves to a position where the corresponding inset is not
256 void updateDialogs();
258 /** Show dialog could be called from arbitrary threads.
259 \param name == "bibtex", "citation" etc; an identifier used to
260 launch a particular dialog.
261 \param data is a string representation of the Inset contents.
262 It is often little more than the output from Inset::write.
263 It is passed to, and parsed by, the frontend dialog.
264 Several of these dialogs do not need any data,
265 so it defaults to string().
266 \param inset ownership is _not_ passed to the frontend dialog.
267 It is stored internally and used by the kernel to ascertain
268 what to do with the FuncRequest dispatched from the frontend
269 dialog on 'Apply'; should it be used to create a new inset at
270 the current cursor position or modify an existing, 'open' inset?
272 void showDialog(std::string const & name,
273 std::string const & data, Inset * inset = 0);
275 /** \param name == "citation", "bibtex" etc; an identifier used
276 to reset the contents of a particular dialog with \param data.
277 See the comments to 'show', above.
279 void updateDialog(std::string const & name, std::string const & data);
281 /** All Dialogs of the given \param name will be closed if they are
282 connected to the given \param inset.
284 void hideDialog(std::string const & name, Inset * inset);
286 void disconnectDialog(std::string const & name);
290 void saveLayout() const;
292 bool restoreLayout();
294 GuiToolbar * toolbar(std::string const & name);
296 void constructToolbars();
300 void lfunUiToggle(FuncRequest const & cmd);
302 void toggleFullScreen();
304 void insertLyXFile(docstring const & fname);
306 void insertPlaintextFile(docstring const & fname,
309 /// Save a buffer as a new file.
311 Write a buffer to a new file name and rename the buffer
312 according to the new file name.
314 This function is e.g. used by menu callbacks and
315 LFUN_BUFFER_WRITE_AS.
317 If 'newname' is empty, the user is asked via a
318 dialog for the buffer's new name and location.
320 If 'newname' is non-empty and has an absolute path, that is used.
321 Otherwise the base directory of the buffer is used as the base
322 for any relative path in 'newname'.
324 bool renameBuffer(Buffer & b, docstring const & newname);
326 bool saveBuffer(Buffer & b);
327 /// closes a workarea, if close_buffer is true the buffer will
328 /// also be released, otherwise the buffer will be hidden.
329 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
330 /// closes the tabworkarea and all tabs. If we are in a close event,
331 /// all buffers will be closed, otherwise they will be hidden.
332 bool closeTabWorkArea(TabWorkArea * twa);
333 /// gives the user the possibility to save his work
334 /// or to discard the changes. If hiding is true, the
335 /// document will be reloaded.
336 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
337 /// closes all workareas
338 bool closeWorkAreaAll();
339 /// write all open workareas into the session file
340 void writeSession() const;
341 /// is the buffer in this workarea also shown in another tab ?
342 /// This tab can either be in the same view or in another one.
343 bool inMultiTabs(GuiWorkArea * wa);
344 /// is the buffer in this workarea also shown in another view ?
345 bool inMultiViews(GuiWorkArea * wa);
347 enum NextOrPrevious {
352 void gotoNextOrPreviousBuffer(NextOrPrevious np);
354 /// Is the dialog currently visible?
355 bool isDialogVisible(std::string const & name) const;
357 Dialog * findOrBuild(std::string const & name, bool hide_it);
359 Dialog * build(std::string const & name);
363 void dispatchVC(FuncRequest const & cmd);
370 /// flag to avoid two concurrent close events.
374 } // namespace frontend