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