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>
23 #include <QMouseEvent>
25 #include <QResizeEvent>
32 class QDragEnterEvent;
49 /// types of cursor in work area
53 /// L-shape for locked insets of a different language
55 /// reverse L-shape for RTL text
59 /// for emulating triple click
63 DoubleClick() : state(Qt::NoButton), active(false) {}
65 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
67 bool operator==(QMouseEvent const & e) { return state == e.button(); }
71 Qt::MouseButton state;
76 /** Qt only emits mouse events when the mouse is being moved, but
77 * we want to generate 'pseudo' mouse events when the mouse button is
78 * pressed and the mouse cursor is below the bottom, or above the top
79 * of the work area. In this way, we'll be able to continue scrolling
80 * (and selecting) the text.
82 * This class stores all the parameters needed to make this happen.
84 class SyntheticMouseEvent
87 SyntheticMouseEvent();
94 double scrollbar_value_old;
99 * Implementation of the work area (buffer view GUI)
103 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
109 GuiWorkArea(Buffer & buffer, GuiView & lv);
114 * Update the scrollbar.
115 * @param height the total document height in pixels
116 * @param pos the current position in the document, in pixels
117 * @param line_height the line-scroll amount, in pixels
119 void setScrollbarParams(int height, int pos, int line_height);
121 void scheduleRedraw() { schedule_redraw_ = true; }
123 /// update the passed area.
124 void update(int x, int y, int w, int h);
126 /// copies specified area of pixmap to screen
127 virtual void expose(int x, int y, int exp_width, int exp_height);
129 /// paint the cursor and store the background
130 virtual void showCursor(int x, int y, int h, CursorShape shape);
133 virtual void removeCursor();
135 BufferView & bufferView();
137 BufferView const & bufferView() const;
141 void stopBlinkingCursor();
143 void startBlinkingCursor();
144 /// Process Key pressed event.
145 /// This needs to be public because it is accessed externally by GuiView.
146 void processKeySym(KeySymbol const & key, KeyModifier mod);
149 /// Adjust the LyX buffer view with the position of the scrollbar.
151 * The action argument is not used in the the code, it is there
152 * only for the connection to the vertical srollbar signal which
153 * emits an 'int' action.
155 void adjustViewWithScrollBar(int action = 0);
156 /// timer to limit triple clicks
157 void doubleClickTimeout();
159 /// close this work area.
160 /// Slot for Buffer::closing signal.
163 void setWindowTitle(docstring const & t, docstring const & it);
167 void titleChanged(GuiWorkArea *);
170 /// This function is called when the buffer readonly status change.
171 void setReadOnly(bool);
173 /// Update window titles of all users.
174 void updateWindowTitle();
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);
205 void resizeBufferView();
206 /// hide the visible cursor, if it is visible
208 /// show the cursor if it is not visible
210 /// toggle the cursor's visibility
213 void updateScrollbar();
216 BufferView * buffer_view_;
219 /// is the cursor currently displayed
220 bool cursor_visible_;
223 Timeout cursor_timeout_;
225 SyntheticMouseEvent synthetic_mouse_event_;
227 DoubleClick dc_event_;
230 CursorWidget * cursor_;
238 bool schedule_redraw_;
244 /// A tabbed set of GuiWorkAreas.
245 class TabWorkArea : public QTabWidget
249 TabWorkArea(QWidget * parent = 0);
251 void showBar(bool show);
253 bool setCurrentWorkArea(GuiWorkArea *);
254 bool removeWorkArea(GuiWorkArea *);
255 GuiWorkArea * currentWorkArea();
256 GuiWorkArea * workArea(Buffer & buffer);
260 void currentWorkAreaChanged(GuiWorkArea *);
264 void on_currentTabChanged(int index);
266 void closeCurrentTab();
268 void updateTabText(GuiWorkArea *);
271 } // namespace frontend