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