]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Improve conversion/reversion of index strings
[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         void scheduleRedraw() { schedule_redraw_ = true; }
115         ///
116         BufferView & bufferView();
117         ///
118         BufferView const & bufferView() const;
119         ///
120         void redraw();
121         ///
122         void stopBlinkingCursor();
123         ///
124         void startBlinkingCursor();
125         /// Process Key pressed event.
126         /// This needs to be public because it is accessed externally by GuiView.
127         void processKeySym(KeySymbol const & key, KeyModifier mod);
128         ///
129         void resizeBufferView();
130
131 Q_SIGNALS:
132         ///
133         void titleChanged(GuiWorkArea *);
134
135 private Q_SLOTS:
136         /// Adjust the LyX buffer view with the position of the scrollbar.
137         /**
138         * The action argument is not used in the the code, it is there
139         * only for the connection to the vertical srollbar signal which
140         * emits an 'int' action.
141         */
142         void adjustViewWithScrollBar(int action = 0);
143         /// timer to limit triple clicks
144         void doubleClickTimeout();
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         void focusInEvent(QFocusEvent *);
169         ///
170         void focusOutEvent(QFocusEvent *);
171         /// repaint part of the widget
172         void paintEvent(QPaintEvent * ev);
173         /// widget has been resized
174         void resizeEvent(QResizeEvent * ev);
175         /// mouse button press
176         void mousePressEvent(QMouseEvent * ev);
177         /// mouse button release
178         void mouseReleaseEvent(QMouseEvent * ev);
179         /// mouse double click of button
180         void mouseDoubleClickEvent(QMouseEvent * ev);
181         /// mouse motion
182         void mouseMoveEvent(QMouseEvent * ev);
183         /// wheel event
184         void wheelEvent(QWheelEvent * ev);
185         /// key press
186         void keyPressEvent(QKeyEvent * ev);
187         /// IM events
188         void inputMethodEvent(QInputMethodEvent * ev);
189         /// IM query
190         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
191
192         /// The slot connected to SyntheticMouseEvent::timeout.
193         void generateSyntheticMouseEvent();
194         ///
195         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
196         /// hide the visible cursor, if it is visible
197         void hideCursor();
198         /// show the cursor if it is not visible
199         void showCursor();
200         /// toggle the cursor's visibility
201         void toggleCursor();
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         Timeout 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