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>
29 class QDragEnterEvent;
47 /// types of cursor in work area
51 /// L-shape for locked insets of a different language
53 /// reverse L-shape for RTL text
57 /// for emulating triple click
61 DoubleClick() : state(Qt::NoButton), active(false) {}
63 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
65 bool operator==(QMouseEvent const & e) { return state == e.button(); }
69 Qt::MouseButton state;
74 /** Qt only emits mouse events when the mouse is being moved, but
75 * we want to generate 'pseudo' mouse events when the mouse button is
76 * pressed and the mouse cursor is below the bottom, or above the top
77 * of the work area. In this way, we'll be able to continue scrolling
78 * (and selecting) the text.
80 * This class stores all the parameters needed to make this happen.
82 class SyntheticMouseEvent
85 SyntheticMouseEvent();
92 double scrollbar_value_old;
97 * Implementation of the work area (buffer view GUI)
101 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
107 GuiWorkArea(Buffer & buffer, GuiView & lv);
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();
131 void titleChanged(GuiWorkArea *);
134 /// Adjust the LyX buffer view with the position of the scrollbar.
136 * The action argument is not used in the the code, it is there
137 * only for the connection to the vertical srollbar signal which
138 * emits an 'int' action.
140 void adjustViewWithScrollBar(int action = 0);
141 /// timer to limit triple clicks
142 void doubleClickTimeout();
144 /// close this work area.
145 /// Slot for Buffer::closing signal.
149 /// update the passed area.
150 void update(int x, int y, int w, int h);
154 /// paint the cursor and store the background
155 virtual void showCursor(int x, int y, int h, CursorShape shape);
158 virtual void removeCursor();
160 /// This function is called when the buffer readonly status change.
161 void setReadOnly(bool);
163 /// Update window titles of all users.
164 void updateWindowTitle();
166 void focusInEvent(QFocusEvent *);
168 void focusOutEvent(QFocusEvent *);
169 /// repaint part of the widget
170 void paintEvent(QPaintEvent * ev);
171 /// widget has been resized
172 void resizeEvent(QResizeEvent * ev);
173 /// mouse button press
174 void mousePressEvent(QMouseEvent * ev);
175 /// mouse button release
176 void mouseReleaseEvent(QMouseEvent * ev);
177 /// mouse double click of button
178 void mouseDoubleClickEvent(QMouseEvent * ev);
180 void mouseMoveEvent(QMouseEvent * ev);
182 void wheelEvent(QWheelEvent * ev);
184 void keyPressEvent(QKeyEvent * ev);
186 void inputMethodEvent(QInputMethodEvent * ev);
188 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
190 /// The slot connected to SyntheticMouseEvent::timeout.
191 void generateSyntheticMouseEvent();
193 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
194 /// hide the visible cursor, if it is visible
196 /// show the cursor if it is not visible
198 /// toggle the cursor's visibility
201 void updateScrollbar();
204 BufferView * buffer_view_;
207 /// is the cursor currently displayed
208 bool cursor_visible_;
211 Timeout cursor_timeout_;
213 SyntheticMouseEvent synthetic_mouse_event_;
215 DoubleClick dc_event_;
218 CursorWidget * cursor_;
224 bool schedule_redraw_;
230 /// A tabbed set of GuiWorkAreas.
231 class TabWorkArea : public QTabWidget
235 TabWorkArea(QWidget * parent = 0);
237 void showBar(bool show);
239 bool setCurrentWorkArea(GuiWorkArea *);
240 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
241 bool removeWorkArea(GuiWorkArea *);
242 GuiWorkArea * currentWorkArea();
243 GuiWorkArea * workArea(Buffer & buffer);
247 void currentWorkAreaChanged(GuiWorkArea *);
251 void on_currentTabChanged(int index);
253 void closeCurrentTab();
255 void updateTabText(GuiWorkArea *);
258 } // namespace frontend