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 int min_scrollbar_old;
91 int max_scrollbar_old;
96 * Implementation of the work area (buffer view GUI)
100 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
106 GuiWorkArea(QWidget *);
108 GuiWorkArea(Buffer & buffer, GuiView & gv);
115 void setBuffer(Buffer &);
117 void setGuiView(GuiView &);
119 void setFullScreen(bool full_screen);
120 /// is LyXView in fullscreen mode?
123 void scheduleRedraw() { schedule_redraw_ = true; }
125 BufferView & bufferView();
127 BufferView const & bufferView() const;
131 void stopBlinkingCursor();
133 void startBlinkingCursor();
134 /// Process Key pressed event.
135 /// This needs to be public because it is accessed externally by GuiView.
136 void processKeySym(KeySymbol const & key, KeyModifier mod);
138 void resizeBufferView();
140 bool inDialogMode() const { return dialog_mode_; }
141 void setDialogMode(bool mode) { dialog_mode_ = mode; }
144 GuiCompleter & completer() { return *completer_; }
147 /// Return the GuiView this workArea belongs to
148 GuiView const & view() const { return *lyx_view_; }
149 GuiView & view() { return *lyx_view_; }
153 void titleChanged(GuiWorkArea *);
156 /// Scroll the BufferView.
158 * This is a slot for the valueChanged() signal of the vertical scrollbar.
159 * \p value value of the scrollbar.
161 void scrollTo(int value);
162 /// timer to limit triple clicks
163 void doubleClickTimeout();
164 /// toggle the cursor's visibility
166 /// close this work area.
167 /// Slot for Buffer::closing signal.
169 /// Slot to restore proper scrollbar behaviour.
170 void fixVerticalScrollBar();
173 friend class GuiCompleter;
175 /// update the passed area.
176 void update(int x, int y, int w, int h);
180 /// paint the cursor and store the background
181 virtual void showCursor(int x, int y, int h,
182 bool l_shape, bool rtl, bool completable);
185 virtual void removeCursor();
187 /// This function is called when the buffer readonly status change.
188 void setReadOnly(bool);
190 /// Update window titles of all users.
191 void updateWindowTitle();
193 bool event(QEvent *);
195 void contextMenuEvent(QContextMenuEvent *);
197 void focusInEvent(QFocusEvent *);
199 void focusOutEvent(QFocusEvent *);
200 /// repaint part of the widget
201 void paintEvent(QPaintEvent * ev);
202 /// widget has been resized
203 void resizeEvent(QResizeEvent * ev);
204 /// mouse button press
205 void mousePressEvent(QMouseEvent * ev);
206 /// mouse button release
207 void mouseReleaseEvent(QMouseEvent * ev);
208 /// mouse double click of button
209 void mouseDoubleClickEvent(QMouseEvent * ev);
211 void mouseMoveEvent(QMouseEvent * ev);
213 void wheelEvent(QWheelEvent * ev);
215 void keyPressEvent(QKeyEvent * ev);
217 void inputMethodEvent(QInputMethodEvent * ev);
219 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
221 /// The slot connected to SyntheticMouseEvent::timeout.
222 void generateSyntheticMouseEvent();
224 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
225 /// hide the visible cursor, if it is visible
227 /// show the cursor if it is not visible
230 void updateScrollbar();
233 BufferView * buffer_view_;
236 /// is the cursor currently displayed
237 bool cursor_visible_;
240 QTimer cursor_timeout_;
242 SyntheticMouseEvent synthetic_mouse_event_;
244 DoubleClick dc_event_;
247 CursorWidget * cursor_;
253 bool schedule_redraw_;
258 GuiCompleter * completer_;
260 /// Special mode in which Esc and Enter (with or without Shift)
263 /// store the position of the rightclick when the mouse is
264 /// pressed. This is used to get the correct context menu
265 /// when the menu is actually shown (after releasing on Windwos).
266 QPoint context_target_pos_;
270 class EmbeddedWorkArea : public GuiWorkArea
275 EmbeddedWorkArea(QWidget *);
278 /// Dummy methods for Designer.
279 void setWidgetResizable(bool) {}
280 void setWidget(QWidget *) {}
287 void closeEvent(QCloseEvent * ev);
289 void hideEvent(QHideEvent *ev);
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 /// hide current tab, or the one given by \c clicked_tab_
324 void hideCurrentTab();
325 /// close the tab given by \c index
326 void closeTab(int index);
328 void updateTabTexts();
332 void on_currentTabChanged(int index);
334 void showContextMenu(const QPoint & pos);
336 void moveTab(int fromIndex, int toIndex);
342 QToolButton * closeBufferButton;
346 class DragTabBar : public QTabBar
351 DragTabBar(QWidget * parent = 0);
353 #if QT_VERSION < 0x040300
355 int tabAt(QPoint const & position) const;
360 void mousePressEvent(QMouseEvent * event);
362 void mouseMoveEvent(QMouseEvent * event);
364 void dragEnterEvent(QDragEnterEvent * event);
366 void dropEvent(QDropEvent * event);
370 QPoint dragStartPos_;
372 int dragCurrentIndex_;
376 void tabMoveRequested(int fromIndex, int toIndex);
379 } // namespace frontend