]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiWorkArea.h
make WorkArea a pure interface, move all implementation to GuiWorkArea
[features.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 "FuncRequest.h"
19 #include "support/Timeout.h"
20
21 #include <QAbstractScrollArea>
22 #include <QKeyEvent>
23 #include <QMouseEvent>
24 #include <QPixmap>
25 #include <QResizeEvent>
26 #include <QTabWidget>
27 #include <QTimer>
28
29 #include <queue>
30
31 class QWidget;
32 class QDragEnterEvent;
33 class QDropEvent;
34 class QWheelEvent;
35 class QPaintEvent;
36
37 #ifdef CursorShape
38 #undef CursorShape
39 #endif
40
41 namespace lyx {
42
43 class Buffer;
44
45 namespace frontend {
46
47 class LyXView;
48
49 /// types of cursor in work area
50 enum CursorShape {
51         /// normal I-beam
52         BAR_SHAPE,
53         /// L-shape for locked insets of a different language
54         L_SHAPE,
55         /// reverse L-shape for RTL text
56         REVERSED_L_SHAPE
57 };
58
59 /// for emulating triple click
60 class DoubleClick {
61 public:
62         ///
63         DoubleClick() : state(Qt::NoButton), active(false) {}
64         ///
65         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
66         ///
67         bool operator==(QMouseEvent const & e) { return state == e.button(); }
68         ///
69 public:
70         ///
71         Qt::MouseButton state;
72         ///
73         bool active;
74 };
75
76 /** Qt only emits mouse events when the mouse is being moved, but
77  *  we want to generate 'pseudo' mouse events when the mouse button is
78  *  pressed and the mouse cursor is below the bottom, or above the top
79  *  of the work area. In this way, we'll be able to continue scrolling
80  *  (and selecting) the text.
81  *
82  *  This class stores all the parameters needed to make this happen.
83  */
84 class SyntheticMouseEvent
85 {
86 public:
87         SyntheticMouseEvent();
88
89         FuncRequest cmd;
90         Timeout timeout;
91         bool restart_timeout;
92         int x_old;
93         int y_old;
94         double scrollbar_value_old;
95 };
96
97
98 /**
99  * Implementation of the work area (buffer view GUI)
100 */
101 class CursorWidget;
102
103 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
104 {
105         Q_OBJECT
106
107 public:
108         ///
109         GuiWorkArea(Buffer & buffer, LyXView & lv);
110         ///
111         ~GuiWorkArea();
112
113         ///
114         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
115         bool isVisible() const { return QAbstractScrollArea::isVisible(); }
116
117         /// return the width of the content pane
118         virtual int width() const { return viewport()->width(); }
119         /// return the height of the content pane
120         virtual int height() const { return viewport()->height(); }
121         ///
122         virtual void setScrollbarParams(int height, int pos, int line_height);
123         ///
124         virtual void scheduleRedraw() { schedule_redraw_ = true; }
125
126         /// update the passed area.
127         void update(int x, int y, int w, int h);
128
129         /// copies specified area of pixmap to screen
130         virtual void expose(int x, int y, int exp_width, int exp_height);
131
132         /// paint the cursor and store the background
133         virtual void showCursor(int x, int y, int h, CursorShape shape);
134
135         /// hide the cursor
136         virtual void removeCursor();
137         ///
138         void setLyXView(LyXView & lv) { lyx_view_ = &lv; }
139         ///
140         BufferView & bufferView();
141         ///
142         BufferView const & bufferView() const;
143         ///
144         void redraw();
145         ///
146         void stopBlinkingCursor();
147         ///
148         void startBlinkingCursor();
149         ///
150         void processKeySym(KeySymbol const & key, KeyModifier mod);
151
152 public Q_SLOTS:
153         /// Adjust the LyX buffer view with the position of the scrollbar.
154         /**
155         * The action argument is not used in the the code, it is there
156         * only for the connection to the vertical srollbar signal which
157         * emits an 'int' action.
158         */
159         void adjustViewWithScrollBar(int action = 0);
160         /// timer to limit triple clicks
161         void doubleClickTimeout();
162
163         /// close this work area.
164         /// Slot for Buffer::closing signal.
165         void close();
166         ////
167         void setWindowTitle(docstring const & t, docstring const & it);
168
169 Q_SIGNALS:
170         ///
171         void titleChanged(GuiWorkArea *);
172
173 private:
174         /// This function is called when the buffer readonly status change.
175         void setReadOnly(bool);
176
177         /// Update window titles of all users.
178         void updateWindowTitle();
179         ///
180         void focusInEvent(QFocusEvent *);
181         ///
182         void focusOutEvent(QFocusEvent *);
183         /// repaint part of the widget
184         void paintEvent(QPaintEvent * ev);
185         /// widget has been resized
186         void resizeEvent(QResizeEvent * ev);
187         /// mouse button press
188         void mousePressEvent(QMouseEvent * ev);
189         /// mouse button release
190         void mouseReleaseEvent(QMouseEvent * ev);
191         /// mouse double click of button
192         void mouseDoubleClickEvent(QMouseEvent * ev);
193         /// mouse motion
194         void mouseMoveEvent(QMouseEvent * ev);
195         /// wheel event
196         void wheelEvent(QWheelEvent * ev);
197         /// key press
198         void keyPressEvent(QKeyEvent * ev);
199         /// IM events
200         void inputMethodEvent(QInputMethodEvent * ev);
201         /// IM query
202         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
203
204         /// The slot connected to SyntheticMouseEvent::timeout.
205         void generateSyntheticMouseEvent();
206         ///
207         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
208         ///
209         void resizeBufferView();
210         /// hide the visible cursor, if it is visible
211         void hideCursor();
212         /// show the cursor if it is not visible
213         void showCursor();
214         /// toggle the cursor's visibility
215         void toggleCursor();
216         ///
217         void updateScrollbar();
218
219         ///
220         BufferView * buffer_view_;
221         ///
222         LyXView * lyx_view_;
223         /// is the cursor currently displayed
224         bool cursor_visible_;
225
226         ///
227         Timeout cursor_timeout_;
228         ///
229         SyntheticMouseEvent synthetic_mouse_event_;
230         ///
231         DoubleClick dc_event_;
232
233         ///
234         CursorWidget * cursor_;
235         ///
236         void updateScreen();
237         ///
238         QPixmap screen_;
239         ///
240         bool need_resize_;
241         ///
242         bool schedule_redraw_;
243         ///
244         int preedit_lines_;
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         void showBar(bool show);
256         void closeAll();
257         bool setCurrentWorkArea(GuiWorkArea *);
258         bool removeWorkArea(GuiWorkArea *);
259         GuiWorkArea * currentWorkArea();
260         GuiWorkArea * workArea(Buffer & buffer);
261
262 Q_SIGNALS:
263         ///
264         void currentWorkAreaChanged(GuiWorkArea *);
265
266 public Q_SLOTS:
267         ///
268         void on_currentTabChanged(int index);
269         ///
270         void closeCurrentTab();
271         ///
272         void updateTabText(GuiWorkArea *);
273 }; // TabWorkArea
274
275 } // namespace frontend
276 } // namespace lyx
277
278 #endif // WORKAREA_H