]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
GUI API Cleanup step 2: merge of the "younes" branch.
[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 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 #ifdef emit
18 #undef emit
19 #endif
20
21 #include "frontends/WorkArea.h"
22
23 #include "QLPainter.h"
24
25 #include "funcrequest.h"
26 #include "frontends/Timeout.h"
27
28 #include <QAbstractScrollArea>
29 #include <QMouseEvent>
30 #include <QWheelEvent>
31 #include <QResizeEvent>
32 #include <QKeyEvent>
33 #include <QPaintEvent>
34 #include <QTimer>
35 #include <QImage>
36 #include <QPixmap>
37
38 #include <queue>
39
40 class Painter;
41
42 class QWidget;
43 class QDragEnterEvent;
44 class QDropEvent;
45 class QMouseEvent;
46
47 namespace lyx {
48 namespace frontend {
49
50 class GuiView;
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 /** Qt only emits mouse events when the mouse is being moved, but
74  *  we want to generate 'pseudo' mouse events when the mouse button is
75  *  pressed and the mouse cursor is below the bottom, or above the top
76  *  of the work area. In this way, we'll be able to continue scrolling
77  *  (and selecting) the text.
78  *
79  *  This class stores all the parameters needed to make this happen.
80  */
81 class SyntheticMouseEvent
82 {
83 public:
84         SyntheticMouseEvent();
85
86         FuncRequest cmd;
87         Timeout timeout;
88         bool restart_timeout;
89         int x_old;
90         int y_old;
91         double scrollbar_value_old;
92 };
93
94 /**
95  * Qt-specific implementation of the work area
96  * (buffer view GUI)
97 */
98 class GuiWorkArea: public QAbstractScrollArea, public WorkArea {
99
100         Q_OBJECT
101
102 public:
103
104         GuiWorkArea(int width, int height, QWidget * parent, BufferView * buffer_view = 0);
105
106         virtual ~GuiWorkArea();
107         /// return the width of the content pane
108         virtual int width() const { return workWidth_; }
109
110         /// return the height of the content pane
111         virtual int height() const { return workHeight_; }
112         ///
113         virtual void setScrollbarParams(int height, int pos, int line_height);
114
115         ///
116         virtual void dragEnterEvent(QDragEnterEvent * event);
117
118         ///
119         virtual void dropEvent(QDropEvent* event);
120
121         /// return the widget's painter
122         virtual Painter & getPainter() { return (Painter &) painter_; }
123
124         /// return the backing pixmap
125         QPaintDevice * paintDevice() { return &paint_device_; }
126
127         /// update the passed area.
128         void update(int x, int y, int w, int h);
129
130         /// return a screen copy of the defined area.
131         QPixmap copyScreen(int x, int y, int w, int h) const;
132
133         /// Draw a pixmap onto the backing pixmap.
134         /**
135         QPixmap is implicitely shared so no need to pass by reference.
136         */
137         void drawScreen(int x, int y, QPixmap pixmap);
138
139         /// copies specified area of pixmap to screen
140         virtual void expose(int x, int y, int exp_width, int exp_height);
141
142         /// paint the cursor and store the background
143         virtual void showCursor(int x, int y, int h, CursorShape shape);
144
145         /// hide the cursor
146         virtual void removeCursor();
147
148 protected:
149
150         /// repaint part of the widget
151         void paintEvent(QPaintEvent * e);
152         /// widget has been resized
153         void resizeEvent(QResizeEvent * e);
154         /// mouse button press
155         void mousePressEvent(QMouseEvent * e);
156         /// mouse button release
157         void mouseReleaseEvent(QMouseEvent * e);
158         /// mouse double click of button
159         void mouseDoubleClickEvent(QMouseEvent * e);
160         /// mouse motion
161         void mouseMoveEvent(QMouseEvent * e);
162         /// wheel event
163         void wheelEvent(QWheelEvent * e);
164         /// key press
165         void keyPressEvent(QKeyEvent * e);
166
167 protected:
168         /// IM events
169         void inputMethodEvent(QInputMethodEvent * e);
170
171 public slots:
172
173         /// Timeout event Slot for keyboard bufferring.
174         /// \todo This is not used currently in the code, remove?
175         void keyeventTimeout();
176
177         /// Adjust the LyX buffer view with the position of the scrollbar.
178         /**
179         * The action argument is not used in the the code, it is there
180         * only for the connection to the vertical srollbar signal which
181         * emits an 'int' action.
182         */
183         void adjustViewWithScrollBar(int action = 0);
184
185 private:
186         /// Buffer view width.
187         int workWidth_;
188
189         /// Buffer view height.
190         int workHeight_;
191
192         /// Our painter.
193         QLPainter painter_;
194
195         /// The slot connected to SyntheticMouseEvent::timeout.
196         void generateSyntheticMouseEvent();
197
198         ///
199         SyntheticMouseEvent synthetic_mouse_event_;
200
201         /// Our client side painting device.
202         //QImage paint_device_;
203         QPixmap paint_device_;
204
205         /// Our server side painting device.
206         //QPixmap screen_device_;
207
208         /// \todo remove
209         QTimer step_timer_;
210
211         /// \todo remove
212         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
213
214         double_click dc_event_;
215
216         ///
217         int cursor_x_;
218         ///
219         int cursor_y_;
220         ///
221         int cursor_w_;
222         ///
223         int cursor_h_;
224         ///
225         QPixmap hcursor_;
226         ///
227         QPixmap vcursor_;
228         ///
229         bool show_hcursor_;
230         ///
231         bool show_vcursor_;
232         ///
233         bool lshape_cursor_;
234         ///
235         QColor cursor_color_;
236         ///
237         CursorShape cursor_shape_;
238 };
239
240 } // namespace frontend
241 } // namespace lyx
242
243 #endif // WORKAREA_H