]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Remove TextClassPtr without losing the type safety it provided.
[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         /// 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         ///
140         GuiCompleter & completer() { return completer_; }
141         
142 Q_SIGNALS:
143         ///
144         void titleChanged(GuiWorkArea *);
145
146 private Q_SLOTS:
147         /// Scroll the BufferView.
148         /**
149           * This is a slot for the valueChanged() signal of the vertical scrollbar.
150           * \p value value of the scrollbar.
151         */
152         void scrollTo(int value);
153         /// timer to limit triple clicks
154         void doubleClickTimeout();
155         /// toggle the cursor's visibility
156         void toggleCursor();
157         /// close this work area.
158         /// Slot for Buffer::closing signal.
159         void close();
160
161 private:
162         friend class GuiCompleter;
163
164         /// update the passed area.
165         void update(int x, int y, int w, int h);
166         ///
167         void updateScreen();
168
169         /// paint the cursor and store the background
170         virtual void showCursor(int x, int y, int h, CursorShape shape);
171
172         /// hide the cursor
173         virtual void removeCursor();
174
175         /// This function is called when the buffer readonly status change.
176         void setReadOnly(bool);
177
178         /// Update window titles of all users.
179         void updateWindowTitle();
180         ///
181         bool event(QEvent *);
182         ///
183         void contextMenuEvent(QContextMenuEvent *);
184         ///
185         void focusInEvent(QFocusEvent *);
186         ///
187         void focusOutEvent(QFocusEvent *);
188         /// repaint part of the widget
189         void paintEvent(QPaintEvent * ev);
190         /// widget has been resized
191         void resizeEvent(QResizeEvent * ev);
192         /// mouse button press
193         void mousePressEvent(QMouseEvent * ev);
194         /// mouse button release
195         void mouseReleaseEvent(QMouseEvent * ev);
196         /// mouse double click of button
197         void mouseDoubleClickEvent(QMouseEvent * ev);
198         /// mouse motion
199         void mouseMoveEvent(QMouseEvent * ev);
200         /// wheel event
201         void wheelEvent(QWheelEvent * ev);
202         /// key press
203         void keyPressEvent(QKeyEvent * ev);
204         /// IM events
205         void inputMethodEvent(QInputMethodEvent * ev);
206         /// IM query
207         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
208
209         /// The slot connected to SyntheticMouseEvent::timeout.
210         void generateSyntheticMouseEvent();
211         ///
212         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
213         /// hide the visible cursor, if it is visible
214         void hideCursor();
215         /// show the cursor if it is not visible
216         void showCursor();
217         ///
218         void updateScrollbar();
219
220         ///
221         BufferView * buffer_view_;
222         ///
223         GuiView * lyx_view_;
224         /// is the cursor currently displayed
225         bool cursor_visible_;
226
227         ///
228         QTimer cursor_timeout_;
229         ///
230         SyntheticMouseEvent synthetic_mouse_event_;
231         ///
232         DoubleClick dc_event_;
233
234         ///
235         CursorWidget * cursor_;
236         ///
237         QPixmap screen_;
238         ///
239         bool need_resize_;
240         ///
241         bool schedule_redraw_;
242         ///
243         int preedit_lines_;
244
245         ///
246         GuiCompleter completer_;
247 }; // GuiWorkArea
248
249
250 /// A tabbed set of GuiWorkAreas.
251 class TabWorkArea : public QTabWidget
252 {
253         Q_OBJECT
254 public:
255         TabWorkArea(QWidget * parent = 0);
256
257         ///
258         void setFullScreen(bool full_screen);
259         void showBar(bool show);
260         void closeAll();
261         bool setCurrentWorkArea(GuiWorkArea *);
262         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
263         bool removeWorkArea(GuiWorkArea *);
264         GuiWorkArea * currentWorkArea();
265         GuiWorkArea * workArea(Buffer & buffer);
266
267 Q_SIGNALS:
268         ///
269         void currentWorkAreaChanged(GuiWorkArea *);
270
271 public Q_SLOTS:
272         ///
273         void on_currentTabChanged(int index);
274         ///
275         void closeCurrentBuffer();
276         ///
277         void closeCurrentTab();
278         ///
279         void updateTabText(GuiWorkArea *);
280 }; // TabWorkArea
281
282 } // namespace frontend
283 } // namespace lyx
284
285 #endif // WORKAREA_H