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