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