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>
26 class QDragEnterEvent;
36 namespace support { class FileName; }
57 * GuiView - Qt main LyX window
59 * This class represents the main LyX window and provides
60 * accessor functions to its content.
62 * Note: a QObject emits a destroyed(QObject *) Qt signal when it
63 * is deleted. This might be useful for closing other dialogs
64 * depending on a given GuiView.
66 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
67 public GuiBufferDelegate
72 /// create a main window of the given dimensions
77 /// closes the view such that the view knows that is closed
78 /// programmatically and not by the user clicking the x.
79 bool closeScheduled();
81 /// Things that need to be done when the OSes session manager
82 /// requests a log out.
83 bool prepareAllBuffersForLogout();
85 int id() const { return id_; }
90 /// Signal that the any "auto" minibuffer can be closed now.
91 void resetCommandExecute();
93 /// \name Generic accessor functions
95 /// The current BufferView refers to the BufferView that has the focus,
96 /// including for example the one that is created when you use the
97 /// advanced search and replace pane.
98 /// \return the currently selected buffer view.
99 BufferView * currentBufferView();
100 BufferView const * currentBufferView() const;
102 /// The document BufferView always refers to the view's main document
103 /// BufferView. So, even if the BufferView in e.g., the advanced
104 /// search and replace pane has the focus.
105 /// \return the current document buffer view.
106 BufferView * documentBufferView();
107 BufferView const * documentBufferView() const;
109 void newDocument(std::string const & filename,
110 std::string templatefile = std::string(),
111 bool fromTemplate = false);
113 /// display a message in the view
114 /// could be called from any thread
115 void message(docstring const &) override;
117 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
118 /// dispatch command.
119 /// \return true if the \c FuncRequest has been dispatched.
120 void dispatch(FuncRequest const & cmd, DispatchResult & dr);
123 /// Update the completion popup and the inline completion state.
124 /// If \c start is true, then a new completion might be started.
125 /// If \c keep is true, an active completion will be kept active
126 /// even though the cursor moved. The update flags of \c cur might
128 void updateCompletion(Cursor & cur, bool start, bool keep);
132 bool hasFocus() const;
135 void focusInEvent(QFocusEvent * e) override;
136 /// Add a Buffer to the View
137 /// \param b Buffer to set.
138 /// \param switch_to Whether to set it to the current workarea.
139 void setBuffer(Buffer * b, bool switch_to = true);
141 /// load a document into the current workarea.
142 Buffer * loadDocument(
143 support::FileName const & name, ///< File to load.
144 bool tolastfiles = true ///< append to the "Open recent" menu?
147 /// add toolbar, if newline==true, add a toolbar break before the toolbar
148 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
149 void updateStatusBar();
151 /// updates the possible layouts selectable
152 void updateLayoutList();
153 void updateToolbars();
156 LayoutBox * getLayoutDialog() const;
158 /// hides the workarea and makes sure it is clean
159 bool hideWorkArea(GuiWorkArea * wa);
160 /// closes workarea; close buffer only if no other workareas point to it
161 bool closeWorkArea(GuiWorkArea * wa);
162 /// closes the buffer
163 bool closeBuffer(Buffer & buf);
165 void openDocument(std::string const & filename);
167 void importDocument(std::string const &);
169 /// \name GuiBufferDelegate.
171 void resetAutosaveTimers() override;
172 // shows an error list
173 // if from_master is true, show master's error list
174 void errors(std::string const &, bool from_master = false) override;
175 void structureChanged() override;
176 void updateTocItem(std::string const &, DocIterator const &) override;
180 TocModels & tocModels();
182 /// called on timeout
185 /// check for external change of any opened buffer, mainly for svn usage
186 void checkExternallyModifiedBuffers();
188 /** redraw \c inset in all the BufferViews in which it is currently
189 * visible. If successful return a pointer to the owning Buffer.
191 Buffer const * updateInset(Inset const *);
193 /// \return the \c Workarea associated to \p Buffer
194 /// \retval 0 if no \c WorkArea is found.
195 GuiWorkArea * workArea(Buffer & buffer);
196 /// \return the \c Workarea at index \c index
197 GuiWorkArea * workArea(int index);
199 /// Add a \c WorkArea
200 /// \return the \c Workarea associated to \p Buffer
201 /// \retval 0 if no \c WorkArea is found.
202 GuiWorkArea * addWorkArea(Buffer & buffer);
203 /// \param work_area The current \c WorkArea, or \c NULL
204 void setCurrentWorkArea(GuiWorkArea * work_area);
206 void removeWorkArea(GuiWorkArea * work_area);
207 /// return the current WorkArea (the one that has the focus).
208 GuiWorkArea const * currentWorkArea() const;
209 /// return the current WorkArea (the one that has the focus).
210 GuiWorkArea * currentWorkArea();
212 /// return the current document WorkArea (it may not have the focus).
213 GuiWorkArea const * currentMainWorkArea() const;
214 /// return the current document WorkArea (it may not have the focus).
215 GuiWorkArea * currentMainWorkArea();
217 /// Current ratio between physical pixels and device-independent pixels
218 double pixelRatio() const;
222 void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
223 // emitted when the work area or its buffer view changed
224 void bufferViewChanged();
225 /// emitted when zoom is modified
226 void currentZoomChanged(int);
230 void setBusy(bool) override;
232 /// clear any temporary message and replace with current status.
235 void updateWindowTitle(GuiWorkArea * wa);
237 void disableShellEscape();
241 void resetWindowTitle();
243 void flatGroupBoxes(const QObject * object, bool flag);
246 void checkCancelBackground();
248 void zoomSliderMoved(int);
250 void zoomValueChanged(int);
252 void zoomInPressed();
254 void zoomOutPressed();
256 void on_currentWorkAreaChanged(GuiWorkArea *);
258 void onBufferViewChanged();
260 void on_lastWorkAreaRemoved();
262 /// For completion of autosave or export threads.
263 void processingThreadStarted();
264 void processingThreadFinished();
265 void autoSaveThreadFinished();
267 /// must be called in GUI thread
268 void doShowDialog(QString const & qname, QString const & qdata,
271 /// must be called from GUI thread
272 void updateStatusBarMessage(QString const & str);
273 void clearMessageText();
276 void toolBarPopup(const QPoint &pos);
279 /// Open given child document in current buffer directory.
280 void openChildDocument(std::string const & filename);
281 /// Close current document buffer.
283 /// Close all document buffers.
284 bool closeBufferAll();
286 TabWorkArea * addTabWorkArea();
288 /// connect to signals in the given BufferView
289 void connectBufferView(BufferView & bv);
290 /// disconnect from signals in the given BufferView
291 void disconnectBufferView();
292 /// connect to signals in the given buffer
293 void connectBuffer(Buffer & buf);
294 /// disconnect from signals in the given buffer
295 void disconnectBuffer();
297 void dragEnterEvent(QDragEnterEvent * ev) override;
299 void dropEvent(QDropEvent * ev) override;
300 /// make sure we quit cleanly
301 void closeEvent(QCloseEvent * e) override;
303 void showEvent(QShowEvent *) override;
305 /// in order to catch Tab key press.
306 bool event(QEvent * e) override;
307 bool focusNextPrevChild(bool) override;
310 bool goToFileRow(std::string const & argument);
313 class GuiViewPrivate;
318 /// dialogs for this view
324 /// Hide all visible dialogs
325 void hideAll() const;
327 /// Update all visible dialogs.
329 * Check the status of all visible dialogs and disable or re-enable
330 * them as appropriate.
332 * Disabling is needed for example when a dialog is open and the
333 * cursor moves to a position where the corresponding inset is not
336 void updateDialogs();
338 /** Show dialog could be called from arbitrary threads.
339 \param name == "bibtex", "citation" etc; an identifier used to
340 launch a particular dialog.
341 \param data is a string representation of the Inset contents.
342 It is often little more than the output from Inset::write.
343 It is passed to, and parsed by, the frontend dialog.
344 Several of these dialogs do not need any data,
345 so it defaults to string().
346 \param inset ownership is _not_ passed to the frontend dialog.
347 It is stored internally and used by the kernel to ascertain
348 what to do with the FuncRequest dispatched from the frontend
349 dialog on 'Apply'; should it be used to create a new inset at
350 the current cursor position or modify an existing, 'open' inset?
352 void showDialog(std::string const & name,
353 std::string const & data, Inset * inset = 0) override;
355 /** \param name == "citation", "bibtex" etc; an identifier used
356 to reset the contents of a particular dialog with \param data.
357 See the comments to 'show', above.
359 void updateDialog(std::string const & name, std::string const & data) override;
361 /** All Dialogs of the given \param name will be closed if they are
362 connected to the given \param inset.
364 void hideDialog(std::string const & name, Inset * inset);
366 void disconnectDialog(std::string const & name);
368 bool develMode() const { return devel_mode_; }
370 void setCurrentZoom(int const v);
373 /// Saves the layout and geometry of the window
374 void saveLayout() const;
375 /// Saves the settings of toolbars and all dialogs
376 void saveUISettings() const;
378 bool restoreLayout();
380 GuiToolbar * toolbar(std::string const & name);
382 void constructToolbars();
386 void initToolbar(std::string const & name);
387 /// Update lock (all) toolbars position
388 void updateLockToolbars();
389 /// refill the toolbars (dark/light mode switch)
390 void refillToolbars();
392 bool lfunUiToggle(std::string const & ui_component);
394 void toggleFullScreen();
395 /// \return whether we did anything
396 bool insertLyXFile(docstring const & fname, bool ignorelang = false);
398 /// Open Export As ... dialog. \p iformat is the format the
399 /// filter is initially set to.
400 bool exportBufferAs(Buffer & b, docstring const & iformat);
405 LV_WRITE_AS_TEMPLATE,
409 /// Get a path for LFUN_BUFFER_WRITE_AS_TEMPLATE
410 std::string const getTemplatesPath(Buffer & buf);
411 /// Save a buffer as a new file.
413 * Write a buffer to a new file name and rename the buffer
414 * according to the new file name.
416 * This function is e.g. used by menu callbacks and
417 * LFUN_BUFFER_WRITE_AS.
419 * If 'newname' is empty, the user is asked via a
420 * dialog for the buffer's new name and location.
422 * If 'newname' is non-empty and has an absolute path, that is used.
423 * Otherwise the base directory of the buffer is used as the base
424 * for any relative path in 'newname'.
426 * \p kind controls what is done besides the pure renaming:
427 * LV_WRITE_AS => The buffer is written without version control actions.
428 * LV_VC_RENAME => The file is renamed in version control.
429 * LV_VC_COPY => The file is copied in version control.
431 bool renameBuffer(Buffer & b, docstring const & newname,
432 RenameKind kind = LV_WRITE_AS);
434 bool saveBuffer(Buffer & b);
435 /// save and rename buffer to fn. If fn is empty, the buffer
436 /// is just saved as the filename it already has.
437 bool saveBuffer(Buffer & b, support::FileName const & fn);
438 /// closes a workarea, if close_buffer is true the buffer will
439 /// also be released, otherwise the buffer will be hidden.
440 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
441 /// closes the tabworkarea and all tabs. If we are in a close event,
442 /// all buffers will be closed, otherwise they will be hidden.
443 bool closeTabWorkArea(TabWorkArea * twa);
444 /// gives the user the possibility to save their work
445 /// or to discard the changes. If hiding is true, the
446 /// document will be reloaded.
447 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
448 /// closes all workareas
449 bool closeWorkAreaAll();
450 /// write all open workareas into the session file
451 void writeSession() const;
452 /// is the buffer in this workarea also shown in another tab ?
453 /// This tab can either be in the same view or in another one.
454 bool inMultiTabs(GuiWorkArea * wa);
455 /// is the buffer shown in some other view ?
456 bool inOtherView(Buffer & buf);
458 enum NextOrPrevious {
463 void gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move);
465 /// Is the dialog currently visible?
466 bool isDialogVisible(std::string const & name) const;
468 Dialog * findOrBuild(std::string const & name, bool hide_it);
470 Dialog * build(std::string const & name);
472 bool reloadBuffer(Buffer & buffer);
474 void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
476 void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
483 /// flag to avoid two concurrent close events.
485 /// if the view is busy the cursor shouldn't blink for instance.
486 /// This counts the number of times more often we called
487 /// setBusy(true) compared to setBusy(false), so we can nest
488 /// functions that call setBusy;
491 /// Request to open the command toolbar if it is "auto"
492 bool command_execute_;
493 /// Request to give focus to minibuffer
494 bool minibuffer_focus_;
496 /// Statusbar widget that shows shell-escape status
497 QLabel * shell_escape_;
498 /// Statusbar widget that shows read-only status
500 /// Statusbar widget that shows version control status
501 QLabel * version_control_;
502 /// Statusbar widget that shows zoom value
503 QLabel * zoom_value_;
504 /// The zoom slider widget
505 QSlider * zoom_slider_;
506 /// Zoom in ("+") Button
507 QPushButton * zoom_in_;
508 /// Zoom out ("-") Button
509 QPushButton * zoom_out_;
511 /// The rate from which the actual zoom value is calculated
512 /// from the default zoom pref
513 double zoom_ratio_ = 1.0;
514 /// Minimum zoom percentage
515 static int const zoom_min_ = 10;
517 // movability flag of all toolbars
518 bool toolbarsMovable_;
525 class SEMenu : public QMenu
529 explicit SEMenu(QWidget * parent);
532 void showMenu(QPoint const &) { exec(QCursor::pos()); }
535 } // namespace frontend