]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
* completion cursor
[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 #include "frontends/qt4/GuiCompleter.h"
18
19 #include "DocIterator.h"
20 #include "FuncRequest.h"
21 #include "qt_helpers.h"
22 #include "support/docstring.h"
23 #include "support/Timeout.h"
24
25 #include <QAbstractScrollArea>
26 #include <QMouseEvent>
27 #include <QPixmap>
28 #include <QResizeEvent>
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 GuiView;
51 class GuiWorkArea;
52
53 /// for emulating triple click
54 class DoubleClick {
55 public:
56         ///
57         DoubleClick() : state(Qt::NoButton), active(false) {}
58         ///
59         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
60         ///
61         bool operator==(QMouseEvent const & e) { return state == e.button(); }
62         ///
63 public:
64         ///
65         Qt::MouseButton state;
66         ///
67         bool active;
68 };
69
70 /** Qt only emits mouse events when the mouse is being moved, but
71  *  we want to generate 'pseudo' mouse events when the mouse button is
72  *  pressed and the mouse cursor is below the bottom, or above the top
73  *  of the work area. In this way, we'll be able to continue scrolling
74  *  (and selecting) the text.
75  *
76  *  This class stores all the parameters needed to make this happen.
77  */
78 class SyntheticMouseEvent
79 {
80 public:
81         SyntheticMouseEvent();
82
83         FuncRequest cmd;
84         Timeout timeout;
85         bool restart_timeout;
86         int x_old;
87         int y_old;
88         double scrollbar_value_old;
89 };
90
91
92 /**
93  * Implementation of the work area (buffer view GUI)
94 */
95 class CursorWidget;
96
97 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
98 {
99         Q_OBJECT
100
101 public:
102         ///
103         GuiWorkArea(Buffer & buffer, GuiView & lv);
104         ///
105         ~GuiWorkArea();
106
107         ///
108         void setFullScreen(bool full_screen);
109         /// is LyXView in fullscreen mode?
110         bool isFullScreen();
111         ///
112         void scheduleRedraw() { schedule_redraw_ = true; }
113         ///
114         BufferView & bufferView();
115         ///
116         BufferView const & bufferView() const;
117         ///
118         void redraw();
119         ///
120         void stopBlinkingCursor();
121         ///
122         void startBlinkingCursor();
123         /// Process Key pressed event.
124         /// This needs to be public because it is accessed externally by GuiView.
125         void processKeySym(KeySymbol const & key, KeyModifier mod);
126         ///
127         void resizeBufferView();
128
129         ///
130         GuiCompleter & completer() { return completer_; }
131         
132 Q_SIGNALS:
133         ///
134         void titleChanged(GuiWorkArea *);
135
136 private Q_SLOTS:
137         /// Scroll the BufferView.
138         /**
139           * This is a slot for the valueChanged() signal of the vertical scrollbar.
140           * \p value value of the scrollbar.
141         */
142         void scrollTo(int value);
143         /// timer to limit triple clicks
144         void doubleClickTimeout();
145         /// toggle the cursor's visibility
146         void toggleCursor();
147         /// close this work area.
148         /// Slot for Buffer::closing signal.
149         void close();
150
151 private:
152         friend class GuiCompleter;
153
154         /// update the passed area.
155         void update(int x, int y, int w, int h);
156         ///
157         void updateScreen();
158
159         /// paint the cursor and store the background
160         virtual void showCursor(int x, int y, int h,
161                 bool l_shape, bool rtl, bool completable);
162
163         /// hide the cursor
164         virtual void removeCursor();
165
166         /// This function is called when the buffer readonly status change.
167         void setReadOnly(bool);
168
169         /// Update window titles of all users.
170         void updateWindowTitle();
171         ///
172         bool event(QEvent *);
173         ///
174         void contextMenuEvent(QContextMenuEvent *);
175         ///
176         void focusInEvent(QFocusEvent *);
177         ///
178         void focusOutEvent(QFocusEvent *);
179         /// repaint part of the widget
180         void paintEvent(QPaintEvent * ev);
181         /// widget has been resized
182         void resizeEvent(QResizeEvent * ev);
183         /// mouse button press
184         void mousePressEvent(QMouseEvent * ev);
185         /// mouse button release
186         void mouseReleaseEvent(QMouseEvent * ev);
187         /// mouse double click of button
188         void mouseDoubleClickEvent(QMouseEvent * ev);
189         /// mouse motion
190         void mouseMoveEvent(QMouseEvent * ev);
191         /// wheel event
192         void wheelEvent(QWheelEvent * ev);
193         /// key press
194         void keyPressEvent(QKeyEvent * ev);
195         /// IM events
196         void inputMethodEvent(QInputMethodEvent * ev);
197         /// IM query
198         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
199
200         /// The slot connected to SyntheticMouseEvent::timeout.
201         void generateSyntheticMouseEvent();
202         ///
203         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
204         /// hide the visible cursor, if it is visible
205         void hideCursor();
206         /// show the cursor if it is not visible
207         void showCursor();
208         ///
209         void updateScrollbar();
210
211         ///
212         BufferView * buffer_view_;
213         ///
214         GuiView * lyx_view_;
215         /// is the cursor currently displayed
216         bool cursor_visible_;
217
218         ///
219         QTimer cursor_timeout_;
220         ///
221         SyntheticMouseEvent synthetic_mouse_event_;
222         ///
223         DoubleClick dc_event_;
224
225         ///
226         CursorWidget * cursor_;
227         ///
228         QPixmap screen_;
229         ///
230         bool need_resize_;
231         ///
232         bool schedule_redraw_;
233         ///
234         int preedit_lines_;
235
236         ///
237         GuiCompleter completer_;
238 }; // GuiWorkArea
239
240
241 /// A tabbed set of GuiWorkAreas.
242 class TabWorkArea : public QTabWidget
243 {
244         Q_OBJECT
245 public:
246         TabWorkArea(QWidget * parent = 0);
247
248         ///
249         void setFullScreen(bool full_screen);
250         void showBar(bool show);
251         void closeAll();
252         bool setCurrentWorkArea(GuiWorkArea *);
253         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
254         bool removeWorkArea(GuiWorkArea *);
255         GuiWorkArea * currentWorkArea();
256         GuiWorkArea * workArea(Buffer & buffer);
257
258 Q_SIGNALS:
259         ///
260         void currentWorkAreaChanged(GuiWorkArea *);
261
262 public Q_SLOTS:
263         ///
264         void on_currentTabChanged(int index);
265         ///
266         void closeCurrentBuffer();
267         ///
268         void closeCurrentTab();
269         ///
270         void updateTabText(GuiWorkArea *);
271 }; // TabWorkArea
272
273 } // namespace frontend
274 } // namespace lyx
275
276 #endif // WORKAREA_H