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
66 int id() const { return id_; }
69 /// returns true if this view has the focus.
70 bool hasFocus() const;
72 /// add toolbar, if newline==true, add a toolbar break before the toolbar
73 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
74 virtual void updateStatusBar();
75 virtual void message(docstring const & str);
77 /// updates the possible layouts selectable
78 void updateLayoutList();
79 void updateToolbars();
80 QMenu * createPopupMenu();
81 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
82 bool dispatch(FuncRequest const & cmd);
85 void setLayoutDialog(GuiLayoutBox *);
87 /// \return the buffer currently shown in this window
89 Buffer const * buffer() const;
90 /// set a buffer to the current workarea.
91 void setBuffer(Buffer * b); ///< \c Buffer to set.
94 /// load a document into the current workarea.
95 Buffer * loadDocument(support::FileName const & name, ///< File to load.
96 bool tolastfiles = true); ///< append to the "Open recent" menu?
98 void openDocument(std::string const & filename);
100 void importDocument(std::string const &);
102 void newDocument(std::string const & filename, bool fromTemplate);
104 /// GuiBufferDelegate.
106 void resetAutosaveTimers();
107 void errors(std::string const &);
108 void structureChanged();
109 void updateTocItem(std::string const &, DocIterator const &);
113 TocModels & tocModels();
115 /// called on timeout
118 /// \return the current buffer view.
121 /** redraw \c inset in all the BufferViews in which it is currently
122 * visible. If successful return a pointer to the owning Buffer.
124 Buffer const * updateInset(Inset const *);
126 void restartCursor();
128 /// \return the \c Workarea associated to \p Buffer
129 /// \retval 0 if no \c WorkArea is found.
130 GuiWorkArea * workArea(Buffer & buffer);
132 /// Add a \c WorkArea
133 /// \return the \c Workarea associated to \p Buffer
134 /// \retval 0 if no \c WorkArea is found.
135 GuiWorkArea * addWorkArea(Buffer & buffer);
137 void setCurrentWorkArea(GuiWorkArea * work_area);
139 void removeWorkArea(GuiWorkArea * work_area);
140 /// return the current WorkArea (the one that has the focus).
141 GuiWorkArea const * currentWorkArea() const;
148 /// clear any temporary message and replace with current status.
153 void updateWindowTitle(GuiWorkArea * wa);
155 void resetWindowTitleAndIconText();
158 void on_currentWorkAreaChanged(GuiWorkArea *);
160 void on_lastWorkAreaRemoved();
162 /// slots to change the icon size
163 void smallSizedIcons();
164 void normalSizedIcons();
165 void bigSizedIcons();
169 TabWorkArea * addTabWorkArea();
171 /// connect to signals in the given BufferView
172 void connectBufferView(BufferView & bv);
173 /// disconnect from signals in the given BufferView
174 void disconnectBufferView();
175 /// connect to signals in the given buffer
176 void connectBuffer(Buffer & buf);
177 /// disconnect from signals in the given buffer
178 void disconnectBuffer();
180 void dragEnterEvent(QDragEnterEvent * ev);
182 void dropEvent(QDropEvent * ev);
183 /// make sure we quit cleanly
184 void closeEvent(QCloseEvent * e);
186 void showEvent(QShowEvent *);
188 /// in order to catch Tab key press.
189 bool event(QEvent * e);
190 bool focusNextPrevChild(bool);
193 struct GuiViewPrivate;
198 /// dialogs for this view
204 /// Hide all visible dialogs
205 void hideAll() const;
207 /// Update all visible dialogs.
209 * Check the status of all visible dialogs and disable or reenable
210 * them as appropriate.
212 * Disabling is needed for example when a dialog is open and the
213 * cursor moves to a position where the corresponding inset is not
216 void updateDialogs();
218 /** \param name == "bibtex", "citation" etc; an identifier used to
219 launch a particular dialog.
220 \param data is a string representation of the Inset contents.
221 It is often little more than the output from Inset::write.
222 It is passed to, and parsed by, the frontend dialog.
223 Several of these dialogs do not need any data,
224 so it defaults to string().
225 \param inset ownership is _not_ passed to the frontend dialog.
226 It is stored internally and used by the kernel to ascertain
227 what to do with the FuncRequest dispatched from the frontend
228 dialog on 'Apply'; should it be used to create a new inset at
229 the current cursor position or modify an existing, 'open' inset?
231 void showDialog(std::string const & name,
232 std::string const & data, Inset * inset = 0);
234 /** \param name == "citation", "bibtex" etc; an identifier used
235 to reset the contents of a particular dialog with \param data.
236 See the comments to 'show', above.
238 void updateDialog(std::string const & name, std::string const & data);
240 /** All Dialogs of the given \param name will be closed if they are
241 connected to the given \param inset.
243 void hideDialog(std::string const & name, Inset * inset);
245 void disconnectDialog(std::string const & name);
248 void updateCompletion(Cursor & cur, bool start, bool keep);
252 void saveLayout() const;
254 bool restoreLayout();
256 GuiToolbar * toolbar(std::string const & name);
258 void constructToolbars();
262 void lfunUiToggle(FuncRequest const & cmd);
264 void toggleFullScreen();
266 void insertLyXFile(docstring const & fname);
268 void insertPlaintextFile(docstring const & fname,
271 /// Save a buffer as a new file.
273 Write a buffer to a new file name and rename the buffer
274 according to the new file name.
276 This function is e.g. used by menu callbacks and
277 LFUN_BUFFER_WRITE_AS.
279 If 'newname' is empty, the user is asked via a
280 dialog for the buffer's new name and location.
282 If 'newname' is non-empty and has an absolute path, that is used.
283 Otherwise the base directory of the buffer is used as the base
284 for any relative path in 'newname'.
286 bool renameBuffer(Buffer & b, docstring const & newname);
288 bool saveBuffer(Buffer & b);
290 bool closeBuffer(Buffer & buf, bool tolastopened = false);
293 Inset * getOpenInset(std::string const & name) const;
295 /// Is the dialog currently visible?
296 bool isDialogVisible(std::string const & name) const;
298 Dialog * findOrBuild(std::string const & name, bool hide_it);
300 Dialog * build(std::string const & name);
305 /// flag to avoid two concurrent close events.
309 } // namespace frontend