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();
92 * Implementation of the work area (buffer view GUI)
96 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
102 GuiWorkArea(QWidget *);
104 GuiWorkArea(Buffer & buffer, GuiView & gv);
111 void setBuffer(Buffer &);
113 void setGuiView(GuiView &);
115 void setFullScreen(bool full_screen);
116 /// is GuiView in fullscreen mode?
119 void scheduleRedraw() { schedule_redraw_ = true; }
121 BufferView & bufferView();
123 BufferView const & bufferView() const;
125 void redraw(bool update_metrics);
127 void stopBlinkingCursor();
129 void startBlinkingCursor();
130 /// Process Key pressed event.
131 /// This needs to be public because it is accessed externally by GuiView.
132 void processKeySym(KeySymbol const & key, KeyModifier mod);
134 void resizeBufferView();
136 bool inDialogMode() const { return dialog_mode_; }
137 void setDialogMode(bool mode) { dialog_mode_ = mode; }
140 GuiCompleter & completer() { return *completer_; }
142 Qt::CursorShape cursorShape() const;
143 void setCursorShape(Qt::CursorShape shape);
145 /// Change the cursor when the mouse hovers over a clickable inset
146 void updateCursorShape();
148 /// Return the GuiView this workArea belongs to
149 GuiView const & view() const { return *lyx_view_; }
150 GuiView & view() { return *lyx_view_; }
154 void titleChanged(GuiWorkArea *);
157 /// Scroll the BufferView.
159 * This is a slot for the valueChanged() signal of the vertical scrollbar.
160 * \p value value of the scrollbar.
162 void scrollTo(int value);
163 /// timer to limit triple clicks
164 void doubleClickTimeout();
165 /// toggle the cursor's visibility
167 /// close this work area.
168 /// Slot for Buffer::closing signal.
170 /// Slot to restore proper scrollbar behaviour.
171 void fixVerticalScrollBar();
174 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 should be called to update the buffer readonly status.
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_;
235 /// Read only Buffer status cache.
239 /// is the cursor currently displayed
240 bool cursor_visible_;
243 QTimer cursor_timeout_;
245 SyntheticMouseEvent synthetic_mouse_event_;
247 DoubleClick dc_event_;
250 CursorWidget * cursor_;
256 bool schedule_redraw_;
261 GuiCompleter * completer_;
263 /// Special mode in which Esc and Enter (with or without Shift)
266 /// store the position of the rightclick when the mouse is
267 /// pressed. This is used to get the correct context menu
268 /// when the menu is actually shown (after releasing on Windwos).
269 QPoint context_target_pos_;
273 class EmbeddedWorkArea : public GuiWorkArea
278 EmbeddedWorkArea(QWidget *);
281 /// Dummy methods for Designer.
282 void setWidgetResizable(bool) {}
283 void setWidget(QWidget *) {}
285 QSize sizeHint () const;
291 void closeEvent(QCloseEvent * ev);
293 void hideEvent(QHideEvent *ev);
298 }; // EmbeddedWorkArea
301 /// A tabbed set of GuiWorkAreas.
302 class TabWorkArea : public QTabWidget
306 TabWorkArea(QWidget * parent = 0);
309 void setFullScreen(bool full_screen);
310 void showBar(bool show);
312 bool setCurrentWorkArea(GuiWorkArea *);
313 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
314 bool removeWorkArea(GuiWorkArea *);
315 GuiWorkArea * currentWorkArea();
316 GuiWorkArea * workArea(Buffer & buffer);
317 GuiWorkArea * workArea(int index);
321 void currentWorkAreaChanged(GuiWorkArea *);
323 void lastWorkAreaRemoved();
326 /// close current buffer, or the one given by \c clicked_tab_
327 void closeCurrentBuffer();
328 /// hide current tab, or the one given by \c clicked_tab_
329 void hideCurrentTab();
330 /// close the tab given by \c index
331 void closeTab(int index);
333 void updateTabTexts();
337 void on_currentTabChanged(int index);
339 void showContextMenu(const QPoint & pos);
341 void moveTab(int fromIndex, int toIndex);
343 void mouseDoubleClickEvent(QMouseEvent * event);
349 QToolButton * closeBufferButton;
353 class DragTabBar : public QTabBar
358 DragTabBar(QWidget * parent = 0);
360 #if QT_VERSION < 0x040300
362 int tabAt(QPoint const & position) const;
367 void mousePressEvent(QMouseEvent * event);
369 void mouseMoveEvent(QMouseEvent * event);
371 void dragEnterEvent(QDragEnterEvent * event);
373 void dropEvent(QDropEvent * event);
377 QPoint dragStartPos_;
379 int dragCurrentIndex_;
383 void tabMoveRequested(int fromIndex, int toIndex);
386 } // namespace frontend