]> 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 "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         /// return a screen copy of the defined area.
123         QPixmap copyScreen(int x, int y, int w, int h) const;
124
125         /// Draw a pixmap onto the backing pixmap.
126         void drawScreen(int x, int y, const QPixmap & pixmap);
127
128         /// copies specified area of pixmap to screen
129         virtual void expose(int x, int y, int exp_width, int exp_height);
130
131         /// paint the cursor and store the background
132         virtual void showCursor(int x, int y, int h, CursorShape shape);
133
134         /// hide the cursor
135         virtual void removeCursor();
136
137 protected:
138
139         /// repaint part of the widget
140         void paintEvent(QPaintEvent * e);
141         /// widget has been resized
142         void resizeEvent(QResizeEvent * e);
143         /// mouse button press
144         void mousePressEvent(QMouseEvent * e);
145         /// mouse button release
146         void mouseReleaseEvent(QMouseEvent * e);
147         /// mouse double click of button
148         void mouseDoubleClickEvent(QMouseEvent * e);
149         /// mouse motion
150         void mouseMoveEvent(QMouseEvent * e);
151         /// wheel event
152         void wheelEvent(QWheelEvent * e);
153         /// key press
154         void keyPressEvent(QKeyEvent * e);
155         /// IM events
156         void inputMethodEvent(QInputMethodEvent * e);
157
158 public Q_SLOTS:
159
160         /// Timeout event Slot for keyboard bufferring.
161         /// \todo This is not used currently in the code, remove?
162         void keyeventTimeout();
163
164         /// Adjust the LyX buffer view with the position of the scrollbar.
165         /**
166         * The action argument is not used in the the code, it is there
167         * only for the connection to the vertical srollbar signal which
168         * emits an 'int' action.
169         */
170         void adjustViewWithScrollBar(int action = 0);
171
172 private:
173
174         /// Our painter.
175         QLPainter painter_;
176
177         /// The slot connected to SyntheticMouseEvent::timeout.
178         void generateSyntheticMouseEvent();
179
180         ///
181         SyntheticMouseEvent synthetic_mouse_event_;
182
183         /// Our client side painting device.
184         QPixmap paint_device_;
185
186         /// \todo remove
187         QTimer step_timer_;
188
189         /// \todo remove
190         std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
191
192         double_click dc_event_;
193
194         ///
195         int cursor_x_;
196         ///
197         int cursor_y_;
198         ///
199         int cursor_w_;
200         ///
201         int cursor_h_;
202         ///
203         QPixmap hcursor_;
204         ///
205         QPixmap vcursor_;
206         ///
207         bool show_hcursor_;
208         ///
209         bool show_vcursor_;
210         ///
211         bool lshape_cursor_;
212         ///
213         QColor cursor_color_;
214         ///
215         CursorShape cursor_shape_;
216 };
217
218 } // namespace frontend
219 } // namespace lyx
220
221 #endif // WORKAREA_H