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