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 showEvent(QShowEvent * ev);
282 /// this happens when the dialog is simply closed/hidden
283 void closeEvent(QCloseEvent * e);
286 /// this happens 100ms after dialog showEvent()
287 void onDelayedFocus();
290 /// @TODO: Investigate on focus issue and remove this ugly hack, please !
291 QTimer delayed_focus_timer_;
294 }; // EmbeddedWorkArea
297 /// A tabbed set of GuiWorkAreas.
298 class TabWorkArea : public QTabWidget
302 TabWorkArea(QWidget * parent = 0);
305 void setFullScreen(bool full_screen);
306 void showBar(bool show);
308 bool setCurrentWorkArea(GuiWorkArea *);
309 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
310 bool removeWorkArea(GuiWorkArea *);
311 GuiWorkArea * currentWorkArea();
312 GuiWorkArea * workArea(Buffer & buffer);
316 void currentWorkAreaChanged(GuiWorkArea *);
318 void lastWorkAreaRemoved();
321 /// close current buffer, or the one given by \c clicked_tab_
322 void closeCurrentBuffer();
323 /// close current tab, or the one given by \c clicked_tab_
324 void closeCurrentTab();
326 void updateTabTexts();
330 void on_currentTabChanged(int index);
332 void showContextMenu(const QPoint & pos);
334 void moveTab(int fromIndex, int toIndex);
341 class DragTabBar : public QTabBar
346 DragTabBar(QWidget * parent = 0);
348 #if QT_VERSION < 0x040300
350 int tabAt(QPoint const & position) const;
355 void mousePressEvent(QMouseEvent * event);
357 void mouseMoveEvent(QMouseEvent * event);
359 void dragEnterEvent(QDragEnterEvent * event);
361 void dropEvent(QDropEvent * event);
365 QPoint dragStartPos_;
367 int dragCurrentIndex_;
371 void tabMoveRequested(int fromIndex, int toIndex);
374 } // namespace frontend