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