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 /// return a screen copy of the defined area.
123 QPixmap copyScreen(int x, int y, int w, int h) const;
125 /// Draw a pixmap onto the backing pixmap.
126 void drawScreen(int x, int y, const QPixmap & pixmap);
128 /// copies specified area of pixmap to screen
129 virtual void expose(int x, int y, int exp_width, int exp_height);
131 /// paint the cursor and store the background
132 virtual void showCursor(int x, int y, int h, CursorShape shape);
135 virtual void removeCursor();
139 /// repaint part of the widget
140 void paintEvent(QPaintEvent * e);
141 /// widget has been resized
142 void resizeEvent(QResizeEvent * e);
143 /// mouse button press
144 void mousePressEvent(QMouseEvent * e);
145 /// mouse button release
146 void mouseReleaseEvent(QMouseEvent * e);
147 /// mouse double click of button
148 void mouseDoubleClickEvent(QMouseEvent * e);
150 void mouseMoveEvent(QMouseEvent * e);
152 void wheelEvent(QWheelEvent * e);
154 void keyPressEvent(QKeyEvent * e);
156 void inputMethodEvent(QInputMethodEvent * e);
160 /// Timeout event Slot for keyboard bufferring.
161 /// \todo This is not used currently in the code, remove?
162 void keyeventTimeout();
164 /// Adjust the LyX buffer view with the position of the scrollbar.
166 * The action argument is not used in the the code, it is there
167 * only for the connection to the vertical srollbar signal which
168 * emits an 'int' action.
170 void adjustViewWithScrollBar(int action = 0);
177 /// The slot connected to SyntheticMouseEvent::timeout.
178 void generateSyntheticMouseEvent();
181 SyntheticMouseEvent synthetic_mouse_event_;
183 /// Our client side painting device.
184 QPixmap paint_device_;
190 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
192 double_click dc_event_;
213 QColor cursor_color_;
215 CursorShape cursor_shape_;
218 } // namespace frontend