]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Merge branch 'master' of git.lyx.org:lyx
[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 "support/docstring.h"
19
20 #include <QAbstractScrollArea>
21 #include <QTabBar>
22 #include <QTabWidget>
23
24 class QDragEnterEvent;
25 class QDropEvent;
26 class QToolButton;
27 class QWidget;
28
29 #ifdef CursorShape
30 #undef CursorShape
31 #endif
32
33 namespace lyx {
34
35 class Buffer;
36
37 namespace frontend {
38
39 class GuiCompleter;
40 class GuiView;
41
42 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
43 {
44         Q_OBJECT
45
46 public:
47         ///
48         GuiWorkArea(QWidget *);
49         ///
50         GuiWorkArea(Buffer & buffer, GuiView & gv);
51         ///
52         ~GuiWorkArea();
53
54         ///
55         void init();
56         ///
57         void setBuffer(Buffer &);
58         ///
59         void setGuiView(GuiView &);
60         ///
61         void setFullScreen(bool full_screen);
62         /// is GuiView in fullscreen mode?
63         bool isFullScreen() const;
64         ///
65         void scheduleRedraw();
66         ///
67         BufferView & bufferView();
68         ///
69         BufferView const & bufferView() const;
70         ///
71         void redraw(bool update_metrics);
72
73         /// Process Key pressed event.
74         /// This needs to be public because it is accessed externally by GuiView.
75         void processKeySym(KeySymbol const & key, KeyModifier mod);
76
77         bool inDialogMode() const;
78         void setDialogMode(bool mode);
79
80         ///
81         GuiCompleter & completer();
82
83         Qt::CursorShape cursorShape() const;
84
85         /// Return the GuiView this workArea belongs to
86         GuiView const & view() const;
87         GuiView & view();
88
89 public Q_SLOTS:
90         ///
91         void stopBlinkingCursor();
92         ///
93         void startBlinkingCursor();
94
95 Q_SIGNALS:
96         ///
97         void titleChanged(GuiWorkArea *);
98         ///
99         void busy(bool);
100
101 private Q_SLOTS:
102         /// Scroll the BufferView.
103         /**
104           * This is a slot for the valueChanged() signal of the vertical scrollbar.
105           * \p value value of the scrollbar.
106         */
107         void scrollTo(int value);
108         /// timer to limit triple clicks
109         void doubleClickTimeout();
110         /// toggle the cursor's visibility
111         void toggleCursor();
112         /// close this work area.
113         /// Slot for Buffer::closing signal.
114         void close();
115         /// Slot to restore proper scrollbar behaviour.
116         void fixVerticalScrollBar();
117
118 private:
119         /// Update window titles of all users.
120         void updateWindowTitle();
121         ///
122         bool event(QEvent *);
123         ///
124         void contextMenuEvent(QContextMenuEvent *);
125         ///
126         void focusInEvent(QFocusEvent *);
127         ///
128         void focusOutEvent(QFocusEvent *);
129         /// repaint part of the widget
130         void paintEvent(QPaintEvent * ev);
131         /// widget has been resized
132         void resizeEvent(QResizeEvent * ev);
133         /// mouse button press
134         void mousePressEvent(QMouseEvent * ev);
135         /// mouse button release
136         void mouseReleaseEvent(QMouseEvent * ev);
137         /// mouse double click of button
138         void mouseDoubleClickEvent(QMouseEvent * ev);
139         /// mouse motion
140         void mouseMoveEvent(QMouseEvent * ev);
141         /// wheel event
142         void wheelEvent(QWheelEvent * ev);
143         /// key press
144         void keyPressEvent(QKeyEvent * ev);
145         /// IM events
146         void inputMethodEvent(QInputMethodEvent * ev);
147         /// IM query
148         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
149
150         /// The slot connected to SyntheticMouseEvent::timeout.
151         void generateSyntheticMouseEvent();
152
153         friend class GuiCompleter;
154         struct Private;
155         Private * const d;
156 }; // GuiWorkArea
157
158
159 class EmbeddedWorkArea : public GuiWorkArea
160 {
161         Q_OBJECT
162 public:
163         ///
164         EmbeddedWorkArea(QWidget *);
165         ~EmbeddedWorkArea();
166
167         /// Dummy methods for Designer.
168         void setWidgetResizable(bool) {}
169         void setWidget(QWidget *) {}
170
171         QSize sizeHint () const;
172         ///
173         void disable();
174
175 protected:
176         ///
177         void closeEvent(QCloseEvent * ev);
178         ///
179         void hideEvent(QHideEvent *ev);
180
181 private:
182         /// Embedded Buffer.
183         Buffer * buffer_;
184 }; // EmbeddedWorkArea
185
186
187 /// A tabbed set of GuiWorkAreas.
188 class TabWorkArea : public QTabWidget
189 {
190         Q_OBJECT
191 public:
192         TabWorkArea(QWidget * parent = 0);
193
194         ///
195         void setFullScreen(bool full_screen);
196         void showBar(bool show);
197         void closeAll();
198         bool setCurrentWorkArea(GuiWorkArea *);
199         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
200         bool removeWorkArea(GuiWorkArea *);
201         GuiWorkArea * currentWorkArea();
202         GuiWorkArea * workArea(Buffer & buffer);
203         GuiWorkArea * workArea(int index);
204         void paintEvent(QPaintEvent *);
205
206 Q_SIGNALS:
207         ///
208         void currentWorkAreaChanged(GuiWorkArea *);
209         ///
210         void lastWorkAreaRemoved();
211
212 public Q_SLOTS:
213         /// close current buffer, or the one given by \c clicked_tab_
214         void closeCurrentBuffer();
215         /// hide current tab, or the one given by \c clicked_tab_
216         void hideCurrentTab();
217         /// close the tab given by \c index
218         void closeTab(int index);
219         ///
220         void updateTabTexts();
221         
222 private Q_SLOTS:
223         ///
224         void on_currentTabChanged(int index);
225         ///
226         void showContextMenu(const QPoint & pos);
227         ///
228         void moveTab(int fromIndex, int toIndex);
229         ///
230         void mouseDoubleClickEvent(QMouseEvent * event);
231
232 private:
233         ///
234         int clicked_tab_;
235         ///
236         QToolButton * closeBufferButton;
237 }; // TabWorkArea
238
239
240 class DragTabBar : public QTabBar
241 {
242         Q_OBJECT
243 public:
244         ///
245         DragTabBar(QWidget * parent = 0);
246
247 protected:
248         ///
249         void mousePressEvent(QMouseEvent * event);
250         ///
251         void mouseMoveEvent(QMouseEvent * event);
252         ///
253         void dragEnterEvent(QDragEnterEvent * event);
254         ///
255         void dropEvent(QDropEvent * event);
256
257 private:
258         ///
259         QPoint dragStartPos_;
260         ///
261         int dragCurrentIndex_;
262
263 Q_SIGNALS:
264         ///
265         void tabMoveRequested(int fromIndex, int toIndex);
266 };
267
268 } // namespace frontend
269 } // namespace lyx
270
271 #endif // WORKAREA_H