]> git.lyx.org Git - lyx.git/commitdiff
Make InsetInfo math/IPA icons visible in dark mode
authorJuergen Spitzmueller <spitz@lyx.org>
Sun, 13 Dec 2020 08:51:32 +0000 (09:51 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sun, 13 Dec 2020 08:51:32 +0000 (09:51 +0100)
This does not show the real colors, but the icons are at least readable.

15 files changed:
src/frontends/NullPainter.h
src/frontends/Painter.h
src/frontends/qt/GuiPainter.cpp
src/frontends/qt/GuiPainter.h
src/insets/InsetGraphics.cpp
src/insets/InsetGraphicsParams.cpp
src/insets/InsetGraphicsParams.h
src/insets/InsetInfo.cpp
src/insets/RenderBase.h
src/insets/RenderButton.cpp
src/insets/RenderButton.h
src/insets/RenderGraphic.cpp
src/insets/RenderGraphic.h
src/insets/RenderPreview.cpp
src/insets/RenderPreview.h

index 4a4b5941b7cd64d96cdb48cadf7a4279b1c4bb83..8f7efff2ec8dda3aae8437bc13665011923c02ef 100644 (file)
@@ -57,7 +57,7 @@ public:
        void point(int, int, Color) override {}
 
        /// draw an image from the image cache
-       void image(int, int, int, int, graphics::Image const &) override {}
+       void image(int, int, int, int, graphics::Image const &, bool) override {}
 
        /// draw a string
        void text(int, int, docstring const &, FontInfo const &) override {}
index e2796d97d92e518f13adb015de42b7eaba0bc2ac..6deeda608dd325afc2aba16cf12990c64ee0ee4a 100644 (file)
@@ -127,7 +127,7 @@ public:
 
        /// draw an image from the image cache
        virtual void image(int x, int y, int w, int h,
-               graphics::Image const & image) = 0;
+               graphics::Image const & image, bool const darkmode = false) = 0;
 
        /// draw a string at position x, y (y is the baseline).
        virtual void text(int x, int y, docstring const & str, FontInfo const & f) = 0;
index 79bbf5603e85fc9ec31e435c6618a25d61fa5b7a..a143b2b05372e1feea17b5a5ec2ee0ca96089531 100644 (file)
@@ -233,14 +233,24 @@ void GuiPainter::arc(int x, int y, unsigned int w, unsigned int h,
 }
 
 
-void GuiPainter::image(int x, int y, int w, int h, graphics::Image const & i)
+void GuiPainter::image(int x, int y, int w, int h, graphics::Image const & i, bool const darkmode)
 {
        graphics::GuiImage const & qlimage =
                static_cast<graphics::GuiImage const &>(i);
 
        fillRectangle(x, y, w, h, Color_graphicsbg);
 
-       QImage const & image = qlimage.image();
+       QImage image = qlimage.image();
+       
+       QPalette palette = QPalette();
+       QColor text_color = palette.color(QPalette::Active, QPalette::WindowText);
+       QColor bg_color = palette.color(QPalette::Active, QPalette::Window);
+       // guess whether we are in dark mode
+       if (darkmode && text_color.black() < bg_color.black())
+               // FIXME this is only a cheap approximation
+               // Ideally, replace colors as in GuiApplication::prepareForDarkmode()
+               image.invertPixels();
+
        QRectF const drect = QRectF(x, y, w, h);
        QRectF const srect = QRectF(0, 0, image.width(), image.height());
        // Bilinear filtering is needed on a rare occasion for instant previews when
index bffcd9ae5af52a0a756465ffd9638a0a1d50be01..bdf3e462e72dbe15ec4131f7754f64eda56f9499 100644 (file)
@@ -104,7 +104,7 @@ public:
 
        /// draw an image from the image cache
        void image(int x, int y, int w, int h,
-               lyx::graphics::Image const & image) override;
+               lyx::graphics::Image const & image, bool const darkmode = false) override;
 
        /// draw a string at position x, y (y is the baseline).
        void text(int x, int y, docstring const & str, FontInfo const & f) override;
index d8fabd6f4d523732be26883c7e54cdf1842bd361..7daa40d9aaf392438b293f99ac81b2b18b7ee25f 100644 (file)
@@ -293,7 +293,7 @@ void InsetGraphics::metrics(MetricsInfo & mi, Dimension & dim) const
 
 void InsetGraphics::draw(PainterInfo & pi, int x, int y) const
 {
-       graphic_->draw(pi, x, y);
+       graphic_->draw(pi, x, y, params_.darkModeSensitive);
 }
 
 
index a8c2a26239994033f0036aac749edcb08e96a917..13b57c07753ea97223a90a3ef55aeb7e78687d00 100644 (file)
@@ -74,6 +74,7 @@ void InsetGraphicsParams::init()
 
        bbox = graphics::BoundingBox(); // bounding box
        clip = false;                   // clip image
+       darkModeSensitive = false;      // dark mode dependency (InsetInfo)
 
        rotateAngle = "0";              // angle of rotation in degrees
        rotateOrigin.erase();           // Origin of rotation
@@ -96,6 +97,7 @@ void InsetGraphicsParams::copy(InsetGraphicsParams const & params)
 
        bbox = params.bbox;
        clip = params.clip;
+       darkModeSensitive = params.darkModeSensitive;
 
        rotateAngle = params.rotateAngle;
        rotateOrigin = params.rotateOrigin;
@@ -119,6 +121,7 @@ bool operator==(InsetGraphicsParams const & left,
 
            left.bbox == right.bbox &&
            left.clip == right.clip &&
+           left.darkModeSensitive == right.darkModeSensitive &&
 
            left.rotateAngle == right.rotateAngle &&
            left.rotateOrigin == right.rotateOrigin &&
index 315f4c70827bd34b0890d4473122aeaff84ecf1f..1aa0b23d5b68cd8f742ca3aa9c6f0e443375558a 100644 (file)
@@ -63,6 +63,10 @@ public:
        /// any userdefined special command
        std::string special;
 
+       /// Does this need to be handled specifically
+       /// in dark mode? (use by InsetInfo)
+       bool darkModeSensitive;
+
        ///
        InsetGraphicsParams();
        ///
index 96c3062ebff1714e4b1d6eb7232df93f8a1f2b47..819d8ff62e55ec92eb8858ecdb556642b8787a87 100644 (file)
@@ -1078,6 +1078,10 @@ void InsetInfo::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                igp.lyxscale = percent_scale;
                igp.scale = string();
                igp.width = Length(1, Length::EM);
+               if (contains(file.absoluteFilePath(), from_ascii("math"))
+                   || contains(file.absoluteFilePath(), from_ascii("ert-insert"))
+                   || suffixIs(file.onlyPath().absoluteFilePath(), from_ascii("ipa")))
+                       igp.darkModeSensitive = true;
                inset->setParams(igp);
                clear();
                Font const f(inherit_font, params_.lang);
index 4fb3f84bb6e5071d03679211e6bca0f842f30a73..b522978ef62e32b3cf60120d4ecab8fcef9dc388 100644 (file)
@@ -36,7 +36,7 @@ public:
        /// \retval true if the metrics has changed.
        virtual void metrics(MetricsInfo & mi, Dimension & dim) const = 0;
        /// draw inset and update (xo, yo)-cache
-       virtual void draw(PainterInfo & pi, int x, int y) const = 0;
+       virtual void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const = 0;
 
        /// render state, exact meaning of state is render-specific
        void setRenderState(bool state) { state_ = state; }
index a00a4c5a73577ffc4bc9eae8f3417d2d667b0cfa..c5bc4af87bf1bda2212872d6537d1e3d951048a3 100644 (file)
@@ -54,7 +54,7 @@ void RenderButton::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
-void RenderButton::draw(PainterInfo & pi, int x, int y) const
+void RenderButton::draw(PainterInfo & pi, int x, int y, bool) const
 {
        // Draw it as a box with the LaTeX text
        FontInfo font = inherit_font_ ? pi.base.font : sane_font;
index 69513f09adc38da022b6370b1e4233be0460e14f..ab68de2947e5bce8bdd4f6009c58ddb3857b37a6 100644 (file)
@@ -30,7 +30,7 @@ public:
        /// compute the size of the object returned in dim
        void metrics(MetricsInfo & mi, Dimension & dim) const override;
        /// draw inset and update (xo, yo)-cache
-       void draw(PainterInfo & pi, int x, int y) const override;
+       void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
 
        /// Provide the text for the button
        void update(docstring const &, bool editable,
index 280a657ceb61ac0490c48230bddaec5046518937..318f8aab0d7507aedf23f163c0bd5ba332306e60 100644 (file)
@@ -187,7 +187,7 @@ void RenderGraphic::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
-void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
+void RenderGraphic::draw(PainterInfo & pi, int x, int y, bool const darkmode) const
 {
        // This will draw the graphics. If the graphics has not been
        // loaded yet, we draw just a rectangle.
@@ -197,7 +197,7 @@ void RenderGraphic::draw(PainterInfo & pi, int x, int y) const
        int const h = dim_.height();
 
        if (displayGraphic(params_) && readyToDisplay(loader_))
-               pi.pain.image(x1, y1, w, h, *loader_.image());
+               pi.pain.image(x1, y1, w, h, *loader_.image(), darkmode);
 
        else {
                Color c = pi.change.changed() ? pi.change.color() : Color_foreground;
index 8b17bd882474ebaca86d5dfccd7900a9e3ad7f96..fc631a0c7aed2c73605e5fac8816101119c748a6 100644 (file)
@@ -31,7 +31,7 @@ public:
        /// compute the size of the object returned in dim
        void metrics(MetricsInfo & mi, Dimension & dim) const override;
        /// draw inset
-       void draw(PainterInfo & pi, int x, int y) const override;
+       void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
 
        /// Refresh the info about which file to display and how to display it.
        void update(graphics::Params const & params);
index 0b17d2f83c5ff40d9d938ba66642d01df4c4d87a..2ed69bb61f72df2248ac06cf3155eed590069765 100644 (file)
@@ -154,7 +154,7 @@ void RenderPreview::metrics(MetricsInfo & mi, Dimension & dim) const
 }
 
 
-void RenderPreview::draw(PainterInfo & pi, int x, int y) const
+void RenderPreview::draw(PainterInfo & pi, int x, int y, bool const) const
 {
        LBUFERR(pi.base.bv);
 
@@ -280,7 +280,7 @@ void RenderMonitoredPreview::setAbsFile(FileName const & file)
 }
 
 
-void RenderMonitoredPreview::draw(PainterInfo & pi, int x, int y) const
+void RenderMonitoredPreview::draw(PainterInfo & pi, int x, int y, bool const) const
 {
        RenderPreview::draw(pi, x, y);
        startMonitoring();
index ca85c04e95e0762d413b12bd02d2b584890b3257..97725d862d8dac36c7f12a02bcc8f64004ffec68 100644 (file)
@@ -52,7 +52,7 @@ public:
        /// Compute the size of the object, returned in dim
        void metrics(MetricsInfo &, Dimension & dim) const override;
        ///
-       void draw(PainterInfo & pi, int x, int y) const override;
+       void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
 
        /** Find the PreviewLoader and add a LaTeX snippet to it.
         *  Do not start the loading process.
@@ -112,7 +112,7 @@ class RenderMonitoredPreview : public RenderPreview {
 public:
        explicit RenderMonitoredPreview(Inset const *);
        ///
-       void draw(PainterInfo & pi, int x, int y) const override;
+       void draw(PainterInfo & pi, int x, int y, bool const darkmode = false) const override;
        ///
        void setAbsFile(support::FileName const & file);
        ///