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"
17 #include "frontends/qt4/GuiCompleter.h"
19 #include "DocIterator.h"
20 #include "FuncRequest.h"
21 #include "qt_helpers.h"
22 #include "support/docstring.h"
23 #include "support/Timeout.h"
25 #include <QAbstractScrollArea>
26 #include <QMouseEvent>
28 #include <QResizeEvent>
32 class QContextMenuEvent;
33 class QDragEnterEvent;
53 /// types of cursor in work area
57 /// L-shape for locked insets of a different language
59 /// reverse L-shape for RTL text
63 /// for emulating triple click
67 DoubleClick() : state(Qt::NoButton), active(false) {}
69 DoubleClick(QMouseEvent * e) : state(e->button()), active(true) {}
71 bool operator==(QMouseEvent const & e) { return state == e.button(); }
75 Qt::MouseButton state;
80 /** Qt only emits mouse events when the mouse is being moved, but
81 * we want to generate 'pseudo' mouse events when the mouse button is
82 * pressed and the mouse cursor is below the bottom, or above the top
83 * of the work area. In this way, we'll be able to continue scrolling
84 * (and selecting) the text.
86 * This class stores all the parameters needed to make this happen.
88 class SyntheticMouseEvent
91 SyntheticMouseEvent();
98 double scrollbar_value_old;
103 * Implementation of the work area (buffer view GUI)
107 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
113 GuiWorkArea(Buffer & buffer, GuiView & lv);
118 void setFullScreen(bool full_screen);
120 void scheduleRedraw() { schedule_redraw_ = true; }
122 BufferView & bufferView();
124 BufferView const & bufferView() const;
128 void stopBlinkingCursor();
130 void startBlinkingCursor();
131 /// Process Key pressed event.
132 /// This needs to be public because it is accessed externally by GuiView.
133 void processKeySym(KeySymbol const & key, KeyModifier mod);
135 void resizeBufferView();
138 GuiCompleter & completer() { return completer_; }
142 void titleChanged(GuiWorkArea *);
145 /// Scroll the BufferView.
147 * This is a slot for the valueChanged() signal of the vertical scrollbar.
148 * \p value value of the scrollbar.
150 void scrollTo(int value);
151 /// timer to limit triple clicks
152 void doubleClickTimeout();
153 /// toggle the cursor's visibility
155 /// close this work area.
156 /// Slot for Buffer::closing signal.
160 friend class GuiCompleter;
162 /// update the passed area.
163 void update(int x, int y, int w, int h);
167 /// paint the cursor and store the background
168 virtual void showCursor(int x, int y, int h, CursorShape shape);
171 virtual void removeCursor();
173 /// This function is called when the buffer readonly status change.
174 void setReadOnly(bool);
176 /// Update window titles of all users.
177 void updateWindowTitle();
179 bool event(QEvent *);
181 void contextMenuEvent(QContextMenuEvent *);
183 void focusInEvent(QFocusEvent *);
185 void focusOutEvent(QFocusEvent *);
186 /// repaint part of the widget
187 void paintEvent(QPaintEvent * ev);
188 /// widget has been resized
189 void resizeEvent(QResizeEvent * ev);
190 /// mouse button press
191 void mousePressEvent(QMouseEvent * ev);
192 /// mouse button release
193 void mouseReleaseEvent(QMouseEvent * ev);
194 /// mouse double click of button
195 void mouseDoubleClickEvent(QMouseEvent * ev);
197 void mouseMoveEvent(QMouseEvent * ev);
199 void wheelEvent(QWheelEvent * ev);
201 void keyPressEvent(QKeyEvent * ev);
203 void inputMethodEvent(QInputMethodEvent * ev);
205 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
207 /// The slot connected to SyntheticMouseEvent::timeout.
208 void generateSyntheticMouseEvent();
210 void dispatch(FuncRequest const & cmd0, KeyModifier = NoModifier);
211 /// hide the visible cursor, if it is visible
213 /// show the cursor if it is not visible
216 void updateScrollbar();
219 BufferView * buffer_view_;
222 /// is the cursor currently displayed
223 bool cursor_visible_;
226 QTimer cursor_timeout_;
228 SyntheticMouseEvent synthetic_mouse_event_;
230 DoubleClick dc_event_;
233 CursorWidget * cursor_;
239 bool schedule_redraw_;
244 GuiCompleter completer_;
248 /// A tabbed set of GuiWorkAreas.
249 class TabWorkArea : public QTabWidget
253 TabWorkArea(QWidget * parent = 0);
256 void setFullScreen(bool full_screen);
257 void showBar(bool show);
259 bool setCurrentWorkArea(GuiWorkArea *);
260 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
261 bool removeWorkArea(GuiWorkArea *);
262 GuiWorkArea * currentWorkArea();
263 GuiWorkArea * workArea(Buffer & buffer);
267 void currentWorkAreaChanged(GuiWorkArea *);
271 void on_currentTabChanged(int index);
273 void closeCurrentBuffer();
275 void closeCurrentTab();
277 void updateTabText(GuiWorkArea *);
280 } // namespace frontend