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