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 - Qt 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
69 /// create a main window of the given dimensions
74 /// closes the view such that the view knows that is closed
75 /// programmatically and not by the user clicking the x.
76 bool closeScheduled();
78 /// Things that need to be done when the OSes session manager
79 /// requests a log out.
80 bool prepareAllBuffersForLogout();
82 int id() const { return id_; }
88 /// \name Generic accessor functions
90 /// The current BufferView refers to the BufferView that has the focus,
91 /// including for example the one that is created when you use the
92 /// advanced search and replace pane.
93 /// \return the currently selected buffer view.
94 BufferView * currentBufferView();
95 BufferView const * currentBufferView() const;
97 /// The document BufferView always refers to the view's main document
98 /// BufferView. So, even if the BufferView in e.g., the advanced
99 /// search and replace pane has the focus.
100 /// \return the current document buffer view.
101 BufferView * documentBufferView();
102 BufferView const * documentBufferView() const;
104 void newDocument(std::string const & filename,
107 /// display a message in the view
108 /// could be called from any thread
109 void message(docstring const &);
111 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
112 /// dispatch command.
113 /// \return true if the \c FuncRequest has been dispatched.
114 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
116 void restartCursor();
117 /// Update the completion popup and the inline completion state.
118 /// If \c start is true, then a new completion might be started.
119 /// If \c keep is true, an active completion will be kept active
120 /// even though the cursor moved. The update flags of \c cur might
122 void updateCompletion(Cursor & cur, bool start, bool keep);
126 bool hasFocus() const;
129 void focusInEvent(QFocusEvent * e);
130 /// set a buffer to the current workarea.
131 void setBuffer(Buffer * b); ///< \c Buffer to set.
133 /// load a document into the current workarea.
134 Buffer * loadDocument(
135 support::FileName const & name, ///< File to load.
136 bool tolastfiles = true ///< append to the "Open recent" menu?
139 /// add toolbar, if newline==true, add a toolbar break before the toolbar
140 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
141 void updateStatusBar();
143 /// updates the possible layouts selectable
144 void updateLayoutList();
145 void updateToolbars();
146 QMenu * createPopupMenu();
149 LayoutBox * getLayoutDialog() const;
151 /// hides the workarea and makes sure it is clean
152 bool hideWorkArea(GuiWorkArea * wa);
153 /// closes workarea; close buffer only if no other workareas point to it
154 bool closeWorkArea(GuiWorkArea * wa);
155 /// closes the buffer
156 bool closeBuffer(Buffer & buf);
158 void openDocument(std::string const & filename);
160 void importDocument(std::string const &);
162 /// \name GuiBufferDelegate.
164 void resetAutosaveTimers();
165 void errors(std::string const &, bool from_master = false);
166 void structureChanged();
167 void updateTocItem(std::string const &, DocIterator const &);
171 TocModels & tocModels();
173 /// called on timeout
176 /// check for external change of any opened buffer, mainly for svn usage
177 void checkExternallyModifiedBuffers();
179 /** redraw \c inset in all the BufferViews in which it is currently
180 * visible. If successful return a pointer to the owning Buffer.
182 Buffer const * updateInset(Inset const *);
184 /// \return the \c Workarea associated to \p Buffer
185 /// \retval 0 if no \c WorkArea is found.
186 GuiWorkArea * workArea(Buffer & buffer);
187 /// \return the \c Workarea at index \c index
188 GuiWorkArea * workArea(int index);
190 /// Add a \c WorkArea
191 /// \return the \c Workarea associated to \p Buffer
192 /// \retval 0 if no \c WorkArea is found.
193 GuiWorkArea * addWorkArea(Buffer & buffer);
194 /// \param work_area The current \c WorkArea, or \c NULL
195 void setCurrentWorkArea(GuiWorkArea * work_area);
197 void removeWorkArea(GuiWorkArea * work_area);
198 /// return the current WorkArea (the one that has the focus).
199 GuiWorkArea const * currentWorkArea() const;
200 /// return the current WorkArea (the one that has the focus).
201 GuiWorkArea * currentWorkArea();
203 /// return the current document WorkArea (it may not have the focus).
204 GuiWorkArea const * currentMainWorkArea() const;
205 /// return the current document WorkArea (it may not have the focus).
206 GuiWorkArea * currentMainWorkArea();
208 /// Current ratio between physical pixels and device-independent pixels
209 double pixelRatio() const;
213 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
219 /// clear any temporary message and replace with current status.
224 void updateWindowTitle(GuiWorkArea * wa);
226 void resetWindowTitleAndIconText();
229 void on_currentWorkAreaChanged(GuiWorkArea *);
231 void on_lastWorkAreaRemoved();
233 /// slots to change the icon size
234 void smallSizedIcons();
235 void normalSizedIcons();
236 void bigSizedIcons();
237 void hugeSizedIcons();
238 void giantSizedIcons();
240 /// For completion of autosave or export threads.
241 void processingThreadStarted();
242 void processingThreadFinished();
243 void autoSaveThreadFinished();
245 /// must be called in GUI thread
246 void doShowDialog(QString const & qname, QString const & qdata,
249 /// must be called from GUI thread
250 void updateStatusBarMessage(QString const & str);
251 void clearMessageText();
254 /// Open given child document in current buffer directory.
255 void openChildDocument(std::string const & filename);
256 /// Close current document buffer.
258 /// Close all document buffers.
259 bool closeBufferAll();
261 TabWorkArea * addTabWorkArea();
263 /// connect to signals in the given BufferView
264 void connectBufferView(BufferView & bv);
265 /// disconnect from signals in the given BufferView
266 void disconnectBufferView();
267 /// connect to signals in the given buffer
268 void connectBuffer(Buffer & buf);
269 /// disconnect from signals in the given buffer
270 void disconnectBuffer();
272 void dragEnterEvent(QDragEnterEvent * ev);
274 void dropEvent(QDropEvent * ev);
275 /// make sure we quit cleanly
276 void closeEvent(QCloseEvent * e);
278 void showEvent(QShowEvent *);
280 /// in order to catch Tab key press.
281 bool event(QEvent * e);
282 bool focusNextPrevChild(bool);
285 bool goToFileRow(std::string const & argument);
288 struct GuiViewPrivate;
293 /// dialogs for this view
299 /// Hide all visible dialogs
300 void hideAll() const;
302 /// Update all visible dialogs.
304 * Check the status of all visible dialogs and disable or reenable
305 * them as appropriate.
307 * Disabling is needed for example when a dialog is open and the
308 * cursor moves to a position where the corresponding inset is not
311 void updateDialogs();
313 /** Show dialog could be called from arbitrary threads.
314 \param name == "bibtex", "citation" etc; an identifier used to
315 launch a particular dialog.
316 \param data is a string representation of the Inset contents.
317 It is often little more than the output from Inset::write.
318 It is passed to, and parsed by, the frontend dialog.
319 Several of these dialogs do not need any data,
320 so it defaults to string().
321 \param inset ownership is _not_ passed to the frontend dialog.
322 It is stored internally and used by the kernel to ascertain
323 what to do with the FuncRequest dispatched from the frontend
324 dialog on 'Apply'; should it be used to create a new inset at
325 the current cursor position or modify an existing, 'open' inset?
327 void showDialog(std::string const & name,
328 std::string const & data, Inset * inset = 0);
330 /** \param name == "citation", "bibtex" etc; an identifier used
331 to reset the contents of a particular dialog with \param data.
332 See the comments to 'show', above.
334 void updateDialog(std::string const & name, std::string const & data);
336 /** All Dialogs of the given \param name will be closed if they are
337 connected to the given \param inset.
339 void hideDialog(std::string const & name, Inset * inset);
341 void disconnectDialog(std::string const & name);
344 /// Saves the layout and geometry of the window
345 void saveLayout() const;
346 /// Saves the settings of toolbars and all dialogs
347 void saveUISettings() const;
349 bool restoreLayout();
351 GuiToolbar * toolbar(std::string const & name);
353 void constructToolbars();
357 void initToolbar(std::string const & name);
359 bool lfunUiToggle(std::string const & ui_component);
361 void toggleFullScreen();
363 void insertLyXFile(docstring const & fname);
365 void insertPlaintextFile(docstring const & fname,
367 /// Open Export As ... dialog. \p iformat is the format the
368 /// filter is initially set to.
369 bool exportBufferAs(Buffer & b, docstring const & iformat);
372 enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY };
373 /// Save a buffer as a new file.
375 Write a buffer to a new file name and rename the buffer
376 according to the new file name.
378 This function is e.g. used by menu callbacks and
379 LFUN_BUFFER_WRITE_AS.
381 If 'newname' is empty, the user is asked via a
382 dialog for the buffer's new name and location.
384 If 'newname' is non-empty and has an absolute path, that is used.
385 Otherwise the base directory of the buffer is used as the base
386 for any relative path in 'newname'.
388 \p kind controls what is done besides the pure renaming:
389 * LV_WRITE_AS => The buffer is written without version control actions.
390 * LV_VC_RENAME => The file is renamed in version control.
391 * LV_VC_COPY => The file is copied in version control.
393 bool renameBuffer(Buffer & b, docstring const & newname,
394 RenameKind kind = LV_WRITE_AS);
396 bool saveBuffer(Buffer & b);
397 /// save and rename buffer to fn. If fn is empty, the buffer
398 /// is just saved as the filename it already has.
399 bool saveBuffer(Buffer & b, support::FileName const & fn);
400 /// closes a workarea, if close_buffer is true the buffer will
401 /// also be released, otherwise the buffer will be hidden.
402 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
403 /// closes the tabworkarea and all tabs. If we are in a close event,
404 /// all buffers will be closed, otherwise they will be hidden.
405 bool closeTabWorkArea(TabWorkArea * twa);
406 /// gives the user the possibility to save his work
407 /// or to discard the changes. If hiding is true, the
408 /// document will be reloaded.
409 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
410 /// closes all workareas
411 bool closeWorkAreaAll();
412 /// write all open workareas into the session file
413 void writeSession() const;
414 /// is the buffer in this workarea also shown in another tab ?
415 /// This tab can either be in the same view or in another one.
416 bool inMultiTabs(GuiWorkArea * wa);
417 /// is the buffer shown in some other view ?
418 bool inOtherView(Buffer & buf);
420 enum NextOrPrevious {
425 void gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move);
427 /// Is the dialog currently visible?
428 bool isDialogVisible(std::string const & name) const;
430 Dialog * findOrBuild(std::string const & name, bool hide_it);
432 Dialog * build(std::string const & name);
434 bool reloadBuffer(Buffer & buffer);
436 void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
438 void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
445 /// flag to avoid two concurrent close events.
447 /// if the view is busy the cursor shouldn't blink for instance.
448 /// This counts the number of times more often we called
449 /// setBusy(true) compared to setBusy(false), so we can nest
450 /// functions that call setBusy;
455 } // namespace frontend