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);
113 void setBuffer(Buffer &);
115 void setGuiView(GuiView &);
117 void setFullScreen(bool full_screen);
118 /// is LyXView in fullscreen mode?
121 void scheduleRedraw() { schedule_redraw_ = true; }
123 BufferView & bufferView();
125 BufferView const & bufferView() const;
129 void stopBlinkingCursor();
131 void startBlinkingCursor();
132 /// Process Key pressed event.
133 /// This needs to be public because it is accessed externally by GuiView.
134 void processKeySym(KeySymbol const & key, KeyModifier mod);
136 void resizeBufferView();
138 bool inDialogMode() const { return dialog_mode_; }
139 void setDialogMode(bool mode) { dialog_mode_ = mode; }
142 GuiCompleter & completer() { return *completer_; }
145 /// Return the GuiView this workArea belongs to
146 GuiView const & view() const { return *lyx_view_; }
147 GuiView & view() { return *lyx_view_; }
151 void titleChanged(GuiWorkArea *);
154 /// Scroll the BufferView.
156 * This is a slot for the valueChanged() signal of the vertical scrollbar.
157 * \p value value of the scrollbar.
159 void scrollTo(int value);
160 /// timer to limit triple clicks
161 void doubleClickTimeout();
162 /// toggle the cursor's visibility
164 /// close this work area.
165 /// Slot for Buffer::closing signal.
167 /// Slot to restore proper scrollbar behaviour.
168 void fixVerticalScrollBar();
171 friend class GuiCompleter;
173 /// update the passed area.
174 void update(int x, int y, int w, int h);
178 /// paint the cursor and store the background
179 virtual void showCursor(int x, int y, int h,
180 bool l_shape, bool rtl, bool completable);
183 virtual void removeCursor();
185 /// This function is called when the buffer readonly status change.
186 void setReadOnly(bool);
188 /// Update window titles of all users.
189 void updateWindowTitle();
191 bool event(QEvent *);
193 void contextMenuEvent(QContextMenuEvent *);
195 void focusInEvent(QFocusEvent *);
197 void focusOutEvent(QFocusEvent *);
198 /// repaint part of the widget
199 void paintEvent(QPaintEvent * ev);
200 /// widget has been resized
201 void resizeEvent(QResizeEvent * ev);
202 /// mouse button press
203 void mousePressEvent(QMouseEvent * ev);
204 /// mouse button release
205 void mouseReleaseEvent(QMouseEvent * ev);
206 /// mouse double click of button
207 void mouseDoubleClickEvent(QMouseEvent * ev);
209 void mouseMoveEvent(QMouseEvent * ev);
211 void wheelEvent(QWheelEvent * ev);
213 void keyPressEvent(QKeyEvent * ev);
215 void inputMethodEvent(QInputMethodEvent * ev);
217 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
219 /// The slot connected to SyntheticMouseEvent::timeout.
220 void generateSyntheticMouseEvent();
222 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
223 /// hide the visible cursor, if it is visible
225 /// show the cursor if it is not visible
228 void updateScrollbar();
231 BufferView * buffer_view_;
234 /// is the cursor currently displayed
235 bool cursor_visible_;
238 QTimer cursor_timeout_;
240 SyntheticMouseEvent synthetic_mouse_event_;
242 DoubleClick dc_event_;
245 CursorWidget * cursor_;
251 bool schedule_redraw_;
256 GuiCompleter * completer_;
258 /// Special mode in which Esc and Enter (with or without Shift)
264 class EmbeddedWorkArea : public GuiWorkArea
269 EmbeddedWorkArea(QWidget *);
272 /// Dummy methods for Designer.
273 void setWidgetResizable(bool) {}
274 void setWidget(QWidget *) {}
281 void closeEvent(QCloseEvent * ev);
283 void hideEvent(QHideEvent *ev);
288 }; // EmbeddedWorkArea
291 /// A tabbed set of GuiWorkAreas.
292 class TabWorkArea : public QTabWidget
296 TabWorkArea(QWidget * parent = 0);
299 void setFullScreen(bool full_screen);
300 void showBar(bool show);
302 bool setCurrentWorkArea(GuiWorkArea *);
303 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
304 bool removeWorkArea(GuiWorkArea *);
305 GuiWorkArea * currentWorkArea();
306 GuiWorkArea * workArea(Buffer & buffer);
310 void currentWorkAreaChanged(GuiWorkArea *);
312 void lastWorkAreaRemoved();
315 /// close current buffer, or the one given by \c clicked_tab_
316 void closeCurrentBuffer();
317 /// close current tab, or the one given by \c clicked_tab_
318 void closeCurrentTab();
320 void updateTabTexts();
324 void on_currentTabChanged(int index);
326 void showContextMenu(const QPoint & pos);
328 void moveTab(int fromIndex, int toIndex);
335 class DragTabBar : public QTabBar
340 DragTabBar(QWidget * parent = 0);
342 #if QT_VERSION < 0x040300
344 int tabAt(QPoint const & position) const;
349 void mousePressEvent(QMouseEvent * event);
351 void mouseMoveEvent(QMouseEvent * event);
353 void dragEnterEvent(QDragEnterEvent * event);
355 void dropEvent(QDropEvent * event);
359 QPoint dragStartPos_;
361 int dragCurrentIndex_;
365 void tabMoveRequested(int fromIndex, int toIndex);
368 } // namespace frontend