]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
* LyXView::updateInset(): schedule a redraw instead of redraw immediately.
[lyx.git] / src / frontends / qt4 / GuiWorkArea.h
1 // -*- C++ -*-
2 /**
3  * \file GuiWorkArea.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author John Levon
8  * \author Abdelrazak Younes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef WORKAREA_H
14 #define WORKAREA_H
15
16 #include "frontends/WorkArea.h"
17
18 #include "funcrequest.h"
19 #include "frontends/Timeout.h"
20
21 #include <QAbstractScrollArea>
22 #include <QMouseEvent>
23 #include <QResizeEvent>
24 #include <QKeyEvent>
25 #include <QTimer>
26 #include <QPixmap>
27
28 #include <queue>
29
30 class QWidget;
31 class QDragEnterEvent;
32 class QDropEvent;
33 class QWheelEvent;
34 class QPaintEvent;
35
36 namespace lyx {
37 namespace frontend {
38
39 class GuiView;
40 class QLPainter;
41
42 /// for emulating triple click
43 class double_click {
44 public:
45         int x;
46         int y;
47         Qt::MouseButton state;
48         bool active;
49
50         bool operator==(QMouseEvent const & e) {
51                 return x == e.x() && y == e.y()
52                         && state == e.button();
53         }
54
55         double_click()
56                 : x(0), y(0), state(Qt::NoButton), active(false) {}
57
58         double_click(QMouseEvent * e)
59                 : x(e->x()), y(e->y()),
60                 state(e->button()), active(true) {}
61 };
62
63 /** Qt only emits mouse events when the mouse is being moved, but
64  *  we want to generate 'pseudo' mouse events when the mouse button is
65  *  pressed and the mouse cursor is below the bottom, or above the top
66  *  of the work area. In this way, we'll be able to continue scrolling
67  *  (and selecting) the text.
68  *
69  *  This class stores all the parameters needed to make this happen.
70  */
71 class SyntheticMouseEvent
72 {
73 public:
74         SyntheticMouseEvent();
75
76         FuncRequest cmd;
77         Timeout timeout;
78         bool restart_timeout;
79         int x_old;
80         int y_old;
81         double scrollbar_value_old;
82 };
83
84 /**
85  * Qt-specific implementation of the work area
86  * (buffer view GUI)
87 */
88         class CursorWidget;
89 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
90 {
91         Q_OBJECT
92
93 public:
94         ///
95         GuiWorkArea(int width, int height, int id, LyXView & lyx_view);
96
97         ///
98         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
99
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(); }
104         ///
105         virtual void setScrollbarParams(int height, int pos, int line_height);
106         ///
107         virtual void sheduleRedraw() { shedule_redraw_ = true; }
108
109         /// update the passed area.
110         void update(int x, int y, int w, int h);
111
112         /// copies specified area of pixmap to screen
113         virtual void expose(int x, int y, int exp_width, int exp_height);
114
115         /// paint the cursor and store the background
116         virtual void showCursor(int x, int y, int h, CursorShape shape);
117
118         /// hide the cursor
119         virtual void removeCursor();
120
121 private:
122         void doGreyOut(QLPainter & pain);
123         ///
124         void dragEnterEvent(QDragEnterEvent * ev);
125         ///
126         void dropEvent(QDropEvent * ev);
127         ///
128         void focusInEvent(QFocusEvent *);
129         ///
130         void focusOutEvent(QFocusEvent *);
131         /// repaint part of the widget
132         void paintEvent(QPaintEvent * ev);
133         /// widget has been resized
134         void resizeEvent(QResizeEvent * ev);
135         /// mouse button press
136         void mousePressEvent(QMouseEvent * ev);
137         /// mouse button release
138         void mouseReleaseEvent(QMouseEvent * ev);
139         /// mouse double click of button
140         void mouseDoubleClickEvent(QMouseEvent * ev);
141         /// mouse motion
142         void mouseMoveEvent(QMouseEvent * ev);
143         /// wheel event
144         void wheelEvent(QWheelEvent * ev);
145         /// key press
146         void keyPressEvent(QKeyEvent * ev);
147         /// IM events
148         void inputMethodEvent(QInputMethodEvent * ev);
149
150 public Q_SLOTS:
151         /// Adjust the LyX buffer view with the position of the scrollbar.
152         /**
153         * The action argument is not used in the the code, it is there
154         * only for the connection to the vertical srollbar signal which
155         * emits an 'int' action.
156         */
157         void adjustViewWithScrollBar(int action = 0);
158
159 private:
160         /// The slot connected to SyntheticMouseEvent::timeout.
161         void generateSyntheticMouseEvent();
162
163         ///
164         SyntheticMouseEvent synthetic_mouse_event_;
165         ///
166         double_click dc_event_;
167
168         ///     
169         CursorWidget * cursor_;
170         ///
171         void updateScreen();
172         ///
173         QPixmap screen_;
174         ///
175         bool need_resize_;
176         ///
177         bool shedule_redraw_;
178 };
179
180 } // namespace frontend
181 } // namespace lyx
182
183 #endif // WORKAREA_H