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();
139 bool inDialogMode() { return dialog_mode_; }
140 void setDialogMode(bool mode) { dialog_mode_ = mode; }
143 GuiCompleter & completer() { return *completer_; }
146 /// Return the GuiView this workArea belongs to
147 GuiView const & view() const { return *lyx_view_; }
148 GuiView & view() { return *lyx_view_; }
152 void titleChanged(GuiWorkArea *);
155 /// Scroll the BufferView.
157 * This is a slot for the valueChanged() signal of the vertical scrollbar.
158 * \p value value of the scrollbar.
160 void scrollTo(int value);
161 /// timer to limit triple clicks
162 void doubleClickTimeout();
163 /// toggle the cursor's visibility
165 /// close this work area.
166 /// Slot for Buffer::closing signal.
168 /// Slot to restore proper scrollbar behaviour.
169 void fixVerticalScrollBar();
172 friend class GuiCompleter;
176 /// update the passed area.
177 void update(int x, int y, int w, int h);
181 /// paint the cursor and store the background
182 virtual void showCursor(int x, int y, int h,
183 bool l_shape, bool rtl, bool completable);
186 virtual void removeCursor();
188 /// This function is called when the buffer readonly status change.
189 void setReadOnly(bool);
191 /// Update window titles of all users.
192 void updateWindowTitle();
194 bool event(QEvent *);
196 void contextMenuEvent(QContextMenuEvent *);
198 void focusInEvent(QFocusEvent *);
200 void focusOutEvent(QFocusEvent *);
201 /// repaint part of the widget
202 void paintEvent(QPaintEvent * ev);
203 /// widget has been resized
204 void resizeEvent(QResizeEvent * ev);
205 /// mouse button press
206 void mousePressEvent(QMouseEvent * ev);
207 /// mouse button release
208 void mouseReleaseEvent(QMouseEvent * ev);
209 /// mouse double click of button
210 void mouseDoubleClickEvent(QMouseEvent * ev);
212 void mouseMoveEvent(QMouseEvent * ev);
214 void wheelEvent(QWheelEvent * ev);
216 void keyPressEvent(QKeyEvent * ev);
218 void inputMethodEvent(QInputMethodEvent * ev);
220 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
222 /// The slot connected to SyntheticMouseEvent::timeout.
223 void generateSyntheticMouseEvent();
225 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
226 /// hide the visible cursor, if it is visible
228 /// show the cursor if it is not visible
231 void updateScrollbar();
234 BufferView * buffer_view_;
237 /// is the cursor currently displayed
238 bool cursor_visible_;
241 QTimer cursor_timeout_;
243 SyntheticMouseEvent synthetic_mouse_event_;
245 DoubleClick dc_event_;
248 CursorWidget * cursor_;
254 bool schedule_redraw_;
259 GuiCompleter * completer_;
261 /// Special mode in which Esc and Enter (with or without Shift)
267 /// A tabbed set of GuiWorkAreas.
268 class TabWorkArea : public QTabWidget
272 TabWorkArea(QWidget * parent = 0);
275 void setFullScreen(bool full_screen);
276 void showBar(bool show);
278 bool setCurrentWorkArea(GuiWorkArea *);
279 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
280 bool removeWorkArea(GuiWorkArea *);
281 GuiWorkArea * currentWorkArea();
282 GuiWorkArea * workArea(Buffer & buffer);
286 void currentWorkAreaChanged(GuiWorkArea *);
288 void lastWorkAreaRemoved();
291 /// close current buffer, or the one given by \c clicked_tab_
292 void closeCurrentBuffer();
293 /// close current tab, or the one given by \c clicked_tab_
294 void closeCurrentTab();
296 void updateTabTexts();
300 void on_currentTabChanged(int index);
302 void showContextMenu(const QPoint & pos);
304 void moveTab(int fromIndex, int toIndex);
311 class DragTabBar : public QTabBar
316 DragTabBar(QWidget * parent = 0);
318 #if QT_VERSION < 0x040300
320 int tabAt(QPoint const & position) const;
325 void mousePressEvent(QMouseEvent * event);
327 void mouseMoveEvent(QMouseEvent * event);
329 void dragEnterEvent(QDragEnterEvent * event);
331 void dropEvent(QDropEvent * event);
335 QPoint dragStartPos_;
337 int dragCurrentIndex_;
341 void tabMoveRequested(int fromIndex, int toIndex);
344 } // namespace frontend