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, LyXView & lv);
114 bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
115 bool isVisible() const { return QAbstractScrollArea::isVisible(); }
117 /// return the width of the content pane
118 virtual int width() const { return viewport()->width(); }
119 /// return the height of the content pane
120 virtual int height() const { return viewport()->height(); }
122 virtual void setScrollbarParams(int height, int pos, int line_height);
124 virtual void scheduleRedraw() { schedule_redraw_ = true; }
126 /// update the passed area.
127 void update(int x, int y, int w, int h);
129 /// copies specified area of pixmap to screen
130 virtual void expose(int x, int y, int exp_width, int exp_height);
132 /// paint the cursor and store the background
133 virtual void showCursor(int x, int y, int h, CursorShape shape);
136 virtual void removeCursor();
138 BufferView & bufferView();
140 BufferView const & bufferView() const;
144 void stopBlinkingCursor();
146 void startBlinkingCursor();
148 void processKeySym(KeySymbol const & key, KeyModifier mod);
151 /// Adjust the LyX buffer view with the position of the scrollbar.
153 * The action argument is not used in the the code, it is there
154 * only for the connection to the vertical srollbar signal which
155 * emits an 'int' action.
157 void adjustViewWithScrollBar(int action = 0);
158 /// timer to limit triple clicks
159 void doubleClickTimeout();
161 /// close this work area.
162 /// Slot for Buffer::closing signal.
165 void setWindowTitle(docstring const & t, docstring const & it);
169 void titleChanged(GuiWorkArea *);
172 /// This function is called when the buffer readonly status change.
173 void setReadOnly(bool);
175 /// Update window titles of all users.
176 void updateWindowTitle();
178 void focusInEvent(QFocusEvent *);
180 void focusOutEvent(QFocusEvent *);
181 /// repaint part of the widget
182 void paintEvent(QPaintEvent * ev);
183 /// widget has been resized
184 void resizeEvent(QResizeEvent * ev);
185 /// mouse button press
186 void mousePressEvent(QMouseEvent * ev);
187 /// mouse button release
188 void mouseReleaseEvent(QMouseEvent * ev);
189 /// mouse double click of button
190 void mouseDoubleClickEvent(QMouseEvent * ev);
192 void mouseMoveEvent(QMouseEvent * ev);
194 void wheelEvent(QWheelEvent * ev);
196 void keyPressEvent(QKeyEvent * ev);
198 void inputMethodEvent(QInputMethodEvent * ev);
200 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
202 /// The slot connected to SyntheticMouseEvent::timeout.
203 void generateSyntheticMouseEvent();
205 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
207 void resizeBufferView();
208 /// hide the visible cursor, if it is visible
210 /// show the cursor if it is not visible
212 /// toggle the cursor's visibility
215 void updateScrollbar();
218 BufferView * buffer_view_;
221 /// is the cursor currently displayed
222 bool cursor_visible_;
225 Timeout cursor_timeout_;
227 SyntheticMouseEvent synthetic_mouse_event_;
229 DoubleClick dc_event_;
232 CursorWidget * cursor_;
240 bool schedule_redraw_;
246 /// A tabbed set of GuiWorkAreas.
247 class TabWorkArea : public QTabWidget
251 TabWorkArea(QWidget * parent = 0);
253 void showBar(bool show);
255 bool setCurrentWorkArea(GuiWorkArea *);
256 bool removeWorkArea(GuiWorkArea *);
257 GuiWorkArea * currentWorkArea();
258 GuiWorkArea * workArea(Buffer & buffer);
262 void currentWorkAreaChanged(GuiWorkArea *);
266 void on_currentTabChanged(int index);
268 void closeCurrentTab();
270 void updateTabText(GuiWorkArea *);
273 } // namespace frontend