]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
xpdf support for forward view via synctex. This is quite powerful tool.
[lyx.git] / src / frontends / qt4 / GuiView.h
1 // -*- C++ -*-
2 /**
3  * \file GuiView.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjornes
8  * \author John Levon
9  * \author Abdelrazak Younes
10  * \author Peter Kümmel
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef GUI_VIEW_H
16 #define GUI_VIEW_H
17
18 #include "frontends/Delegates.h"
19
20 #include "support/strfwd.h"
21
22 #include <QMainWindow>
23
24 class QCloseEvent;
25 class QDragEnterEvent;
26 class QDropEvent;
27 class QMenu;
28 class QShowEvent;
29
30
31 namespace lyx {
32
33 namespace support { class FileName; }
34
35 class Buffer;
36 class BufferView;
37 class Cursor;
38 class DispatchResult;
39 class FuncStatus;
40 class FuncRequest;
41 class Inset;
42
43 namespace frontend {
44
45 class Dialog;
46 class LayoutBox;
47 class GuiToolbar;
48 class GuiWorkArea;
49 class TabWorkArea;
50 class TocModels;
51 class ToolbarInfo;
52
53 /**
54  * GuiView - Qt4 main LyX window
55  *
56  * This class represents the main LyX window and provides
57  * accessor functions to its content.
58  *
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.
62  */
63 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
64         public GuiBufferDelegate
65 {
66         Q_OBJECT
67
68 public:
69         /// create a main window of the given dimensions
70         GuiView(int id);
71
72         ~GuiView();
73
74         int id() const { return id_; }
75
76         void setBusy(bool);
77
78         /// \name Generic accessor functions
79         //@{
80         /// The current BufferView refers to the BufferView that has the focus,
81         /// including for example the one that is created when you use the
82         /// advanced search and replace pane.
83         /// \return the currently selected buffer view.
84         BufferView * currentBufferView();
85         BufferView const * currentBufferView() const;
86
87         /// The document BufferView always refers to the view's main document
88         /// BufferView. So, even if the BufferView in e.g., the advanced
89         /// search and replace pane has the focus.
90         /// \return the current document buffer view.
91         BufferView * documentBufferView();
92         BufferView const * documentBufferView() const;
93
94         void newDocument(std::string const & filename,
95                 bool fromTemplate);
96
97         /// display a message in the view
98         /// could be called from any thread
99         void message(docstring const &);
100         
101         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
102         /// dispatch command.
103         /// \return true if the \c FuncRequest has been dispatched.
104         void dispatch(FuncRequest const & cmd, DispatchResult & dr);
105
106         void restartCursor();
107         /// Update the completion popup and the inline completion state.
108         /// If \c start is true, then a new completion might be started.
109         /// If \c keep is true, an active completion will be kept active
110         /// even though the cursor moved. The update flags of \c cur might
111         /// be changed.
112         void updateCompletion(Cursor & cur, bool start, bool keep);
113
114         ///
115         void setFocus();
116
117         ///
118         void focusInEvent(QFocusEvent * e);
119         /// set a buffer to the current workarea.
120         void setBuffer(Buffer * b); ///< \c Buffer to set.
121
122         /// load a document into the current workarea.
123         Buffer * loadDocument(
124                 support::FileName const &  name, ///< File to load.
125                 bool tolastfiles = true  ///< append to the "Open recent" menu?
126                 );
127
128         /// add toolbar, if newline==true, add a toolbar break before the toolbar
129         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
130         void updateStatusBar();
131
132         /// updates the possible layouts selectable
133         void updateLayoutList();
134         void updateToolbars();
135         QMenu * createPopupMenu();
136
137         ///
138         LayoutBox * getLayoutDialog() const;
139
140         /// hides the workarea and makes sure it is clean
141         bool hideWorkArea(GuiWorkArea * wa);
142         /// closes the workarea
143         bool closeWorkArea(GuiWorkArea * wa);
144         /// closes the buffer
145         bool closeBuffer(Buffer & buf);
146         ///
147         void openDocument(std::string const & filename);
148         ///
149         void importDocument(std::string const &);
150
151         /// \name GuiBufferDelegate.
152         //@{
153         void resetAutosaveTimers();
154         void errors(std::string const &, bool from_master = false);
155         void structureChanged();
156         void updateTocItem(std::string const &, DocIterator const &);
157         //@}
158
159         ///
160         TocModels & tocModels();
161         
162         /// called on timeout
163         void autoSave();
164
165         /// check for external change of any opened buffer, mainly for svn usage
166         void checkExternallyModifiedBuffers();
167
168         /** redraw \c inset in all the BufferViews in which it is currently
169          *  visible. If successful return a pointer to the owning Buffer.
170          */
171         Buffer const * updateInset(Inset const *);
172
173         /// \return the \c Workarea associated to \p  Buffer
174         /// \retval 0 if no \c WorkArea is found.
175         GuiWorkArea * workArea(Buffer & buffer);
176
177         /// Add a \c WorkArea 
178         /// \return the \c Workarea associated to \p  Buffer
179         /// \retval 0 if no \c WorkArea is found.
180         GuiWorkArea * addWorkArea(Buffer & buffer);
181         /// \param work_area The current \c WorkArea, or \c NULL
182         void setCurrentWorkArea(GuiWorkArea * work_area);
183         ///
184         void removeWorkArea(GuiWorkArea * work_area);
185         /// return the current WorkArea (the one that has the focus).
186         GuiWorkArea const * currentWorkArea() const;
187         /// return the current WorkArea (the one that has the focus).
188         GuiWorkArea * currentWorkArea();
189
190         /// return the current document WorkArea (it may not have the focus).
191         GuiWorkArea const * currentMainWorkArea() const;
192         /// return the current document WorkArea (it may not have the focus).
193         GuiWorkArea * currentMainWorkArea();
194
195 Q_SIGNALS:
196         void closing(int);
197         void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
198
199 public Q_SLOTS:
200         /// idle timeout.
201         /// clear any temporary message and replace with current status.
202         void clearMessage();
203
204 private Q_SLOTS:
205         ///
206         void updateWindowTitle(GuiWorkArea * wa);
207         ///
208         void resetWindowTitleAndIconText();
209
210         ///
211         void on_currentWorkAreaChanged(GuiWorkArea *);
212         ///
213         void on_lastWorkAreaRemoved();
214
215         /// slots to change the icon size
216         void smallSizedIcons();
217         void normalSizedIcons();
218         void bigSizedIcons();
219
220         /// For completion of autosave or exporrt threads.
221         void threadFinished();
222
223         /// must be called in GUI thread
224         void doShowDialog(QString const & qname, QString const & qdata,
225         Inset * inset);
226
227         /// must be called from GUI thread
228         void updateStatusBarMessage(QString const & str);
229         void clearMessageText();
230
231 private:
232         /// Open given child document in current buffer directory.
233         void openChildDocument(std::string const & filename);
234         /// Close current document buffer.
235         bool closeBuffer();
236         /// Close all document buffers.
237         bool closeBufferAll();
238         ///
239         TabWorkArea * addTabWorkArea();
240
241         /// connect to signals in the given BufferView
242         void connectBufferView(BufferView & bv);
243         /// disconnect from signals in the given BufferView
244         void disconnectBufferView();
245         /// connect to signals in the given buffer
246         void connectBuffer(Buffer & buf);
247         /// disconnect from signals in the given buffer
248         void disconnectBuffer();
249         ///
250         void dragEnterEvent(QDragEnterEvent * ev);
251         ///
252         void dropEvent(QDropEvent * ev);
253         /// make sure we quit cleanly
254         void closeEvent(QCloseEvent * e);
255         ///
256         void showEvent(QShowEvent *);
257
258         /// in order to catch Tab key press.
259         bool event(QEvent * e);
260         bool focusNextPrevChild(bool);
261
262         ///
263         bool goToFileRow(std::string const & argument);
264
265         ///
266         struct GuiViewPrivate;
267         GuiViewPrivate & d;
268
269 public:
270         ///
271         /// dialogs for this view
272         ///
273
274         ///
275         void resetDialogs();
276
277         /// Hide all visible dialogs
278         void hideAll() const;
279
280         /// Update all visible dialogs.
281         /** 
282          *  Check the status of all visible dialogs and disable or reenable
283          *  them as appropriate.
284          *
285          *  Disabling is needed for example when a dialog is open and the
286          *  cursor moves to a position where the corresponding inset is not
287          *  allowed.
288          */
289         void updateDialogs();
290
291         /** Show dialog could be called from arbitrary threads.
292             \param name == "bibtex", "citation" etc; an identifier used to
293             launch a particular dialog.
294             \param data is a string representation of the Inset contents.
295             It is often little more than the output from Inset::write.
296             It is passed to, and parsed by, the frontend dialog.
297             Several of these dialogs do not need any data,
298             so it defaults to string().
299             \param inset ownership is _not_ passed to the frontend dialog.
300             It is stored internally and used by the kernel to ascertain
301             what to do with the FuncRequest dispatched from the frontend
302             dialog on 'Apply'; should it be used to create a new inset at
303             the current cursor position or modify an existing, 'open' inset?
304         */
305         void showDialog(std::string const & name,
306                 std::string const & data, Inset * inset = 0);
307
308         /** \param name == "citation", "bibtex" etc; an identifier used
309             to reset the contents of a particular dialog with \param data.
310             See the comments to 'show', above.
311         */
312         void updateDialog(std::string const & name, std::string const & data);
313
314         /** All Dialogs of the given \param name will be closed if they are
315             connected to the given \param inset.
316         */
317         void hideDialog(std::string const & name, Inset * inset);
318         ///
319         void disconnectDialog(std::string const & name);
320
321 private:
322         ///
323         void saveLayout() const;
324         ///
325         bool restoreLayout();
326         ///
327         GuiToolbar * toolbar(std::string const & name);
328         ///
329         void constructToolbars();
330         ///
331         void initToolbars();
332         ///
333         bool lfunUiToggle(std::string const & ui_component);
334         ///
335         void toggleFullScreen();
336         ///
337         void insertLyXFile(docstring const & fname);
338         ///
339         void insertPlaintextFile(docstring const & fname,
340                 bool asParagraph);
341
342         /// Save a buffer as a new file. 
343         /**
344         Write a buffer to a new file name and rename the buffer
345     according to the new file name.
346
347     This function is e.g. used by menu callbacks and
348     LFUN_BUFFER_WRITE_AS.
349
350     If 'newname' is empty, the user is asked via a
351     dialog for the buffer's new name and location.
352
353     If 'newname' is non-empty and has an absolute path, that is used.
354     Otherwise the base directory of the buffer is used as the base
355     for any relative path in 'newname'.
356         */
357         bool renameBuffer(Buffer & b, docstring const & newname);
358         ///
359         bool saveBuffer(Buffer & b);
360         /// closes a workarea, if close_buffer is true the buffer will
361         /// also be released, otherwise the buffer will be hidden.
362         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
363         /// closes the tabworkarea and all tabs. If we are in a close event,
364         /// all buffers will be closed, otherwise they will be hidden.
365         bool closeTabWorkArea(TabWorkArea * twa);
366         /// gives the user the possibility to save his work 
367         /// or to discard the changes. If hiding is true, the
368         /// document will be reloaded.
369         bool saveBufferIfNeeded(Buffer & buf, bool hiding);
370         /// closes all workareas
371         bool closeWorkAreaAll();
372         /// write all open workareas into the session file
373         void writeSession() const;
374         /// is the buffer in this workarea also shown in another tab ?
375         /// This tab can either be in the same view or in another one.
376         bool inMultiTabs(GuiWorkArea * wa);
377         /// is the buffer in this workarea also shown in another view ?
378         bool inMultiViews(GuiWorkArea * wa);
379         ///
380         enum NextOrPrevious {
381                 NEXTBUFFER,
382                 PREVBUFFER
383         };
384         ///
385         void gotoNextOrPreviousBuffer(NextOrPrevious np);
386
387         /// Is the dialog currently visible?
388         bool isDialogVisible(std::string const & name) const;
389         ///
390         Dialog * findOrBuild(std::string const & name, bool hide_it);
391         ///
392         Dialog * build(std::string const & name);
393         ///
394         void reloadBuffer();
395         ///
396         void dispatchVC(FuncRequest const & cmd);
397         ///
398         void showMessage();
399
400         /// This view ID.
401         int id_;
402
403         /// flag to avoid two concurrent close events.
404         bool closing_;
405 };
406
407 } // namespace frontend
408 } // namespace lyx
409
410 #endif // GUIVIEW_H