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"
17 #include "frontends/qt4/GuiCompleter.h"
19 #include "DocIterator.h"
20 #include "FuncRequest.h"
21 #include "qt_helpers.h"
22 #include "support/docstring.h"
23 #include "support/Timeout.h"
25 #include <QAbstractScrollArea>
26 #include <QMouseEvent>
28 #include <QResizeEvent>
33 class QContextMenuEvent;
34 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(Buffer & buffer, GuiView & lv);
109 void setFullScreen(bool full_screen);
110 /// is LyXView in fullscreen mode?
113 void scheduleRedraw() { schedule_redraw_ = true; }
115 BufferView & bufferView();
117 BufferView const & bufferView() const;
121 void stopBlinkingCursor();
123 void startBlinkingCursor();
124 /// Process Key pressed event.
125 /// This needs to be public because it is accessed externally by GuiView.
126 void processKeySym(KeySymbol const & key, KeyModifier mod);
128 void resizeBufferView();
131 GuiCompleter & completer() { return completer_; }
135 void titleChanged(GuiWorkArea *);
138 /// Scroll the BufferView.
140 * This is a slot for the valueChanged() signal of the vertical scrollbar.
141 * \p value value of the scrollbar.
143 void scrollTo(int value);
144 /// timer to limit triple clicks
145 void doubleClickTimeout();
146 /// toggle the cursor's visibility
148 /// close this work area.
149 /// Slot for Buffer::closing signal.
153 friend class GuiCompleter;
155 /// update the passed area.
156 void update(int x, int y, int w, int h);
160 /// paint the cursor and store the background
161 virtual void showCursor(int x, int y, int h,
162 bool l_shape, bool rtl, bool completable);
165 virtual void removeCursor();
167 /// This function is called when the buffer readonly status change.
168 void setReadOnly(bool);
170 /// Update window titles of all users.
171 void updateWindowTitle();
173 bool event(QEvent *);
175 void contextMenuEvent(QContextMenuEvent *);
177 void focusInEvent(QFocusEvent *);
179 void focusOutEvent(QFocusEvent *);
180 /// repaint part of the widget
181 void paintEvent(QPaintEvent * ev);
182 /// widget has been resized
183 void resizeEvent(QResizeEvent * ev);
184 /// mouse button press
185 void mousePressEvent(QMouseEvent * ev);
186 /// mouse button release
187 void mouseReleaseEvent(QMouseEvent * ev);
188 /// mouse double click of button
189 void mouseDoubleClickEvent(QMouseEvent * ev);
191 void mouseMoveEvent(QMouseEvent * ev);
193 void wheelEvent(QWheelEvent * ev);
195 void keyPressEvent(QKeyEvent * ev);
197 void inputMethodEvent(QInputMethodEvent * ev);
199 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
201 /// The slot connected to SyntheticMouseEvent::timeout.
202 void generateSyntheticMouseEvent();
204 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
205 /// hide the visible cursor, if it is visible
207 /// show the cursor if it is not visible
210 void updateScrollbar();
213 BufferView * buffer_view_;
216 /// is the cursor currently displayed
217 bool cursor_visible_;
220 QTimer cursor_timeout_;
222 SyntheticMouseEvent synthetic_mouse_event_;
224 DoubleClick dc_event_;
227 CursorWidget * cursor_;
233 bool schedule_redraw_;
238 GuiCompleter completer_;
242 /// A tabbed set of GuiWorkAreas.
243 class TabWorkArea : public QTabWidget
247 TabWorkArea(QWidget * parent = 0);
250 void setFullScreen(bool full_screen);
251 void showBar(bool show);
253 bool setCurrentWorkArea(GuiWorkArea *);
254 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
255 bool removeWorkArea(GuiWorkArea *);
256 GuiWorkArea * currentWorkArea();
257 GuiWorkArea * workArea(Buffer & buffer);
261 void currentWorkAreaChanged(GuiWorkArea *);
263 void lastWorkAreaRemoved();
266 /// close current buffer, or the one given by \c clicked_tab_
267 void closeCurrentBuffer();
268 /// close current tab, or the one given by \c clicked_tab_
269 void closeCurrentTab();
271 void updateTabText(GuiWorkArea *);
275 void on_currentTabChanged(int index);
277 void showContextMenu(const QPoint & pos);
279 void moveTab(int fromIndex, int toIndex);
286 class DragTabBar : public QTabBar
291 DragTabBar(QWidget * parent=0);
293 #if QT_VERSION < 0x040300
295 int tabAt(QPoint const & position) const;
300 void mousePressEvent(QMouseEvent * event);
302 void mouseMoveEvent(QMouseEvent * event);
304 void dragEnterEvent(QDragEnterEvent * event);
306 void dropEvent(QDropEvent * event);
310 QPoint dragStartPos_;
312 int dragCurrentIndex_;
316 void tabMoveRequested(int fromIndex, int toIndex);
319 } // namespace frontend