commit 067d6dc759b819d2a40a4dea0b09736d474ddc24
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Oct 21 16:45:03 2019 +0200

    Mark insets with invalid buffer() in red in devel-mode.
    
    We tend to have insets which buffer() member is invalid. To help
    debugging, this commit paints their background in red when devel-mode
    is on.
    
    To this end, a new method develMode() is added to the Painter class.
    
    With this commit, it is easy to see that macro template do not have a
    proper buffer set!
---
 src/MetricsInfo.cpp              |   28 +++++++++++++++-------------
 src/frontends/NullPainter.h      |    2 +-
 src/frontends/Painter.h          |    7 ++++++-
 src/frontends/qt/GuiPainter.cpp  |    4 ++--
 src/frontends/qt/GuiPainter.h    |    2 +-
 src/frontends/qt/GuiWorkArea.cpp |    2 +-
 src/mathed/MathRow.cpp           |    3 +++
 7 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/MetricsInfo.cpp b/src/MetricsInfo.cpp
index e7bbefb..93c6e39 100644
--- a/src/MetricsInfo.cpp
+++ b/src/MetricsInfo.cpp
@@ -158,19 +158,21 @@ ColorCode PainterInfo::backgroundColor(Inset const * 
inset, bool sel) const
        if (selected && sel)
                // This inset is in a selection
                return Color_selection;
-       else {
-               if (color_bg != Color_none)
-                       // This inset has its own color
-                       return color_bg;
-               else {
-                       if (background_color == Color_none)
-                               // This inset has no own color and does not 
inherit a color
-                               return Color_background;
-                       else
-                               // This inset has no own color, but inherits a 
color
-                               return background_color;
-               }
-       }
+
+       if (pain.develMode() && !inset->isBufferValid())
+               // This inset is in error
+               return Color_error;
+
+       if (color_bg != Color_none)
+               // This inset has its own color
+               return color_bg;
+
+       if (background_color == Color_none)
+               // This inset has no own color and does not inherit a color
+               return Color_background;
+
+       // This inset has no own color, but inherits a color
+       return background_color;
 }
 
 
diff --git a/src/frontends/NullPainter.h b/src/frontends/NullPainter.h
index 19ac8b6..6984e7c 100644
--- a/src/frontends/NullPainter.h
+++ b/src/frontends/NullPainter.h
@@ -25,7 +25,7 @@ namespace frontend {
  */
 class NullPainter : public Painter {
 public:
-       NullPainter() : Painter(1) {}
+       NullPainter() : Painter(1, false) {}
 
        ~NullPainter() {}
 
diff --git a/src/frontends/Painter.h b/src/frontends/Painter.h
index 17253b2..1ab4347 100644
--- a/src/frontends/Painter.h
+++ b/src/frontends/Painter.h
@@ -49,7 +49,8 @@ namespace frontend {
  */
 class Painter {
 public:
-       Painter(double pixel_ratio) : pixel_ratio_(pixel_ratio) {}
+       Painter(double pixel_ratio, bool devel_mode)
+               : pixel_ratio_(pixel_ratio), devel_mode_(devel_mode) {}
 
        static const int thin_line;
 
@@ -152,6 +153,8 @@ public:
 
        double pixelRatio() const { return pixel_ratio_; }
 
+       double develMode() const { return devel_mode_; }
+
        /// draw the underbar, strikeout, xout, uuline and uwave font attributes
        virtual void textDecoration(FontInfo const & f, int x, int y, int 
width) = 0;
 
@@ -182,6 +185,8 @@ public:
 private:
        /// Ratio between physical pixels and device-independent pixels
        double pixel_ratio_;
+       /// True when developer more is on at application-level.
+       bool devel_mode_;
 };
 
 } // namespace frontend
diff --git a/src/frontends/qt/GuiPainter.cpp b/src/frontends/qt/GuiPainter.cpp
index c1f3677..d255f50 100644
--- a/src/frontends/qt/GuiPainter.cpp
+++ b/src/frontends/qt/GuiPainter.cpp
@@ -39,8 +39,8 @@ namespace frontend {
 
 const int Painter::thin_line = 1;
 
-GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio)
-       : QPainter(device), Painter(pixel_ratio)
+GuiPainter::GuiPainter(QPaintDevice * device, double pixel_ratio, bool 
devel_mode)
+       : QPainter(device), Painter(pixel_ratio, devel_mode)
 {
        // set cache correctly
        current_color_ = pen().color();
diff --git a/src/frontends/qt/GuiPainter.h b/src/frontends/qt/GuiPainter.h
index a4f40be..0c85194 100644
--- a/src/frontends/qt/GuiPainter.h
+++ b/src/frontends/qt/GuiPainter.h
@@ -34,7 +34,7 @@ namespace frontend {
  */
 class GuiPainter : public QPainter, public Painter {
 public:
-       GuiPainter(QPaintDevice *, double pixel_ratio);
+       GuiPainter(QPaintDevice *, double pixel_ratio, bool devel_mode);
        virtual ~GuiPainter();
 
        /// This painter paints
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 07ad690..ab13c68 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -1330,7 +1330,7 @@ void GuiWorkArea::paintEvent(QPaintEvent * ev)
 
        d->last_pixel_ratio_ = pixelRatio();
 
-       GuiPainter pain(d->screenDevice(), pixelRatio());
+       GuiPainter pain(d->screenDevice(), pixelRatio(), 
d->lyx_view_->develMode());
 
        d->buffer_view_->draw(pain, d->caret_visible_);
 
diff --git a/src/mathed/MathRow.cpp b/src/mathed/MathRow.cpp
index 7c5b945..d66d0d3 100644
--- a/src/mathed/MathRow.cpp
+++ b/src/mathed/MathRow.cpp
@@ -326,6 +326,9 @@ void MathRow::draw(PainterInfo & pi, int x, int const y) 
const
                        Dimension d2 = d;
                        d2.wid -= e.before + e.after;
                        coords.insets().add(e.inset, d2);
+                       if (pi.pain.develMode() && !e.inset->isBufferValid())
+                               pi.pain.fillRectangle(x + e.before, y - 
d2.ascent(),
+                                                     d2.width(), d2.height(), 
Color_error);
                        e.inset->draw(pi, x + e.before, y);
                        coords.insets().add(e.inset, x, y);
                        coords.insets().add(e.inset, d);
-- 
lyx-cvs mailing list
[email protected]
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to