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 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();
132 void titleChanged(GuiWorkArea *);
135 /// Scroll the BufferView.
137 * This is a slot for the valueChanged() signal of the vertical scrollbar.
138 * \p value value of the scrollbar.
140 void scrollTo(int value);
141 /// timer to limit triple clicks
142 void doubleClickTimeout();
143 /// toggle the cursor's visibility
146 /// close this work area.
147 /// Slot for Buffer::closing signal.
151 /// update the passed area.
152 void update(int x, int y, int w, int h);
156 /// paint the cursor and store the background
157 virtual void showCursor(int x, int y, int h, CursorShape shape);
160 virtual void removeCursor();
162 /// This function is called when the buffer readonly status change.
163 void setReadOnly(bool);
165 /// Update window titles of all users.
166 void updateWindowTitle();
168 bool event(QEvent *);
170 void contextMenuEvent(QContextMenuEvent *);
172 void focusInEvent(QFocusEvent *);
174 void focusOutEvent(QFocusEvent *);
175 /// repaint part of the widget
176 void paintEvent(QPaintEvent * ev);
177 /// widget has been resized
178 void resizeEvent(QResizeEvent * ev);
179 /// mouse button press
180 void mousePressEvent(QMouseEvent * ev);
181 /// mouse button release
182 void mouseReleaseEvent(QMouseEvent * ev);
183 /// mouse double click of button
184 void mouseDoubleClickEvent(QMouseEvent * ev);
186 void mouseMoveEvent(QMouseEvent * ev);
188 void wheelEvent(QWheelEvent * ev);
190 void keyPressEvent(QKeyEvent * ev);
192 void inputMethodEvent(QInputMethodEvent * ev);
194 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
196 /// The slot connected to SyntheticMouseEvent::timeout.
197 void generateSyntheticMouseEvent();
199 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
200 /// hide the visible cursor, if it is visible
202 /// show the cursor if it is not visible
205 void updateScrollbar();
208 BufferView * buffer_view_;
211 /// is the cursor currently displayed
212 bool cursor_visible_;
215 QTimer cursor_timeout_;
217 SyntheticMouseEvent synthetic_mouse_event_;
219 DoubleClick dc_event_;
222 CursorWidget * cursor_;
228 bool schedule_redraw_;
234 /// A tabbed set of GuiWorkAreas.
235 class TabWorkArea : public QTabWidget
239 TabWorkArea(QWidget * parent = 0);
241 void showBar(bool show);
243 bool setCurrentWorkArea(GuiWorkArea *);
244 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
245 bool removeWorkArea(GuiWorkArea *);
246 GuiWorkArea * currentWorkArea();
247 GuiWorkArea * workArea(Buffer & buffer);
251 void currentWorkAreaChanged(GuiWorkArea *);
255 void on_currentTabChanged(int index);
257 void closeCurrentTab();
259 void updateTabText(GuiWorkArea *);
262 } // namespace frontend