Make Cantor’s LaTeX renderer friendlier with dark themes
ClosedPublic

Authored by lhuard on Apr 15 2017, 6:45 AM.

Details

Summary

When the user selects a dark theme, the background of the windows (including Cantor’s ones) is dark whereas the text printed in them is white.
It works pretty well in Cantor, expect when the LaTeX renderer is enabled in which case the formulas rendered by LaTeX are still in black on white background. This creates unsightly frames as it can be seen of the following screenshot:

This patch makes Cantor pass the currently active background and foreground colors to LaTeX so that LaTeX rendered outputs are looking much more integrated. Please see the following screenshot showing the effect of this patch:

Diff Detail

Repository
R55 Cantor
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
lhuard created this revision.Apr 15 2017, 6:45 AM
asemke added a subscriber: asemke.Apr 16 2017, 9:45 AM

why not to use a single assignment and a single call of arg() here?

QString expressiontTex = tex.arg(d->header(), backgroundColor.redF(), ... );
lhuard updated this revision to Diff 13542.Apr 17 2017, 5:20 PM

why not to use a single assignment and a single call of arg() here?

QString expressiontTex = tex.arg(d->header(), backgroundColor.redF(), ... );

It is not possible to use a single call of arg() because there’s no overload that allows replacement of several values in one pass except when all the values are all of QString type.
As a consequence, the following patch:

+    KColorScheme scheme(QPalette::Active);
+    const QColor &backgroundColor=scheme.background().color();
+    const QColor &foregroundColor=scheme.foreground().color();
     QString expressionTex=tex;
-    expressionTex=expressionTex.arg(d->header);
+    expressionTex=expressionTex.arg(d->header,
+                                    backgroundColor.redF(), backgroundColor.greenF(), backgroundColor.blueF(),
+                                    foregroundColor.redF(), foregroundColor.greenF(), foregroundColor.blueF());

produces the following compiler error:

/home/lenaic/doc/devel/open-source/cantor/src/lib/latexrenderer.cpp: In member function 'void Cantor::LatexRenderer::renderWithLatex()':
/home/lenaic/doc/devel/open-source/cantor/src/lib/latexrenderer.cpp:190:110: error: no matching function for call to 'QString::arg(QString&, qreal, qreal, qreal, qreal, qreal, qreal)'
                                     foregroundColor.redF(), foregroundColor.greenF(), foregroundColor.blueF());

It is also not possible to call arg() directly on the tex variable to save one assignment because the type of tex doesn’t implement any arg() method. It needs to be converted to a QString first.
As a consequence, the following patch:

-    QString expressionTex=tex;
-    expressionTex=expressionTex.arg(d->header);
+    KColorScheme scheme(QPalette::Active);
+    const QColor &backgroundColor=scheme.background().color();
+    const QColor &foregroundColor=scheme.foreground().color();
+    QString expressionTex=tex.arg(d->header)
+                             .arg(backgroundColor.redF()).arg(backgroundColor.greenF()).arg(backgroundColor.blueF())
+                             .arg(foregroundColor.redF()).arg(foregroundColor.greenF()).arg(foregroundColor.blueF());

produces the following compiler error:

/home/lenaic/doc/devel/open-source/cantor/src/lib/latexrenderer.cpp: In member function 'void Cantor::LatexRenderer::renderWithLatex()':
/home/lenaic/doc/devel/open-source/cantor/src/lib/latexrenderer.cpp:187:31: error: 'const class QLatin1String' has no member named 'arg'
     QString expressionTex=tex.arg(d->header)
                               ^~~

So, I updated this patch to only group all arg() calls in a single chain.

asemke accepted this revision.Apr 21 2017, 7:49 AM

Thanks for the explanaition. I'll add this logic to the latex renderer class in LabPlot, too. Thanks for this idea/patch.

This revision is now accepted and ready to land.Apr 21 2017, 7:49 AM
filipesaraiva accepted this revision.Apr 28 2017, 1:23 PM
filipesaraiva added a subscriber: filipesaraiva.

Thanks @lhuard, I am going to push your patch.

This revision was automatically updated to reflect the committed changes.
filipesaraiva added a comment.EditedApr 28 2017, 1:28 PM

Sorry @lhuard, I thought arc land would use your name and e-mail in the commit authorship... :\