]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
4a36dd166dcf6026ea71dd38e046dd723acf3465
[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 <QResizeEvent>
28 #include <QTabBar>
29 #include <QTabWidget>
30 #include <QTimer>
31
32 class QContextMenuEvent;
33 class QDragEnterEvent;
34 class QDropEvent;
35 class QKeyEvent;
36 class QWheelEvent;
37 class QPaintEvent;
38 class QWidget;
39
40 #ifdef CursorShape
41 #undef CursorShape
42 #endif
43
44 namespace lyx {
45
46 class Buffer;
47
48 namespace frontend {
49
50 class GuiCompleter;
51 class GuiView;
52 class GuiWorkArea;
53
54 /// for emulating triple click
55 class DoubleClick {
56 public:
57         ///
58         DoubleClick() : state(Qt::NoButton), active(false) {}
59         ///
60         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
61         ///
62         bool operator==(QMouseEvent const & e) { return state == e.button(); }
63         ///
64 public:
65         ///
66         Qt::MouseButton state;
67         ///
68         bool active;
69 };
70
71 /** Qt only emits mouse events when the mouse is being moved, but
72  *  we want to generate 'pseudo' mouse events when the mouse button is
73  *  pressed and the mouse cursor is below the bottom, or above the top
74  *  of the work area. In this way, we'll be able to continue scrolling
75  *  (and selecting) the text.
76  *
77  *  This class stores all the parameters needed to make this happen.
78  */
79 class SyntheticMouseEvent
80 {
81 public:
82         SyntheticMouseEvent();
83
84         FuncRequest cmd;
85         Timeout timeout;
86         bool restart_timeout;
87         int x_old;
88         int y_old;
89         double scrollbar_value_old;
90 };
91
92
93 /**
94  * Implementation of the work area (buffer view GUI)
95 */
96 class CursorWidget;
97
98 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
99 {
100         Q_OBJECT
101
102 public:
103         ///
104         GuiWorkArea(QWidget *);
105         ///
106         GuiWorkArea(Buffer & buffer, GuiView & gv);
107         ///
108         ~GuiWorkArea();
109
110         ///
111         void setBuffer(Buffer &);
112         ///
113         void setGuiView(GuiView &);
114         /// Dummy methods for Designer.
115         void setWidgetResizable(bool) {}
116         void setWidget(QWidget *) {}
117         ///
118         void setFullScreen(bool full_screen);
119         /// is LyXView in fullscreen mode?
120         bool isFullScreen();
121         ///
122         void scheduleRedraw() { schedule_redraw_ = true; }
123         ///
124         BufferView & bufferView();
125         ///
126         BufferView const & bufferView() const;
127         ///
128         void redraw();
129         ///
130         void stopBlinkingCursor();
131         ///
132         void startBlinkingCursor();
133         /// Process Key pressed event.
134         /// This needs to be public because it is accessed externally by GuiView.
135         void processKeySym(KeySymbol const & key, KeyModifier mod);
136         ///
137         void resizeBufferView();
138
139         bool inDialogMode() { return dialog_mode_; }
140         void setDialogMode(bool mode) { dialog_mode_ = mode; }
141
142         ///
143         GuiCompleter & completer() { return *completer_; }
144
145
146         /// Return the GuiView this workArea belongs to
147         GuiView const & view() const { return *lyx_view_; }
148         GuiView & view() { return *lyx_view_; }
149
150 Q_SIGNALS:
151         ///
152         void titleChanged(GuiWorkArea *);
153
154 private Q_SLOTS:
155         /// Scroll the BufferView.
156         /**
157           * This is a slot for the valueChanged() signal of the vertical scrollbar.
158           * \p value value of the scrollbar.
159         */
160         void scrollTo(int value);
161         /// timer to limit triple clicks
162         void doubleClickTimeout();
163         /// toggle the cursor's visibility
164         void toggleCursor();
165         /// close this work area.
166         /// Slot for Buffer::closing signal.
167         void close();
168         /// Slot to restore proper scrollbar behaviour.
169         void fixVerticalScrollBar();
170
171 private:
172         friend class GuiCompleter;
173         ///
174         void init();
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 is called when the buffer readonly status change.
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         ///
236         GuiView * lyx_view_;
237         /// is the cursor currently displayed
238         bool cursor_visible_;
239
240         ///
241         QTimer cursor_timeout_;
242         ///
243         SyntheticMouseEvent synthetic_mouse_event_;
244         ///
245         DoubleClick dc_event_;
246
247         ///
248         CursorWidget * cursor_;
249         ///
250         QPixmap screen_;
251         ///
252         bool need_resize_;
253         ///
254         bool schedule_redraw_;
255         ///
256         int preedit_lines_;
257
258         ///
259         GuiCompleter * completer_;
260
261         /// Special mode in which Esc and Enter (with or without Shift)
262         /// are ignored
263         bool dialog_mode_;
264 }; // GuiWorkArea
265
266
267 /// A tabbed set of GuiWorkAreas.
268 class TabWorkArea : public QTabWidget
269 {
270         Q_OBJECT
271 public:
272         TabWorkArea(QWidget * parent = 0);
273
274         ///
275         void setFullScreen(bool full_screen);
276         void showBar(bool show);
277         void closeAll();
278         bool setCurrentWorkArea(GuiWorkArea *);
279         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
280         bool removeWorkArea(GuiWorkArea *);
281         GuiWorkArea * currentWorkArea();
282         GuiWorkArea * workArea(Buffer & buffer);
283
284 Q_SIGNALS:
285         ///
286         void currentWorkAreaChanged(GuiWorkArea *);
287         ///
288         void lastWorkAreaRemoved();
289
290 public Q_SLOTS:
291         /// close current buffer, or the one given by \c clicked_tab_
292         void closeCurrentBuffer();
293         /// close current tab, or the one given by \c clicked_tab_
294         void closeCurrentTab();
295         ///
296         void updateTabTexts();
297         
298 private Q_SLOTS:
299         ///
300         void on_currentTabChanged(int index);
301         ///
302         void showContextMenu(const QPoint & pos);
303         ///
304         void moveTab(int fromIndex, int toIndex);
305
306 private:
307         int clicked_tab_;
308 }; // TabWorkArea
309
310
311 class DragTabBar : public QTabBar
312 {
313         Q_OBJECT
314 public:
315         ///
316         DragTabBar(QWidget * parent = 0);
317
318 #if QT_VERSION < 0x040300
319         ///
320         int tabAt(QPoint const & position) const;
321 #endif
322
323 protected:
324         ///
325         void mousePressEvent(QMouseEvent * event);
326         ///
327         void mouseMoveEvent(QMouseEvent * event);
328         ///
329         void dragEnterEvent(QDragEnterEvent * event);
330         ///
331         void dropEvent(QDropEvent * event);
332
333 private:
334         ///
335         QPoint dragStartPos_;
336         ///
337         int dragCurrentIndex_;
338
339 Q_SIGNALS:
340         ///
341         void tabMoveRequested(int fromIndex, int toIndex);
342 };
343
344 } // namespace frontend
345 } // namespace lyx
346
347 #endif // WORKAREA_H