]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Cleanup and simplify WorkArea code
[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 namespace lyx {
30
31 class Buffer;
32 class FuncRequest;
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         void scheduleRedraw();
63         ///
64         BufferView & bufferView();
65         ///
66         BufferView const & bufferView() const;
67         ///
68         void redraw(bool update_metrics);
69
70         /// return true if the key is part of a shortcut
71         bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
72         /// Process Key pressed event.
73         /// This needs to be public because it is accessed externally by GuiView.
74         void processKeySym(KeySymbol const & key, KeyModifier mod);
75
76         bool inDialogMode() const;
77         void setDialogMode(bool mode);
78
79         ///
80         GuiCompleter & completer();
81
82         /// Return the GuiView this workArea belongs to
83         GuiView const & view() const;
84         GuiView & view();
85
86         /// Current ratio between physical pixels and device-independent pixels
87         double pixelRatio() const;
88
89 public Q_SLOTS:
90         ///
91         void stopBlinkingCaret();
92         ///
93         void startBlinkingCaret();
94
95 Q_SIGNALS:
96         ///
97         void titleChanged(GuiWorkArea *);
98         ///
99         void busy(bool);
100         ///
101         void bufferViewChanged();
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 cursor's visibility
113         void toggleCaret();
114         /// close this work area.
115         /// Slot for Buffer::closing signal.
116         void close();
117         /// Slot to restore proper scrollbar behaviour.
118         void fixVerticalScrollBar();
119
120 private:
121         /// Update window titles of all users.
122         void updateWindowTitle();
123         ///
124         bool event(QEvent *);
125         ///
126         void contextMenuEvent(QContextMenuEvent *);
127         ///
128         void focusInEvent(QFocusEvent *);
129         ///
130         void focusOutEvent(QFocusEvent *);
131         /// repaint part of the widget
132         void paintEvent(QPaintEvent * ev);
133         /// widget has been resized
134         void resizeEvent(QResizeEvent * ev);
135         /// mouse button press
136         void mousePressEvent(QMouseEvent * ev);
137         /// mouse button release
138         void mouseReleaseEvent(QMouseEvent * ev);
139         /// mouse double click of button
140         void mouseDoubleClickEvent(QMouseEvent * ev);
141         /// mouse motion
142         void mouseMoveEvent(QMouseEvent * ev);
143         /// wheel event
144         void wheelEvent(QWheelEvent * ev);
145         /// key press event. It also knows how to handle ShortcutOverride events to
146         /// avoid code duplication.
147         void keyPressEvent(QKeyEvent * ev);
148         /// IM events
149         void inputMethodEvent(QInputMethodEvent * ev);
150         /// IM query
151         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
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 class EmbeddedWorkArea : public GuiWorkArea
163 {
164         Q_OBJECT
165 public:
166         ///
167         EmbeddedWorkArea(QWidget *);
168         ~EmbeddedWorkArea();
169
170         /// Dummy methods for Designer.
171         void setWidgetResizable(bool) {}
172         void setWidget(QWidget *) {}
173
174         QSize sizeHint () const;
175         ///
176         void disable();
177
178 protected:
179         ///
180         void closeEvent(QCloseEvent * ev);
181         ///
182         void hideEvent(QHideEvent *ev);
183
184 private:
185         /// Embedded Buffer.
186         Buffer * buffer_;
187 }; // EmbeddedWorkArea
188
189
190 class GuiWorkAreaContainer;
191
192 /// A tabbed set of GuiWorkAreas.
193 class TabWorkArea : public QTabWidget
194 {
195         Q_OBJECT
196 public:
197         TabWorkArea(QWidget * parent = 0);
198
199         /// hide QTabWidget methods
200         GuiWorkAreaContainer * currentWidget() const;
201         GuiWorkAreaContainer * widget(int index) const;
202
203         ///
204         void setFullScreen(bool full_screen);
205         void showBar(bool show);
206         void closeAll();
207         bool setCurrentWorkArea(GuiWorkArea *);
208         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
209         bool removeWorkArea(GuiWorkArea *);
210         GuiWorkArea * currentWorkArea() const;
211         GuiWorkArea * workArea(Buffer & buffer) const;
212         GuiWorkArea * workArea(int index) const;
213         void paintEvent(QPaintEvent *);
214
215 Q_SIGNALS:
216         ///
217         void currentWorkAreaChanged(GuiWorkArea *);
218         ///
219         void lastWorkAreaRemoved();
220
221 public Q_SLOTS:
222         /// close current buffer, or the one given by \c clicked_tab_
223         void closeCurrentBuffer();
224         /// hide current tab, or the one given by \c clicked_tab_
225         void hideCurrentTab();
226         /// close the tab given by \c index
227         void closeTab(int index);
228         ///
229         void moveTab(int fromIndex, int toIndex);
230         ///
231         void updateTabTexts();
232
233 private Q_SLOTS:
234         ///
235         void on_currentTabChanged(int index);
236         ///
237         void showContextMenu(const QPoint & pos);
238         /// enable closing tab on middle-click
239         void mousePressEvent(QMouseEvent * me);
240         void mouseReleaseEvent(QMouseEvent * me);
241         ///
242         void mouseDoubleClickEvent(QMouseEvent * event);
243         ///
244         int indexOfWorkArea(GuiWorkArea * w) const;
245
246 private:
247         using QTabWidget::addTab;
248         using QTabWidget::insertTab;
249
250         /// true if position is a tab (rather than the blank space in tab bar)
251         bool posIsTab(QPoint position);
252
253         int clicked_tab_;
254         ///
255         int midpressed_tab_;
256         ///
257         QToolButton * closeBufferButton;
258 }; // TabWorkArea
259
260
261 class DragTabBar : public QTabBar
262 {
263         Q_OBJECT
264 public:
265         ///
266         DragTabBar(QWidget * parent = 0);
267
268 protected:
269         ///
270         void mousePressEvent(QMouseEvent * event);
271         ///
272         void mouseMoveEvent(QMouseEvent * event);
273         ///
274         void dragEnterEvent(QDragEnterEvent * event);
275         ///
276         void dropEvent(QDropEvent * event);
277
278 private:
279         ///
280         QPoint dragStartPos_;
281
282 Q_SIGNALS:
283         ///
284         void tabMoveRequested(int fromIndex, int toIndex);
285 };
286
287
288 class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
289 {
290         Q_OBJECT
291         // non-null
292         GuiWorkArea * const wa_;
293         void dispatch(FuncRequest f) const;
294
295 private Q_SLOTS:
296         void updateDisplay();
297         void reload() const;
298         void ignore() const;
299
300 protected:
301         void mouseDoubleClickEvent(QMouseEvent * event); //override
302
303 public:
304         /// wa != 0
305         GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
306         /// non-null
307         GuiWorkArea * workArea() const { return wa_; }
308 };
309
310
311
312 } // namespace frontend
313 } // namespace lyx
314
315 #endif // WORKAREA_H