]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Fix the tab ordering of GuiDocument components.
[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 "frontends/WorkArea.h"
17
18 #include "DocIterator.h"
19 #include "FuncRequest.h"
20 #include "qt_helpers.h"
21 #include "support/docstring.h"
22 #include "support/Timeout.h"
23
24 #include <QAbstractScrollArea>
25 #include <QMouseEvent>
26 #include <QPixmap>
27 #include <QTabBar>
28 #include <QTabWidget>
29 #include <QTimer>
30
31 class QContextMenuEvent;
32 class QDragEnterEvent;
33 class QDropEvent;
34 class QKeyEvent;
35 class QPaintEvent;
36 class QResizeEvent;
37 class QToolButton;
38 class QWheelEvent;
39 class QWidget;
40
41 #ifdef CursorShape
42 #undef CursorShape
43 #endif
44
45 namespace lyx {
46
47 class Buffer;
48
49 namespace frontend {
50
51 class GuiCompleter;
52 class GuiView;
53 class GuiWorkArea;
54
55 /// for emulating triple click
56 class DoubleClick {
57 public:
58         ///
59         DoubleClick() : state(Qt::NoButton), active(false) {}
60         ///
61         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
62         ///
63         bool operator==(QMouseEvent const & e) { return state == e.button(); }
64         ///
65 public:
66         ///
67         Qt::MouseButton state;
68         ///
69         bool active;
70 };
71
72 /** Qt only emits mouse events when the mouse is being moved, but
73  *  we want to generate 'pseudo' mouse events when the mouse button is
74  *  pressed and the mouse cursor is below the bottom, or above the top
75  *  of the work area. In this way, we'll be able to continue scrolling
76  *  (and selecting) the text.
77  *
78  *  This class stores all the parameters needed to make this happen.
79  */
80 class SyntheticMouseEvent
81 {
82 public:
83         SyntheticMouseEvent();
84
85         FuncRequest cmd;
86         Timeout timeout;
87         bool restart_timeout;
88 };
89
90
91 /**
92  * Implementation of the work area (buffer view GUI)
93 */
94 class CursorWidget;
95
96 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
97 {
98         Q_OBJECT
99
100 public:
101         ///
102         GuiWorkArea(QWidget *);
103         ///
104         GuiWorkArea(Buffer & buffer, GuiView & gv);
105         ///
106         ~GuiWorkArea();
107
108         ///
109         void init();
110         ///
111         void setBuffer(Buffer &);
112         ///
113         void setGuiView(GuiView &);
114         ///
115         void setFullScreen(bool full_screen);
116         /// is GuiView in fullscreen mode?
117         bool isFullScreen();
118         ///
119         void scheduleRedraw() { schedule_redraw_ = true; }
120         ///
121         BufferView & bufferView();
122         ///
123         BufferView const & bufferView() const;
124         ///
125         void redraw(bool update_metrics);
126         ///
127         void stopBlinkingCursor();
128         ///
129         void startBlinkingCursor();
130         /// Process Key pressed event.
131         /// This needs to be public because it is accessed externally by GuiView.
132         void processKeySym(KeySymbol const & key, KeyModifier mod);
133         ///
134         void resizeBufferView();
135
136         bool inDialogMode() const { return dialog_mode_; }
137         void setDialogMode(bool mode) { dialog_mode_ = mode; }
138
139         ///
140         GuiCompleter & completer() { return *completer_; }
141
142         Qt::CursorShape cursorShape() const;
143         void setCursorShape(Qt::CursorShape shape);
144
145         /// Change the cursor when the mouse hovers over a clickable inset
146         void updateCursorShape();
147
148         /// Return the GuiView this workArea belongs to
149         GuiView const & view() const { return *lyx_view_; }
150         GuiView & view() { return *lyx_view_; }
151
152 Q_SIGNALS:
153         ///
154         void titleChanged(GuiWorkArea *);
155
156 private Q_SLOTS:
157         /// Scroll the BufferView.
158         /**
159           * This is a slot for the valueChanged() signal of the vertical scrollbar.
160           * \p value value of the scrollbar.
161         */
162         void scrollTo(int value);
163         /// timer to limit triple clicks
164         void doubleClickTimeout();
165         /// toggle the cursor's visibility
166         void toggleCursor();
167         /// close this work area.
168         /// Slot for Buffer::closing signal.
169         void close();
170         /// Slot to restore proper scrollbar behaviour.
171         void fixVerticalScrollBar();
172
173 private:
174         friend class GuiCompleter;
175
176         /// update the passed area.
177         void update(int x, int y, int w, int h);
178         ///
179         void updateScreen();
180
181         /// paint the cursor and store the background
182         virtual void showCursor(int x, int y, int h,
183                 bool l_shape, bool rtl, bool completable);
184
185         /// hide the cursor
186         virtual void removeCursor();
187
188         /// This function should be called to update the buffer readonly status.
189         void setReadOnly(bool);
190
191         /// Update window titles of all users.
192         void updateWindowTitle();
193         ///
194         bool event(QEvent *);
195         ///
196         void contextMenuEvent(QContextMenuEvent *);
197         ///
198         void focusInEvent(QFocusEvent *);
199         ///
200         void focusOutEvent(QFocusEvent *);
201         /// repaint part of the widget
202         void paintEvent(QPaintEvent * ev);
203         /// widget has been resized
204         void resizeEvent(QResizeEvent * ev);
205         /// mouse button press
206         void mousePressEvent(QMouseEvent * ev);
207         /// mouse button release
208         void mouseReleaseEvent(QMouseEvent * ev);
209         /// mouse double click of button
210         void mouseDoubleClickEvent(QMouseEvent * ev);
211         /// mouse motion
212         void mouseMoveEvent(QMouseEvent * ev);
213         /// wheel event
214         void wheelEvent(QWheelEvent * ev);
215         /// key press
216         void keyPressEvent(QKeyEvent * ev);
217         /// IM events
218         void inputMethodEvent(QInputMethodEvent * ev);
219         /// IM query
220         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
221
222         /// The slot connected to SyntheticMouseEvent::timeout.
223         void generateSyntheticMouseEvent();
224         ///
225         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
226         /// hide the visible cursor, if it is visible
227         void hideCursor();
228         /// show the cursor if it is not visible
229         void showCursor();
230         ///
231         void updateScrollbar();
232
233         ///
234         BufferView * buffer_view_;
235         /// Read only Buffer status cache.
236         bool read_only_;
237         ///
238         GuiView * lyx_view_;
239         /// is the cursor currently displayed
240         bool cursor_visible_;
241
242         ///
243         QTimer cursor_timeout_;
244         ///
245         SyntheticMouseEvent synthetic_mouse_event_;
246         ///
247         DoubleClick dc_event_;
248
249         ///
250         CursorWidget * cursor_;
251         ///
252         QPixmap screen_;
253         ///
254         bool need_resize_;
255         ///
256         bool schedule_redraw_;
257         ///
258         int preedit_lines_;
259
260         ///
261         GuiCompleter * completer_;
262
263         /// Special mode in which Esc and Enter (with or without Shift)
264         /// are ignored
265         bool dialog_mode_;
266         /// store the name of the context menu when the mouse is
267         /// pressed. This is used to get the correct context menu 
268         /// when the menu is actually shown (after releasing on Windows)
269         /// and after the DEPM has done its job.
270         docstring context_menu_name_;
271 }; // GuiWorkArea
272
273
274 class EmbeddedWorkArea : public GuiWorkArea
275 {
276         Q_OBJECT
277 public:
278         ///
279         EmbeddedWorkArea(QWidget *);
280         ~EmbeddedWorkArea();
281
282         /// Dummy methods for Designer.
283         void setWidgetResizable(bool) {}
284         void setWidget(QWidget *) {}
285
286         QSize sizeHint () const;
287         ///
288         void disable();
289
290 protected:
291         ///
292         void closeEvent(QCloseEvent * ev);
293         ///
294         void hideEvent(QHideEvent *ev);
295
296 private:
297         /// Embedded Buffer.
298         Buffer * buffer_;
299 }; // EmbeddedWorkArea
300
301
302 /// A tabbed set of GuiWorkAreas.
303 class TabWorkArea : public QTabWidget
304 {
305         Q_OBJECT
306 public:
307         TabWorkArea(QWidget * parent = 0);
308
309         ///
310         void setFullScreen(bool full_screen);
311         void showBar(bool show);
312         void closeAll();
313         bool setCurrentWorkArea(GuiWorkArea *);
314         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
315         bool removeWorkArea(GuiWorkArea *);
316         GuiWorkArea * currentWorkArea();
317         GuiWorkArea * workArea(Buffer & buffer);
318         GuiWorkArea * workArea(int index);
319
320 Q_SIGNALS:
321         ///
322         void currentWorkAreaChanged(GuiWorkArea *);
323         ///
324         void lastWorkAreaRemoved();
325
326 public Q_SLOTS:
327         /// close current buffer, or the one given by \c clicked_tab_
328         void closeCurrentBuffer();
329         /// hide current tab, or the one given by \c clicked_tab_
330         void hideCurrentTab();
331         /// close the tab given by \c index
332         void closeTab(int index);
333         ///
334         void updateTabTexts();
335         
336 private Q_SLOTS:
337         ///
338         void on_currentTabChanged(int index);
339         ///
340         void showContextMenu(const QPoint & pos);
341         ///
342         void moveTab(int fromIndex, int toIndex);
343         ///
344         void mouseDoubleClickEvent(QMouseEvent * event);
345
346 private:
347         ///
348         int clicked_tab_;
349         ///
350         QToolButton * closeBufferButton;
351 }; // TabWorkArea
352
353
354 class DragTabBar : public QTabBar
355 {
356         Q_OBJECT
357 public:
358         ///
359         DragTabBar(QWidget * parent = 0);
360
361 #if QT_VERSION < 0x040300
362         ///
363         int tabAt(QPoint const & position) const;
364 #endif
365
366 protected:
367         ///
368         void mousePressEvent(QMouseEvent * event);
369         ///
370         void mouseMoveEvent(QMouseEvent * event);
371         ///
372         void dragEnterEvent(QDragEnterEvent * event);
373         ///
374         void dropEvent(QDropEvent * event);
375
376 private:
377         ///
378         QPoint dragStartPos_;
379         ///
380         int dragCurrentIndex_;
381
382 Q_SIGNALS:
383         ///
384         void tabMoveRequested(int fromIndex, int toIndex);
385 };
386
387 } // namespace frontend
388 } // namespace lyx
389
390 #endif // WORKAREA_H