2006-03-05 17:24:44 +00:00
|
|
|
// -*- C++ -*-
|
|
|
|
/**
|
2006-06-20 08:39:16 +00:00
|
|
|
* \file GuiWorkArea.h
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
* \author Abdelrazak Younes
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#ifndef WORKAREA_H
|
|
|
|
#define WORKAREA_H
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2017-03-01 23:41:02 +00:00
|
|
|
#include "ui_WorkAreaUi.h"
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
#include "frontends/WorkArea.h"
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include <QAbstractScrollArea>
|
2008-03-15 02:13:01 +00:00
|
|
|
#include <QTabBar>
|
2007-10-06 15:48:58 +00:00
|
|
|
#include <QTabWidget>
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2009-03-08 10:21:33 +00:00
|
|
|
class QToolButton;
|
2007-12-25 20:12:07 +00:00
|
|
|
class QWidget;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace lyx {
|
2007-11-12 22:15:51 +00:00
|
|
|
|
|
|
|
class Buffer;
|
2020-10-13 06:40:24 +00:00
|
|
|
class BufferView;
|
2017-03-01 23:41:02 +00:00
|
|
|
class FuncRequest;
|
2020-10-19 14:15:45 +00:00
|
|
|
class KeySymbol;
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
namespace frontend {
|
|
|
|
|
2008-04-21 19:12:15 +00:00
|
|
|
class GuiCompleter;
|
2007-11-13 09:52:28 +00:00
|
|
|
class GuiView;
|
2007-11-12 22:15:51 +00:00
|
|
|
|
2006-10-23 08:46:09 +00:00
|
|
|
class GuiWorkArea : public QAbstractScrollArea, public WorkArea
|
2006-08-17 17:15:17 +00:00
|
|
|
{
|
2006-03-05 17:24:44 +00:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2006-10-22 17:58:09 +00:00
|
|
|
///
|
2008-11-15 22:34:52 +00:00
|
|
|
GuiWorkArea(QWidget *);
|
|
|
|
///
|
|
|
|
GuiWorkArea(Buffer & buffer, GuiView & gv);
|
2007-11-12 22:15:51 +00:00
|
|
|
///
|
|
|
|
~GuiWorkArea();
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
///
|
|
|
|
void init();
|
2008-11-15 22:34:52 +00:00
|
|
|
///
|
|
|
|
void setBuffer(Buffer &);
|
|
|
|
///
|
|
|
|
void setGuiView(GuiView &);
|
2008-02-09 18:03:53 +00:00
|
|
|
///
|
|
|
|
void setFullScreen(bool full_screen);
|
2010-02-09 17:06:40 +00:00
|
|
|
/// is GuiView in fullscreen mode?
|
2011-10-16 22:48:26 +00:00
|
|
|
bool isFullScreen() const;
|
2006-11-04 07:29:25 +00:00
|
|
|
///
|
2007-11-12 22:15:51 +00:00
|
|
|
BufferView & bufferView();
|
|
|
|
///
|
|
|
|
BufferView const & bufferView() const;
|
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
void scheduleRedraw(bool update_metrics) override;
|
2011-10-23 20:21:01 +00:00
|
|
|
|
2016-07-04 02:23:32 +00:00
|
|
|
/// return true if the key is part of a shortcut
|
|
|
|
bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
|
2006-03-20 17:25:02 +00:00
|
|
|
|
2011-10-16 22:48:26 +00:00
|
|
|
bool inDialogMode() const;
|
|
|
|
void setDialogMode(bool mode);
|
2008-11-15 22:34:52 +00:00
|
|
|
|
2008-02-21 19:42:34 +00:00
|
|
|
///
|
2011-10-16 22:48:26 +00:00
|
|
|
GuiCompleter & completer();
|
2008-11-15 22:34:52 +00:00
|
|
|
|
|
|
|
/// Return the GuiView this workArea belongs to
|
2011-10-16 22:48:26 +00:00
|
|
|
GuiView const & view() const;
|
|
|
|
GuiView & view();
|
2008-11-15 22:34:52 +00:00
|
|
|
|
2014-10-12 17:23:13 +00:00
|
|
|
/// Current ratio between physical pixels and device-independent pixels
|
|
|
|
double pixelRatio() const;
|
|
|
|
|
2011-10-23 20:21:01 +00:00
|
|
|
public Q_SLOTS:
|
2018-01-12 14:41:27 +00:00
|
|
|
/// Process Key pressed event.
|
|
|
|
/// This needs to be public because it is accessed externally by GuiView.
|
|
|
|
void processKeySym(KeySymbol const & key, KeyModifier mod);
|
2011-10-23 20:21:01 +00:00
|
|
|
///
|
2017-07-21 23:19:45 +00:00
|
|
|
void stopBlinkingCaret();
|
2011-10-23 20:21:01 +00:00
|
|
|
///
|
2017-07-21 23:19:45 +00:00
|
|
|
void startBlinkingCaret();
|
2011-10-23 20:21:01 +00:00
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
///
|
|
|
|
void titleChanged(GuiWorkArea *);
|
2011-10-23 20:21:01 +00:00
|
|
|
///
|
|
|
|
void busy(bool);
|
2016-09-28 19:33:44 +00:00
|
|
|
///
|
|
|
|
void bufferViewChanged();
|
2018-01-12 09:58:31 +00:00
|
|
|
/// send key event to CompressorProxy
|
|
|
|
void compressKeySym(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
|
2007-11-14 17:39:16 +00:00
|
|
|
|
|
|
|
private Q_SLOTS:
|
2008-01-29 12:54:23 +00:00
|
|
|
/// Scroll the BufferView.
|
2007-11-12 22:15:51 +00:00
|
|
|
/**
|
2008-01-29 12:54:23 +00:00
|
|
|
* This is a slot for the valueChanged() signal of the vertical scrollbar.
|
|
|
|
* \p value value of the scrollbar.
|
2007-11-12 22:15:51 +00:00
|
|
|
*/
|
2008-01-29 12:54:23 +00:00
|
|
|
void scrollTo(int value);
|
2007-11-12 22:15:51 +00:00
|
|
|
/// timer to limit triple clicks
|
|
|
|
void doubleClickTimeout();
|
2017-08-24 15:37:56 +00:00
|
|
|
/// toggle the caret's visibility
|
2017-07-21 23:19:45 +00:00
|
|
|
void toggleCaret();
|
2007-11-12 22:15:51 +00:00
|
|
|
/// close this work area.
|
|
|
|
/// Slot for Buffer::closing signal.
|
2020-10-04 14:56:53 +00:00
|
|
|
void close() override;
|
2008-04-06 11:52:11 +00:00
|
|
|
/// Slot to restore proper scrollbar behaviour.
|
|
|
|
void fixVerticalScrollBar();
|
2007-11-11 22:30:21 +00:00
|
|
|
|
2007-11-14 17:39:16 +00:00
|
|
|
private:
|
2007-11-12 22:15:51 +00:00
|
|
|
/// Update window titles of all users.
|
2020-10-04 14:56:53 +00:00
|
|
|
void updateWindowTitle() override;
|
2006-10-23 08:46:09 +00:00
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
bool event(QEvent *) override;
|
2007-12-25 18:53:38 +00:00
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
void contextMenuEvent(QContextMenuEvent *) override;
|
2007-12-25 20:12:07 +00:00
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
void focusInEvent(QFocusEvent *) override;
|
2006-10-27 23:26:52 +00:00
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
void focusOutEvent(QFocusEvent *) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// repaint part of the widget
|
2020-10-04 14:56:53 +00:00
|
|
|
void paintEvent(QPaintEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// widget has been resized
|
2020-10-04 14:56:53 +00:00
|
|
|
void resizeEvent(QResizeEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse button press
|
2020-10-04 14:56:53 +00:00
|
|
|
void mousePressEvent(QMouseEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse button release
|
2020-10-04 14:56:53 +00:00
|
|
|
void mouseReleaseEvent(QMouseEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse double click of button
|
2020-10-04 14:56:53 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// mouse motion
|
2020-10-04 14:56:53 +00:00
|
|
|
void mouseMoveEvent(QMouseEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// wheel event
|
2020-10-04 14:56:53 +00:00
|
|
|
void wheelEvent(QWheelEvent * ev) override;
|
2016-07-04 02:23:32 +00:00
|
|
|
/// key press event. It also knows how to handle ShortcutOverride events to
|
|
|
|
/// avoid code duplication.
|
2020-10-03 12:42:14 +00:00
|
|
|
void keyPressEvent(QKeyEvent * ev) override;
|
2006-03-05 17:24:44 +00:00
|
|
|
/// IM events
|
2020-10-04 14:56:53 +00:00
|
|
|
void inputMethodEvent(QInputMethodEvent * ev) override;
|
2007-04-01 09:14:08 +00:00
|
|
|
/// IM query
|
2020-10-04 14:56:53 +00:00
|
|
|
QVariant inputMethodQuery(Qt::InputMethodQuery query) const override;
|
2006-03-05 17:24:44 +00:00
|
|
|
|
|
|
|
/// The slot connected to SyntheticMouseEvent::timeout.
|
|
|
|
void generateSyntheticMouseEvent();
|
2006-06-02 12:01:28 +00:00
|
|
|
|
2011-10-16 22:48:26 +00:00
|
|
|
friend class GuiCompleter;
|
|
|
|
struct Private;
|
|
|
|
Private * const d;
|
2007-11-12 22:15:51 +00:00
|
|
|
}; // GuiWorkArea
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
|
2018-01-12 09:58:31 +00:00
|
|
|
/// CompressorProxy adapted from Kuba Ober https://stackoverflow.com/a/21006207
|
|
|
|
class CompressorProxy : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
bool emitCheck(bool isAutoRepeat);
|
|
|
|
bool flag_;
|
|
|
|
// input: event to compress
|
|
|
|
Q_SLOT void slot(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
|
|
|
|
// output: compressed event
|
|
|
|
Q_SIGNAL void signal(KeySymbol sym, KeyModifier mod);
|
|
|
|
public:
|
|
|
|
// No default constructor, since the proxy must be a child of the
|
|
|
|
// target object.
|
|
|
|
explicit CompressorProxy(GuiWorkArea * wa);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
class EmbeddedWorkArea : public GuiWorkArea
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
|
|
|
///
|
|
|
|
EmbeddedWorkArea(QWidget *);
|
|
|
|
~EmbeddedWorkArea();
|
|
|
|
|
|
|
|
/// Dummy methods for Designer.
|
|
|
|
void setWidgetResizable(bool) {}
|
|
|
|
void setWidget(QWidget *) {}
|
|
|
|
|
2020-10-04 14:56:53 +00:00
|
|
|
QSize sizeHint () const override;
|
2008-11-22 15:21:45 +00:00
|
|
|
///
|
|
|
|
void disable();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
///
|
2020-10-03 12:42:14 +00:00
|
|
|
void closeEvent(QCloseEvent * ev) override;
|
2008-11-22 17:35:17 +00:00
|
|
|
///
|
2020-10-03 12:42:14 +00:00
|
|
|
void hideEvent(QHideEvent *ev) override;
|
2008-11-22 15:21:45 +00:00
|
|
|
|
2008-11-22 14:45:47 +00:00
|
|
|
private:
|
|
|
|
/// Embedded Buffer.
|
|
|
|
Buffer * buffer_;
|
|
|
|
}; // EmbeddedWorkArea
|
|
|
|
|
|
|
|
|
2017-03-18 14:08:20 +00:00
|
|
|
class GuiWorkAreaContainer;
|
|
|
|
|
2007-10-06 15:48:58 +00:00
|
|
|
/// A tabbed set of GuiWorkAreas.
|
|
|
|
class TabWorkArea : public QTabWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
public:
|
2020-05-18 05:15:50 +00:00
|
|
|
TabWorkArea(QWidget * parent = nullptr);
|
2007-11-11 22:30:21 +00:00
|
|
|
|
2017-03-18 14:08:20 +00:00
|
|
|
/// hide QTabWidget methods
|
|
|
|
GuiWorkAreaContainer * currentWidget() const;
|
|
|
|
GuiWorkAreaContainer * widget(int index) const;
|
|
|
|
|
2008-02-09 18:29:15 +00:00
|
|
|
///
|
|
|
|
void setFullScreen(bool full_screen);
|
2007-10-06 15:48:58 +00:00
|
|
|
void showBar(bool show);
|
2007-10-07 08:12:20 +00:00
|
|
|
void closeAll();
|
2007-10-07 08:05:02 +00:00
|
|
|
bool setCurrentWorkArea(GuiWorkArea *);
|
2007-11-19 10:04:14 +00:00
|
|
|
GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
|
2007-10-07 08:05:02 +00:00
|
|
|
bool removeWorkArea(GuiWorkArea *);
|
2017-03-18 14:08:20 +00:00
|
|
|
GuiWorkArea * currentWorkArea() const;
|
|
|
|
GuiWorkArea * workArea(Buffer & buffer) const;
|
|
|
|
GuiWorkArea * workArea(int index) const;
|
2020-10-04 14:56:53 +00:00
|
|
|
void paintEvent(QPaintEvent *) override;
|
2007-10-06 15:48:58 +00:00
|
|
|
|
|
|
|
Q_SIGNALS:
|
|
|
|
///
|
|
|
|
void currentWorkAreaChanged(GuiWorkArea *);
|
2008-03-14 23:24:59 +00:00
|
|
|
///
|
|
|
|
void lastWorkAreaRemoved();
|
2007-10-06 15:48:58 +00:00
|
|
|
|
|
|
|
public Q_SLOTS:
|
2008-03-15 01:00:25 +00:00
|
|
|
/// close current buffer, or the one given by \c clicked_tab_
|
2008-02-21 12:29:26 +00:00
|
|
|
void closeCurrentBuffer();
|
2009-10-31 18:14:21 +00:00
|
|
|
/// hide current tab, or the one given by \c clicked_tab_
|
|
|
|
void hideCurrentTab();
|
2009-10-31 18:10:18 +00:00
|
|
|
/// close the tab given by \c index
|
|
|
|
void closeTab(int index);
|
2007-11-11 22:30:21 +00:00
|
|
|
///
|
2015-04-08 03:18:21 +00:00
|
|
|
void moveTab(int fromIndex, int toIndex);
|
|
|
|
///
|
2008-04-29 15:44:07 +00:00
|
|
|
void updateTabTexts();
|
2017-03-18 14:08:20 +00:00
|
|
|
|
2008-03-15 01:00:25 +00:00
|
|
|
private Q_SLOTS:
|
2008-03-15 02:13:01 +00:00
|
|
|
///
|
|
|
|
void on_currentTabChanged(int index);
|
2008-03-15 01:00:25 +00:00
|
|
|
///
|
|
|
|
void showContextMenu(const QPoint & pos);
|
2016-07-13 06:42:35 +00:00
|
|
|
/// enable closing tab on middle-click
|
2020-10-04 14:56:53 +00:00
|
|
|
void mousePressEvent(QMouseEvent * me) override;
|
|
|
|
void mouseReleaseEvent(QMouseEvent * me) override;
|
2008-03-15 02:13:01 +00:00
|
|
|
///
|
2020-10-04 14:56:53 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent * event) override;
|
2017-03-01 23:41:02 +00:00
|
|
|
///
|
|
|
|
int indexOfWorkArea(GuiWorkArea * w) const;
|
2008-03-15 01:00:25 +00:00
|
|
|
|
|
|
|
private:
|
2017-03-18 14:08:20 +00:00
|
|
|
using QTabWidget::addTab;
|
|
|
|
using QTabWidget::insertTab;
|
|
|
|
|
2016-07-21 23:16:19 +00:00
|
|
|
/// true if position is a tab (rather than the blank space in tab bar)
|
|
|
|
bool posIsTab(QPoint position);
|
|
|
|
|
2008-03-15 01:00:25 +00:00
|
|
|
int clicked_tab_;
|
2009-03-08 10:21:33 +00:00
|
|
|
///
|
2016-07-13 06:42:35 +00:00
|
|
|
int midpressed_tab_;
|
|
|
|
///
|
2009-03-08 10:21:33 +00:00
|
|
|
QToolButton * closeBufferButton;
|
2007-10-06 15:48:58 +00:00
|
|
|
}; // TabWorkArea
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2008-03-15 02:13:01 +00:00
|
|
|
|
2017-03-01 23:41:02 +00:00
|
|
|
class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2017-03-18 14:08:20 +00:00
|
|
|
// non-null
|
2017-03-01 23:41:02 +00:00
|
|
|
GuiWorkArea * const wa_;
|
|
|
|
void dispatch(FuncRequest f) const;
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void updateDisplay();
|
|
|
|
void reload() const;
|
|
|
|
void ignore() const;
|
|
|
|
|
|
|
|
protected:
|
2020-10-01 07:42:11 +00:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent * event) override;
|
2017-03-01 23:41:02 +00:00
|
|
|
|
|
|
|
public:
|
2017-03-18 14:08:20 +00:00
|
|
|
/// wa != 0
|
2020-05-18 05:15:50 +00:00
|
|
|
GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = nullptr);
|
2017-03-18 14:08:20 +00:00
|
|
|
/// non-null
|
2017-03-01 23:41:02 +00:00
|
|
|
GuiWorkArea * workArea() const { return wa_; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-06-20 08:39:16 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
|
|
|
|
|
|
|
#endif // WORKAREA_H
|