]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Move the global formats and system_formats variables into the
[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 #ifdef CursorShape
30 #undef CursorShape
31 #endif
32
33 namespace lyx {
34
35 class Buffer;
36 class FuncRequest;
37
38 namespace frontend {
39
40 class GuiCompleter;
41 class GuiView;
42
43 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
44 {
45         Q_OBJECT
46
47 public:
48         ///
49         GuiWorkArea(QWidget *);
50         ///
51         GuiWorkArea(Buffer & buffer, GuiView & gv);
52         ///
53         ~GuiWorkArea();
54
55         ///
56         void init();
57         ///
58         void setBuffer(Buffer &);
59         ///
60         void setGuiView(GuiView &);
61         ///
62         void setFullScreen(bool full_screen);
63         /// is GuiView in fullscreen mode?
64         bool isFullScreen() const;
65         ///
66         void scheduleRedraw();
67         ///
68         BufferView & bufferView();
69         ///
70         BufferView const & bufferView() const;
71         ///
72         void redraw(bool update_metrics);
73
74         /// return true if the key is part of a shortcut
75         bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
76         /// Process Key pressed event.
77         /// This needs to be public because it is accessed externally by GuiView.
78         void processKeySym(KeySymbol const & key, KeyModifier mod);
79
80         bool inDialogMode() const;
81         void setDialogMode(bool mode);
82
83         ///
84         GuiCompleter & completer();
85
86         Qt::CursorShape cursorShape() const;
87
88         /// Return the GuiView this workArea belongs to
89         GuiView const & view() const;
90         GuiView & view();
91
92         /// Current ratio between physical pixels and device-independent pixels
93         double pixelRatio() const;
94
95 public Q_SLOTS:
96         ///
97         void stopBlinkingCursor();
98         ///
99         void startBlinkingCursor();
100
101 Q_SIGNALS:
102         ///
103         void titleChanged(GuiWorkArea *);
104         ///
105         void busy(bool);
106         ///
107         void bufferViewChanged();
108
109 private Q_SLOTS:
110         /// Scroll the BufferView.
111         /**
112           * This is a slot for the valueChanged() signal of the vertical scrollbar.
113           * \p value value of the scrollbar.
114         */
115         void scrollTo(int value);
116         /// timer to limit triple clicks
117         void doubleClickTimeout();
118         /// toggle the cursor's visibility
119         void toggleCursor();
120         /// close this work area.
121         /// Slot for Buffer::closing signal.
122         void close();
123         /// Slot to restore proper scrollbar behaviour.
124         void fixVerticalScrollBar();
125
126 private:
127         /// Update window titles of all users.
128         void updateWindowTitle();
129         ///
130         bool event(QEvent *);
131         ///
132         void contextMenuEvent(QContextMenuEvent *);
133         ///
134         void focusInEvent(QFocusEvent *);
135         ///
136         void focusOutEvent(QFocusEvent *);
137         /// repaint part of the widget
138         void paintEvent(QPaintEvent * ev);
139         /// widget has been resized
140         void resizeEvent(QResizeEvent * ev);
141         /// mouse button press
142         void mousePressEvent(QMouseEvent * ev);
143         /// mouse button release
144         void mouseReleaseEvent(QMouseEvent * ev);
145         /// mouse double click of button
146         void mouseDoubleClickEvent(QMouseEvent * ev);
147         /// mouse motion
148         void mouseMoveEvent(QMouseEvent * ev);
149         /// wheel event
150         void wheelEvent(QWheelEvent * ev);
151         /// key press event. It also knows how to handle ShortcutOverride events to
152         /// avoid code duplication.
153         void keyPressEvent(QKeyEvent * ev);
154         /// IM events
155         void inputMethodEvent(QInputMethodEvent * ev);
156         /// IM query
157         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
158
159         /// The slot connected to SyntheticMouseEvent::timeout.
160         void generateSyntheticMouseEvent();
161
162         friend class GuiCompleter;
163         struct Private;
164         Private * const d;
165 }; // GuiWorkArea
166
167
168 class EmbeddedWorkArea : public GuiWorkArea
169 {
170         Q_OBJECT
171 public:
172         ///
173         EmbeddedWorkArea(QWidget *);
174         ~EmbeddedWorkArea();
175
176         /// Dummy methods for Designer.
177         void setWidgetResizable(bool) {}
178         void setWidget(QWidget *) {}
179
180         QSize sizeHint () const;
181         ///
182         void disable();
183
184 protected:
185         ///
186         void closeEvent(QCloseEvent * ev);
187         ///
188         void hideEvent(QHideEvent *ev);
189
190 private:
191         /// Embedded Buffer.
192         Buffer * buffer_;
193 }; // EmbeddedWorkArea
194
195
196 /// A tabbed set of GuiWorkAreas.
197 class TabWorkArea : public QTabWidget
198 {
199         Q_OBJECT
200 public:
201         TabWorkArea(QWidget * parent = 0);
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();
211         GuiWorkArea * workArea(Buffer & buffer);
212         GuiWorkArea const * workArea(int index) const;
213         GuiWorkArea * workArea(int index);
214         void paintEvent(QPaintEvent *);
215
216 Q_SIGNALS:
217         ///
218         void currentWorkAreaChanged(GuiWorkArea *);
219         ///
220         void lastWorkAreaRemoved();
221
222 public Q_SLOTS:
223         /// close current buffer, or the one given by \c clicked_tab_
224         void closeCurrentBuffer();
225         /// hide current tab, or the one given by \c clicked_tab_
226         void hideCurrentTab();
227         /// close the tab given by \c index
228         void closeTab(int index);
229         ///
230         void moveTab(int fromIndex, int toIndex);
231         ///
232         void updateTabTexts();
233         
234 private Q_SLOTS:
235         ///
236         void on_currentTabChanged(int index);
237         ///
238         void showContextMenu(const QPoint & pos);
239         /// enable closing tab on middle-click
240         void mousePressEvent(QMouseEvent * me);
241         void mouseReleaseEvent(QMouseEvent * me);
242         ///
243         void mouseDoubleClickEvent(QMouseEvent * event);
244         ///
245         int indexOfWorkArea(GuiWorkArea * w) const;
246
247 private:
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         GuiWorkArea * const wa_;
290         void dispatch(FuncRequest f) const;
291
292 private Q_SLOTS:
293         void updateDisplay();
294         void reload() const;
295         void ignore() const;
296
297 protected:
298         void mouseDoubleClickEvent(QMouseEvent * event); //override
299
300 public:
301         ///
302         GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
303         GuiWorkArea * workArea() const { return wa_; }
304 };
305
306
307
308 } // namespace frontend
309 } // namespace lyx
310
311 #endif // WORKAREA_H