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 "FuncRequest.h"
19 #include "support/Timeout.h"
21 #include <QAbstractScrollArea>
22 #include <QMouseEvent>
24 #include <QResizeEvent>
28 class QContextMenuEvent;
29 class QDragEnterEvent;
48 /// types of cursor in work area
52 /// L-shape for locked insets of a different language
54 /// reverse L-shape for RTL text
58 /// for emulating triple click
62 DoubleClick() : state(Qt::NoButton), active(false) {}
64 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
66 bool operator==(QMouseEvent const & e) { return state == e.button(); }
70 Qt::MouseButton state;
75 /** Qt only emits mouse events when the mouse is being moved, but
76 * we want to generate 'pseudo' mouse events when the mouse button is
77 * pressed and the mouse cursor is below the bottom, or above the top
78 * of the work area. In this way, we'll be able to continue scrolling
79 * (and selecting) the text.
81 * This class stores all the parameters needed to make this happen.
83 class SyntheticMouseEvent
86 SyntheticMouseEvent();
93 double scrollbar_value_old;
98 * Implementation of the work area (buffer view GUI)
102 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
108 GuiWorkArea(Buffer & buffer, GuiView & lv);
113 void setFullScreen(bool full_screen);
115 void scheduleRedraw() { schedule_redraw_ = true; }
117 BufferView & bufferView();
119 BufferView const & bufferView() const;
123 void stopBlinkingCursor();
125 void startBlinkingCursor();
126 /// Process Key pressed event.
127 /// This needs to be public because it is accessed externally by GuiView.
128 void processKeySym(KeySymbol const & key, KeyModifier mod);
130 void resizeBufferView();
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 /// update the passed area.
153 void update(int x, int y, int w, int h);
157 /// paint the cursor and store the background
158 virtual void showCursor(int x, int y, int h, CursorShape shape);
161 virtual void removeCursor();
163 /// This function is called when the buffer readonly status change.
164 void setReadOnly(bool);
166 /// Update window titles of all users.
167 void updateWindowTitle();
169 bool event(QEvent *);
171 void contextMenuEvent(QContextMenuEvent *);
173 void focusInEvent(QFocusEvent *);
175 void focusOutEvent(QFocusEvent *);
176 /// repaint part of the widget
177 void paintEvent(QPaintEvent * ev);
178 /// widget has been resized
179 void resizeEvent(QResizeEvent * ev);
180 /// mouse button press
181 void mousePressEvent(QMouseEvent * ev);
182 /// mouse button release
183 void mouseReleaseEvent(QMouseEvent * ev);
184 /// mouse double click of button
185 void mouseDoubleClickEvent(QMouseEvent * ev);
187 void mouseMoveEvent(QMouseEvent * ev);
189 void wheelEvent(QWheelEvent * ev);
191 void keyPressEvent(QKeyEvent * ev);
193 void inputMethodEvent(QInputMethodEvent * ev);
195 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
197 /// The slot connected to SyntheticMouseEvent::timeout.
198 void generateSyntheticMouseEvent();
200 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
201 /// hide the visible cursor, if it is visible
203 /// show the cursor if it is not visible
206 void updateScrollbar();
209 BufferView * buffer_view_;
212 /// is the cursor currently displayed
213 bool cursor_visible_;
216 QTimer cursor_timeout_;
218 SyntheticMouseEvent synthetic_mouse_event_;
220 DoubleClick dc_event_;
223 CursorWidget * cursor_;
229 bool schedule_redraw_;
235 /// A tabbed set of GuiWorkAreas.
236 class TabWorkArea : public QTabWidget
240 TabWorkArea(QWidget * parent = 0);
243 void setFullScreen(bool full_screen);
244 void showBar(bool show);
246 bool setCurrentWorkArea(GuiWorkArea *);
247 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
248 bool removeWorkArea(GuiWorkArea *);
249 GuiWorkArea * currentWorkArea();
250 GuiWorkArea * workArea(Buffer & buffer);
254 void currentWorkAreaChanged(GuiWorkArea *);
258 void on_currentTabChanged(int index);
260 void closeCurrentBuffer();
262 void closeCurrentTab();
264 void updateTabText(GuiWorkArea *);
267 } // namespace frontend