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