]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiWorkArea_Private.h
Use <cstdint> instead of <boost/cstdint.hpp>
[lyx.git] / src / frontends / qt4 / GuiWorkArea_Private.h
index 7198c569feeab8498ebbcc27a94b02c4db9ed28e..83012fa99f10123329936de2a27f254a7387d87e 100644 (file)
 #include <QMouseEvent>
 #include <QTimer>
 
+#ifdef Q_OS_MAC
+/* Qt on macOS does not respect the Qt::WA_OpaquePaintEvent attribute
+ * and resets the widget backing store at each update. Therefore, we
+ * use our own backing store in this case */
+#define LYX_BACKINGSTORE 1
+#include <QPainter>
+#endif
+
 namespace lyx {
 
 class Buffer;
@@ -85,10 +93,12 @@ struct GuiWorkArea::Private
 
        ///
        void dispatch(FuncRequest const & cmd0);
-       /// hide the visible cursor, if it is visible
-       void hideCaret();
-       /// show the cursor if it is not visible
+       /// recompute the shape and position of the caret
+       void updateCaretGeometry();
+       /// show the caret if it is not visible
        void showCaret();
+       /// hide the caret if it is visible
+       void hideCaret();
        /// Set the range and value of the scrollbar and connect to its valueChanged
        /// signal.
        void updateScrollbar();
@@ -97,10 +107,38 @@ struct GuiWorkArea::Private
 
        void paintPreeditText(GuiPainter & pain);
 
-       bool needResize() const {
-               return need_resize_ || p->pixelRatio() != pixel_ratio_;
+       void resetScreen() {
+#ifdef LYX_BACKINGSTORE
+               int const pr = p->pixelRatio();
+               screen_ = QImage(static_cast<int>(pr * p->viewport()->width()),
+                                static_cast<int>(pr * p->viewport()->height()),
+                                QImage::Format_ARGB32_Premultiplied);
+#  if QT_VERSION >= 0x050000
+               screen_.setDevicePixelRatio(pr);
+#  endif
+#endif
+       }
+
+       QPaintDevice * screenDevice() {
+#ifdef LYX_BACKINGSTORE
+               return &screen_;
+#else
+               return p->viewport();
+#endif
        }
 
+#ifdef LYX_BACKINGSTORE
+       void updateScreen(QRectF const & rc) {
+               QPainter qpain(p->viewport());
+               double const pr = p->pixelRatio();
+               QRectF const rcs = QRectF(rc.x() * pr, rc.y() * pr,
+                                         rc.width() * pr, rc.height() * pr);
+               qpain.drawImage(rc, screen_, rcs);
+       }
+#else
+       void updateScreen(QRectF const & ) {}
+#endif
+
        ///
        GuiWorkArea * p;
        ///
@@ -108,9 +146,13 @@ struct GuiWorkArea::Private
        ///
        GuiView * lyx_view_;
 
+#ifdef LYX_BACKINGSTORE
+       ///
+       QImage screen_;
+#endif
        ///
        CaretWidget * caret_;
-       /// is the cursor currently displayed
+       /// is the caret currently displayed
        bool caret_visible_;
        ///
        QTimer caret_timeout_;
@@ -122,8 +164,6 @@ struct GuiWorkArea::Private
 
        ///
        bool need_resize_;
-       ///
-       bool schedule_redraw_;
 
        /// the current preedit text of the input method
        docstring preedit_string_;
@@ -135,7 +175,7 @@ struct GuiWorkArea::Private
        /// Ratio between physical pixels and device-independent pixels
        /// We save the last used value to detect changes of the
        /// current pixel_ratio of the viewport.
-       double pixel_ratio_;
+       double last_pixel_ratio_;
        ///
        GuiCompleter * completer_;