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