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