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 "funcrequest.h"
26 #include "frontends/Timeout.h"
29 #include "QLPainter.h"
32 #include <QAbstractScrollArea>
33 #include <QMouseEvent>
34 #include <QWheelEvent>
35 #include <QResizeEvent>
37 #include <QPaintEvent>
40 #include <boost/scoped_ptr.hpp>
47 class QDragEnterEvent;
51 /// for emulating triple click
56 Qt::ButtonState state;
59 bool operator==(QMouseEvent const & e) {
60 return x == e.x() && y == e.y()
61 && state == e.button();
65 : x(0), y(0), state(Qt::NoButton), active(false) {}
67 double_click(QMouseEvent * e)
68 : x(e->x()), y(e->y()),
69 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 QWorkArea : public QAbstractScrollArea, public WorkArea {
104 QWorkArea(LyXView & owner, int w, int h);
106 virtual ~QWorkArea();
107 /// return the width of the content pane
108 virtual int workWidth() const { return workWidth_; }
110 /// return the height of the content pane
111 virtual int workHeight() const { return workHeight_; }
113 virtual void setScrollbarParams(int height, int pos, int line_height);
115 /// a selection exists
116 virtual void haveSelection(bool) const;
119 virtual std::string const getClipboard() const;
122 virtual void putClipboard(std::string const &) const;
125 virtual void dragEnterEvent(QDragEnterEvent * event);
128 virtual void dropEvent(QDropEvent* event);
130 /// return the widget's painter
131 virtual Painter & getPainter() { return (Painter &) painter_; }
134 //virtual QPaintDevice & paintDevice() { return content_->pixmap(); }
136 /// return the backing pixmap
137 QPixmap * pixmap() const { return pixmap_.get(); }
139 /// return the widget's painter
140 //virtual QLPainter & getQLPainter() const { return painter_; }
142 /// get the content pane widget
143 QWidget * getContent() const { return viewport(); }
147 /// repaint part of the widget
148 void paintEvent(QPaintEvent * e);
149 /// widget has been resized
150 void resizeEvent(QResizeEvent * e);
151 /// mouse button press
152 void mousePressEvent(QMouseEvent * e);
153 /// mouse button release
154 void mouseReleaseEvent(QMouseEvent * e);
155 /// mouse double click of button
156 void mouseDoubleClickEvent(QMouseEvent * e);
158 void mouseMoveEvent(QMouseEvent * e);
160 void wheelEvent(QWheelEvent * e);
162 void keyPressEvent(QKeyEvent * e);
164 #if USE_INPUT_METHODS
167 void QWorkArea::inputMethodEvent(QInputMethodEvent * e)
172 void keyeventTimeout();
173 void adjustViewWithScrollBar(int action);
185 /// The slot connected to SyntheticMouseEvent::timeout.
186 void generateSyntheticMouseEvent();
188 SyntheticMouseEvent synthetic_mouse_event_;
190 /// the double buffered pixmap
191 boost::scoped_ptr<QPixmap> pixmap_;
194 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
196 double_click dc_event_;
198 bool scrolled_with_mouse_;
199 bool scrolled_with_keyboard_;
202 #endif // QWORKAREA_H