]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
rename buffer parameter math_number_before to math_numbering_side
[lyx.git] / src / frontends / qt4 / GuiWorkArea.h
1 // -*- C++ -*-
2 /**
3  * \file GuiWorkArea.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef WORKAREA_H
14 #define WORKAREA_H
15
16 #include "ui_WorkAreaUi.h"
17
18 #include "frontends/WorkArea.h"
19
20 #include <QAbstractScrollArea>
21 #include <QTabBar>
22 #include <QTabWidget>
23
24 class QDragEnterEvent;
25 class QDropEvent;
26 class QToolButton;
27 class QWidget;
28
29 #ifdef CursorShape
30 #undef CursorShape
31 #endif
32
33 namespace lyx {
34
35 class Buffer;
36 class FuncRequest;
37
38 namespace frontend {
39
40 class GuiCompleter;
41 class GuiView;
42
43 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
44 {
45         Q_OBJECT
46
47 public:
48         ///
49         GuiWorkArea(QWidget *);
50         ///
51         GuiWorkArea(Buffer & buffer, GuiView & gv);
52         ///
53         ~GuiWorkArea();
54
55         ///
56         void init();
57         ///
58         void setBuffer(Buffer &);
59         ///
60         void setGuiView(GuiView &);
61         ///
62         void setFullScreen(bool full_screen);
63         /// is GuiView in fullscreen mode?
64         bool isFullScreen() const;
65         ///
66         void scheduleRedraw();
67         ///
68         BufferView & bufferView();
69         ///
70         BufferView const & bufferView() const;
71         ///
72         void redraw(bool update_metrics);
73
74         /// return true if the key is part of a shortcut
75         bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
76         /// Process Key pressed event.
77         /// This needs to be public because it is accessed externally by GuiView.
78         void processKeySym(KeySymbol const & key, KeyModifier mod);
79
80         bool inDialogMode() const;
81         void setDialogMode(bool mode);
82
83         ///
84         GuiCompleter & completer();
85
86         Qt::CursorShape cursorShape() const;
87
88         /// Return the GuiView this workArea belongs to
89         GuiView const & view() const;
90         GuiView & view();
91
92         /// Current ratio between physical pixels and device-independent pixels
93         double pixelRatio() const;
94
95 public Q_SLOTS:
96         ///
97         void stopBlinkingCursor();
98         ///
99         void startBlinkingCursor();
100
101 Q_SIGNALS:
102         ///
103         void titleChanged(GuiWorkArea *);
104         ///
105         void busy(bool);
106         ///
107         void bufferViewChanged();
108
109 private Q_SLOTS:
110         /// Scroll the BufferView.
111         /**
112           * This is a slot for the valueChanged() signal of the vertical scrollbar.
113           * \p value value of the scrollbar.
114         */
115         void scrollTo(int value);
116         /// timer to limit triple clicks
117         void doubleClickTimeout();
118         /// toggle the cursor's visibility
119         void toggleCursor();
120         /// close this work area.
121         /// Slot for Buffer::closing signal.
122         void close();
123         /// Slot to restore proper scrollbar behaviour.
124         void fixVerticalScrollBar();
125
126 private:
127         /// Update window titles of all users.
128         void updateWindowTitle();
129         ///
130         bool event(QEvent *);
131         ///
132         void contextMenuEvent(QContextMenuEvent *);
133         ///
134         void focusInEvent(QFocusEvent *);
135         ///
136         void focusOutEvent(QFocusEvent *);
137         /// repaint part of the widget
138         void paintEvent(QPaintEvent * ev);
139         /// widget has been resized
140         void resizeEvent(QResizeEvent * ev);
141         /// mouse button press
142         void mousePressEvent(QMouseEvent * ev);
143         /// mouse button release
144         void mouseReleaseEvent(QMouseEvent * ev);
145         /// mouse double click of button
146         void mouseDoubleClickEvent(QMouseEvent * ev);
147         /// mouse motion
148         void mouseMoveEvent(QMouseEvent * ev);
149         /// wheel event
150         void wheelEvent(QWheelEvent * ev);
151         /// key press event. It also knows how to handle ShortcutOverride events to
152         /// avoid code duplication.
153         void keyPressEvent(QKeyEvent * ev);
154         /// IM events
155         void inputMethodEvent(QInputMethodEvent * ev);
156         /// IM query
157         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
158
159         /// The slot connected to SyntheticMouseEvent::timeout.
160         void generateSyntheticMouseEvent();
161
162         friend class GuiCompleter;
163         struct Private;
164         Private * const d;
165 }; // GuiWorkArea
166
167
168 class EmbeddedWorkArea : public GuiWorkArea
169 {
170         Q_OBJECT
171 public:
172         ///
173         EmbeddedWorkArea(QWidget *);
174         ~EmbeddedWorkArea();
175
176         /// Dummy methods for Designer.
177         void setWidgetResizable(bool) {}
178         void setWidget(QWidget *) {}
179
180         QSize sizeHint () const;
181         ///
182         void disable();
183
184 protected:
185         ///
186         void closeEvent(QCloseEvent * ev);
187         ///
188         void hideEvent(QHideEvent *ev);
189
190 private:
191         /// Embedded Buffer.
192         Buffer * buffer_;
193 }; // EmbeddedWorkArea
194
195
196 class GuiWorkAreaContainer;
197
198 /// A tabbed set of GuiWorkAreas.
199 class TabWorkArea : public QTabWidget
200 {
201         Q_OBJECT
202 public:
203         TabWorkArea(QWidget * parent = 0);
204
205         /// hide QTabWidget methods
206         GuiWorkAreaContainer * currentWidget() const;
207         GuiWorkAreaContainer * widget(int index) const;
208
209         ///
210         void setFullScreen(bool full_screen);
211         void showBar(bool show);
212         void closeAll();
213         bool setCurrentWorkArea(GuiWorkArea *);
214         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
215         bool removeWorkArea(GuiWorkArea *);
216         GuiWorkArea * currentWorkArea() const;
217         GuiWorkArea * workArea(Buffer & buffer) const;
218         GuiWorkArea * workArea(int index) const;
219         void paintEvent(QPaintEvent *);
220
221 Q_SIGNALS:
222         ///
223         void currentWorkAreaChanged(GuiWorkArea *);
224         ///
225         void lastWorkAreaRemoved();
226
227 public Q_SLOTS:
228         /// close current buffer, or the one given by \c clicked_tab_
229         void closeCurrentBuffer();
230         /// hide current tab, or the one given by \c clicked_tab_
231         void hideCurrentTab();
232         /// close the tab given by \c index
233         void closeTab(int index);
234         ///
235         void moveTab(int fromIndex, int toIndex);
236         ///
237         void updateTabTexts();
238
239 private Q_SLOTS:
240         ///
241         void on_currentTabChanged(int index);
242         ///
243         void showContextMenu(const QPoint & pos);
244         /// enable closing tab on middle-click
245         void mousePressEvent(QMouseEvent * me);
246         void mouseReleaseEvent(QMouseEvent * me);
247         ///
248         void mouseDoubleClickEvent(QMouseEvent * event);
249         ///
250         int indexOfWorkArea(GuiWorkArea * w) const;
251
252 private:
253         using QTabWidget::addTab;
254         using QTabWidget::insertTab;
255
256         /// true if position is a tab (rather than the blank space in tab bar)
257         bool posIsTab(QPoint position);
258
259         int clicked_tab_;
260         ///
261         int midpressed_tab_;
262         ///
263         QToolButton * closeBufferButton;
264 }; // TabWorkArea
265
266
267 class DragTabBar : public QTabBar
268 {
269         Q_OBJECT
270 public:
271         ///
272         DragTabBar(QWidget * parent = 0);
273
274 protected:
275         ///
276         void mousePressEvent(QMouseEvent * event);
277         ///
278         void mouseMoveEvent(QMouseEvent * event);
279         ///
280         void dragEnterEvent(QDragEnterEvent * event);
281         ///
282         void dropEvent(QDropEvent * event);
283
284 private:
285         ///
286         QPoint dragStartPos_;
287
288 Q_SIGNALS:
289         ///
290         void tabMoveRequested(int fromIndex, int toIndex);
291 };
292
293
294 class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
295 {
296         Q_OBJECT
297         // non-null
298         GuiWorkArea * const wa_;
299         void dispatch(FuncRequest f) const;
300
301 private Q_SLOTS:
302         void updateDisplay();
303         void reload() const;
304         void ignore() const;
305
306 protected:
307         void mouseDoubleClickEvent(QMouseEvent * event); //override
308
309 public:
310         /// wa != 0
311         GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
312         /// non-null
313         GuiWorkArea * workArea() const { return wa_; }
314 };
315
316
317
318 } // namespace frontend
319 } // namespace lyx
320
321 #endif // WORKAREA_H