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;
55 /// for emulating triple click
59 DoubleClick() : state(Qt::NoButton), active(false) {}
61 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
63 bool operator==(QMouseEvent const & e) { return state == e.button(); }
67 Qt::MouseButton state;
72 /** Qt only emits mouse events when the mouse is being moved, but
73 * we want to generate 'pseudo' mouse events when the mouse button is
74 * pressed and the mouse cursor is below the bottom, or above the top
75 * of the work area. In this way, we'll be able to continue scrolling
76 * (and selecting) the text.
78 * This class stores all the parameters needed to make this happen.
80 class SyntheticMouseEvent
83 SyntheticMouseEvent();
90 double scrollbar_value_old;
95 * Implementation of the work area (buffer view GUI)
99 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
105 GuiWorkArea(QWidget *);
107 GuiWorkArea(Buffer & buffer, GuiView & gv);
114 void setBuffer(Buffer &);
116 void setGuiView(GuiView &);
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() const { 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;
174 /// update the passed area.
175 void update(int x, int y, int w, int h);
179 /// paint the cursor and store the background
180 virtual void showCursor(int x, int y, int h,
181 bool l_shape, bool rtl, bool completable);
184 virtual void removeCursor();
186 /// This function is called when the buffer readonly status change.
187 void setReadOnly(bool);
189 /// Update window titles of all users.
190 void updateWindowTitle();
192 bool event(QEvent *);
194 void contextMenuEvent(QContextMenuEvent *);
196 void focusInEvent(QFocusEvent *);
198 void focusOutEvent(QFocusEvent *);
199 /// repaint part of the widget
200 void paintEvent(QPaintEvent * ev);
201 /// widget has been resized
202 void resizeEvent(QResizeEvent * ev);
203 /// mouse button press
204 void mousePressEvent(QMouseEvent * ev);
205 /// mouse button release
206 void mouseReleaseEvent(QMouseEvent * ev);
207 /// mouse double click of button
208 void mouseDoubleClickEvent(QMouseEvent * ev);
210 void mouseMoveEvent(QMouseEvent * ev);
212 void wheelEvent(QWheelEvent * ev);
214 void keyPressEvent(QKeyEvent * ev);
216 void inputMethodEvent(QInputMethodEvent * ev);
218 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
220 /// The slot connected to SyntheticMouseEvent::timeout.
221 void generateSyntheticMouseEvent();
223 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
224 /// hide the visible cursor, if it is visible
226 /// show the cursor if it is not visible
229 void updateScrollbar();
232 BufferView * buffer_view_;
235 /// is the cursor currently displayed
236 bool cursor_visible_;
239 QTimer cursor_timeout_;
241 SyntheticMouseEvent synthetic_mouse_event_;
243 DoubleClick dc_event_;
246 CursorWidget * cursor_;
252 bool schedule_redraw_;
257 GuiCompleter * completer_;
259 /// Special mode in which Esc and Enter (with or without Shift)
265 class EmbeddedWorkArea : public GuiWorkArea
270 EmbeddedWorkArea(QWidget *);
273 /// Dummy methods for Designer.
274 void setWidgetResizable(bool) {}
275 void setWidget(QWidget *) {}
282 void closeEvent(QCloseEvent * ev);
284 void hideEvent(QHideEvent *ev);
289 }; // EmbeddedWorkArea
292 /// A tabbed set of GuiWorkAreas.
293 class TabWorkArea : public QTabWidget
297 TabWorkArea(QWidget * parent = 0);
300 void setFullScreen(bool full_screen);
301 void showBar(bool show);
303 bool setCurrentWorkArea(GuiWorkArea *);
304 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
305 bool removeWorkArea(GuiWorkArea *);
306 GuiWorkArea * currentWorkArea();
307 GuiWorkArea * workArea(Buffer & buffer);
311 void currentWorkAreaChanged(GuiWorkArea *);
313 void lastWorkAreaRemoved();
316 /// close current buffer, or the one given by \c clicked_tab_
317 void closeCurrentBuffer();
318 /// close current tab, or the one given by \c clicked_tab_
319 void closeCurrentTab();
321 void updateTabTexts();
325 void on_currentTabChanged(int index);
327 void showContextMenu(const QPoint & pos);
329 void moveTab(int fromIndex, int toIndex);
335 QToolButton * closeBufferButton;
339 class DragTabBar : public QTabBar
344 DragTabBar(QWidget * parent = 0);
346 #if QT_VERSION < 0x040300
348 int tabAt(QPoint const & position) const;
353 void mousePressEvent(QMouseEvent * event);
355 void mouseMoveEvent(QMouseEvent * event);
357 void dragEnterEvent(QDragEnterEvent * event);
359 void dropEvent(QDropEvent * event);
363 QPoint dragStartPos_;
365 int dragCurrentIndex_;
369 void tabMoveRequested(int fromIndex, int toIndex);
372 } // namespace frontend