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"
20 #include <QAbstractScrollArea>
39 class GuiWorkArea : public QAbstractScrollArea, public WorkArea
45 GuiWorkArea(QWidget *);
47 GuiWorkArea(Buffer & buffer, GuiView & gv);
54 void setBuffer(Buffer &);
56 void setGuiView(GuiView &);
58 void setFullScreen(bool full_screen);
59 /// is GuiView in fullscreen mode?
60 bool isFullScreen() const;
62 BufferView & bufferView();
64 BufferView const & bufferView() const;
66 void scheduleRedraw(bool update_metrics) override;
68 /// return true if the key is part of a shortcut
69 bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
71 bool inDialogMode() const;
72 void setDialogMode(bool mode);
75 GuiCompleter & completer();
77 /// Return the GuiView this workArea belongs to
78 GuiView const & view() const;
81 /// Current ratio between physical pixels and device-independent pixels
82 double pixelRatio() const;
85 /// Process Key pressed event.
86 /// This needs to be public because it is accessed externally by GuiView.
87 void processKeySym(KeySymbol const & key, KeyModifier mod);
89 void stopBlinkingCaret();
91 void startBlinkingCaret();
95 void titleChanged(GuiWorkArea *);
99 void bufferViewChanged();
100 /// send key event to CompressorProxy
101 void compressKeySym(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
104 /// Scroll the BufferView.
106 * This is a slot for the valueChanged() signal of the vertical scrollbar.
107 * \p value value of the scrollbar.
109 void scrollTo(int value);
110 /// timer to limit triple clicks
111 void doubleClickTimeout();
112 /// toggle the caret's visibility
114 /// close this work area.
115 /// Slot for Buffer::closing signal.
116 void close() override;
117 /// Slot to restore proper scrollbar behaviour.
118 void fixVerticalScrollBar();
121 /// Update window titles of all users.
122 void updateWindowTitle() override;
124 bool event(QEvent *) override;
126 void contextMenuEvent(QContextMenuEvent *) override;
128 void focusInEvent(QFocusEvent *) override;
130 void focusOutEvent(QFocusEvent *) override;
131 /// repaint part of the widget
132 void paintEvent(QPaintEvent * ev) override;
133 /// widget has been resized
134 void resizeEvent(QResizeEvent * ev) override;
135 /// mouse button press
136 void mousePressEvent(QMouseEvent * ev) override;
137 /// mouse button release
138 void mouseReleaseEvent(QMouseEvent * ev) override;
139 /// mouse double click of button
140 void mouseDoubleClickEvent(QMouseEvent * ev) override;
142 void mouseMoveEvent(QMouseEvent * ev) override;
144 void wheelEvent(QWheelEvent * ev) override;
145 /// key press event. It also knows how to handle ShortcutOverride events to
146 /// avoid code duplication.
147 void keyPressEvent(QKeyEvent * ev) override;
149 void inputMethodEvent(QInputMethodEvent * ev) override;
151 QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
153 /// The slot connected to SyntheticMouseEvent::timeout.
154 void generateSyntheticMouseEvent();
156 friend class GuiCompleter;
162 /// CompressorProxy adapted from Kuba Ober https://stackoverflow.com/a/21006207
163 class CompressorProxy : public QObject
166 bool emitCheck(bool isAutoRepeat);
168 // input: event to compress
169 Q_SLOT void slot(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
170 // output: compressed event
171 Q_SIGNAL void signal(KeySymbol sym, KeyModifier mod);
173 // No default constructor, since the proxy must be a child of the
175 explicit CompressorProxy(GuiWorkArea * wa);
179 class EmbeddedWorkArea : public GuiWorkArea
184 EmbeddedWorkArea(QWidget *);
187 /// Dummy methods for Designer.
188 void setWidgetResizable(bool) {}
189 void setWidget(QWidget *) {}
191 QSize sizeHint () const override;
197 void closeEvent(QCloseEvent * ev) override;
199 void hideEvent(QHideEvent *ev) override;
204 }; // EmbeddedWorkArea
207 class GuiWorkAreaContainer;
209 /// A tabbed set of GuiWorkAreas.
210 class TabWorkArea : public QTabWidget
214 TabWorkArea(QWidget * parent = nullptr);
216 /// hide QTabWidget methods
217 GuiWorkAreaContainer * currentWidget() const;
218 GuiWorkAreaContainer * widget(int index) const;
221 void setFullScreen(bool full_screen);
222 void showBar(bool show);
224 bool setCurrentWorkArea(GuiWorkArea *);
225 GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
226 bool removeWorkArea(GuiWorkArea *);
227 GuiWorkArea * currentWorkArea() const;
228 GuiWorkArea * workArea(Buffer & buffer) const;
229 GuiWorkArea * workArea(int index) const;
230 void paintEvent(QPaintEvent *) override;
234 void currentWorkAreaChanged(GuiWorkArea *);
236 void lastWorkAreaRemoved();
239 /// close current buffer, or the one given by \c clicked_tab_
240 void closeCurrentBuffer();
241 /// hide current tab, or the one given by \c clicked_tab_
242 void hideCurrentTab();
243 /// close the tab given by \c index
244 void closeTab(int index);
246 void moveTab(int fromIndex, int toIndex);
248 void updateTabTexts();
252 void on_currentTabChanged(int index);
254 void showContextMenu(const QPoint & pos);
255 /// enable closing tab on middle-click
256 void mousePressEvent(QMouseEvent * me) override;
257 void mouseReleaseEvent(QMouseEvent * me) override;
259 void mouseDoubleClickEvent(QMouseEvent * event) override;
261 int indexOfWorkArea(GuiWorkArea * w) const;
264 using QTabWidget::addTab;
265 using QTabWidget::insertTab;
267 /// true if position is a tab (rather than the blank space in tab bar)
268 bool posIsTab(QPoint position);
274 QToolButton * closeBufferButton;
278 class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
282 GuiWorkArea * const wa_;
283 void dispatch(FuncRequest const & f) const;
286 void updateDisplay();
291 void mouseDoubleClickEvent(QMouseEvent * event) override;
295 GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = nullptr);
297 GuiWorkArea * workArea() const { return wa_; }
302 } // namespace frontend