diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml index 194b058..7e5ef9c 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml @@ -22,6 +22,8 @@ import QtQuick.Dialogs 1.3 import eu.ad5001.MixedMenu 1.1 import "js/objects.js" as Objects import "js/historylib.js" as HistoryLib +import "js/math/latex.js" as Latex + /*! \qmltype AppMenuBar @@ -139,6 +141,21 @@ MenuBar { onTriggered: Helper.setSettingBool("reset_redo_stack", checked) icon.name: 'timeline' } + + Action { + id: enableLatexSetting + text: qsTr("Enable LaTeX rendering") + checkable: true + checked: Helper.getSettingBool("enable_latex") + onTriggered: { + Helper.setSettingBool("enable_latex", checked) + Latex.enabled = checked + drawCanvas.requestPaint() + } + icon.name: 'Expression' + + Component.onCompleted: Latex.enabled = checked + } } Menu { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml index 2e50d88..e35950a 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogGraphCanvas.qml @@ -355,10 +355,11 @@ Canvas { Return format: dictionary {"width": width, "height": height} */ function measureText(ctx, text) { - var theight = 0 - var twidth = 0 + let theight = 0 + let twidth = 0 + let defaultHeight = ctx.measureText("M").width // Approximate but good enough! text.split("\n").forEach(function(txt, i){ - theight += canvas.textsize + theight += defaultHeight if(ctx.measureText(txt).width > twidth) twidth = ctx.measureText(txt).width }) return {'width': twidth, 'height': theight} diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml index e99cd17..15c1587 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/Popup/GreetScreen.qml @@ -18,6 +18,7 @@ import QtQuick 2.12 import QtQuick.Controls 2.12 +import "../js/math/latex.js" as Latex /*! \qmltype GreetScreen @@ -101,7 +102,7 @@ Popup { text: qsTr('Check for updates on startup (requires online connectivity)') onClicked: { Helper.setSettingBool("check_for_updates", checked) - checkForUpdatesMenuSetting.checked = checked + //checkForUpdatesMenuSetting.checked = checked } } @@ -113,7 +114,20 @@ Popup { text: qsTr('Reset redo stack when a new action is added to history') onClicked: { Helper.setSettingBool("reset_redo_stack", checked) - resetRedoStackMenuSetting.checked = checked + //resetRedoStackMenuSetting.checked = checked + } + } + + CheckBox { + id: enableLatexSetting + anchors.horizontalCenter: parent.horizontalCenter + anchors.top: resetRedoStackSetting.bottom + checked: Helper.getSettingBool("enable_latex") + text: qsTr('Enable LaTeX rendering') + onClicked: { + Helper.setSettingBool("enable_latex", checked) + Latex.enabled = checked + drawCanvas.requestPaint() } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js index d5b30e6..4c57b07 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js @@ -21,6 +21,11 @@ .import "../expr-eval.js" as ExprEval +/** + * true if latex has been enabled by the user, false otherwise. + */ +var enabled = false + /** * Puts element within parenthesis. * diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js index 956ecf6..3864b2f 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/common.js @@ -279,7 +279,7 @@ class DrawableObject { * @param {function|null} getLatexFunction - Function (no argument) to get the latex markup to be displayed * @param {function|null} getTextFunction - Function (no argument) to get the text to be displayed * @param {function|null} drawFunctionLatex - Function (x,y,imageData) to display the latex image - * @param {function|null} drawFunctionText - Function (x,y,text) to display the text + * @param {function|null} drawFunctionText - Function (x,y,text,textSize) to display the text */ drawLabel(canvas, ctx, labelPosition, posX, posY, forceText = false, getLatexFunction = null, getTextFunction = null, drawFunctionLatex = null, drawFunctionText = null) { @@ -291,13 +291,13 @@ class DrawableObject { if(drawFunctionLatex == null) drawFunctionLatex = (x,y,ltxImg) => canvas.drawVisibleImage(ctx, ltxImg.source, x, y, ltxImg.width, ltxImg.height) if(drawFunctionText == null) - drawFunctionText = (x,y,text) => canvas.drawVisibleText(ctx, text, x, textSize.height+5) + drawFunctionText = (x,y,text,textSize) => canvas.drawVisibleText(ctx, text, x, y+textSize.height) // Positioned from left bottom // Drawing the label let offset - if(!forceText && true) { // TODO: Check for user setting with Latex. + if(!forceText && Latex.enabled) { // TODO: Check for user setting with Latex. // With latex let drawLblCb = function(canvas, ctx, ltxImg) { - this.drawPositionDivergence(labelPosition, 8, ltxImg, posX, posY, (x,y) => drawFunctionLatex(x,y,ltxImg)) + this.drawPositionDivergence(labelPosition, 8+ctx.lineWidth/2, ltxImg, posX, posY, (x,y) => drawFunctionLatex(x,y,ltxImg)) } let ltxLabel = getLatexFunction(); if(ltxLabel != "") @@ -306,7 +306,8 @@ class DrawableObject { // Without latex let text = getTextFunction() ctx.font = `${canvas.textsize}px sans-serif` - this.drawPositionDivergence(labelPosition, 4, canvas.measureText(ctx, text), posX, posY, (x,y) => drawFunctionText(x,y,text)) + let textSize = canvas.measureText(ctx, text) + this.drawPositionDivergence(labelPosition, 8+ctx.lineWidth/2, textSize, posX, posY, (x,y) => drawFunctionText(x,y,text,textSize)) } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js index 56c6fe4..52c989f 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/objs/xcursor.js @@ -168,7 +168,7 @@ class XCursor extends Common.DrawableObject { // Drawing label at the top of the canvas. this.drawLabel(canvas, ctx, this.labelPosition, xpos, 0, false, null, null, (x,y,ltxImg) => canvas.drawVisibleImage(ctx, ltxImg.source, x, 5, ltxImg.width, ltxImg.height), - (x,y,text) => canvas.drawVisibleText(ctx, text, x, textSize.height+5)) + (x,y,text,textSize) => canvas.drawVisibleText(ctx, text, x, textSize.height+5)) // Drawing label at the position of the target element. if(this.targetValuePosition == 'Next to target' && this.targetElement != null) { @@ -176,7 +176,7 @@ class XCursor extends Common.DrawableObject { this.drawLabel(canvas, ctx, this.labelPosition, xpos, ypos, false, this.getTargetValueLatexLabel.bind(this), this.getTargetValueLabel.bind(this), (x,y,ltxImg) => canvas.drawVisibleImage(ctx, ltxImg.source, x, y, ltxImg.width, ltxImg.height), - (x,y,text) => canvas.drawVisibleText(ctx, text, x, y)) + (x,y,text,textSize) => canvas.drawVisibleText(ctx, text, x, y+textSize.height)) } } } diff --git a/LogarithmPlotter/util/config.py b/LogarithmPlotter/util/config.py index ce59163..ecaa214 100644 --- a/LogarithmPlotter/util/config.py +++ b/LogarithmPlotter/util/config.py @@ -26,6 +26,7 @@ DEFAULT_SETTINGS = { "check_for_updates": True, "reset_redo_stack": True, "last_install_greet": "0", + "enable_latex": True } # Create config directory