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;
44 /// for emulating triple click
47 Qt::MouseButton state;
50 bool operator==(QMouseEvent const & e) {
51 return state == e.button();
55 : state(Qt::NoButton), active(false) {}
57 double_click(QMouseEvent * e)
58 : state(e->button()), active(true) {}
61 /** Qt only emits mouse events when the mouse is being moved, but
62 * we want to generate 'pseudo' mouse events when the mouse button is
63 * pressed and the mouse cursor is below the bottom, or above the top
64 * of the work area. In this way, we'll be able to continue scrolling
65 * (and selecting) the text.
67 * This class stores all the parameters needed to make this happen.
69 class SyntheticMouseEvent
72 SyntheticMouseEvent();
79 double scrollbar_value_old;
83 * Qt-specific implementation of the work area
87 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
93 GuiWorkArea(Buffer & buffer, LyXView & lv);
96 bool hasFocus() const { return QAbstractScrollArea::hasFocus(); }
97 bool isVisible() const { return QAbstractScrollArea::isVisible(); }
99 /// return the width of the content pane
100 virtual int width() const { return viewport()->width(); }
101 /// return the height of the content pane
102 virtual int height() const { return viewport()->height(); }
104 virtual void setScrollbarParams(int height, int pos, int line_height);
106 virtual void scheduleRedraw() { schedule_redraw_ = true; }
108 /// update the passed area.
109 void update(int x, int y, int w, int h);
111 /// copies specified area of pixmap to screen
112 virtual void expose(int x, int y, int exp_width, int exp_height);
114 /// paint the cursor and store the background
115 virtual void showCursor(int x, int y, int h, CursorShape shape);
118 virtual void removeCursor();
122 void focusInEvent(QFocusEvent *);
124 void focusOutEvent(QFocusEvent *);
125 /// repaint part of the widget
126 void paintEvent(QPaintEvent * ev);
127 /// widget has been resized
128 void resizeEvent(QResizeEvent * ev);
129 /// mouse button press
130 void mousePressEvent(QMouseEvent * ev);
131 /// mouse button release
132 void mouseReleaseEvent(QMouseEvent * ev);
133 /// mouse double click of button
134 void mouseDoubleClickEvent(QMouseEvent * ev);
136 void mouseMoveEvent(QMouseEvent * ev);
138 void wheelEvent(QWheelEvent * ev);
140 void keyPressEvent(QKeyEvent * ev);
142 void inputMethodEvent(QInputMethodEvent * ev);
144 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
147 /// Adjust the LyX buffer view with the position of the scrollbar.
149 * The action argument is not used in the the code, it is there
150 * only for the connection to the vertical srollbar signal which
151 * emits an 'int' action.
153 void adjustViewWithScrollBar(int action = 0);
154 /// timer to limit triple clicks
155 void doubleClickTimeout();
158 /// The slot connected to SyntheticMouseEvent::timeout.
159 void generateSyntheticMouseEvent();
162 SyntheticMouseEvent synthetic_mouse_event_;
164 double_click dc_event_;
167 CursorWidget * cursor_;
175 bool schedule_redraw_;
180 /// A tabbed set of GuiWorkAreas.
181 class TabWorkArea : public QTabWidget
185 TabWorkArea(QWidget * parent = 0);
186 void showBar(bool show);
188 bool setCurrentWorkArea(GuiWorkArea *);
189 bool removeWorkArea(GuiWorkArea *);
190 GuiWorkArea * currentWorkArea();
191 GuiWorkArea * workArea(Buffer & buffer);
195 void currentWorkAreaChanged(GuiWorkArea *);
199 void on_currentTabChanged(int index);
201 void closeCurrentTab();
204 } // namespace frontend