]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
rename a few view functions from foo() to fooView()
[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 "support/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 /// for emulating triple click
40 class double_click {
41 public:
42         Qt::MouseButton state;
43         bool active;
44
45         bool operator==(QMouseEvent const & e) {
46                 return state == e.button();
47         }
48
49         double_click()
50                 : state(Qt::NoButton), active(false) {}
51
52         double_click(QMouseEvent * e)
53                 : state(e->button()), active(true) {}
54 };
55
56 /** Qt only emits mouse events when the mouse is being moved, but
57  *  we want to generate 'pseudo' mouse events when the mouse button is
58  *  pressed and the mouse cursor is below the bottom, or above the top
59  *  of the work area. In this way, we'll be able to continue scrolling
60  *  (and selecting) the text.
61  *
62  *  This class stores all the parameters needed to make this happen.
63  */
64 class SyntheticMouseEvent
65 {
66 public:
67         SyntheticMouseEvent();
68
69         FuncRequest cmd;
70         Timeout timeout;
71         bool restart_timeout;
72         int x_old;
73         int y_old;
74         double scrollbar_value_old;
75 };
76
77 /**
78  * Qt-specific implementation of the work area
79  * (buffer view GUI)
80 */
81         class CursorWidget;
82 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
83 {
84         Q_OBJECT
85
86 public:
87         ///
88         GuiWorkArea(Buffer & buffer, LyXView & lv);
89
90         ///
91         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
92         bool isVisible() const { return QAbstractScrollArea::isVisible(); }
93
94         /// return the width of the content pane
95         virtual int width() const { return viewport()->width(); }
96         /// return the height of the content pane
97         virtual int height() const { return viewport()->height(); }
98         ///
99         virtual void setScrollbarParams(int height, int pos, int line_height);
100         ///
101         virtual void scheduleRedraw() { schedule_redraw_ = true; }
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         ///
117         void focusInEvent(QFocusEvent *);
118         ///
119         void focusOutEvent(QFocusEvent *);
120         /// repaint part of the widget
121         void paintEvent(QPaintEvent * ev);
122         /// widget has been resized
123         void resizeEvent(QResizeEvent * ev);
124         /// mouse button press
125         void mousePressEvent(QMouseEvent * ev);
126         /// mouse button release
127         void mouseReleaseEvent(QMouseEvent * ev);
128         /// mouse double click of button
129         void mouseDoubleClickEvent(QMouseEvent * ev);
130         /// mouse motion
131         void mouseMoveEvent(QMouseEvent * ev);
132         /// wheel event
133         void wheelEvent(QWheelEvent * ev);
134         /// key press
135         void keyPressEvent(QKeyEvent * ev);
136         /// IM events
137         void inputMethodEvent(QInputMethodEvent * ev);
138         /// IM query
139         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
140
141 public Q_SLOTS:
142         /// Adjust the LyX buffer view with the position of the scrollbar.
143         /**
144         * The action argument is not used in the the code, it is there
145         * only for the connection to the vertical srollbar signal which
146         * emits an 'int' action.
147         */
148         void adjustViewWithScrollBar(int action = 0);
149         /// timer to limit triple clicks
150         void doubleClickTimeout();
151
152 private:
153         /// The slot connected to SyntheticMouseEvent::timeout.
154         void generateSyntheticMouseEvent();
155
156         ///
157         SyntheticMouseEvent synthetic_mouse_event_;
158         ///
159         double_click dc_event_;
160
161         ///
162         CursorWidget * cursor_;
163         ///
164         void updateScreen();
165         ///
166         QPixmap screen_;
167         ///
168         bool need_resize_;
169         ///
170         bool schedule_redraw_;
171         ///
172         int preedit_lines_;
173 };
174
175 } // namespace frontend
176 } // namespace lyx
177
178 #endif // WORKAREA_H