]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
004d26042044c56de5cc96ca98c6db5741280569
[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 "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 GuiView;
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, GuiView & lv);
110         ///
111         ~GuiWorkArea();
112
113         /**
114          * Update the scrollbar.
115          * @param height the total document height in pixels
116          * @param pos the current position in the document, in pixels
117          * @param line_height the line-scroll amount, in pixels
118          */
119         void setScrollbarParams(int height, int pos, int line_height);
120         ///
121         void scheduleRedraw() { schedule_redraw_ = true; }
122
123         /// update the passed area.
124         void update(int x, int y, int w, int h);
125
126         /// copies specified area of pixmap to screen
127         virtual void expose(int x, int y, int exp_width, int exp_height);
128
129         /// paint the cursor and store the background
130         virtual void showCursor(int x, int y, int h, CursorShape shape);
131
132         /// hide the cursor
133         virtual void removeCursor();
134         ///
135         BufferView & bufferView();
136         ///
137         BufferView const & bufferView() const;
138         ///
139         void redraw();
140         ///
141         void stopBlinkingCursor();
142         ///
143         void startBlinkingCursor();
144         /// Process Key pressed event.
145         /// This needs to be public because it is accessed externally by GuiView.
146         void processKeySym(KeySymbol const & key, KeyModifier mod);
147
148 public Q_SLOTS:
149         /// Adjust the LyX buffer view with the position of the scrollbar.
150         /**
151         * The action argument is not used in the the code, it is there
152         * only for the connection to the vertical srollbar signal which
153         * emits an 'int' action.
154         */
155         void adjustViewWithScrollBar(int action = 0);
156         /// timer to limit triple clicks
157         void doubleClickTimeout();
158
159         /// close this work area.
160         /// Slot for Buffer::closing signal.
161         void close();
162         ////
163         void setWindowTitle(docstring const & t, docstring const & it);
164
165 Q_SIGNALS:
166         ///
167         void titleChanged(GuiWorkArea *);
168
169 private:
170         /// This function is called when the buffer readonly status change.
171         void setReadOnly(bool);
172
173         /// Update window titles of all users.
174         void updateWindowTitle();
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         ///
205         void resizeBufferView();
206         /// hide the visible cursor, if it is visible
207         void hideCursor();
208         /// show the cursor if it is not visible
209         void showCursor();
210         /// toggle the cursor's visibility
211         void toggleCursor();
212         ///
213         void updateScrollbar();
214
215         ///
216         BufferView * buffer_view_;
217         ///
218         GuiView * lyx_view_;
219         /// is the cursor currently displayed
220         bool cursor_visible_;
221
222         ///
223         Timeout cursor_timeout_;
224         ///
225         SyntheticMouseEvent synthetic_mouse_event_;
226         ///
227         DoubleClick dc_event_;
228
229         ///
230         CursorWidget * cursor_;
231         ///
232         void updateScreen();
233         ///
234         QPixmap screen_;
235         ///
236         bool need_resize_;
237         ///
238         bool schedule_redraw_;
239         ///
240         int preedit_lines_;
241 }; // GuiWorkArea
242
243
244 /// A tabbed set of GuiWorkAreas.
245 class TabWorkArea : public QTabWidget
246 {
247         Q_OBJECT
248 public:
249         TabWorkArea(QWidget * parent = 0);
250
251         void showBar(bool show);
252         void closeAll();
253         bool setCurrentWorkArea(GuiWorkArea *);
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 closeCurrentTab();
267         ///
268         void updateTabText(GuiWorkArea *);
269 }; // TabWorkArea
270
271 } // namespace frontend
272 } // namespace lyx
273
274 #endif // WORKAREA_H