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