]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
e380561df5f1e500d339db620450aa4afd44cbf6
[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 #include "frontends/qt4/GuiCompleter.h"
18
19 #include "DocIterator.h"
20 #include "FuncRequest.h"
21 #include "qt_helpers.h"
22 #include "support/docstring.h"
23 #include "support/Timeout.h"
24
25 #include <QAbstractScrollArea>
26 #include <QMouseEvent>
27 #include <QPixmap>
28 #include <QResizeEvent>
29 #include <QTabBar>
30 #include <QTabWidget>
31 #include <QTimer>
32
33 class QContextMenuEvent;
34 class QDragEnterEvent;
35 class QDropEvent;
36 class QKeyEvent;
37 class QWheelEvent;
38 class QPaintEvent;
39 class QWidget;
40
41 #ifdef CursorShape
42 #undef CursorShape
43 #endif
44
45 namespace lyx {
46
47 class Buffer;
48
49 namespace frontend {
50
51 class GuiView;
52 class GuiWorkArea;
53
54 /// for emulating triple click
55 class DoubleClick {
56 public:
57         ///
58         DoubleClick() : state(Qt::NoButton), active(false) {}
59         ///
60         DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
61         ///
62         bool operator==(QMouseEvent const & e) { return state == e.button(); }
63         ///
64 public:
65         ///
66         Qt::MouseButton state;
67         ///
68         bool active;
69 };
70
71 /** Qt only emits mouse events when the mouse is being moved, but
72  *  we want to generate 'pseudo' mouse events when the mouse button is
73  *  pressed and the mouse cursor is below the bottom, or above the top
74  *  of the work area. In this way, we'll be able to continue scrolling
75  *  (and selecting) the text.
76  *
77  *  This class stores all the parameters needed to make this happen.
78  */
79 class SyntheticMouseEvent
80 {
81 public:
82         SyntheticMouseEvent();
83
84         FuncRequest cmd;
85         Timeout timeout;
86         bool restart_timeout;
87         int x_old;
88         int y_old;
89         double scrollbar_value_old;
90 };
91
92
93 /**
94  * Implementation of the work area (buffer view GUI)
95 */
96 class CursorWidget;
97
98 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
99 {
100         Q_OBJECT
101
102 public:
103         ///
104         GuiWorkArea(Buffer & buffer, GuiView & lv);
105         ///
106         ~GuiWorkArea();
107
108         ///
109         void setFullScreen(bool full_screen);
110         /// is LyXView in fullscreen mode?
111         bool isFullScreen();
112         ///
113         void scheduleRedraw() { schedule_redraw_ = true; }
114         ///
115         BufferView & bufferView();
116         ///
117         BufferView const & bufferView() const;
118         ///
119         void redraw();
120         ///
121         void stopBlinkingCursor();
122         ///
123         void startBlinkingCursor();
124         /// Process Key pressed event.
125         /// This needs to be public because it is accessed externally by GuiView.
126         void processKeySym(KeySymbol const & key, KeyModifier mod);
127         ///
128         void resizeBufferView();
129
130         ///
131         GuiCompleter & completer() { return completer_; }
132         
133 Q_SIGNALS:
134         ///
135         void titleChanged(GuiWorkArea *);
136
137 private Q_SLOTS:
138         /// Scroll the BufferView.
139         /**
140           * This is a slot for the valueChanged() signal of the vertical scrollbar.
141           * \p value value of the scrollbar.
142         */
143         void scrollTo(int value);
144         /// timer to limit triple clicks
145         void doubleClickTimeout();
146         /// toggle the cursor's visibility
147         void toggleCursor();
148         /// close this work area.
149         /// Slot for Buffer::closing signal.
150         void close();
151
152 private:
153         friend class GuiCompleter;
154
155         /// update the passed area.
156         void update(int x, int y, int w, int h);
157         ///
158         void updateScreen();
159
160         /// paint the cursor and store the background
161         virtual void showCursor(int x, int y, int h,
162                 bool l_shape, bool rtl, bool completable);
163
164         /// hide the cursor
165         virtual void removeCursor();
166
167         /// This function is called when the buffer readonly status change.
168         void setReadOnly(bool);
169
170         /// Update window titles of all users.
171         void updateWindowTitle();
172         ///
173         bool event(QEvent *);
174         ///
175         void contextMenuEvent(QContextMenuEvent *);
176         ///
177         void focusInEvent(QFocusEvent *);
178         ///
179         void focusOutEvent(QFocusEvent *);
180         /// repaint part of the widget
181         void paintEvent(QPaintEvent * ev);
182         /// widget has been resized
183         void resizeEvent(QResizeEvent * ev);
184         /// mouse button press
185         void mousePressEvent(QMouseEvent * ev);
186         /// mouse button release
187         void mouseReleaseEvent(QMouseEvent * ev);
188         /// mouse double click of button
189         void mouseDoubleClickEvent(QMouseEvent * ev);
190         /// mouse motion
191         void mouseMoveEvent(QMouseEvent * ev);
192         /// wheel event
193         void wheelEvent(QWheelEvent * ev);
194         /// key press
195         void keyPressEvent(QKeyEvent * ev);
196         /// IM events
197         void inputMethodEvent(QInputMethodEvent * ev);
198         /// IM query
199         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
200
201         /// The slot connected to SyntheticMouseEvent::timeout.
202         void generateSyntheticMouseEvent();
203         ///
204         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
205         /// hide the visible cursor, if it is visible
206         void hideCursor();
207         /// show the cursor if it is not visible
208         void showCursor();
209         ///
210         void updateScrollbar();
211
212         ///
213         BufferView * buffer_view_;
214         ///
215         GuiView * lyx_view_;
216         /// is the cursor currently displayed
217         bool cursor_visible_;
218
219         ///
220         QTimer cursor_timeout_;
221         ///
222         SyntheticMouseEvent synthetic_mouse_event_;
223         ///
224         DoubleClick dc_event_;
225
226         ///
227         CursorWidget * cursor_;
228         ///
229         QPixmap screen_;
230         ///
231         bool need_resize_;
232         ///
233         bool schedule_redraw_;
234         ///
235         int preedit_lines_;
236
237         ///
238         GuiCompleter completer_;
239 }; // GuiWorkArea
240
241
242 /// A tabbed set of GuiWorkAreas.
243 class TabWorkArea : public QTabWidget
244 {
245         Q_OBJECT
246 public:
247         TabWorkArea(QWidget * parent = 0);
248
249         ///
250         void setFullScreen(bool full_screen);
251         void showBar(bool show);
252         void closeAll();
253         bool setCurrentWorkArea(GuiWorkArea *);
254         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
255         bool removeWorkArea(GuiWorkArea *);
256         GuiWorkArea * currentWorkArea();
257         GuiWorkArea * workArea(Buffer & buffer);
258
259 Q_SIGNALS:
260         ///
261         void currentWorkAreaChanged(GuiWorkArea *);
262         ///
263         void lastWorkAreaRemoved();
264
265 public Q_SLOTS:
266         /// close current buffer, or the one given by \c clicked_tab_
267         void closeCurrentBuffer();
268         /// close current tab, or the one given by \c clicked_tab_
269         void closeCurrentTab();
270         ///
271         void updateTabText(GuiWorkArea *);
272         
273 private Q_SLOTS:
274         ///
275         void on_currentTabChanged(int index);
276         ///
277         void showContextMenu(const QPoint & pos);
278         ///
279         void moveTab(int fromIndex, int toIndex);
280
281 private:
282         int clicked_tab_;
283 }; // TabWorkArea
284
285
286 class DragTabBar : public QTabBar
287 {
288         Q_OBJECT
289 public:
290         ///
291         DragTabBar(QWidget * parent=0);
292
293 #if QT_VERSION < 0x040300
294         ///
295         int tabAt(QPoint const & position) const;
296 #endif
297
298 protected:
299         ///
300         void mousePressEvent(QMouseEvent * event);
301         ///
302         void mouseMoveEvent(QMouseEvent * event);
303         ///
304         void dragEnterEvent(QDragEnterEvent * event);
305         ///
306         void dropEvent(QDropEvent * event);
307
308 private:
309         ///
310         QPoint dragStartPos_;
311         ///
312         int dragCurrentIndex_;
313
314 Q_SIGNALS:
315         ///
316         void tabMoveRequested(int fromIndex, int toIndex);
317 };
318
319 } // namespace frontend
320 } // namespace lyx
321
322 #endif // WORKAREA_H