]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea.h
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiWorkArea.h
index 42bde9de90e25d5ce910d6712f47668901774f54..22e8bfdc0a32cc0589ee605230d714520baf8490 100644 (file)
 #ifndef WORKAREA_H
 #define WORKAREA_H
 
-#include "frontends/WorkArea.h"
+#include "ui_WorkAreaUi.h"
 
-#include "support/docstring.h"
+#include "frontends/WorkArea.h"
+#include "frontends/KeySymbol.h"
 
 #include <QAbstractScrollArea>
 #include <QTabBar>
@@ -26,13 +27,10 @@ class QDropEvent;
 class QToolButton;
 class QWidget;
 
-#ifdef CursorShape
-#undef CursorShape
-#endif
-
 namespace lyx {
 
 class Buffer;
+class FuncRequest;
 
 namespace frontend {
 
@@ -62,17 +60,14 @@ public:
        /// is GuiView in fullscreen mode?
        bool isFullScreen() const;
        ///
-       void scheduleRedraw();
-       ///
        BufferView & bufferView();
        ///
        BufferView const & bufferView() const;
        ///
-       void redraw(bool update_metrics);
+       void scheduleRedraw(bool update_metrics);
 
-       /// Process Key pressed event.
-       /// This needs to be public because it is accessed externally by GuiView.
-       void processKeySym(KeySymbol const & key, KeyModifier mod);
+       /// return true if the key is part of a shortcut
+       bool queryKeySym(KeySymbol const & key, KeyModifier mod) const;
 
        bool inDialogMode() const;
        void setDialogMode(bool mode);
@@ -80,23 +75,31 @@ public:
        ///
        GuiCompleter & completer();
 
-       Qt::CursorShape cursorShape() const;
-
        /// Return the GuiView this workArea belongs to
        GuiView const & view() const;
        GuiView & view();
 
+       /// Current ratio between physical pixels and device-independent pixels
+       double pixelRatio() const;
+
 public Q_SLOTS:
+       /// Process Key pressed event.
+       /// This needs to be public because it is accessed externally by GuiView.
+       void processKeySym(KeySymbol const & key, KeyModifier mod);
        ///
-       void stopBlinkingCursor();
+       void stopBlinkingCaret();
        ///
-       void startBlinkingCursor();
+       void startBlinkingCaret();
 
 Q_SIGNALS:
        ///
        void titleChanged(GuiWorkArea *);
        ///
        void busy(bool);
+       ///
+       void bufferViewChanged();
+       /// send key event to CompressorProxy
+       void compressKeySym(KeySymbol sym, KeyModifier mod, bool isAutoRepeat);
 
 private Q_SLOTS:
        /// Scroll the BufferView.
@@ -107,8 +110,8 @@ private Q_SLOTS:
        void scrollTo(int value);
        /// timer to limit triple clicks
        void doubleClickTimeout();
-       /// toggle the cursor's visibility
-       void toggleCursor();
+       /// toggle the caret's visibility
+       void toggleCaret();
        /// close this work area.
        /// Slot for Buffer::closing signal.
        void close();
@@ -140,7 +143,8 @@ private:
        void mouseMoveEvent(QMouseEvent * ev);
        /// wheel event
        void wheelEvent(QWheelEvent * ev);
-       /// key press
+       /// key press event. It also knows how to handle ShortcutOverride events to
+       /// avoid code duplication.
        void keyPressEvent(QKeyEvent * ev);
        /// IM events
        void inputMethodEvent(QInputMethodEvent * ev);
@@ -156,6 +160,23 @@ private:
 }; // GuiWorkArea
 
 
+/// 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);
+};
+
+
 class EmbeddedWorkArea : public GuiWorkArea
 {
        Q_OBJECT
@@ -184,6 +205,8 @@ private:
 }; // EmbeddedWorkArea
 
 
+class GuiWorkAreaContainer;
+
 /// A tabbed set of GuiWorkAreas.
 class TabWorkArea : public QTabWidget
 {
@@ -191,6 +214,10 @@ class TabWorkArea : public QTabWidget
 public:
        TabWorkArea(QWidget * parent = 0);
 
+       /// hide QTabWidget methods
+       GuiWorkAreaContainer * currentWidget() const;
+       GuiWorkAreaContainer * widget(int index) const;
+
        ///
        void setFullScreen(bool full_screen);
        void showBar(bool show);
@@ -198,9 +225,10 @@ public:
        bool setCurrentWorkArea(GuiWorkArea *);
        GuiWorkArea * addWorkArea(Buffer & buffer, GuiView & view);
        bool removeWorkArea(GuiWorkArea *);
-       GuiWorkArea * currentWorkArea();
-       GuiWorkArea * workArea(Buffer & buffer);
-       GuiWorkArea * workArea(int index);
+       GuiWorkArea * currentWorkArea() const;
+       GuiWorkArea * workArea(Buffer & buffer) const;
+       GuiWorkArea * workArea(int index) const;
+       void paintEvent(QPaintEvent *);
 
 Q_SIGNALS:
        ///
@@ -216,59 +244,62 @@ public Q_SLOTS:
        /// close the tab given by \c index
        void closeTab(int index);
        ///
+       void moveTab(int fromIndex, int toIndex);
+       ///
        void updateTabTexts();
-       
+
 private Q_SLOTS:
        ///
        void on_currentTabChanged(int index);
        ///
        void showContextMenu(const QPoint & pos);
-       ///
-       void moveTab(int fromIndex, int toIndex);
+       /// enable closing tab on middle-click
+       void mousePressEvent(QMouseEvent * me);
+       void mouseReleaseEvent(QMouseEvent * me);
        ///
        void mouseDoubleClickEvent(QMouseEvent * event);
+       ///
+       int indexOfWorkArea(GuiWorkArea * w) const;
 
 private:
-       ///
+       using QTabWidget::addTab;
+       using QTabWidget::insertTab;
+
+       /// true if position is a tab (rather than the blank space in tab bar)
+       bool posIsTab(QPoint position);
+
        int clicked_tab_;
        ///
+       int midpressed_tab_;
+       ///
        QToolButton * closeBufferButton;
 }; // TabWorkArea
 
 
-class DragTabBar : public QTabBar
+class GuiWorkAreaContainer : public QWidget, public Ui::WorkAreaUi
 {
        Q_OBJECT
-public:
-       ///
-       DragTabBar(QWidget * parent = 0);
+       // non-null
+       GuiWorkArea * const wa_;
+       void dispatch(FuncRequest f) const;
 
-#if QT_VERSION < 0x040300
-       ///
-       int tabAt(QPoint const & position) const;
-#endif
+private Q_SLOTS:
+       void updateDisplay();
+       void reload() const;
+       void ignore() const;
 
 protected:
-       ///
-       void mousePressEvent(QMouseEvent * event);
-       ///
-       void mouseMoveEvent(QMouseEvent * event);
-       ///
-       void dragEnterEvent(QDragEnterEvent * event);
-       ///
-       void dropEvent(QDropEvent * event);
-
-private:
-       ///
-       QPoint dragStartPos_;
-       ///
-       int dragCurrentIndex_;
+       void mouseDoubleClickEvent(QMouseEvent * event); //override
 
-Q_SIGNALS:
-       ///
-       void tabMoveRequested(int fromIndex, int toIndex);
+public:
+       /// wa != 0
+       GuiWorkAreaContainer(GuiWorkArea * wa, QWidget * parent = 0);
+       /// non-null
+       GuiWorkArea * workArea() const { return wa_; }
 };
 
+
+
 } // namespace frontend
 } // namespace lyx