]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiView.h
Transfer createView() from Application to GuiApplication and get rid of LyXView:...
[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/LyXView.h"
19
20 #include <QMainWindow>
21 #include <QTimer>
22
23 class QCloseEvent;
24 class QDragEnterEvent;
25 class QDropEvent;
26 class QMenu;
27
28
29 namespace lyx {
30
31 class Timeout;
32 class ToolbarInfo;
33
34 namespace frontend {
35
36 class GuiToolbar;
37 class GuiWorkArea;
38
39 QWidget * mainWindow();
40
41 /**
42  * GuiView - Qt4 implementation of LyXView
43  *
44  * qt4-private implementation of the main LyX window.
45  *
46  * Note: a QObject emits a destroyed(QObject *) Qt signal when it
47  * is deleted. This might be useful for closing other dialogs
48  * depending on a given GuiView.
49  */
50 class GuiView : public QMainWindow, public LyXView
51 {
52         Q_OBJECT
53 public:
54         /// create a main window of the given dimensions
55         GuiView(int id);
56
57         ~GuiView();
58
59         virtual void init();
60         virtual void close();
61         virtual void setFocus();
62
63         enum Maximized {
64                 NotMaximized = 0, // LyX::newLyXView() relies on this to be zero!
65                 VerticallyMaximized,
66                 HorizontallyMaximized,
67                 CompletelyMaximized
68         };
69         ///
70         virtual void setGeometry(
71                 unsigned int width,
72                 unsigned int height,
73                 int posx, int posy,
74                 Maximized maximized,
75                 unsigned int iconSizeXY,
76                 const std::string & geometryArg);
77         /// save the geometry state in the session manager.
78         virtual void saveGeometry();
79         virtual void setBusy(bool);
80         /// add toolbar, if newline==true, add a toolbar break before the toolbar
81         GuiToolbar * makeToolbar(ToolbarInfo const & tbinfo, bool newline);
82         virtual void updateStatusBar();
83         virtual void message(docstring const & str);
84         virtual bool hasFocus() const;
85         void showMiniBuffer(bool);
86         void updateLayoutChoice(bool force);
87         bool isToolbarVisible(std::string const & id);
88         void updateToolbars();
89         ///
90         QMenu * createPopupMenu();
91
92         /// dispatch to current BufferView
93         void dispatch(FuncRequest const & cmd);
94
95         /// \return the buffer currently shown in this window
96         Buffer * buffer();
97         Buffer const * buffer() const;
98         /// set a buffer to the current workarea.
99         void setBuffer(Buffer * b); ///< \c Buffer to set.
100
101         /// GuiBufferDelegate.
102         ///@{
103         void resetAutosaveTimers();
104         void errors(std::string const &);
105         void structureChanged() { updateToc(); }
106         ///@}
107
108         ////
109         void showDialog(std::string const & name);
110         void showDialogWithData(std::string const & name,
111                 std::string const & data);
112         void showInsetDialog(std::string const & name,
113                 std::string const & data, Inset * inset);
114         void updateDialog(std::string const & name,
115                 std::string const & data);
116         
117         /// called on timeout
118         void autoSave();
119         ///
120         void updateEmbeddedFiles();
121
122         /// \return the current buffer view.
123         BufferView * view();
124
125         /// get access to the dialogs
126         Dialogs & getDialogs() { return *dialogs_; }
127         ///
128         Dialogs const & getDialogs() const { return *dialogs_; }
129
130         /// load a buffer into the current workarea.
131         Buffer * loadLyXFile(support::FileName const &  name, ///< File to load.
132                 bool tolastfiles = true);  ///< append to the "Open recent" menu?
133
134         /** redraw \c inset in all the BufferViews in which it is currently
135          *  visible. If successful return a pointer to the owning Buffer.
136          */
137         Buffer const * updateInset(Inset const *);
138         ///
139         void restartCursor();
140
141         /// \return the \c Workarea associated to \p  Buffer
142         /// \retval 0 if no \c WorkArea is found.
143         GuiWorkArea * workArea(Buffer & buffer);
144
145         /// Add a \c WorkArea 
146         /// \return the \c Workarea associated to \p  Buffer
147         /// \retval 0 if no \c WorkArea is found.
148         GuiWorkArea * addWorkArea(Buffer & buffer);
149         ///
150         void setCurrentWorkArea(GuiWorkArea * work_area);
151         ///
152         void removeWorkArea(GuiWorkArea * work_area);
153         /// return the current WorkArea (the one that has the focus).
154         GuiWorkArea const * currentWorkArea() const;
155
156 Q_SIGNALS:
157         void closing(int);
158
159 public Q_SLOTS:
160         /// idle timeout.
161         /// clear any temporary message and replace with current status.
162         void clearMessage();
163
164 private Q_SLOTS:
165         ///
166         void updateWindowTitle(GuiWorkArea * wa);
167
168         ///
169         void on_currentWorkAreaChanged(GuiWorkArea *);
170
171         /// slots to change the icon size
172         void smallSizedIcons();
173         void normalSizedIcons();
174         void bigSizedIcons();
175
176 private:
177         ///
178         void addTabWorkArea();
179
180         /// connect to signals in the given BufferView
181         void connectBufferView(BufferView & bv);
182         /// disconnect from signals in the given BufferView
183         void disconnectBufferView();
184         /// connect to signals in the given buffer
185         void connectBuffer(Buffer & buf);
186         /// disconnect from signals in the given buffer
187         void disconnectBuffer();
188         ///
189         void updateToc();
190         ///
191         void dragEnterEvent(QDragEnterEvent * ev);
192         ///
193         void dropEvent(QDropEvent * ev);
194         /// make sure we quit cleanly
195         virtual void closeEvent(QCloseEvent * e);
196         ///
197         virtual void resizeEvent(QResizeEvent * e);
198         ///
199         virtual void moveEvent(QMoveEvent * e);
200
201         /// in order to catch Tab key press.
202         bool event(QEvent * e);
203         bool focusNextPrevChild(bool);
204         ///
205         QRect updateFloatingGeometry();
206         ///
207         void setIconSize(unsigned int size);
208
209         ///
210         struct GuiViewPrivate;
211         GuiViewPrivate & d;
212
213         ///
214         QTimer statusbar_timer_;
215
216         /// are we quitting by the menu?
217         bool quitting_by_menu_;
218
219         ///
220         QRect floatingGeometry_;
221
222         struct ToolbarSize {
223                 int top_width;
224                 int bottom_width;
225                 int left_height;
226                 int right_height;
227         };
228
229         ToolbarSize toolbarSize_;
230
231         /// auto-saving of buffers
232         Timeout * const autosave_timeout_;
233         /// dialogs for this view
234         Dialogs * dialogs_;
235 };
236
237
238 } // namespace frontend
239 } // namespace lyx
240
241 #endif // GUIVIEW_H