From 1866c042480b2275774c1348ede336b86818b9de Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Mon, 21 Oct 2019 16:45:03 +0200 Subject: [PATCH] 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 e7bbefbf0d..93c6e396f1 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 19ac8b66a2..6984e7ca50 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 17253b2f44..1ab43476c7 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 c1f3677815..d255f507cb 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 a4f40be51c..0c85194a4d 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 07ad690469..ab13c687d7 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 7c5b9456ac..d66d0d3e16 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); -- 2.39.5