]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/QWorkArea.h
This patch removes qscreen.[Ch] and simplify the cursor drawing on screen. Basically...
[lyx.git] / src / frontends / qt4 / QWorkArea.h
1 // -*- C++ -*-
2 /**
3  * \file QWorkArea.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 QWORKAREA_H
15 #define QWORKAREA_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 "WorkArea.h"
26 #include "QLPainter.h"
27 #include "LyXView.h"
28 #include "screen.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 /// for emulating triple click
53 class double_click {
54 public:
55         int x;
56         int y;
57         Qt::ButtonState state;
58         bool active;
59
60         bool operator==(QMouseEvent const & e) {
61                 return x == e.x() && y == e.y()
62                         && state == e.button();
63         }
64
65         double_click()
66                 : x(0), y(0), state(Qt::NoButton), active(false) {}
67
68         double_click(QMouseEvent * e)
69                 : x(e->x()), y(e->y()),
70                 state(e->button()), active(true) {}
71 };
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  * Qt-specific implementation of the work area
97  * (buffer view GUI)
98 */
99 class QWorkArea : public QAbstractScrollArea, public WorkArea, public LyXScreen {
100
101         Q_OBJECT
102
103 public:
104
105         QWorkArea(LyXView & owner, int w, int h);
106
107         virtual ~QWorkArea();
108         /// return the width of the content pane
109         virtual int workWidth() const { return workWidth_; }
110
111         /// return the height of the content pane
112         virtual int workHeight() const { return workHeight_; }
113         ///
114         virtual void setScrollbarParams(int height, int pos, int line_height);
115
116         /// a selection exists
117         virtual void haveSelection(bool) const;
118
119         ///
120         virtual std::string const getClipboard() const;
121
122         ///
123         virtual void putClipboard(std::string const &) const;
124
125         ///
126         virtual void dragEnterEvent(QDragEnterEvent * event);
127
128         ///
129         virtual void dropEvent(QDropEvent* event);
130
131         /// return the widget's painter
132         virtual Painter & getPainter() { return (Painter &) painter_; }
133
134         /// return the backing pixmap
135         QPaintDevice * paintDevice() { return &paint_device_; }
136
137         /// update the passed area.
138         void update(int x, int y, int w, int h);
139
140         /// return a screen copy of the defined area.
141         QPixmap copyScreen(int x, int y, int w, int h) const;
142
143         /// Draw a pixmap onto the backing pixmap.
144         /**
145         QPixmap is implicitely shared so no need to pass by reference.
146         */
147         void drawScreen(int x, int y, QPixmap pixmap);
148         
149         LyXView & view() { return view_; }
150
151         // LyXScreen overloaded methods:
152
153         /// get the work area
154         virtual WorkArea & workarea();
155
156         /// copies specified area of pixmap to screen
157         virtual void expose(int x, int y, int exp_width, int exp_height);
158
159         /// paint the cursor and store the background
160         virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
161
162         /// hide the cursor
163         virtual void removeCursor();
164
165 protected:
166
167         /// repaint part of the widget
168         void paintEvent(QPaintEvent * e);
169         /// widget has been resized
170         void resizeEvent(QResizeEvent * e);
171         /// mouse button press
172         void mousePressEvent(QMouseEvent * e);
173         /// mouse button release
174         void mouseReleaseEvent(QMouseEvent * e);
175         /// mouse double click of button
176         void mouseDoubleClickEvent(QMouseEvent * e);
177         /// mouse motion
178         void mouseMoveEvent(QMouseEvent * e);
179         /// wheel event
180         void wheelEvent(QWheelEvent * e);
181         /// key press
182         void keyPressEvent(QKeyEvent * e);
183
184 #if USE_INPUT_METHODS
185 protected:
186         /// IM events
187         void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
188 #endif
189
190 public slots:
191
192         /// Timeout event Slot for keyboard bufferring.
193         /// \todo This is not used currently in the code, remove?
194         void keyeventTimeout();
195
196         /// Adjust the LyX buffer view with the position of the scrollbar.
197         /**
198         * The action argument is not used in the the code, it is there
199         * only for the connection to the vertical srollbar signal which
200         * emits an 'int' action.
201         */
202         void adjustViewWithScrollBar(int action = 0);
203
204 private:
205         ///
206         LyXView & view_;
207         
208         /// Buffer view width.
209         int workWidth_;
210
211         /// Buffer view height.
212         int workHeight_;
213
214         /// Our painter.
215         QLPainter painter_;
216
217         /// The slot connected to SyntheticMouseEvent::timeout.
218         void generateSyntheticMouseEvent();
219
220         ///
221         SyntheticMouseEvent synthetic_mouse_event_;
222
223         /// Our client side painting device.
224         //QImage paint_device_;
225         QPixmap paint_device_;
226
227         /// Our server side painting device.
228         //QPixmap screen_device_;
229
230         /// \todo remove
231         QTimer step_timer_;
232
233         /// \todo remove
234         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
235
236         double_click dc_event_;
237
238         ///
239         int cursor_x_;
240         ///
241         int cursor_y_;
242         ///
243         int cursor_w_;
244         ///
245         int cursor_h_;
246         ///
247         QPixmap hcursor_;
248         ///
249         QPixmap vcursor_;
250         ///
251         bool show_hcursor_;
252         ///
253         bool show_vcursor_;
254         ///
255         bool lshape_cursor_;
256         ///
257         QColor cursor_color_;
258         ///
259         Cursor_Shape cursor_shape_;
260 };
261
262 #endif // QWORKAREA_H