]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
delete unneeded Menubar virtual interface.
[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 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(Buffer & buffer, LyXView & lv);
92
93         ///
94         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
95         bool isVisible() const { return QAbstractScrollArea::isVisible(); }
96
97         /// return the width of the content pane
98         virtual int width() const { return viewport()->width(); }
99         /// return the height of the content pane
100         virtual int height() const { return viewport()->height(); }
101         ///
102         virtual void setScrollbarParams(int height, int pos, int line_height);
103         ///
104         virtual void scheduleRedraw() { schedule_redraw_ = true; }
105
106         /// update the passed area.
107         void update(int x, int y, int w, int h);
108
109         /// copies specified area of pixmap to screen
110         virtual void expose(int x, int y, int exp_width, int exp_height);
111
112         /// paint the cursor and store the background
113         virtual void showCursor(int x, int y, int h, CursorShape shape);
114
115         /// hide the cursor
116         virtual void removeCursor();
117
118 private:
119         void doGreyOut(QLPainter & pain);
120         ///
121         void focusInEvent(QFocusEvent *);
122         ///
123         void focusOutEvent(QFocusEvent *);
124         /// repaint part of the widget
125         void paintEvent(QPaintEvent * ev);
126         /// widget has been resized
127         void resizeEvent(QResizeEvent * ev);
128         /// mouse button press
129         void mousePressEvent(QMouseEvent * ev);
130         /// mouse button release
131         void mouseReleaseEvent(QMouseEvent * ev);
132         /// mouse double click of button
133         void mouseDoubleClickEvent(QMouseEvent * ev);
134         /// mouse motion
135         void mouseMoveEvent(QMouseEvent * ev);
136         /// wheel event
137         void wheelEvent(QWheelEvent * ev);
138         /// key press
139         void keyPressEvent(QKeyEvent * ev);
140         /// IM events
141         void inputMethodEvent(QInputMethodEvent * ev);
142         /// IM query
143         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
144
145 public Q_SLOTS:
146         /// Adjust the LyX buffer view with the position of the scrollbar.
147         /**
148         * The action argument is not used in the the code, it is there
149         * only for the connection to the vertical srollbar signal which
150         * emits an 'int' action.
151         */
152         void adjustViewWithScrollBar(int action = 0);
153         /// timer to limit triple clicks
154         void doubleClickTimeout();
155
156 private:
157         /// The slot connected to SyntheticMouseEvent::timeout.
158         void generateSyntheticMouseEvent();
159
160         ///
161         SyntheticMouseEvent synthetic_mouse_event_;
162         ///
163         double_click dc_event_;
164
165         ///
166         CursorWidget * cursor_;
167         ///
168         void updateScreen();
169         ///
170         QPixmap screen_;
171         ///
172         bool need_resize_;
173         ///
174         bool schedule_redraw_;
175         ///
176         int preedit_lines_;
177 };
178
179 } // namespace frontend
180 } // namespace lyx
181
182 #endif // WORKAREA_H