]> git.lyx.org Git - features.git/blob - src/frontends/qt4/GuiWorkArea.h
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[features.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 unknown
8  * \author John Levon
9  * \author Abdelrazak Younes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef WORKAREA_H
15 #define WORKAREA_H
16
17 #if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
18 #define USE_INPUT_METHODS 1
19 #endif
20
21 #ifdef emit
22 #undef emit
23 #endif
24
25 #include "frontends/LyXView.h"
26 #include "frontends/WorkArea.h"
27
28 #include "QLPainter.h"
29
30 #include "funcrequest.h"
31 #include "frontends/Timeout.h"
32
33 #include <QAbstractScrollArea>
34 #include <QMouseEvent>
35 #include <QWheelEvent>
36 #include <QResizeEvent>
37 #include <QKeyEvent>
38 #include <QPaintEvent>
39 #include <QTimer>
40 #include <QImage>
41 #include <QPixmap>
42
43 #include <queue>
44
45 class Painter;
46
47 class QWidget;
48 class QDragEnterEvent;
49 class QDropEvent;
50 class QMouseEvent;
51
52 namespace lyx {
53 namespace frontend {
54
55 /// for emulating triple click
56 class double_click {
57 public:
58         int x;
59         int y;
60         Qt::ButtonState state;
61         bool active;
62
63         bool operator==(QMouseEvent const & e) {
64                 return x == e.x() && y == e.y()
65                         && state == e.button();
66         }
67
68         double_click()
69                 : x(0), y(0), state(Qt::NoButton), active(false) {}
70
71         double_click(QMouseEvent * e)
72                 : x(e->x()), y(e->y()),
73                 state(e->button()), active(true) {}
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  * Qt-specific implementation of the work area
99  * (buffer view GUI)
100 */
101 class GuiWorkArea: public QAbstractScrollArea, public WorkArea {
102
103         Q_OBJECT
104
105 public:
106
107         GuiWorkArea(LyXView & owner, int w, int h);
108
109         virtual ~GuiWorkArea();
110         /// return the width of the content pane
111         virtual int width() const { return workWidth_; }
112
113         /// return the height of the content pane
114         virtual int height() const { return workHeight_; }
115         ///
116         virtual void setScrollbarParams(int height, int pos, int line_height);
117
118         ///
119         virtual void dragEnterEvent(QDragEnterEvent * event);
120
121         ///
122         virtual void dropEvent(QDropEvent* event);
123
124         /// return the widget's painter
125         virtual Painter & getPainter() { return (Painter &) painter_; }
126
127         /// return the backing pixmap
128         QPaintDevice * paintDevice() { return &paint_device_; }
129
130         /// update the passed area.
131         void update(int x, int y, int w, int h);
132
133         /// return a screen copy of the defined area.
134         QPixmap copyScreen(int x, int y, int w, int h) const;
135
136         /// Draw a pixmap onto the backing pixmap.
137         /**
138         QPixmap is implicitely shared so no need to pass by reference.
139         */
140         void drawScreen(int x, int y, QPixmap pixmap);
141         
142         LyXView & view() { return view_; }
143
144         /// copies specified area of pixmap to screen
145         virtual void expose(int x, int y, int exp_width, int exp_height);
146
147         /// paint the cursor and store the background
148         virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
149
150         /// hide the cursor
151         virtual void removeCursor();
152
153 protected:
154
155         /// repaint part of the widget
156         void paintEvent(QPaintEvent * e);
157         /// widget has been resized
158         void resizeEvent(QResizeEvent * e);
159         /// mouse button press
160         void mousePressEvent(QMouseEvent * e);
161         /// mouse button release
162         void mouseReleaseEvent(QMouseEvent * e);
163         /// mouse double click of button
164         void mouseDoubleClickEvent(QMouseEvent * e);
165         /// mouse motion
166         void mouseMoveEvent(QMouseEvent * e);
167         /// wheel event
168         void wheelEvent(QWheelEvent * e);
169         /// key press
170         void keyPressEvent(QKeyEvent * e);
171
172 #if USE_INPUT_METHODS
173 protected:
174         /// IM events
175         void inputMethodEvent(QInputMethodEvent * e);
176 #endif
177
178 public slots:
179
180         /// Timeout event Slot for keyboard bufferring.
181         /// \todo This is not used currently in the code, remove?
182         void keyeventTimeout();
183
184         /// Adjust the LyX buffer view with the position of the scrollbar.
185         /**
186         * The action argument is not used in the the code, it is there
187         * only for the connection to the vertical srollbar signal which
188         * emits an 'int' action.
189         */
190         void adjustViewWithScrollBar(int action = 0);
191
192 private:
193         ///
194         LyXView & view_;
195         
196         /// Buffer view width.
197         int workWidth_;
198
199         /// Buffer view height.
200         int workHeight_;
201
202         /// Our painter.
203         QLPainter painter_;
204
205         /// The slot connected to SyntheticMouseEvent::timeout.
206         void generateSyntheticMouseEvent();
207
208         ///
209         SyntheticMouseEvent synthetic_mouse_event_;
210
211         /// Our client side painting device.
212         //QImage paint_device_;
213         QPixmap paint_device_;
214
215         /// Our server side painting device.
216         //QPixmap screen_device_;
217
218         /// \todo remove
219         QTimer step_timer_;
220
221         /// \todo remove
222         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
223
224         double_click dc_event_;
225
226         ///
227         int cursor_x_;
228         ///
229         int cursor_y_;
230         ///
231         int cursor_w_;
232         ///
233         int cursor_h_;
234         ///
235         QPixmap hcursor_;
236         ///
237         QPixmap vcursor_;
238         ///
239         bool show_hcursor_;
240         ///
241         bool show_vcursor_;
242         ///
243         bool lshape_cursor_;
244         ///
245         QColor cursor_color_;
246         ///
247         Cursor_Shape cursor_shape_;
248 };
249
250 } // namespace frontend
251 } // namespace lyx
252
253 #endif // WORKAREA_H