]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Transfer readOnly() and updateWindowTitle() from Delegates to WorkArea/WorkAreaManage...
[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 #ifdef CursorShape
38 #undef CursorShape
39 #endif
40
41 namespace lyx {
42 namespace frontend {
43
44 /// for emulating triple click
45 class double_click {
46 public:
47         Qt::MouseButton state;
48         bool active;
49
50         bool operator==(QMouseEvent const & e) {
51                 return state == e.button();
52         }
53
54         double_click()
55                 : state(Qt::NoButton), active(false) {}
56
57         double_click(QMouseEvent * e)
58                 : state(e->button()), active(true) {}
59 };
60
61 /** Qt only emits mouse events when the mouse is being moved, but
62  *  we want to generate 'pseudo' mouse events when the mouse button is
63  *  pressed and the mouse cursor is below the bottom, or above the top
64  *  of the work area. In this way, we'll be able to continue scrolling
65  *  (and selecting) the text.
66  *
67  *  This class stores all the parameters needed to make this happen.
68  */
69 class SyntheticMouseEvent
70 {
71 public:
72         SyntheticMouseEvent();
73
74         FuncRequest cmd;
75         Timeout timeout;
76         bool restart_timeout;
77         int x_old;
78         int y_old;
79         double scrollbar_value_old;
80 };
81
82 /**
83  * Qt-specific implementation of the work area
84  * (buffer view GUI)
85 */
86         class CursorWidget;
87 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
88 {
89         Q_OBJECT
90
91 public:
92         ///
93         GuiWorkArea(Buffer & buffer, LyXView & lv);
94
95         ///
96         bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
97         bool isVisible() const { return QAbstractScrollArea::isVisible(); }
98
99         /// return the width of the content pane
100         virtual int width() const { return viewport()->width(); }
101         /// return the height of the content pane
102         virtual int height() const { return viewport()->height(); }
103         ///
104         virtual void setScrollbarParams(int height, int pos, int line_height);
105         ///
106         virtual void scheduleRedraw() { schedule_redraw_ = true; }
107
108         /// update the passed area.
109         void update(int x, int y, int w, int h);
110
111         /// copies specified area of pixmap to screen
112         virtual void expose(int x, int y, int exp_width, int exp_height);
113
114         /// paint the cursor and store the background
115         virtual void showCursor(int x, int y, int h, CursorShape shape);
116
117         /// hide the cursor
118         virtual void removeCursor();
119
120         void setWindowTitle(docstring const & t, docstring const & it);
121
122 Q_SIGNALS:
123         ///
124         void titleChanged(GuiWorkArea *);
125
126 private:
127         ///
128         void focusInEvent(QFocusEvent *);
129         ///
130         void focusOutEvent(QFocusEvent *);
131         /// repaint part of the widget
132         void paintEvent(QPaintEvent * ev);
133         /// widget has been resized
134         void resizeEvent(QResizeEvent * ev);
135         /// mouse button press
136         void mousePressEvent(QMouseEvent * ev);
137         /// mouse button release
138         void mouseReleaseEvent(QMouseEvent * ev);
139         /// mouse double click of button
140         void mouseDoubleClickEvent(QMouseEvent * ev);
141         /// mouse motion
142         void mouseMoveEvent(QMouseEvent * ev);
143         /// wheel event
144         void wheelEvent(QWheelEvent * ev);
145         /// key press
146         void keyPressEvent(QKeyEvent * ev);
147         /// IM events
148         void inputMethodEvent(QInputMethodEvent * ev);
149         /// IM query
150         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
151
152 public Q_SLOTS:
153         /// Adjust the LyX buffer view with the position of the scrollbar.
154         /**
155         * The action argument is not used in the the code, it is there
156         * only for the connection to the vertical srollbar signal which
157         * emits an 'int' action.
158         */
159         void adjustViewWithScrollBar(int action = 0);
160         /// timer to limit triple clicks
161         void doubleClickTimeout();
162
163 private:
164         /// The slot connected to SyntheticMouseEvent::timeout.
165         void generateSyntheticMouseEvent();
166
167         ///
168         SyntheticMouseEvent synthetic_mouse_event_;
169         ///
170         double_click dc_event_;
171
172         ///
173         CursorWidget * cursor_;
174         ///
175         void updateScreen();
176         ///
177         QPixmap screen_;
178         ///
179         bool need_resize_;
180         ///
181         bool schedule_redraw_;
182         ///
183         int preedit_lines_;
184 }; //GuiWorkArea
185
186 /// A tabbed set of GuiWorkAreas.
187 class TabWorkArea : public QTabWidget
188 {
189         Q_OBJECT
190 public:
191         TabWorkArea(QWidget * parent = 0);
192
193         void showBar(bool show);
194         void closeAll();
195         bool setCurrentWorkArea(GuiWorkArea *);
196         bool removeWorkArea(GuiWorkArea *);
197         GuiWorkArea * currentWorkArea();
198         GuiWorkArea * workArea(Buffer & buffer);
199
200 Q_SIGNALS:
201         ///
202         void currentWorkAreaChanged(GuiWorkArea *);
203
204 public Q_SLOTS:
205         ///
206         void on_currentTabChanged(int index);
207         ///
208         void closeCurrentTab();
209         ///
210         void updateTabText(GuiWorkArea *);
211 }; // TabWorkArea
212
213 } // namespace frontend
214 } // namespace lyx
215
216 #endif // WORKAREA_H