]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Transfer some code from GuiView to TabWorkArea.
[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 <QKeyEvent>
23 #include <QMouseEvent>
24 #include <QPixmap>
25 #include <QResizeEvent>
26 #include <QTabWidget>
27 #include <QTimer>
28
29 #include <queue>
30
31 class QWidget;
32 class QDragEnterEvent;
33 class QDropEvent;
34 class QWheelEvent;
35 class QPaintEvent;
36
37 namespace lyx {
38 namespace frontend {
39
40 /// for emulating triple click
41 class double_click {
42 public:
43         Qt::MouseButton state;
44         bool active;
45
46         bool operator==(QMouseEvent const & e) {
47                 return state == e.button();
48         }
49
50         double_click()
51                 : state(Qt::NoButton), active(false) {}
52
53         double_click(QMouseEvent * e)
54                 : state(e->button()), active(true) {}
55 };
56
57 /** Qt only emits mouse events when the mouse is being moved, but
58  *  we want to generate 'pseudo' mouse events when the mouse button is
59  *  pressed and the mouse cursor is below the bottom, or above the top
60  *  of the work area. In this way, we'll be able to continue scrolling
61  *  (and selecting) the text.
62  *
63  *  This class stores all the parameters needed to make this happen.
64  */
65 class SyntheticMouseEvent
66 {
67 public:
68         SyntheticMouseEvent();
69
70         FuncRequest cmd;
71         Timeout timeout;
72         bool restart_timeout;
73         int x_old;
74         int y_old;
75         double scrollbar_value_old;
76 };
77
78 /**
79  * Qt-specific implementation of the work area
80  * (buffer view GUI)
81 */
82         class CursorWidget;
83 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
84 {
85         Q_OBJECT
86
87 public:
88         ///
89         GuiWorkArea(Buffer & buffer, LyXView & lv);
90
91         ///
92         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
93         bool isVisible() const { return QAbstractScrollArea::isVisible(); }
94
95         /// return the width of the content pane
96         virtual int width() const { return viewport()->width(); }
97         /// return the height of the content pane
98         virtual int height() const { return viewport()->height(); }
99         ///
100         virtual void setScrollbarParams(int height, int pos, int line_height);
101         ///
102         virtual void scheduleRedraw() { schedule_redraw_ = true; }
103
104         /// update the passed area.
105         void update(int x, int y, int w, int h);
106
107         /// copies specified area of pixmap to screen
108         virtual void expose(int x, int y, int exp_width, int exp_height);
109
110         /// paint the cursor and store the background
111         virtual void showCursor(int x, int y, int h, CursorShape shape);
112
113         /// hide the cursor
114         virtual void removeCursor();
115
116 private:
117         ///
118         void focusInEvent(QFocusEvent *);
119         ///
120         void focusOutEvent(QFocusEvent *);
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         /// IM query
140         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
141
142 public Q_SLOTS:
143         /// Adjust the LyX buffer view with the position of the scrollbar.
144         /**
145         * The action argument is not used in the the code, it is there
146         * only for the connection to the vertical srollbar signal which
147         * emits an 'int' action.
148         */
149         void adjustViewWithScrollBar(int action = 0);
150         /// timer to limit triple clicks
151         void doubleClickTimeout();
152
153 private:
154         /// The slot connected to SyntheticMouseEvent::timeout.
155         void generateSyntheticMouseEvent();
156
157         ///
158         SyntheticMouseEvent synthetic_mouse_event_;
159         ///
160         double_click dc_event_;
161
162         ///
163         CursorWidget * cursor_;
164         ///
165         void updateScreen();
166         ///
167         QPixmap screen_;
168         ///
169         bool need_resize_;
170         ///
171         bool schedule_redraw_;
172         ///
173         int preedit_lines_;
174 }; //GuiWorkArea
175
176 /// A tabbed set of GuiWorkAreas.
177 class TabWorkArea : public QTabWidget
178 {
179         Q_OBJECT
180 public:
181         TabWorkArea(QWidget * parent = 0);
182         void showBar(bool show);
183         bool setCurrentWorkArea(GuiWorkArea *);
184         bool removeWorkArea(GuiWorkArea *);
185
186 Q_SIGNALS:
187         ///
188         void currentWorkAreaChanged(GuiWorkArea *);
189
190 public Q_SLOTS:
191         ///
192         void on_currentTabChanged(int index);
193         ///
194         void closeCurrentTab();
195 }; // TabWorkArea
196
197 } // namespace frontend
198 } // namespace lyx
199
200 #endif // WORKAREA_H