4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
16 #include "frontends/WorkArea.h"
18 #include "QLPainter.h"
20 #include "funcrequest.h"
21 #include "frontends/Timeout.h"
23 #include <QAbstractScrollArea>
24 #include <QMouseEvent>
25 #include <QResizeEvent>
33 class QDragEnterEvent;
46 /// for emulating triple click
51 Qt::MouseButton state;
54 bool operator==(QMouseEvent const & e) {
55 return x == e.x() && y == e.y()
56 && state == e.button();
60 : x(0), y(0), state(Qt::NoButton), active(false) {}
62 double_click(QMouseEvent * e)
63 : x(e->x()), y(e->y()),
64 state(e->button()), active(true) {}
67 /** Qt only emits mouse events when the mouse is being moved, but
68 * we want to generate 'pseudo' mouse events when the mouse button is
69 * pressed and the mouse cursor is below the bottom, or above the top
70 * of the work area. In this way, we'll be able to continue scrolling
71 * (and selecting) the text.
73 * This class stores all the parameters needed to make this happen.
75 class SyntheticMouseEvent
78 SyntheticMouseEvent();
85 double scrollbar_value_old;
89 * Qt-specific implementation of the work area
92 class GuiWorkArea: public QAbstractScrollArea, public WorkArea
98 GuiWorkArea(int width, int height, LyXView & lyx_view);
100 /// return the width of the content pane
101 virtual int width() const { return viewport()->width(); }
102 /// return the height of the content pane
103 virtual int height() const { return viewport()->height(); }
105 virtual void setScrollbarParams(int height, int pos, int line_height);
108 virtual void dragEnterEvent(QDragEnterEvent * event);
111 virtual void dropEvent(QDropEvent* event);
113 /// return the widget's painter
114 virtual Painter & getPainter() { return (Painter &) painter_; }
116 /// return the backing pixmap
117 QPaintDevice * paintDevice() { return &paint_device_; }
119 /// update the passed area.
120 void update(int x, int y, int w, int h);
122 /// copies specified area of pixmap to screen
123 virtual void expose(int x, int y, int exp_width, int exp_height);
125 /// paint the cursor and store the background
126 virtual void showCursor(int x, int y, int h, CursorShape shape);
129 virtual void removeCursor();
133 /// repaint part of the widget
134 void paintEvent(QPaintEvent * e);
135 /// widget has been resized
136 void resizeEvent(QResizeEvent * e);
137 /// mouse button press
138 void mousePressEvent(QMouseEvent * e);
139 /// mouse button release
140 void mouseReleaseEvent(QMouseEvent * e);
141 /// mouse double click of button
142 void mouseDoubleClickEvent(QMouseEvent * e);
144 void mouseMoveEvent(QMouseEvent * e);
146 void wheelEvent(QWheelEvent * e);
148 void keyPressEvent(QKeyEvent * e);
150 void inputMethodEvent(QInputMethodEvent * e);
154 /// Timeout event Slot for keyboard bufferring.
155 /// \todo This is not used currently in the code, remove?
156 void keyeventTimeout();
158 /// Adjust the LyX buffer view with the position of the scrollbar.
160 * The action argument is not used in the the code, it is there
161 * only for the connection to the vertical srollbar signal which
162 * emits an 'int' action.
164 void adjustViewWithScrollBar(int action = 0);
171 /// The slot connected to SyntheticMouseEvent::timeout.
172 void generateSyntheticMouseEvent();
175 SyntheticMouseEvent synthetic_mouse_event_;
177 /// Our client side painting device.
178 QPixmap paint_device_;
184 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
186 double_click dc_event_;
207 QColor cursor_color_;
209 CursorShape cursor_shape_;
212 } // namespace frontend