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.
17 #if (defined(Q_WS_X11) && QT_VERSION >= 0x030200)
18 #define USE_INPUT_METHODS 1
25 #include "frontends/LyXView.h"
26 #include "frontends/WorkArea.h"
28 #include "QLPainter.h"
30 #include "funcrequest.h"
31 #include "frontends/Timeout.h"
33 #include <QAbstractScrollArea>
34 #include <QMouseEvent>
35 #include <QWheelEvent>
36 #include <QResizeEvent>
38 #include <QPaintEvent>
48 class QDragEnterEvent;
55 /// for emulating triple click
60 Qt::ButtonState state;
63 bool operator==(QMouseEvent const & e) {
64 return x == e.x() && y == e.y()
65 && state == e.button();
69 : x(0), y(0), state(Qt::NoButton), active(false) {}
71 double_click(QMouseEvent * e)
72 : x(e->x()), y(e->y()),
73 state(e->button()), active(true) {}
76 /** Qt only emits mouse events when the mouse is being moved, but
77 * we want to generate 'pseudo' mouse events when the mouse button is
78 * pressed and the mouse cursor is below the bottom, or above the top
79 * of the work area. In this way, we'll be able to continue scrolling
80 * (and selecting) the text.
82 * This class stores all the parameters needed to make this happen.
84 class SyntheticMouseEvent
87 SyntheticMouseEvent();
94 double scrollbar_value_old;
98 * Qt-specific implementation of the work area
101 class GuiWorkArea: public QAbstractScrollArea, public WorkArea {
107 GuiWorkArea(LyXView & owner, int w, int h);
109 virtual ~GuiWorkArea();
110 /// return the width of the content pane
111 virtual int width() const { return workWidth_; }
113 /// return the height of the content pane
114 virtual int height() const { return workHeight_; }
116 virtual void setScrollbarParams(int height, int pos, int line_height);
119 virtual void dragEnterEvent(QDragEnterEvent * event);
122 virtual void dropEvent(QDropEvent* event);
124 /// return the widget's painter
125 virtual Painter & getPainter() { return (Painter &) painter_; }
127 /// return the backing pixmap
128 QPaintDevice * paintDevice() { return &paint_device_; }
130 /// update the passed area.
131 void update(int x, int y, int w, int h);
133 /// return a screen copy of the defined area.
134 QPixmap copyScreen(int x, int y, int w, int h) const;
136 /// Draw a pixmap onto the backing pixmap.
138 QPixmap is implicitely shared so no need to pass by reference.
140 void drawScreen(int x, int y, QPixmap pixmap);
142 LyXView & view() { return view_; }
144 /// copies specified area of pixmap to screen
145 virtual void expose(int x, int y, int exp_width, int exp_height);
147 /// paint the cursor and store the background
148 virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
151 virtual void removeCursor();
155 /// repaint part of the widget
156 void paintEvent(QPaintEvent * e);
157 /// widget has been resized
158 void resizeEvent(QResizeEvent * e);
159 /// mouse button press
160 void mousePressEvent(QMouseEvent * e);
161 /// mouse button release
162 void mouseReleaseEvent(QMouseEvent * e);
163 /// mouse double click of button
164 void mouseDoubleClickEvent(QMouseEvent * e);
166 void mouseMoveEvent(QMouseEvent * e);
168 void wheelEvent(QWheelEvent * e);
170 void keyPressEvent(QKeyEvent * e);
172 #if USE_INPUT_METHODS
175 void inputMethodEvent(QInputMethodEvent * e);
180 /// Timeout event Slot for keyboard bufferring.
181 /// \todo This is not used currently in the code, remove?
182 void keyeventTimeout();
184 /// Adjust the LyX buffer view with the position of the scrollbar.
186 * The action argument is not used in the the code, it is there
187 * only for the connection to the vertical srollbar signal which
188 * emits an 'int' action.
190 void adjustViewWithScrollBar(int action = 0);
196 /// Buffer view width.
199 /// Buffer view height.
205 /// The slot connected to SyntheticMouseEvent::timeout.
206 void generateSyntheticMouseEvent();
209 SyntheticMouseEvent synthetic_mouse_event_;
211 /// Our client side painting device.
212 //QImage paint_device_;
213 QPixmap paint_device_;
215 /// Our server side painting device.
216 //QPixmap screen_device_;
222 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
224 double_click dc_event_;
245 QColor cursor_color_;
247 Cursor_Shape cursor_shape_;
250 } // namespace frontend