]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
- LyX is dead slow, so the least we can do is use anti-alised text
[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 "QLPainter.h"
19
20 #include "funcrequest.h"
21 #include "frontends/Timeout.h"
22
23 #include <QAbstractScrollArea>
24 #include <QMouseEvent>
25 #include <QResizeEvent>
26 #include <QKeyEvent>
27 #include <QTimer>
28 #include <QPixmap>
29
30 #include <queue>
31
32 class QWidget;
33 class QDragEnterEvent;
34 class QDropEvent;
35 class QWheelEvent;
36 class QPaintEvent;
37
38 namespace lyx {
39
40 class Painter;
41
42 namespace frontend {
43
44 class GuiView;
45
46 /// for emulating triple click
47 class double_click {
48 public:
49         int x;
50         int y;
51         Qt::MouseButton state;
52         bool active;
53
54         bool operator==(QMouseEvent const & e) {
55                 return x == e.x() && y == e.y()
56                         && state == e.button();
57         }
58
59         double_click()
60                 : x(0), y(0), state(Qt::NoButton), active(false) {}
61
62         double_click(QMouseEvent * e)
63                 : x(e->x()), y(e->y()),
64                 state(e->button()), active(true) {}
65 };
66
67 /** Qt only emits mouse events when the mouse is being moved, but
68  *  we want to generate 'pseudo' mouse events when the mouse button is
69  *  pressed and the mouse cursor is below the bottom, or above the top
70  *  of the work area. In this way, we'll be able to continue scrolling
71  *  (and selecting) the text.
72  *
73  *  This class stores all the parameters needed to make this happen.
74  */
75 class SyntheticMouseEvent
76 {
77 public:
78         SyntheticMouseEvent();
79
80         FuncRequest cmd;
81         Timeout timeout;
82         bool restart_timeout;
83         int x_old;
84         int y_old;
85         double scrollbar_value_old;
86 };
87
88 /**
89  * Qt-specific implementation of the work area
90  * (buffer view GUI)
91 */
92 class GuiWorkArea: public QAbstractScrollArea, public WorkArea
93 {
94         Q_OBJECT
95
96 public:
97         ///
98         GuiWorkArea(int width, int height, LyXView & lyx_view);
99
100         /// return the width of the content pane
101         virtual int width() const { return viewport()->width(); }
102         /// return the height of the content pane
103         virtual int height() const { return viewport()->height(); }
104         ///
105         virtual void setScrollbarParams(int height, int pos, int line_height);
106
107         ///
108         virtual void dragEnterEvent(QDragEnterEvent * event);
109
110         ///
111         virtual void dropEvent(QDropEvent* event);
112
113         /// return the widget's painter
114         virtual Painter & getPainter() { return (Painter &) painter_; }
115
116         /// return the backing pixmap
117         QPaintDevice * paintDevice() { return &paint_device_; }
118
119         /// update the passed area.
120         void update(int x, int y, int w, int h);
121
122         /// copies specified area of pixmap to screen
123         virtual void expose(int x, int y, int exp_width, int exp_height);
124
125         /// paint the cursor and store the background
126         virtual void showCursor(int x, int y, int h, CursorShape shape);
127
128         /// hide the cursor
129         virtual void removeCursor();
130
131 protected:
132
133         /// repaint part of the widget
134         void paintEvent(QPaintEvent * e);
135         /// widget has been resized
136         void resizeEvent(QResizeEvent * e);
137         /// mouse button press
138         void mousePressEvent(QMouseEvent * e);
139         /// mouse button release
140         void mouseReleaseEvent(QMouseEvent * e);
141         /// mouse double click of button
142         void mouseDoubleClickEvent(QMouseEvent * e);
143         /// mouse motion
144         void mouseMoveEvent(QMouseEvent * e);
145         /// wheel event
146         void wheelEvent(QWheelEvent * e);
147         /// key press
148         void keyPressEvent(QKeyEvent * e);
149         /// IM events
150         void inputMethodEvent(QInputMethodEvent * e);
151
152 public Q_SLOTS:
153
154         /// Timeout event Slot for keyboard bufferring.
155         /// \todo This is not used currently in the code, remove?
156         void keyeventTimeout();
157
158         /// Adjust the LyX buffer view with the position of the scrollbar.
159         /**
160         * The action argument is not used in the the code, it is there
161         * only for the connection to the vertical srollbar signal which
162         * emits an 'int' action.
163         */
164         void adjustViewWithScrollBar(int action = 0);
165
166 private:
167
168         /// Our painter.
169         QLPainter painter_;
170
171         /// The slot connected to SyntheticMouseEvent::timeout.
172         void generateSyntheticMouseEvent();
173
174         ///
175         SyntheticMouseEvent synthetic_mouse_event_;
176
177         /// Our client side painting device.
178         QPixmap paint_device_;
179
180         /// \todo remove
181         QTimer step_timer_;
182
183         /// \todo remove
184         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
185
186         double_click dc_event_;
187
188         ///
189         int cursor_x_;
190         ///
191         int cursor_y_;
192         ///
193         int cursor_w_;
194         ///
195         int cursor_h_;
196         ///
197         QPixmap hcursor_;
198         ///
199         QPixmap vcursor_;
200         ///
201         bool show_hcursor_;
202         ///
203         bool show_vcursor_;
204         ///
205         bool lshape_cursor_;
206         ///
207         QColor cursor_color_;
208         ///
209         CursorShape cursor_shape_;
210 };
211
212 } // namespace frontend
213 } // namespace lyx
214
215 #endif // WORKAREA_H