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;
40 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
46 GuiWorkArea(QWidget *);
48 GuiWorkArea(Buffer & buffer, GuiView & gv);
55 void setBuffer(Buffer &);
57 void setGuiView(GuiView &);
59 void setFullScreen(bool full_screen);
60 /// is GuiView in fullscreen mode?
61 bool isFullScreen() const;
63 void scheduleRedraw();
65 BufferView & bufferView();
67 BufferView const & bufferView() const;
69 void redraw(bool update_metrics);
71 /// return true if the key is part of a shortcut
72 bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
74 bool inDialogMode() const;
75 void setDialogMode(bool mode);
78 GuiCompleter & completer();
80 /// Return the GuiView this workArea belongs to
81 GuiView const & view() const;
84 /// Current ratio between physical pixels and device-independent pixels
85 double pixelRatio() const;
88 /// Process Key pressed event.
89 /// This needs to be public because it is accessed externally by GuiView.
90 void processKeySym(KeySymbol const & key, KeyModifier mod);
92 void stopBlinkingCaret();
94 void startBlinkingCaret();
98 void titleChanged(GuiWorkArea *);
102 void bufferViewChanged();
103 /// send key event to CompressorProxy
104 void compressKeySym(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
107 /// Scroll the BufferView.
109 * This is a slot for the valueChanged() signal of the vertical scrollbar.
110 * \p value value of the scrollbar.
112 void scrollTo(int value);
113 /// timer to limit triple clicks
114 void doubleClickTimeout();
115 /// toggle the caret's visibility
117 /// close this work area.
118 /// Slot for Buffer::closing signal.
120 /// Slot to restore proper scrollbar behaviour.
121 void fixVerticalScrollBar();
124 /// Update window titles of all users.
125 void updateWindowTitle();
127 bool event(QEvent *);
129 void contextMenuEvent(QContextMenuEvent *);
131 void focusInEvent(QFocusEvent *);
133 void focusOutEvent(QFocusEvent *);
134 /// repaint part of the widget
135 void paintEvent(QPaintEvent * ev);
136 /// widget has been resized
137 void resizeEvent(QResizeEvent * ev);
138 /// mouse button press
139 void mousePressEvent(QMouseEvent * ev);
140 /// mouse button release
141 void mouseReleaseEvent(QMouseEvent * ev);
142 /// mouse double click of button
143 void mouseDoubleClickEvent(QMouseEvent * ev);
145 void mouseMoveEvent(QMouseEvent * ev);
147 void wheelEvent(QWheelEvent * ev);
148 /// key press event. It also knows how to handle ShortcutOverride events to
149 /// avoid code duplication.
150 void keyPressEvent(QKeyEvent * ev);
152 void inputMethodEvent(QInputMethodEvent * ev);
154 QVariant inputMethodQuery(Qt::InputMethodQuery query) const;
156 /// The slot connected to SyntheticMouseEvent::timeout.
157 void generateSyntheticMouseEvent();
159 friend class GuiCompleter;
165 /// CompressorProxy adapted from Kuba Ober https://stackoverflow.com/a/21006207
166 class CompressorProxy : public QObject
169 bool emitCheck(bool isAutoRepeat);
171 // input: event to compress
172 Q_SLOT void slot(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
173 // output: compressed event
174 Q_SIGNAL void signal(KeySymbol sym, KeyModifier mod);
176 // No default constructor, since the proxy must be a child of the
178 explicit CompressorProxy(GuiWorkArea * wa);
182 class EmbeddedWorkArea : public GuiWorkArea
187 EmbeddedWorkArea(QWidget *);
190 /// Dummy methods for Designer.
191 void setWidgetResizable(bool) {}
192 void setWidget(QWidget *) {}
194 QSize sizeHint () const;
200 void closeEvent(QCloseEvent * ev);
202 void hideEvent(QHideEvent *ev);
207 }; // EmbeddedWorkArea
210 class GuiWorkAreaContainer;
212 /// A tabbed set of GuiWorkAreas.
213 class TabWorkArea : public QTabWidget
217 TabWorkArea(QWidget * parent = 0);
219 /// hide QTabWidget methods
220 GuiWorkAreaContainer * currentWidget() const;
221 GuiWorkAreaContainer * widget(int index) const;
224 void setFullScreen(bool full_screen);
225 void showBar(bool show);
227 bool setCurrentWorkArea(GuiWorkArea *);
228 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
229 bool removeWorkArea(GuiWorkArea *);
230 GuiWorkArea * currentWorkArea() const;
231 GuiWorkArea * workArea(Buffer & buffer) const;
232 GuiWorkArea * workArea(int index) const;
233 void paintEvent(QPaintEvent *);
237 void currentWorkAreaChanged(GuiWorkArea *);
239 void lastWorkAreaRemoved();
242 /// close current buffer, or the one given by \c clicked_tab_
243 void closeCurrentBuffer();
244 /// hide current tab, or the one given by \c clicked_tab_
245 void hideCurrentTab();
246 /// close the tab given by \c index
247 void closeTab(int index);
249 void moveTab(int fromIndex, int toIndex);
251 void updateTabTexts();
255 void on_currentTabChanged(int index);
257 void showContextMenu(const QPoint & pos);
258 /// enable closing tab on middle-click
259 void mousePressEvent(QMouseEvent * me);
260 void mouseReleaseEvent(QMouseEvent * me);
262 void mouseDoubleClickEvent(QMouseEvent * event);
264 int indexOfWorkArea(GuiWorkArea * w) const;
267 using QTabWidget::addTab;
268 using QTabWidget::insertTab;
270 /// true if position is a tab (rather than the blank space in tab bar)
271 bool posIsTab(QPoint position);
277 QToolButton * closeBufferButton;
281 class DragTabBar : public QTabBar
286 DragTabBar(QWidget * parent = 0);
290 void mousePressEvent(QMouseEvent * event);
292 void mouseMoveEvent(QMouseEvent * event);
294 void dragEnterEvent(QDragEnterEvent * event);
296 void dropEvent(QDropEvent * event);
300 QPoint dragStartPos_;
304 void tabMoveRequested(int fromIndex, int toIndex);
308 class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
312 GuiWorkArea * const wa_;
313 void dispatch(FuncRequest f) const;
316 void updateDisplay();
321 void mouseDoubleClickEvent(QMouseEvent * event); //override
325 GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
327 GuiWorkArea * workArea() const { return wa_; }
332 } // namespace frontend