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