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>
32 class QContextMenuEvent;
33 class QDragEnterEvent;
53 /// for emulating triple click
57 DoubleClick() : state(Qt::NoButton), active(false) {}
59 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
61 bool operator==(QMouseEvent const & e) { return state == e.button(); }
65 Qt::MouseButton state;
70 /** Qt only emits mouse events when the mouse is being moved, but
71 * we want to generate 'pseudo' mouse events when the mouse button is
72 * pressed and the mouse cursor is below the bottom, or above the top
73 * of the work area. In this way, we'll be able to continue scrolling
74 * (and selecting) the text.
76 * This class stores all the parameters needed to make this happen.
78 class SyntheticMouseEvent
81 SyntheticMouseEvent();
88 double scrollbar_value_old;
93 * Implementation of the work area (buffer view GUI)
97 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
103 GuiWorkArea(Buffer & buffer, GuiView & lv);
108 void setFullScreen(bool full_screen);
109 /// is LyXView in fullscreen mode?
112 void scheduleRedraw() { schedule_redraw_ = true; }
114 BufferView & bufferView();
116 BufferView const & bufferView() const;
120 void stopBlinkingCursor();
122 void startBlinkingCursor();
123 /// Process Key pressed event.
124 /// This needs to be public because it is accessed externally by GuiView.
125 void processKeySym(KeySymbol const & key, KeyModifier mod);
127 void resizeBufferView();
130 GuiCompleter & completer() { return completer_; }
134 void titleChanged(GuiWorkArea *);
137 /// Scroll the BufferView.
139 * This is a slot for the valueChanged() signal of the vertical scrollbar.
140 * \p value value of the scrollbar.
142 void scrollTo(int value);
143 /// timer to limit triple clicks
144 void doubleClickTimeout();
145 /// toggle the cursor's visibility
147 /// close this work area.
148 /// Slot for Buffer::closing signal.
152 friend class GuiCompleter;
154 /// update the passed area.
155 void update(int x, int y, int w, int h);
159 /// paint the cursor and store the background
160 virtual void showCursor(int x, int y, int h,
161 bool l_shape, bool rtl, bool completable);
164 virtual void removeCursor();
166 /// This function is called when the buffer readonly status change.
167 void setReadOnly(bool);
169 /// Update window titles of all users.
170 void updateWindowTitle();
172 bool event(QEvent *);
174 void contextMenuEvent(QContextMenuEvent *);
176 void focusInEvent(QFocusEvent *);
178 void focusOutEvent(QFocusEvent *);
179 /// repaint part of the widget
180 void paintEvent(QPaintEvent * ev);
181 /// widget has been resized
182 void resizeEvent(QResizeEvent * ev);
183 /// mouse button press
184 void mousePressEvent(QMouseEvent * ev);
185 /// mouse button release
186 void mouseReleaseEvent(QMouseEvent * ev);
187 /// mouse double click of button
188 void mouseDoubleClickEvent(QMouseEvent * ev);
190 void mouseMoveEvent(QMouseEvent * ev);
192 void wheelEvent(QWheelEvent * ev);
194 void keyPressEvent(QKeyEvent * ev);
196 void inputMethodEvent(QInputMethodEvent * ev);
198 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
200 /// The slot connected to SyntheticMouseEvent::timeout.
201 void generateSyntheticMouseEvent();
203 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
204 /// hide the visible cursor, if it is visible
206 /// show the cursor if it is not visible
209 void updateScrollbar();
212 BufferView * buffer_view_;
215 /// is the cursor currently displayed
216 bool cursor_visible_;
219 QTimer cursor_timeout_;
221 SyntheticMouseEvent synthetic_mouse_event_;
223 DoubleClick dc_event_;
226 CursorWidget * cursor_;
232 bool schedule_redraw_;
237 GuiCompleter completer_;
241 /// A tabbed set of GuiWorkAreas.
242 class TabWorkArea : public QTabWidget
246 TabWorkArea(QWidget * parent = 0);
249 void setFullScreen(bool full_screen);
250 void showBar(bool show);
252 bool setCurrentWorkArea(GuiWorkArea *);
253 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
254 bool removeWorkArea(GuiWorkArea *);
255 GuiWorkArea * currentWorkArea();
256 GuiWorkArea * workArea(Buffer & buffer);
260 void currentWorkAreaChanged(GuiWorkArea *);
262 void lastWorkAreaRemoved();
266 void on_currentTabChanged(int index);
268 void closeCurrentBuffer();
270 void closeCurrentTab();
272 void updateTabText(GuiWorkArea *);
275 } // namespace frontend