]> git.lyx.org Git - lyx.git/blob - src/frontends/qt4/GuiWorkArea.h
Amend f441590c
[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         /// Current ratio between physical pixels and device-independent pixels
88         double pixelRatio() const;
89
90 public Q_SLOTS:
91         ///
92         void stopBlinkingCursor();
93         ///
94         void startBlinkingCursor();
95
96 Q_SIGNALS:
97         ///
98         void titleChanged(GuiWorkArea *);
99         ///
100         void busy(bool);
101
102 private Q_SLOTS:
103         /// Scroll the BufferView.
104         /**
105           * This is a slot for the valueChanged() signal of the vertical scrollbar.
106           * \p value value of the scrollbar.
107         */
108         void scrollTo(int value);
109         /// timer to limit triple clicks
110         void doubleClickTimeout();
111         /// toggle the cursor's visibility
112         void toggleCursor();
113         /// close this work area.
114         /// Slot for Buffer::closing signal.
115         void close();
116         /// Slot to restore proper scrollbar behaviour.
117         void fixVerticalScrollBar();
118
119 private:
120         /// Update window titles of all users.
121         void updateWindowTitle();
122         ///
123         bool event(QEvent *);
124         ///
125         void contextMenuEvent(QContextMenuEvent *);
126         ///
127         void focusInEvent(QFocusEvent *);
128         ///
129         void focusOutEvent(QFocusEvent *);
130         /// repaint part of the widget
131         void paintEvent(QPaintEvent * ev);
132         /// widget has been resized
133         void resizeEvent(QResizeEvent * ev);
134         /// mouse button press
135         void mousePressEvent(QMouseEvent * ev);
136         /// mouse button release
137         void mouseReleaseEvent(QMouseEvent * ev);
138         /// mouse double click of button
139         void mouseDoubleClickEvent(QMouseEvent * ev);
140         /// mouse motion
141         void mouseMoveEvent(QMouseEvent * ev);
142         /// wheel event
143         void wheelEvent(QWheelEvent * ev);
144         /// key press
145         void keyPressEvent(QKeyEvent * ev);
146         /// IM events
147         void inputMethodEvent(QInputMethodEvent * ev);
148         /// IM query
149         QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
150
151         /// The slot connected to SyntheticMouseEvent::timeout.
152         void generateSyntheticMouseEvent();
153
154         friend class GuiCompleter;
155         struct Private;
156         Private * const d;
157 }; // GuiWorkArea
158
159
160 class EmbeddedWorkArea : public GuiWorkArea
161 {
162         Q_OBJECT
163 public:
164         ///
165         EmbeddedWorkArea(QWidget *);
166         ~EmbeddedWorkArea();
167
168         /// Dummy methods for Designer.
169         void setWidgetResizable(bool) {}
170         void setWidget(QWidget *) {}
171
172         QSize sizeHint () const;
173         ///
174         void disable();
175
176 protected:
177         ///
178         void closeEvent(QCloseEvent * ev);
179         ///
180         void hideEvent(QHideEvent *ev);
181
182 private:
183         /// Embedded Buffer.
184         Buffer * buffer_;
185 }; // EmbeddedWorkArea
186
187
188 /// A tabbed set of GuiWorkAreas.
189 class TabWorkArea : public QTabWidget
190 {
191         Q_OBJECT
192 public:
193         TabWorkArea(QWidget * parent = 0);
194
195         ///
196         void setFullScreen(bool full_screen);
197         void showBar(bool show);
198         void closeAll();
199         bool setCurrentWorkArea(GuiWorkArea *);
200         GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
201         bool removeWorkArea(GuiWorkArea *);
202         GuiWorkArea * currentWorkArea();
203         GuiWorkArea * workArea(Buffer & buffer);
204         GuiWorkArea * workArea(int index);
205         void paintEvent(QPaintEvent *);
206
207 Q_SIGNALS:
208         ///
209         void currentWorkAreaChanged(GuiWorkArea *);
210         ///
211         void lastWorkAreaRemoved();
212
213 public Q_SLOTS:
214         /// close current buffer, or the one given by \c clicked_tab_
215         void closeCurrentBuffer();
216         /// hide current tab, or the one given by \c clicked_tab_
217         void hideCurrentTab();
218         /// close the tab given by \c index
219         void closeTab(int index);
220         ///
221         void moveTab(int fromIndex, int toIndex);
222         ///
223         void updateTabTexts();
224         
225 private Q_SLOTS:
226         ///
227         void on_currentTabChanged(int index);
228         ///
229         void showContextMenu(const QPoint & pos);
230         ///
231         void mouseDoubleClickEvent(QMouseEvent * event);
232
233 private:
234         ///
235         int clicked_tab_;
236         ///
237         QToolButton * closeBufferButton;
238 }; // TabWorkArea
239
240
241 class DragTabBar : public QTabBar
242 {
243         Q_OBJECT
244 public:
245         ///
246         DragTabBar(QWidget * parent = 0);
247
248 protected:
249         ///
250         void mousePressEvent(QMouseEvent * event);
251         ///
252         void mouseMoveEvent(QMouseEvent * event);
253         ///
254         void dragEnterEvent(QDragEnterEvent * event);
255         ///
256         void dropEvent(QDropEvent * event);
257
258 private:
259         ///
260         QPoint dragStartPos_;
261
262 Q_SIGNALS:
263         ///
264         void tabMoveRequested(int fromIndex, int toIndex);
265 };
266
267 } // namespace frontend
268 } // namespace lyx
269
270 #endif // WORKAREA_H