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