4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
16 #include "frontends/WorkArea.h"
18 #include "DocIterator.h"
19 #include "FuncRequest.h"
20 #include "qt_helpers.h"
21 #include "support/docstring.h"
22 #include "support/Timeout.h"
24 #include <QAbstractScrollArea>
25 #include <QMouseEvent>
27 #include <QResizeEvent>
32 class QContextMenuEvent;
33 class QDragEnterEvent;
54 /// for emulating triple click
58 DoubleClick() : state(Qt::NoButton), active(false) {}
60 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
62 bool operator==(QMouseEvent const & e) { return state == e.button(); }
66 Qt::MouseButton state;
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.
77 * This class stores all the parameters needed to make this happen.
79 class SyntheticMouseEvent
82 SyntheticMouseEvent();
89 double scrollbar_value_old;
94 * Implementation of the work area (buffer view GUI)
98 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
104 GuiWorkArea(QWidget *);
106 GuiWorkArea(Buffer & buffer, GuiView & gv);
111 void setBuffer(Buffer &);
113 void setGuiView(GuiView &);
114 /// Dummy methods for Designer.
115 void setWidgetResizable(bool) {}
116 void setWidget(QWidget *) {}
118 void setFullScreen(bool full_screen);
119 /// is LyXView in fullscreen mode?
122 void scheduleRedraw() { schedule_redraw_ = true; }
124 BufferView & bufferView();
126 BufferView const & bufferView() const;
130 void stopBlinkingCursor();
132 void startBlinkingCursor();
133 /// Process Key pressed event.
134 /// This needs to be public because it is accessed externally by GuiView.
135 void processKeySym(KeySymbol const & key, KeyModifier mod);
137 void resizeBufferView();
144 GuiCompleter & completer() { return *completer_; }
146 /// Return true if dialogMode is set
147 bool& dialogMode() { return dialogMode_; }
149 /// Return the GuiView this workArea belongs to
150 GuiView const & view() const { return *lyx_view_; }
151 GuiView & view() { return *lyx_view_; }
155 void titleChanged(GuiWorkArea *);
158 /// Scroll the BufferView.
160 * This is a slot for the valueChanged() signal of the vertical scrollbar.
161 * \p value value of the scrollbar.
163 void scrollTo(int value);
164 /// timer to limit triple clicks
165 void doubleClickTimeout();
166 /// toggle the cursor's visibility
168 /// close this work area.
169 /// Slot for Buffer::closing signal.
171 /// Slot to restore proper scrollbar behaviour.
172 void fixVerticalScrollBar();
175 friend class GuiCompleter;
179 /// update the passed area.
180 void update(int x, int y, int w, int h);
184 /// paint the cursor and store the background
185 virtual void showCursor(int x, int y, int h,
186 bool l_shape, bool rtl, bool completable);
189 virtual void removeCursor();
191 /// This function is called when the buffer readonly status change.
192 void setReadOnly(bool);
194 /// Update window titles of all users.
195 void updateWindowTitle();
197 bool event(QEvent *);
199 void contextMenuEvent(QContextMenuEvent *);
201 void focusInEvent(QFocusEvent *);
203 void focusOutEvent(QFocusEvent *);
204 /// repaint part of the widget
205 void paintEvent(QPaintEvent * ev);
206 /// widget has been resized
207 void resizeEvent(QResizeEvent * ev);
208 /// mouse button press
209 void mousePressEvent(QMouseEvent * ev);
210 /// mouse button release
211 void mouseReleaseEvent(QMouseEvent * ev);
212 /// mouse double click of button
213 void mouseDoubleClickEvent(QMouseEvent * ev);
215 void mouseMoveEvent(QMouseEvent * ev);
217 void wheelEvent(QWheelEvent * ev);
219 void keyPressEvent(QKeyEvent * ev);
221 void inputMethodEvent(QInputMethodEvent * ev);
223 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
225 /// The slot connected to SyntheticMouseEvent::timeout.
226 void generateSyntheticMouseEvent();
228 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
229 /// hide the visible cursor, if it is visible
231 /// show the cursor if it is not visible
234 void updateScrollbar();
237 BufferView * buffer_view_;
240 /// is the cursor currently displayed
241 bool cursor_visible_;
244 QTimer cursor_timeout_;
246 SyntheticMouseEvent synthetic_mouse_event_;
248 DoubleClick dc_event_;
251 CursorWidget * cursor_;
257 bool schedule_redraw_;
262 GuiCompleter * completer_;
264 /// Special mode in which Esc and Enter (with or without Shift)
270 /// A tabbed set of GuiWorkAreas.
271 class TabWorkArea : public QTabWidget
275 TabWorkArea(QWidget * parent = 0);
278 void setFullScreen(bool full_screen);
279 void showBar(bool show);
281 bool setCurrentWorkArea(GuiWorkArea *);
282 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
283 bool removeWorkArea(GuiWorkArea *);
284 GuiWorkArea * currentWorkArea();
285 GuiWorkArea * workArea(Buffer & buffer);
289 void currentWorkAreaChanged(GuiWorkArea *);
291 void lastWorkAreaRemoved();
294 /// close current buffer, or the one given by \c clicked_tab_
295 void closeCurrentBuffer();
296 /// close current tab, or the one given by \c clicked_tab_
297 void closeCurrentTab();
299 void updateTabTexts();
303 void on_currentTabChanged(int index);
305 void showContextMenu(const QPoint & pos);
307 void moveTab(int fromIndex, int toIndex);
314 class DragTabBar : public QTabBar
319 DragTabBar(QWidget * parent = 0);
321 #if QT_VERSION < 0x040300
323 int tabAt(QPoint const & position) const;
328 void mousePressEvent(QMouseEvent * event);
330 void mouseMoveEvent(QMouseEvent * event);
332 void dragEnterEvent(QDragEnterEvent * event);
334 void dropEvent(QDropEvent * event);
338 QPoint dragStartPos_;
340 int dragCurrentIndex_;
344 void tabMoveRequested(int fromIndex, int toIndex);
347 } // namespace frontend