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