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
26 #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;
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) {}
74 /** Qt only emits mouse events when the mouse is being moved, but
75 * we want to generate 'pseudo' mouse events when the mouse button is
76 * pressed and the mouse cursor is below the bottom, or above the top
77 * of the work area. In this way, we'll be able to continue scrolling
78 * (and selecting) the text.
80 * This class stores all the parameters needed to make this happen.
82 class SyntheticMouseEvent
85 SyntheticMouseEvent();
92 double scrollbar_value_old;
96 * Qt-specific implementation of the work area
99 class QWorkArea : public QAbstractScrollArea, public WorkArea, public LyXScreen {
105 QWorkArea(LyXView & owner, int w, int h);
107 virtual ~QWorkArea();
108 /// return the width of the content pane
109 virtual int workWidth() const { return workWidth_; }
111 /// return the height of the content pane
112 virtual int workHeight() const { return workHeight_; }
114 virtual void setScrollbarParams(int height, int pos, int line_height);
116 /// a selection exists
117 virtual void haveSelection(bool) const;
120 virtual std::string const getClipboard() const;
123 virtual void putClipboard(std::string const &) const;
126 virtual void dragEnterEvent(QDragEnterEvent * event);
129 virtual void dropEvent(QDropEvent* event);
131 /// return the widget's painter
132 virtual Painter & getPainter() { return (Painter &) painter_; }
134 /// return the backing pixmap
135 QPaintDevice * paintDevice() { return &paint_device_; }
137 /// update the passed area.
138 void update(int x, int y, int w, int h);
140 /// return a screen copy of the defined area.
141 QPixmap copyScreen(int x, int y, int w, int h) const;
143 /// Draw a pixmap onto the backing pixmap.
145 QPixmap is implicitely shared so no need to pass by reference.
147 void drawScreen(int x, int y, QPixmap pixmap);
149 LyXView & view() { return view_; }
151 // LyXScreen overloaded methods:
153 /// get the work area
154 virtual WorkArea & workarea();
156 /// copies specified area of pixmap to screen
157 virtual void expose(int x, int y, int exp_width, int exp_height);
159 /// paint the cursor and store the background
160 virtual void showCursor(int x, int y, int h, Cursor_Shape shape);
163 virtual void removeCursor();
167 /// repaint part of the widget
168 void paintEvent(QPaintEvent * e);
169 /// widget has been resized
170 void resizeEvent(QResizeEvent * e);
171 /// mouse button press
172 void mousePressEvent(QMouseEvent * e);
173 /// mouse button release
174 void mouseReleaseEvent(QMouseEvent * e);
175 /// mouse double click of button
176 void mouseDoubleClickEvent(QMouseEvent * e);
178 void mouseMoveEvent(QMouseEvent * e);
180 void wheelEvent(QWheelEvent * e);
182 void keyPressEvent(QKeyEvent * e);
184 #if USE_INPUT_METHODS
187 void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
192 /// Timeout event Slot for keyboard bufferring.
193 /// \todo This is not used currently in the code, remove?
194 void keyeventTimeout();
196 /// Adjust the LyX buffer view with the position of the scrollbar.
198 * The action argument is not used in the the code, it is there
199 * only for the connection to the vertical srollbar signal which
200 * emits an 'int' action.
202 void adjustViewWithScrollBar(int action = 0);
208 /// Buffer view width.
211 /// Buffer view height.
217 /// The slot connected to SyntheticMouseEvent::timeout.
218 void generateSyntheticMouseEvent();
221 SyntheticMouseEvent synthetic_mouse_event_;
223 /// Our client side painting device.
224 //QImage paint_device_;
225 QPixmap paint_device_;
227 /// Our server side painting device.
228 //QPixmap screen_device_;
234 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
236 double_click dc_event_;
257 QColor cursor_color_;
259 Cursor_Shape cursor_shape_;
262 #endif // QWORKAREA_H