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 "ui_WorkAreaUi.h"
18 #include "frontends/WorkArea.h"
19 #include "frontends/KeySymbol.h"
21 #include <QAbstractScrollArea>
25 class QDragEnterEvent;
44 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
50 GuiWorkArea(QWidget *);
52 GuiWorkArea(Buffer & buffer, GuiView & gv);
59 void setBuffer(Buffer &);
61 void setGuiView(GuiView &);
63 void setFullScreen(bool full_screen);
64 /// is GuiView in fullscreen mode?
65 bool isFullScreen() const;
67 void scheduleRedraw();
69 BufferView & bufferView();
71 BufferView const & bufferView() const;
73 void redraw(bool update_metrics);
75 /// return true if the key is part of a shortcut
76 bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
78 bool inDialogMode() const;
79 void setDialogMode(bool mode);
82 GuiCompleter & completer();
84 Qt::CursorShape cursorShape() const;
86 /// Return the GuiView this workArea belongs to
87 GuiView const & view() const;
90 /// Current ratio between physical pixels and device-independent pixels
91 double pixelRatio() const;
94 /// Process Key pressed event.
95 /// This needs to be public because it is accessed externally by GuiView.
96 void processKeySym(KeySymbol const & key, KeyModifier mod);
98 void stopBlinkingCursor();
100 void startBlinkingCursor();
104 void titleChanged(GuiWorkArea *);
108 void bufferViewChanged();
109 /// send key event to CompressorProxy
110 void compressKeySym(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
113 /// Scroll the BufferView.
115 * This is a slot for the valueChanged() signal of the vertical scrollbar.
116 * \p value value of the scrollbar.
118 void scrollTo(int value);
119 /// timer to limit triple clicks
120 void doubleClickTimeout();
121 /// toggle the cursor's visibility
123 /// close this work area.
124 /// Slot for Buffer::closing signal.
126 /// Slot to restore proper scrollbar behaviour.
127 void fixVerticalScrollBar();
130 /// Update window titles of all users.
131 void updateWindowTitle();
133 bool event(QEvent *);
135 void contextMenuEvent(QContextMenuEvent *);
137 void focusInEvent(QFocusEvent *);
139 void focusOutEvent(QFocusEvent *);
140 /// repaint part of the widget
141 void paintEvent(QPaintEvent * ev);
142 /// widget has been resized
143 void resizeEvent(QResizeEvent * ev);
144 /// mouse button press
145 void mousePressEvent(QMouseEvent * ev);
146 /// mouse button release
147 void mouseReleaseEvent(QMouseEvent * ev);
148 /// mouse double click of button
149 void mouseDoubleClickEvent(QMouseEvent * ev);
151 void mouseMoveEvent(QMouseEvent * ev);
153 void wheelEvent(QWheelEvent * ev);
154 /// key press event. It also knows how to handle ShortcutOverride events to
155 /// avoid code duplication.
156 void keyPressEvent(QKeyEvent * ev);
158 void inputMethodEvent(QInputMethodEvent * ev);
160 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
162 /// The slot connected to SyntheticMouseEvent::timeout.
163 void generateSyntheticMouseEvent();
165 friend class GuiCompleter;
171 /// CompressorProxy adapted from Kuba Ober https://stackoverflow.com/a/21006207
172 class CompressorProxy : public QObject
175 bool emitCheck(bool isAutoRepeat);
177 // input: event to compress
178 Q_SLOT void slot(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
179 // output: compressed event
180 Q_SIGNAL void signal(KeySymbol sym, KeyModifier mod);
182 // No default constructor, since the proxy must be a child of the
184 explicit CompressorProxy(GuiWorkArea * wa);
188 class EmbeddedWorkArea : public GuiWorkArea
193 EmbeddedWorkArea(QWidget *);
196 /// Dummy methods for Designer.
197 void setWidgetResizable(bool) {}
198 void setWidget(QWidget *) {}
200 QSize sizeHint () const;
206 void closeEvent(QCloseEvent * ev);
208 void hideEvent(QHideEvent *ev);
213 }; // EmbeddedWorkArea
216 class GuiWorkAreaContainer;
218 /// A tabbed set of GuiWorkAreas.
219 class TabWorkArea : public QTabWidget
223 TabWorkArea(QWidget * parent = 0);
225 /// hide QTabWidget methods
226 GuiWorkAreaContainer * currentWidget() const;
227 GuiWorkAreaContainer * widget(int index) const;
230 void setFullScreen(bool full_screen);
231 void showBar(bool show);
233 bool setCurrentWorkArea(GuiWorkArea *);
234 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
235 bool removeWorkArea(GuiWorkArea *);
236 GuiWorkArea * currentWorkArea() const;
237 GuiWorkArea * workArea(Buffer & buffer) const;
238 GuiWorkArea * workArea(int index) const;
239 void paintEvent(QPaintEvent *);
243 void currentWorkAreaChanged(GuiWorkArea *);
245 void lastWorkAreaRemoved();
248 /// close current buffer, or the one given by \c clicked_tab_
249 void closeCurrentBuffer();
250 /// hide current tab, or the one given by \c clicked_tab_
251 void hideCurrentTab();
252 /// close the tab given by \c index
253 void closeTab(int index);
255 void moveTab(int fromIndex, int toIndex);
257 void updateTabTexts();
261 void on_currentTabChanged(int index);
263 void showContextMenu(const QPoint & pos);
264 /// enable closing tab on middle-click
265 void mousePressEvent(QMouseEvent * me);
266 void mouseReleaseEvent(QMouseEvent * me);
268 void mouseDoubleClickEvent(QMouseEvent * event);
270 int indexOfWorkArea(GuiWorkArea * w) const;
273 using QTabWidget::addTab;
274 using QTabWidget::insertTab;
276 /// true if position is a tab (rather than the blank space in tab bar)
277 bool posIsTab(QPoint position);
283 QToolButton * closeBufferButton;
287 class DragTabBar : public QTabBar
292 DragTabBar(QWidget * parent = 0);
296 void mousePressEvent(QMouseEvent * event);
298 void mouseMoveEvent(QMouseEvent * event);
300 void dragEnterEvent(QDragEnterEvent * event);
302 void dropEvent(QDropEvent * event);
306 QPoint dragStartPos_;
310 void tabMoveRequested(int fromIndex, int toIndex);
314 class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
318 GuiWorkArea * const wa_;
319 void dispatch(FuncRequest f) const;
322 void updateDisplay();
327 void mouseDoubleClickEvent(QMouseEvent * event); //override
331 GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
333 GuiWorkArea * workArea() const { return wa_; }
338 } // namespace frontend