4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * \author Abdelrazak Younes
11 * Full author contact details are available in file CREDITS.
21 #include "frontends/WorkArea.h"
23 #include "QLPainter.h"
25 #include "funcrequest.h"
26 #include "frontends/Timeout.h"
28 #include <QAbstractScrollArea>
29 #include <QMouseEvent>
30 #include <QWheelEvent>
31 #include <QResizeEvent>
33 #include <QPaintEvent>
43 class QDragEnterEvent;
52 /// for emulating triple click
57 Qt::ButtonState state;
60 bool operator==(QMouseEvent const & e) {
61 return x == e.x() && y == e.y()
62 && state == e.button();
66 : x(0), y(0), state(Qt::NoButton), active(false) {}
68 double_click(QMouseEvent * e)
69 : x(e->x()), y(e->y()),
70 state(e->button()), active(true) {}
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.
79 * This class stores all the parameters needed to make this happen.
81 class SyntheticMouseEvent
84 SyntheticMouseEvent();
91 double scrollbar_value_old;
95 * Qt-specific implementation of the work area
98 class GuiWorkArea: public QAbstractScrollArea, public WorkArea {
104 GuiWorkArea(int width, int height, QWidget * parent, BufferView * buffer_view = 0);
106 virtual ~GuiWorkArea();
107 /// return the width of the content pane
108 virtual int width() const { return workWidth_; }
110 /// return the height of the content pane
111 virtual int height() const { return workHeight_; }
113 virtual void setScrollbarParams(int height, int pos, int line_height);
116 virtual void dragEnterEvent(QDragEnterEvent * event);
119 virtual void dropEvent(QDropEvent* event);
121 /// return the widget's painter
122 virtual Painter & getPainter() { return (Painter &) painter_; }
124 /// return the backing pixmap
125 QPaintDevice * paintDevice() { return &paint_device_; }
127 /// update the passed area.
128 void update(int x, int y, int w, int h);
130 /// return a screen copy of the defined area.
131 QPixmap copyScreen(int x, int y, int w, int h) const;
133 /// Draw a pixmap onto the backing pixmap.
135 QPixmap is implicitely shared so no need to pass by reference.
137 void drawScreen(int x, int y, QPixmap pixmap);
139 /// copies specified area of pixmap to screen
140 virtual void expose(int x, int y, int exp_width, int exp_height);
142 /// paint the cursor and store the background
143 virtual void showCursor(int x, int y, int h, CursorShape shape);
146 virtual void removeCursor();
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);
161 void mouseMoveEvent(QMouseEvent * e);
163 void wheelEvent(QWheelEvent * e);
165 void keyPressEvent(QKeyEvent * e);
169 void inputMethodEvent(QInputMethodEvent * e);
173 /// Timeout event Slot for keyboard bufferring.
174 /// \todo This is not used currently in the code, remove?
175 void keyeventTimeout();
177 /// Adjust the LyX buffer view with the position of the scrollbar.
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.
183 void adjustViewWithScrollBar(int action = 0);
186 /// Buffer view width.
189 /// Buffer view height.
195 /// The slot connected to SyntheticMouseEvent::timeout.
196 void generateSyntheticMouseEvent();
199 SyntheticMouseEvent synthetic_mouse_event_;
201 /// Our client side painting device.
202 //QImage paint_device_;
203 QPixmap paint_device_;
205 /// Our server side painting device.
206 //QPixmap screen_device_;
212 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
214 double_click dc_event_;
235 QColor cursor_color_;
237 CursorShape cursor_shape_;
240 } // namespace frontend