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 <QWheelEvent>
26 #include <QResizeEvent>
28 #include <QPaintEvent>
38 class QDragEnterEvent;
47 /// for emulating triple click
52 Qt::MouseButton state;
55 bool operator==(QMouseEvent const & e) {
56 return x == e.x() && y == e.y()
57 && state == e.button();
61 : x(0), y(0), state(Qt::NoButton), active(false) {}
63 double_click(QMouseEvent * e)
64 : x(e->x()), y(e->y()),
65 state(e->button()), active(true) {}
68 /** Qt only emits mouse events when the mouse is being moved, but
69 * we want to generate 'pseudo' mouse events when the mouse button is
70 * pressed and the mouse cursor is below the bottom, or above the top
71 * of the work area. In this way, we'll be able to continue scrolling
72 * (and selecting) the text.
74 * This class stores all the parameters needed to make this happen.
76 class SyntheticMouseEvent
79 SyntheticMouseEvent();
86 double scrollbar_value_old;
90 * Qt-specific implementation of the work area
93 class GuiWorkArea: public QAbstractScrollArea, public WorkArea
99 GuiWorkArea(int width, int height, LyXView & lyx_view);
101 virtual ~GuiWorkArea();
102 /// return the width of the content pane
103 virtual int width() const { return viewport()->width(); }
105 /// return the height of the content pane
106 virtual int height() const { return viewport()->height(); }
108 virtual void setScrollbarParams(int height, int pos, int line_height);
111 virtual void dragEnterEvent(QDragEnterEvent * event);
114 virtual void dropEvent(QDropEvent* event);
116 /// return the widget's painter
117 virtual Painter & getPainter() { return (Painter &) painter_; }
119 /// return the backing pixmap
120 QPaintDevice * paintDevice() { return &paint_device_; }
122 /// update the passed area.
123 void update(int x, int y, int w, int h);
125 /// return a screen copy of the defined area.
126 QPixmap copyScreen(int x, int y, int w, int h) const;
128 /// Draw a pixmap onto the backing pixmap.
130 QPixmap is implicitely shared so no need to pass by reference.
132 void drawScreen(int x, int y, QPixmap pixmap);
134 /// copies specified area of pixmap to screen
135 virtual void expose(int x, int y, int exp_width, int exp_height);
137 /// paint the cursor and store the background
138 virtual void showCursor(int x, int y, int h, CursorShape shape);
141 virtual void removeCursor();
145 /// repaint part of the widget
146 void paintEvent(QPaintEvent * e);
147 /// widget has been resized
148 void resizeEvent(QResizeEvent * e);
149 /// mouse button press
150 void mousePressEvent(QMouseEvent * e);
151 /// mouse button release
152 void mouseReleaseEvent(QMouseEvent * e);
153 /// mouse double click of button
154 void mouseDoubleClickEvent(QMouseEvent * e);
156 void mouseMoveEvent(QMouseEvent * e);
158 void wheelEvent(QWheelEvent * e);
160 void keyPressEvent(QKeyEvent * e);
162 void inputMethodEvent(QInputMethodEvent * e);
164 void focusInEvent(QFocusEvent * ev);
166 void focusOutEvent(QFocusEvent * ev);
170 /// Timeout event Slot for keyboard bufferring.
171 /// \todo This is not used currently in the code, remove?
172 void keyeventTimeout();
174 /// Adjust the LyX buffer view with the position of the scrollbar.
176 * The action argument is not used in the the code, it is there
177 * only for the connection to the vertical srollbar signal which
178 * emits an 'int' action.
180 void adjustViewWithScrollBar(int action = 0);
187 /// The slot connected to SyntheticMouseEvent::timeout.
188 void generateSyntheticMouseEvent();
191 SyntheticMouseEvent synthetic_mouse_event_;
193 /// Our client side painting device.
194 QPixmap paint_device_;
200 std::queue<boost::shared_ptr<QKeyEvent> > keyeventQueue_;
202 double_click dc_event_;
223 QColor cursor_color_;
225 CursorShape cursor_shape_;
228 } // namespace frontend