]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Create a new EmbeddedWorkArea for dialog embedding purpose and use that in FindAndRep...
[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 QWidget;
39
40 #ifdef CursorShape
41 #undef CursorShape
42 #endif
43
44 namespace lyx {
45
46 class Buffer;
47
48 namespace frontend {
49
50 class GuiCompleter;
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(QWidget *);
105         ///
106         GuiWorkArea(Buffer & buffer, GuiView & gv);
107         ///
108         ~GuiWorkArea();
109
110         ///
111         void init();
112         ///
113         void setBuffer(Buffer &);
114         ///
115         void setGuiView(GuiView &);
116         ///
117         void setFullScreen(bool full_screen);
118         /// is LyXView in fullscreen mode?
119         bool isFullScreen();
120         ///
121         void scheduleRedraw() { schedule_redraw_ = true; }
122         ///
123         BufferView & bufferView();
124         ///
125         BufferView const & bufferView() const;
126         ///
127         void redraw();
128         ///
129         void stopBlinkingCursor();
130         ///
131         void startBlinkingCursor();
132         /// Process Key pressed event.
133         /// This needs to be public because it is accessed externally by GuiView.
134         void processKeySym(KeySymbol const & key, KeyModifier mod);
135         ///
136         void resizeBufferView();
137
138         bool inDialogMode() const { return dialog_mode_; }
139         void setDialogMode(bool mode) { dialog_mode_ = mode; }
140
141         ///
142         GuiCompleter & completer() { return *completer_; }
143
144
145         /// Return the GuiView this workArea belongs to
146         GuiView const & view() const { return *lyx_view_; }
147         GuiView & view() { return *lyx_view_; }
148
149 Q_SIGNALS:
150         ///
151         void titleChanged(GuiWorkArea *);
152
153 private Q_SLOTS:
154         /// Scroll the BufferView.
155         /**
156           * This is a slot for the valueChanged() signal of the vertical scrollbar.
157           * \p value value of the scrollbar.
158         */
159         void scrollTo(int value);
160         /// timer to limit triple clicks
161         void doubleClickTimeout();
162         /// toggle the cursor's visibility
163         void toggleCursor();
164         /// close this work area.
165         /// Slot for Buffer::closing signal.
166         void close();
167         /// Slot to restore proper scrollbar behaviour.
168         void fixVerticalScrollBar();
169
170 private:
171         friend class GuiCompleter;
172
173         /// update the passed area.
174         void update(int x, int y, int w, int h);
175         ///
176         void updateScreen();
177
178         /// paint the cursor and store the background
179         virtual void showCursor(int x, int y, int h,
180                 bool l_shape, bool rtl, bool completable);
181
182         /// hide the cursor
183         virtual void removeCursor();
184
185         /// This function is called when the buffer readonly status change.
186         void setReadOnly(bool);
187
188         /// Update window titles of all users.
189         void updateWindowTitle();
190         ///
191         bool event(QEvent *);
192         ///
193         void contextMenuEvent(QContextMenuEvent *);
194         ///
195         void focusInEvent(QFocusEvent *);
196         ///
197         void focusOutEvent(QFocusEvent *);
198         /// repaint part of the widget
199         void paintEvent(QPaintEvent * ev);
200         /// widget has been resized
201         void resizeEvent(QResizeEvent * ev);
202         /// mouse button press
203         void mousePressEvent(QMouseEvent * ev);
204         /// mouse button release
205         void mouseReleaseEvent(QMouseEvent * ev);
206         /// mouse double click of button
207         void mouseDoubleClickEvent(QMouseEvent * ev);
208         /// mouse motion
209         void mouseMoveEvent(QMouseEvent * ev);
210         /// wheel event
211         void wheelEvent(QWheelEvent * ev);
212         /// key press
213         void keyPressEvent(QKeyEvent * ev);
214         /// IM events
215         void inputMethodEvent(QInputMethodEvent * ev);
216         /// IM query
217         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
218
219         /// The slot connected to SyntheticMouseEvent::timeout.
220         void generateSyntheticMouseEvent();
221         ///
222         void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
223         /// hide the visible cursor, if it is visible
224         void hideCursor();
225         /// show the cursor if it is not visible
226         void showCursor();
227         ///
228         void updateScrollbar();
229
230         ///
231         BufferView * buffer_view_;
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 }; // GuiWorkArea
262
263
264 class EmbeddedWorkArea : public GuiWorkArea
265 {
266         Q_OBJECT
267 public:
268         ///
269         EmbeddedWorkArea(QWidget *);
270         ~EmbeddedWorkArea();
271
272         /// Dummy methods for Designer.
273         void setWidgetResizable(bool) {}
274         void setWidget(QWidget *) {}
275
276 private:
277         /// Embedded Buffer.
278         Buffer * buffer_;
279 }; // EmbeddedWorkArea
280
281
282 /// A tabbed set of GuiWorkAreas.
283 class TabWorkArea : public QTabWidget
284 {
285         Q_OBJECT
286 public:
287         TabWorkArea(QWidget * parent = 0);
288
289         ///
290         void setFullScreen(bool full_screen);
291         void showBar(bool show);
292         void closeAll();
293         bool setCurrentWorkArea(GuiWorkArea *);
294         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
295         bool removeWorkArea(GuiWorkArea *);
296         GuiWorkArea * currentWorkArea();
297         GuiWorkArea * workArea(Buffer & buffer);
298
299 Q_SIGNALS:
300         ///
301         void currentWorkAreaChanged(GuiWorkArea *);
302         ///
303         void lastWorkAreaRemoved();
304
305 public Q_SLOTS:
306         /// close current buffer, or the one given by \c clicked_tab_
307         void closeCurrentBuffer();
308         /// close current tab, or the one given by \c clicked_tab_
309         void closeCurrentTab();
310         ///
311         void updateTabTexts();
312         
313 private Q_SLOTS:
314         ///
315         void on_currentTabChanged(int index);
316         ///
317         void showContextMenu(const QPoint & pos);
318         ///
319         void moveTab(int fromIndex, int toIndex);
320
321 private:
322         int clicked_tab_;
323 }; // TabWorkArea
324
325
326 class DragTabBar : public QTabBar
327 {
328         Q_OBJECT
329 public:
330         ///
331         DragTabBar(QWidget * parent = 0);
332
333 #if QT_VERSION < 0x040300
334         ///
335         int tabAt(QPoint const & position) const;
336 #endif
337
338 protected:
339         ///
340         void mousePressEvent(QMouseEvent * event);
341         ///
342         void mouseMoveEvent(QMouseEvent * event);
343         ///
344         void dragEnterEvent(QDragEnterEvent * event);
345         ///
346         void dropEvent(QDropEvent * event);
347
348 private:
349         ///
350         QPoint dragStartPos_;
351         ///
352         int dragCurrentIndex_;
353
354 Q_SIGNALS:
355         ///
356         void tabMoveRequested(int fromIndex, int toIndex);
357 };
358
359 } // namespace frontend
360 } // namespace lyx
361
362 #endif // WORKAREA_H