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 setBuffer(Buffer * b);
74 bool hasFocus() const;
75 Buffer * loadDocument(support::FileName const & name,
76 bool tolastfiles = true);
77 void newDocument(std::string const & filename,
79 void message(docstring const &);
80 bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
81 bool dispatch(FuncRequest const & cmd);
83 void updateCompletion(Cursor & cur, bool start, bool keep);
87 /// add toolbar, if newline==true, add a toolbar break before the toolbar
88 GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
89 void updateStatusBar();
91 /// updates the possible layouts selectable
92 void updateLayoutList();
93 void updateToolbars();
94 QMenu * createPopupMenu();
97 LayoutBox * getLayoutDialog() const;
99 /// hides the workarea and makes sure it is clean
100 bool hideWorkArea(GuiWorkArea * wa);
101 /// closes the workarea
102 bool closeWorkArea(GuiWorkArea * wa);
104 void openDocument(std::string const & filename);
106 void importDocument(std::string const &);
108 /// GuiBufferDelegate.
110 void resetAutosaveTimers();
111 void errors(std::string const &, bool from_master = false);
112 void structureChanged();
113 void updateTocItem(std::string const &, DocIterator const &);
117 TocModels & tocModels();
119 /// called on timeout
122 /** redraw \c inset in all the BufferViews in which it is currently
123 * visible. If successful return a pointer to the owning Buffer.
125 Buffer const * updateInset(Inset const *);
127 /// \return the \c Workarea associated to \p Buffer
128 /// \retval 0 if no \c WorkArea is found.
129 GuiWorkArea * workArea(Buffer & buffer);
131 /// Add a \c WorkArea
132 /// \return the \c Workarea associated to \p Buffer
133 /// \retval 0 if no \c WorkArea is found.
134 GuiWorkArea * addWorkArea(Buffer & buffer);
135 /// \param work_area The current \c WorkArea, or \c NULL
136 void setCurrentWorkArea(GuiWorkArea * work_area);
138 void removeWorkArea(GuiWorkArea * work_area);
139 /// return the current WorkArea (the one that has the focus).
140 GuiWorkArea const * currentWorkArea() const;
141 /// return the current WorkArea (the one that has the focus).
142 GuiWorkArea * currentWorkArea();
144 /// return the current document WorkArea (it may not have the focus).
145 GuiWorkArea const * currentMainWorkArea() const;
146 /// return the current document WorkArea (it may not have the focus).
147 GuiWorkArea * currentMainWorkArea();
154 /// clear any temporary message and replace with current status.
159 void updateWindowTitle(GuiWorkArea * wa);
161 void resetWindowTitleAndIconText();
164 void on_currentWorkAreaChanged(GuiWorkArea *);
166 void on_lastWorkAreaRemoved();
168 /// slots to change the icon size
169 void smallSizedIcons();
170 void normalSizedIcons();
171 void bigSizedIcons();
174 /// Close current document buffer.
176 /// Close all document buffers.
177 bool closeBufferAll();
179 TabWorkArea * addTabWorkArea();
181 /// connect to signals in the given BufferView
182 void connectBufferView(BufferView & bv);
183 /// disconnect from signals in the given BufferView
184 void disconnectBufferView();
185 /// connect to signals in the given buffer
186 void connectBuffer(Buffer & buf);
187 /// disconnect from signals in the given buffer
188 void disconnectBuffer();
190 void dragEnterEvent(QDragEnterEvent * ev);
192 void dropEvent(QDropEvent * ev);
193 /// make sure we quit cleanly
194 void closeEvent(QCloseEvent * e);
196 void showEvent(QShowEvent *);
198 /// in order to catch Tab key press.
199 bool event(QEvent * e);
200 bool focusNextPrevChild(bool);
203 struct GuiViewPrivate;
208 /// dialogs for this view
214 /// Hide all visible dialogs
215 void hideAll() const;
217 /// Update all visible dialogs.
219 * Check the status of all visible dialogs and disable or reenable
220 * them as appropriate.
222 * Disabling is needed for example when a dialog is open and the
223 * cursor moves to a position where the corresponding inset is not
226 void updateDialogs();
228 /** \param name == "bibtex", "citation" etc; an identifier used to
229 launch a particular dialog.
230 \param data is a string representation of the Inset contents.
231 It is often little more than the output from Inset::write.
232 It is passed to, and parsed by, the frontend dialog.
233 Several of these dialogs do not need any data,
234 so it defaults to string().
235 \param inset ownership is _not_ passed to the frontend dialog.
236 It is stored internally and used by the kernel to ascertain
237 what to do with the FuncRequest dispatched from the frontend
238 dialog on 'Apply'; should it be used to create a new inset at
239 the current cursor position or modify an existing, 'open' inset?
241 void showDialog(std::string const & name,
242 std::string const & data, Inset * inset = 0);
244 /** \param name == "citation", "bibtex" etc; an identifier used
245 to reset the contents of a particular dialog with \param data.
246 See the comments to 'show', above.
248 void updateDialog(std::string const & name, std::string const & data);
250 /** All Dialogs of the given \param name will be closed if they are
251 connected to the given \param inset.
253 void hideDialog(std::string const & name, Inset * inset);
255 void disconnectDialog(std::string const & name);
259 void saveLayout() const;
261 bool restoreLayout();
263 GuiToolbar * toolbar(std::string const & name);
265 void constructToolbars();
269 void lfunUiToggle(FuncRequest const & cmd);
271 void toggleFullScreen();
273 void insertLyXFile(docstring const & fname);
275 void insertPlaintextFile(docstring const & fname,
278 /// Save a buffer as a new file.
280 Write a buffer to a new file name and rename the buffer
281 according to the new file name.
283 This function is e.g. used by menu callbacks and
284 LFUN_BUFFER_WRITE_AS.
286 If 'newname' is empty, the user is asked via a
287 dialog for the buffer's new name and location.
289 If 'newname' is non-empty and has an absolute path, that is used.
290 Otherwise the base directory of the buffer is used as the base
291 for any relative path in 'newname'.
293 bool renameBuffer(Buffer & b, docstring const & newname);
295 bool saveBuffer(Buffer & b);
296 /// closes a workarea, if close_buffer is true the buffer will
297 /// also be released, otherwise the buffer will be hidden.
298 bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
299 /// closes the tabworkarea and all tabs. If we are in a close event,
300 /// all buffers will be closed, otherwise they will be hidden.
301 bool closeTabWorkArea(TabWorkArea * twa);
302 /// gives the user the possibility to save his work
303 /// or to discard the changes. If hiding is true, the
304 /// document will be reloaded.
305 bool saveBufferIfNeeded(Buffer & buf, bool hiding);
306 /// closes all workareas
307 bool closeWorkAreaAll();
308 /// write all open workareas into the session file
309 void writeSession() const;
310 /// is the buffer in this workarea also shown in another tab ?
311 /// This tab can either be in the same view or in another one.
312 bool inMultiTabs(GuiWorkArea * wa);
313 /// is the buffer in this workarea also shown in another view ?
314 bool inMultiViews(GuiWorkArea * wa);
316 enum NextOrPrevious {
321 void gotoNextOrPreviousBuffer(NextOrPrevious np);
324 Inset * getOpenInset(std::string const & name) const;
326 /// Is the dialog currently visible?
327 bool isDialogVisible(std::string const & name) const;
329 Dialog * findOrBuild(std::string const & name, bool hide_it);
331 Dialog * build(std::string const & name);
335 void dispatchVC(FuncRequest const & cmd);
340 /// flag to avoid two concurrent close events.
344 } // namespace frontend