]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Cosmetics
[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 Q_SIGNALS:
164         ///
165         void titleChanged(GuiWorkArea *);
166
167 private:
168         /// This function is called when the buffer readonly status change.
169         void setReadOnly(bool);
170
171         /// Update window titles of all users.
172         void updateWindowTitle();
173         ///
174         void focusInEvent(QFocusEvent *);
175         ///
176         void focusOutEvent(QFocusEvent *);
177         /// repaint part of the widget
178         void paintEvent(QPaintEvent * ev);
179         /// widget has been resized
180         void resizeEvent(QResizeEvent * ev);
181         /// mouse button press
182         void mousePressEvent(QMouseEvent * ev);
183         /// mouse button release
184         void mouseReleaseEvent(QMouseEvent * ev);
185         /// mouse double click of button
186         void mouseDoubleClickEvent(QMouseEvent * ev);
187         /// mouse motion
188         void mouseMoveEvent(QMouseEvent * ev);
189         /// wheel event
190         void wheelEvent(QWheelEvent * ev);
191         /// key press
192         void keyPressEvent(QKeyEvent * ev);
193         /// IM events
194         void inputMethodEvent(QInputMethodEvent * ev);
195         /// IM query
196         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
197
198         /// The slot connected to SyntheticMouseEvent::timeout.
199         void generateSyntheticMouseEvent();
200         ///
201         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
202         ///
203         void resizeBufferView();
204         /// hide the visible cursor, if it is visible
205         void hideCursor();
206         /// show the cursor if it is not visible
207         void showCursor();
208         /// toggle the cursor's visibility
209         void toggleCursor();
210         ///
211         void updateScrollbar();
212
213         ///
214         BufferView * buffer_view_;
215         ///
216         GuiView * lyx_view_;
217         /// is the cursor currently displayed
218         bool cursor_visible_;
219
220         ///
221         Timeout cursor_timeout_;
222         ///
223         SyntheticMouseEvent synthetic_mouse_event_;
224         ///
225         DoubleClick dc_event_;
226
227         ///
228         CursorWidget * cursor_;
229         ///
230         void updateScreen();
231         ///
232         QPixmap screen_;
233         ///
234         bool need_resize_;
235         ///
236         bool schedule_redraw_;
237         ///
238         int preedit_lines_;
239 }; // GuiWorkArea
240
241
242 /// A tabbed set of GuiWorkAreas.
243 class TabWorkArea : public QTabWidget
244 {
245         Q_OBJECT
246 public:
247         TabWorkArea(QWidget * parent = 0);
248
249         void showBar(bool show);
250         void closeAll();
251         bool setCurrentWorkArea(GuiWorkArea *);
252         bool removeWorkArea(GuiWorkArea *);
253         GuiWorkArea * currentWorkArea();
254         GuiWorkArea * workArea(Buffer & buffer);
255
256 Q_SIGNALS:
257         ///
258         void currentWorkAreaChanged(GuiWorkArea *);
259
260 public Q_SLOTS:
261         ///
262         void on_currentTabChanged(int index);
263         ///
264         void closeCurrentTab();
265         ///
266         void updateTabText(GuiWorkArea *);
267 }; // TabWorkArea
268
269 } // namespace frontend
270 } // namespace lyx
271
272 #endif // WORKAREA_H