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 /// types of cursor in work area
57 /// L-shape for locked insets of a different language
59 /// reverse L-shape for RTL text
63 /// for emulating triple click
67 DoubleClick() : state(Qt::NoButton), active(false) {}
69 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
71 bool operator==(QMouseEvent const & e) { return state == e.button(); }
75 Qt::MouseButton state;
80 /** Qt only emits mouse events when the mouse is being moved, but
81 * we want to generate 'pseudo' mouse events when the mouse button is
82 * pressed and the mouse cursor is below the bottom, or above the top
83 * of the work area. In this way, we'll be able to continue scrolling
84 * (and selecting) the text.
86 * This class stores all the parameters needed to make this happen.
88 class SyntheticMouseEvent
91 SyntheticMouseEvent();
98 double scrollbar_value_old;
103 * Implementation of the work area (buffer view GUI)
107 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
113 GuiWorkArea(Buffer & buffer, GuiView & lv);
118 void setFullScreen(bool full_screen);
119 /// is LyXView in fullscreen mode?
122 void scheduleRedraw() { schedule_redraw_ = true; }
124 BufferView & bufferView();
126 BufferView const & bufferView() const;
130 void stopBlinkingCursor();
132 void startBlinkingCursor();
133 /// Process Key pressed event.
134 /// This needs to be public because it is accessed externally by GuiView.
135 void processKeySym(KeySymbol const & key, KeyModifier mod);
137 void resizeBufferView();
140 GuiCompleter & completer() { return completer_; }
144 void titleChanged(GuiWorkArea *);
147 /// Scroll the BufferView.
149 * This is a slot for the valueChanged() signal of the vertical scrollbar.
150 * \p value value of the scrollbar.
152 void scrollTo(int value);
153 /// timer to limit triple clicks
154 void doubleClickTimeout();
155 /// toggle the cursor's visibility
157 /// close this work area.
158 /// Slot for Buffer::closing signal.
162 friend class GuiCompleter;
164 /// update the passed area.
165 void update(int x, int y, int w, int h);
169 /// paint the cursor and store the background
170 virtual void showCursor(int x, int y, int h, CursorShape shape);
173 virtual void removeCursor();
175 /// This function is called when the buffer readonly status change.
176 void setReadOnly(bool);
178 /// Update window titles of all users.
179 void updateWindowTitle();
181 bool event(QEvent *);
183 void contextMenuEvent(QContextMenuEvent *);
185 void focusInEvent(QFocusEvent *);
187 void focusOutEvent(QFocusEvent *);
188 /// repaint part of the widget
189 void paintEvent(QPaintEvent * ev);
190 /// widget has been resized
191 void resizeEvent(QResizeEvent * ev);
192 /// mouse button press
193 void mousePressEvent(QMouseEvent * ev);
194 /// mouse button release
195 void mouseReleaseEvent(QMouseEvent * ev);
196 /// mouse double click of button
197 void mouseDoubleClickEvent(QMouseEvent * ev);
199 void mouseMoveEvent(QMouseEvent * ev);
201 void wheelEvent(QWheelEvent * ev);
203 void keyPressEvent(QKeyEvent * ev);
205 void inputMethodEvent(QInputMethodEvent * ev);
207 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
209 /// The slot connected to SyntheticMouseEvent::timeout.
210 void generateSyntheticMouseEvent();
212 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
213 /// hide the visible cursor, if it is visible
215 /// show the cursor if it is not visible
218 void updateScrollbar();
221 BufferView * buffer_view_;
224 /// is the cursor currently displayed
225 bool cursor_visible_;
228 QTimer cursor_timeout_;
230 SyntheticMouseEvent synthetic_mouse_event_;
232 DoubleClick dc_event_;
235 CursorWidget * cursor_;
241 bool schedule_redraw_;
246 GuiCompleter completer_;
250 /// A tabbed set of GuiWorkAreas.
251 class TabWorkArea : public QTabWidget
255 TabWorkArea(QWidget * parent = 0);
258 void setFullScreen(bool full_screen);
259 void showBar(bool show);
261 bool setCurrentWorkArea(GuiWorkArea *);
262 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
263 bool removeWorkArea(GuiWorkArea *);
264 GuiWorkArea * currentWorkArea();
265 GuiWorkArea * workArea(Buffer & buffer);
269 void currentWorkAreaChanged(GuiWorkArea *);
273 void on_currentTabChanged(int index);
275 void closeCurrentBuffer();
277 void closeCurrentTab();
279 void updateTabText(GuiWorkArea *);
282 } // namespace frontend