]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Fix warning during runtime with qt4
[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 QLabel;
28 class QMenu;
29 class QShowEvent;
30
31
32 namespace lyx {
33
34 namespace support { class FileName; }
35
36 class Buffer;
37 class BufferView;
38 class Cursor;
39 class DispatchResult;
40 class FuncStatus;
41 class FuncRequest;
42 class Inset;
43
44 namespace frontend {
45
46 class Dialog;
47 class LayoutBox;
48 class GuiToolbar;
49 class GuiWorkArea;
50 class TabWorkArea;
51 class TocModels;
52 class ToolbarInfo;
53
54 /**
55  * GuiView - Qt main LyX window
56  *
57  * This class represents the main LyX window and provides
58  * accessor functions to its content.
59  *
60  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
61  * is deleted. This might be useful for closing other dialogs
62  * depending on a given GuiView.
63  */
64 class GuiView : public QMainWindow, public GuiBufferViewDelegate,
65         public GuiBufferDelegate
66 {
67         Q_OBJECT
68
69 public:
70         /// create a main window of the given dimensions
71         GuiView(int id);
72
73         ~GuiView();
74
75         /// closes the view such that the view knows that is closed
76         /// programmatically and not by the user clicking the x.
77         bool closeScheduled();
78
79         /// Things that need to be done when the OSes session manager
80         /// requests a log out.
81         bool prepareAllBuffersForLogout();
82
83         int id() const { return id_; }
84
85         /// are we busy ?
86         bool busy() const;
87
88         /// Signal that the any "auto" minibuffer can be closed now.
89         void resetCommandExecute();
90
91         /// \name Generic accessor functions
92         //@{
93         /// The current BufferView refers to the BufferView that has the focus,
94         /// including for example the one that is created when you use the
95         /// advanced search and replace pane.
96         /// \return the currently selected buffer view.
97         BufferView * currentBufferView();
98         BufferView const * currentBufferView() const;
99
100         /// The document BufferView always refers to the view's main document
101         /// BufferView. So, even if the BufferView in e.g., the advanced
102         /// search and replace pane has the focus.
103         /// \return the current document buffer view.
104         BufferView * documentBufferView();
105         BufferView const * documentBufferView() const;
106
107         void newDocument(std::string const & filename,
108                 bool fromTemplate);
109
110         /// display a message in the view
111         /// could be called from any thread
112         void message(docstring const &);
113         
114         bool getStatus(FuncRequest const & cmd, FuncStatus & flag);
115         /// dispatch command.
116         /// \return true if the \c FuncRequest has been dispatched.
117         void dispatch(FuncRequest const & cmd, DispatchResult & dr);
118
119         void restartCursor();
120         /// Update the completion popup and the inline completion state.
121         /// If \c start is true, then a new completion might be started.
122         /// If \c keep is true, an active completion will be kept active
123         /// even though the cursor moved. The update flags of \c cur might
124         /// be changed.
125         void updateCompletion(Cursor & cur, bool start, bool keep);
126
127         ///
128         void setFocus();
129         bool hasFocus() const;
130
131         ///
132         void focusInEvent(QFocusEvent * e);
133         /// set a buffer to the current workarea.
134         void setBuffer(Buffer * b); ///< \c Buffer to set.
135
136         /// load a document into the current workarea.
137         Buffer * loadDocument(
138                 support::FileName const &  name, ///< File to load.
139                 bool tolastfiles = true  ///< append to the "Open recent" menu?
140                 );
141
142         /// add toolbar, if newline==true, add a toolbar break before the toolbar
143         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
144         void updateStatusBar();
145
146         /// updates the possible layouts selectable
147         void updateLayoutList();
148         void updateToolbars();
149         QMenu * createPopupMenu();
150
151         ///
152         LayoutBox * getLayoutDialog() const;
153
154         /// hides the workarea and makes sure it is clean
155         bool hideWorkArea(GuiWorkArea * wa);
156         /// closes workarea; close buffer only if no other workareas point to it
157         bool closeWorkArea(GuiWorkArea * wa);
158         /// closes the buffer
159         bool closeBuffer(Buffer & buf);
160         ///
161         void openDocument(std::string const & filename);
162         ///
163         void importDocument(std::string const &);
164
165         /// \name GuiBufferDelegate.
166         //@{
167         void resetAutosaveTimers();
168         void errors(std::string const &, bool from_master = false);
169         void structureChanged();
170         void updateTocItem(std::string const &, DocIterator const &);
171         //@}
172
173         ///
174         TocModels & tocModels();
175         
176         /// called on timeout
177         void autoSave();
178
179         /// check for external change of any opened buffer, mainly for svn usage
180         void checkExternallyModifiedBuffers();
181
182         /** redraw \c inset in all the BufferViews in which it is currently
183          *  visible. If successful return a pointer to the owning Buffer.
184          */
185         Buffer const * updateInset(Inset const *);
186
187         /// \return the \c Workarea associated to \p  Buffer
188         /// \retval 0 if no \c WorkArea is found.
189         GuiWorkArea * workArea(Buffer & buffer);
190         /// \return the \c Workarea at index \c index
191         GuiWorkArea * workArea(int index);
192
193         /// Add a \c WorkArea 
194         /// \return the \c Workarea associated to \p  Buffer
195         /// \retval 0 if no \c WorkArea is found.
196         GuiWorkArea * addWorkArea(Buffer & buffer);
197         /// \param work_area The current \c WorkArea, or \c NULL
198         void setCurrentWorkArea(GuiWorkArea * work_area);
199         ///
200         void removeWorkArea(GuiWorkArea * work_area);
201         /// return the current WorkArea (the one that has the focus).
202         GuiWorkArea const * currentWorkArea() const;
203         /// return the current WorkArea (the one that has the focus).
204         GuiWorkArea * currentWorkArea();
205
206         /// return the current document WorkArea (it may not have the focus).
207         GuiWorkArea const * currentMainWorkArea() const;
208         /// return the current document WorkArea (it may not have the focus).
209         GuiWorkArea * currentMainWorkArea();
210         
211         /// Current ratio between physical pixels and device-independent pixels
212         double pixelRatio() const;
213
214 Q_SIGNALS:
215         void closing(int);
216         void triggerShowDialog(QString const & qname, QString const & qdata, Inset * inset);
217         // emitted when the work area or its buffer view changed
218         void bufferViewChanged();
219
220 public Q_SLOTS:
221         ///
222         void setBusy(bool);
223         /// idle timeout.
224         /// clear any temporary message and replace with current status.
225         void clearMessage();
226         ///
227         void updateWindowTitle(GuiWorkArea * wa);
228
229 private Q_SLOTS:
230         ///
231         void resetWindowTitle();
232
233         ///
234         void on_currentWorkAreaChanged(GuiWorkArea *);
235         ///
236         void onBufferViewChanged();
237         ///
238         void on_lastWorkAreaRemoved();
239
240         /// slots to change the icon size
241         void smallSizedIcons();
242         void normalSizedIcons();
243         void bigSizedIcons();
244         void hugeSizedIcons();
245         void giantSizedIcons();
246
247         /// For completion of autosave or export threads.
248         void processingThreadStarted();
249         void processingThreadFinished();
250         void autoSaveThreadFinished();
251
252         /// must be called in GUI thread
253         void doShowDialog(QString const & qname, QString const & qdata,
254         Inset * inset);
255
256         /// must be called from GUI thread
257         void updateStatusBarMessage(QString const & str);
258         void clearMessageText();
259
260 private:
261         /// Open given child document in current buffer directory.
262         void openChildDocument(std::string const & filename);
263         /// Close current document buffer.
264         bool closeBuffer();
265         /// Close all document buffers.
266         bool closeBufferAll();
267         ///
268         TabWorkArea * addTabWorkArea();
269
270         /// connect to signals in the given BufferView
271         void connectBufferView(BufferView & bv);
272         /// disconnect from signals in the given BufferView
273         void disconnectBufferView();
274         /// connect to signals in the given buffer
275         void connectBuffer(Buffer & buf);
276         /// disconnect from signals in the given buffer
277         void disconnectBuffer();
278         ///
279         void dragEnterEvent(QDragEnterEvent * ev);
280         ///
281         void dropEvent(QDropEvent * ev);
282         /// make sure we quit cleanly
283         void closeEvent(QCloseEvent * e);
284         ///
285         void showEvent(QShowEvent *);
286
287         /// in order to catch Tab key press.
288         bool event(QEvent * e);
289         bool focusNextPrevChild(bool);
290
291         ///
292         bool goToFileRow(std::string const & argument);
293
294         ///
295         class GuiViewPrivate;
296         GuiViewPrivate & d;
297
298 public:
299         ///
300         /// dialogs for this view
301         ///
302
303         ///
304         void resetDialogs();
305
306         /// Hide all visible dialogs
307         void hideAll() const;
308
309         /// Update all visible dialogs.
310         /** 
311          *  Check the status of all visible dialogs and disable or reenable
312          *  them as appropriate.
313          *
314          *  Disabling is needed for example when a dialog is open and the
315          *  cursor moves to a position where the corresponding inset is not
316          *  allowed.
317          */
318         void updateDialogs();
319
320         /** Show dialog could be called from arbitrary threads.
321             \param name == "bibtex", "citation" etc; an identifier used to
322             launch a particular dialog.
323             \param data is a string representation of the Inset contents.
324             It is often little more than the output from Inset::write.
325             It is passed to, and parsed by, the frontend dialog.
326             Several of these dialogs do not need any data,
327             so it defaults to string().
328             \param inset ownership is _not_ passed to the frontend dialog.
329             It is stored internally and used by the kernel to ascertain
330             what to do with the FuncRequest dispatched from the frontend
331             dialog on 'Apply'; should it be used to create a new inset at
332             the current cursor position or modify an existing, 'open' inset?
333         */
334         void showDialog(std::string const & name,
335                 std::string const & data, Inset * inset = 0);
336
337         /** \param name == "citation", "bibtex" etc; an identifier used
338             to reset the contents of a particular dialog with \param data.
339             See the comments to 'show', above.
340         */
341         void updateDialog(std::string const & name, std::string const & data);
342
343         /** All Dialogs of the given \param name will be closed if they are
344             connected to the given \param inset.
345         */
346         void hideDialog(std::string const & name, Inset * inset);
347         ///
348         void disconnectDialog(std::string const & name);
349
350 private:
351         /// Saves the layout and geometry of the window
352         void saveLayout() const;
353         /// Saves the settings of toolbars and all dialogs
354         void saveUISettings() const;
355         ///
356         bool restoreLayout();
357         ///
358         GuiToolbar * toolbar(std::string const & name);
359         ///
360         void constructToolbars();
361         ///
362         void initToolbars();
363         ///
364         void initToolbar(std::string const & name);
365         ///
366         bool lfunUiToggle(std::string const & ui_component);
367         ///
368         void toggleFullScreen();
369         ///
370         void insertLyXFile(docstring const & fname);
371         ///
372         /// Open Export As ... dialog. \p iformat is the format the
373         /// filter is initially set to.
374         bool exportBufferAs(Buffer & b, docstring const & iformat);
375
376         ///
377         enum RenameKind { LV_WRITE_AS, LV_VC_RENAME, LV_VC_COPY };
378         /// Save a buffer as a new file. 
379         /**
380         Write a buffer to a new file name and rename the buffer
381     according to the new file name.
382
383     This function is e.g. used by menu callbacks and
384     LFUN_BUFFER_WRITE_AS.
385
386     If 'newname' is empty, the user is asked via a
387     dialog for the buffer's new name and location.
388
389     If 'newname' is non-empty and has an absolute path, that is used.
390     Otherwise the base directory of the buffer is used as the base
391     for any relative path in 'newname'.
392
393          \p kind controls what is done besides the pure renaming:
394          * LV_WRITE_AS  => The buffer is written without version control actions.
395          * LV_VC_RENAME => The file is renamed in version control.
396          * LV_VC_COPY   => The file is copied in version control.
397          */
398         bool renameBuffer(Buffer & b, docstring const & newname,
399                           RenameKind kind = LV_WRITE_AS);
400         ///
401         bool saveBuffer(Buffer & b);
402         /// save and rename buffer to fn. If fn is empty, the buffer
403         /// is just saved as the filename it already has.
404         bool saveBuffer(Buffer & b, support::FileName const & fn);
405         /// closes a workarea, if close_buffer is true the buffer will
406         /// also be released, otherwise the buffer will be hidden.
407         bool closeWorkArea(GuiWorkArea * wa, bool close_buffer);
408         /// closes the tabworkarea and all tabs. If we are in a close event,
409         /// all buffers will be closed, otherwise they will be hidden.
410         bool closeTabWorkArea(TabWorkArea * twa);
411         /// gives the user the possibility to save his work 
412         /// or to discard the changes. If hiding is true, the
413         /// document will be reloaded.
414         bool saveBufferIfNeeded(Buffer & buf, bool hiding);
415         /// closes all workareas
416         bool closeWorkAreaAll();
417         /// write all open workareas into the session file
418         void writeSession() const;
419         /// is the buffer in this workarea also shown in another tab ?
420         /// This tab can either be in the same view or in another one.
421         bool inMultiTabs(GuiWorkArea * wa);
422         /// is the buffer shown in some other view ?
423         bool inOtherView(Buffer & buf);
424         ///
425         enum NextOrPrevious {
426                 NEXTBUFFER,
427                 PREVBUFFER
428         };
429         ///
430         void gotoNextOrPreviousBuffer(NextOrPrevious np, bool const move);
431
432         /// Is the dialog currently visible?
433         bool isDialogVisible(std::string const & name) const;
434         ///
435         Dialog * findOrBuild(std::string const & name, bool hide_it);
436         ///
437         Dialog * build(std::string const & name);
438         ///
439         bool reloadBuffer(Buffer & buffer);
440         ///
441         void dispatchVC(FuncRequest const & cmd, DispatchResult & dr);
442         ///
443         void dispatchToBufferView(FuncRequest const & cmd, DispatchResult & dr);
444         ///
445         void showMessage();
446
447         /// This view ID.
448         int id_;
449
450         /// flag to avoid two concurrent close events.
451         bool closing_;
452         /// if the view is busy the cursor shouldn't blink for instance.
453         /// This counts the number of times more often we called
454         /// setBusy(true) compared to setBusy(false), so we can nest
455         /// functions that call setBusy;
456         int busy_;
457
458         /// Request to open the command toolbar if it is "auto"
459         bool command_execute_;
460         /// Request to give focus to minibuffer
461         bool minibuffer_focus_;
462
463         /// Statusbar widget that shows read-only status
464         QLabel * read_only_;
465         /// Statusbar widget that shows version control status
466         QLabel * version_control_;
467
468         /// Minimum zoom percentage
469         static unsigned int const zoom_min_ = 10;
470
471 };
472
473 } // namespace frontend
474 } // namespace lyx
475
476 #endif // GUIVIEW_H