From c5851e6d958cbe0dd36847d831ea45283c129560 Mon Sep 17 00:00:00 2001 From: Ad5001 Date: Wed, 19 Oct 2022 17:11:54 +0200 Subject: [PATCH] Adding new 'Position setting' history action. --- LogarithmPlotter/i18n/lp_de.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_en.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_es.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_fr.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_hu.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_nb_NO.ts | 61 +++++++----- LogarithmPlotter/i18n/lp_template.ts | 61 +++++++----- .../eu/ad5001/LogarithmPlotter/AppMenuBar.qml | 8 +- .../LogarithmPlotter/LogarithmPlotter.qml | 12 ++- .../LogarithmPlotter/PickLocationOverlay.qml | 53 ++++++----- .../LogarithmPlotter/js/history/common.js | 65 ++++++++++++- .../js/history/editproperty.js | 4 +- .../LogarithmPlotter/js/history/position.js | 95 +++++++++++++++++++ .../ad5001/LogarithmPlotter/js/historylib.js | 3 + .../ad5001/LogarithmPlotter/js/math/latex.js | 8 ++ 15 files changed, 470 insertions(+), 205 deletions(-) create mode 100644 LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.js diff --git a/LogarithmPlotter/i18n/lp_de.ts b/LogarithmPlotter/i18n/lp_de.ts index 6a90d67..ff300e6 100644 --- a/LogarithmPlotter/i18n/lp_de.ts +++ b/LogarithmPlotter/i18n/lp_de.ts @@ -103,52 +103,52 @@ LaTeX-Rendering aktivieren - + &Help &Hilfe - + &Source code &Quellcode - + &Report a bug Fehler &Melden - + &User manual &Benutzerhandbuch - + &Changelog &Changelog - + &Help translating! &Hilfe beim Übersetzen! - + &Thanks &Danksagungen - + &About &Übrigens - + Save unsaved changes? Änderungen speichern? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Diese Grafik enthält ungespeicherte Änderungen. Dadurch gehen alle ungespeicherten Daten verloren. Fortfahren? @@ -346,62 +346,62 @@ Diese Einstellungen können jederzeit über das Menü "Einstellungen" LogarithmPlotter - + Objects Objekte - + Settings Einstellungen - + History Verlauf - + Saved plot to '%1'. Gespeicherte Grafik auf '%1'. - + Loading file '%1'. Laden der Datei '%1'. - + Unknown object type: %1. Unbekannter Objekttyp: %1. - + Invalid file provided. Ungültige Datei angegeben. - + Could not save file: Die Datei konnte nicht gespeichert werden: - + Loaded file '%1'. Geladene Datei '%1'. - + Copied plot screenshot to clipboard! Grafik in die Zwischenablage kopiert! - + &Update &Aktualisieren - + &Update LogarithmPlotter LogarithmPlotter &aktualisieren @@ -478,12 +478,12 @@ Diese Einstellungen können jederzeit über das Menü "Einstellungen" PickLocationOverlay - + Pointer precision: Genauigkeit des Zeigers: - + Snap to grid Am Gitter einrasten @@ -1190,6 +1190,19 @@ Bitte vergewissern Sie sich, dass Ihre LaTeX-Installation korrekt ist, und melde Punkte + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_en.ts b/LogarithmPlotter/i18n/lp_en.ts index 36f7cca..d51714e 100644 --- a/LogarithmPlotter/i18n/lp_en.ts +++ b/LogarithmPlotter/i18n/lp_en.ts @@ -103,52 +103,52 @@ Enable LaTeX rendering - + &Help &Help - + &Source code &Source code - + &Report a bug &Report a bug - + &User manual &User manual - + &Changelog &Changelog - + &Help translating! &Help translating! - + &Thanks &Thanks - + &About &About - + Save unsaved changes? Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -346,62 +346,62 @@ These settings can be changed at any time from the "Settings" menu. LogarithmPlotter - + Objects Objects - + Settings Settings - + History History - + Saved plot to '%1'. Saved plot to '%1'. - + Loading file '%1'. Loading file '%1'. - + Unknown object type: %1. Unknown object type: %1. - + Invalid file provided. Invalid file provided. - + Could not save file: Could not save file: - + Loaded file '%1'. Loaded file '%1'. - + Copied plot screenshot to clipboard! Copied plot screenshot to clipboard! - + &Update &Update - + &Update LogarithmPlotter &Update LogarithmPlotter @@ -478,12 +478,12 @@ These settings can be changed at any time from the "Settings" menu. PickLocationOverlay - + Pointer precision: Pointer precision: - + Snap to grid Snap to grid @@ -1190,6 +1190,19 @@ Please make sure your LaTeX installation is correct and report a bug if so.Points + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_es.ts b/LogarithmPlotter/i18n/lp_es.ts index 0842196..dfaf15b 100644 --- a/LogarithmPlotter/i18n/lp_es.ts +++ b/LogarithmPlotter/i18n/lp_es.ts @@ -103,52 +103,52 @@ Activar el renderizado de LaTeX - + &Help &Ayuda - + &Source code &Código fuente - + &Report a bug &Informar de un error - + &User manual &Manual del usuario - + &Changelog &Registro de cambios - + &Help translating! &¡Ayuda a la traducción! - + &Thanks &Agradecimientos - + &About &Acerca de - + Save unsaved changes? ¿Guardar los cambios no guardados? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -314,62 +314,62 @@ These settings can be changed at any time from the "Settings" menu. LogarithmPlotter - + Objects - + Settings - + History - + Saved plot to '%1'. - + Loading file '%1'. - + Unknown object type: %1. - + Invalid file provided. - + Could not save file: - + Loaded file '%1'. - + Copied plot screenshot to clipboard! - + &Update - + &Update LogarithmPlotter @@ -426,12 +426,12 @@ These settings can be changed at any time from the "Settings" menu. PickLocationOverlay - + Pointer precision: - + Snap to grid @@ -1099,6 +1099,19 @@ Please make sure your latex installation is correct and report a bug if so. + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_fr.ts b/LogarithmPlotter/i18n/lp_fr.ts index 63cabca..034e753 100644 --- a/LogarithmPlotter/i18n/lp_fr.ts +++ b/LogarithmPlotter/i18n/lp_fr.ts @@ -104,52 +104,52 @@ Activer le rendu LaTeX - + &Help &Aide - + &Source code &Code source - + &Report a bug &Rapport de bug - + &User manual Manuel d'&utilisation - + &Changelog &Historique des modifications - + &Help translating! &Aider à la traduction ! - + &Thanks &Remerciements - + &About &À propos - + Save unsaved changes? Sauvegarder les modifications ? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Ce graphe contient des modifications non sauvegardées. En faisant cela, toutes les données non sauvegardées seront perdues. Continuer ? @@ -354,62 +354,62 @@ These settings can always be changed at any time from the "Settings" m LogarithmPlotter - + Objects Objets - + Settings Paramètres - + History Historique - + Saved plot to '%1'. Graphe sauvegardé dans '%1'. - + Loading file '%1'. Chargement du fichier '%1'. - + Unknown object type: %1. Type d'objet inconnu : %1. - + Invalid file provided. Fichier fourni invalide. - + Could not save file: Impossible de sauvegarder le fichier : - + Loaded file '%1'. Fichier '%1' chargé. - + Copied plot screenshot to clipboard! Image du graphe copiée dans le presse-papiers ! - + &Update &Mise à jour - + &Update LogarithmPlotter &Mettre à jour LogarithmPlotter @@ -486,12 +486,12 @@ These settings can always be changed at any time from the "Settings" m PickLocationOverlay - + Pointer precision: Précision du pointeur : - + Snap to grid Placement sur la grille @@ -1199,6 +1199,19 @@ Vérifiez que votre installation de LaTeX est correcte et signalez un bogue si c Points + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_hu.ts b/LogarithmPlotter/i18n/lp_hu.ts index 124f1ac..a2c2163 100644 --- a/LogarithmPlotter/i18n/lp_hu.ts +++ b/LogarithmPlotter/i18n/lp_hu.ts @@ -103,52 +103,52 @@ LaTeX-megjelenítés engedélyezése - + &Help &Súgó - + &Source code &Forráskód - + &Report a bug &Hiba bejelentése - + &User manual &Használati utasítás - + &Changelog &Változásnapló - + &Help translating! &Segítség a fordításban! - + &Thanks &Köszönjük - + &About &Névjegy - + Save unsaved changes? Menti a változtatásokat? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? Ez az ábra nem mentett változtatásokat tartalmaz. Ezzel az összes nem mentett adat elveszik. Folytatja? @@ -346,62 +346,62 @@ Ezek a beállítások bármikor módosíthatók a „Beállítások” menüben. LogarithmPlotter - + Objects Tárgyak - + Settings Beállítások - + History Előzmények - + Saved plot to '%1'. Ábra mentve ide: „%1”. - + Loading file '%1'. A(z) „%1” fájl betöltése folyamatban van. - + Unknown object type: %1. Ismeretlen objektumtípus: %1. - + Invalid file provided. A megadott fájl érvénytelen. - + Could not save file: A fájl mentése nem sikerült: - + Loaded file '%1'. A(z) „%1” fájl betöltve. - + Copied plot screenshot to clipboard! Ábra képernyőkép vágólapra másolva! - + &Update &Frissítés - + &Update LogarithmPlotter A LogarithmPlotter &frissítése @@ -478,12 +478,12 @@ Ezek a beállítások bármikor módosíthatók a „Beállítások” menüben. PickLocationOverlay - + Pointer precision: Mutató pontossága: - + Snap to grid Rácshoz illesztés @@ -1183,6 +1183,19 @@ Kérjük, ellenőrizze, hogy a LaTeX telepítése helyes-e, és ha igen, jelents Pontok + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_nb_NO.ts b/LogarithmPlotter/i18n/lp_nb_NO.ts index f604460..dfdfd34 100644 --- a/LogarithmPlotter/i18n/lp_nb_NO.ts +++ b/LogarithmPlotter/i18n/lp_nb_NO.ts @@ -103,52 +103,52 @@ - + &Help &Hjelp - + &Source code - + &Report a bug - + &User manual - + &Changelog - + &Help translating! - + &Thanks - + &About &Om - + Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -346,62 +346,62 @@ Disse innstillingene kan endres når som helst fra «Innstillinger»-menyen. LogarithmPlotter - + Objects Objekter - + Settings Innstillinger - + History Historikk - + Saved plot to '%1'. Lagret plott i «%1». - + Loading file '%1'. Laster inn «%1»-fil. - + Unknown object type: %1. Ukjent objekttype: %1. - + Invalid file provided. Ugyldig fil angitt. - + Could not save file: Kunne ikke lagre fil: - + Loaded file '%1'. Lastet inn filen «%1». - + Copied plot screenshot to clipboard! Kopierte plott-skjermavbildning til utklippstavlen! - + &Update &Oppdater - + &Update LogarithmPlotter &Installer ny versjon av LogartimePlotter @@ -478,12 +478,12 @@ Disse innstillingene kan endres når som helst fra «Innstillinger»-menyen. PickLocationOverlay - + Pointer precision: Peker-presisjon: - + Snap to grid Fest til rutenett @@ -1174,6 +1174,19 @@ Please make sure your latex installation is correct and report a bug if so.Punkter + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/i18n/lp_template.ts b/LogarithmPlotter/i18n/lp_template.ts index a22d858..f525586 100644 --- a/LogarithmPlotter/i18n/lp_template.ts +++ b/LogarithmPlotter/i18n/lp_template.ts @@ -103,52 +103,52 @@ - + &Help - + &Source code - + &Report a bug - + &User manual - + &Changelog - + &Help translating! - + &Thanks - + &About - + Save unsaved changes? - + This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue? @@ -314,62 +314,62 @@ These settings can be changed at any time from the "Settings" menu. LogarithmPlotter - + Objects - + Settings - + History - + Saved plot to '%1'. - + Loading file '%1'. - + Unknown object type: %1. - + Invalid file provided. - + Could not save file: - + Loaded file '%1'. - + Copied plot screenshot to clipboard! - + &Update - + &Update LogarithmPlotter @@ -426,12 +426,12 @@ These settings can be changed at any time from the "Settings" menu. PickLocationOverlay - + Pointer precision: - + Snap to grid @@ -1099,6 +1099,19 @@ Please make sure your latex installation is correct and report a bug if so. + + position + + + Position of %1 %2 set from "%3" to "%4". + + + + + Position of %1 set from %2 to %3. + + + prop diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml index 31d9b7b..48cf383 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/AppMenuBar.qml @@ -22,7 +22,7 @@ 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 +import "js/math/latex.js" as LatexJS /*! @@ -143,18 +143,16 @@ MenuBar { } Action { - id: enableLatexSetting + id: enableLatexJSSetting text: qsTr("Enable LaTeX rendering") checkable: true checked: Helper.getSettingBool("enable_latex") onTriggered: { Helper.setSettingBool("enable_latex", checked) - Latex.enabled = checked + LatexJS.enabled = checked drawCanvas.requestPaint() } icon.name: 'Expression' - - Component.onCompleted: Latex.enabled = checked } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml index 445c03c..0c71421 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml @@ -25,6 +25,7 @@ import QtQuick 2.12 import "js/objs/autoload.js" as ALObjects import "js/objects.js" as Objects +import "js/math/latex.js" as LatexJS import eu.ad5001.LogarithmPlotter.History 1.0 import eu.ad5001.LogarithmPlotter.ObjectLists 1.0 import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup @@ -44,7 +45,16 @@ ApplicationWindow { color: sysPalette.window title: "LogarithmPlotter " + (settings.saveFilename != "" ? " - " + settings.saveFilename.split('/').pop() : "") + (history.saved ? "" : "*") - SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active } + SystemPalette { + id: sysPalette; colorGroup: SystemPalette.Active + + Component.onCompleted: { + // LatexJS initialization. + LatexJS.enabled = Helper.getSettingBool("enable_latex") + LatexJS.Renderer = Latex + LatexJS.defaultColor = sysPalette.windowText + } + } SystemPalette { id: sysPaletteIn; colorGroup: SystemPalette.Disabled } menuBar: appMenu.trueItem diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml index 8ef80d6..7e59fd5 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/PickLocationOverlay.qml @@ -92,34 +92,29 @@ Item { acceptedButtons: Qt.LeftButton | Qt.RightButton onClicked: { if(mouse.button == Qt.LeftButton) { // Validate - if(parent.pickX) { - let newValue = picked.mouseX.toString() - newValue = { - 'Expression': () => new MathLib.Expression(newValue), - 'number': () => parseFloat(newValue) - }[Objects.types[objType].properties()[propertyX]]() - let obj = Objects.currentObjectsByName[objName] // getObjectByName(objName, objType) - history.addToHistory(new HistoryLib.EditedProperty( - objName, objType, propertyX, obj[propertyX], newValue + let newValueX = !parent.pickX ? null : parseValue(picked.mouseX.toString(), objType, propertyX) + let newValueY = !parent.pickY ? null : parseValue(picked.mouseY.toString(), objType, propertyY) + let obj = Objects.currentObjectsByName[objName] + // Set values + if(parent.pickX && parent.pickY) { + history.addToHistory(new HistoryLib.EditedPosition( + objName, objType, obj[propertyX], newValueX, obj[propertyY], newValueY )) - obj[propertyX] = newValue - obj.update() - objectLists.update() - } - if(parent.pickY) { - let newValue = picked.mouseY.toString() - newValue = { - 'Expression': () => new MathLib.Expression(newValue), - 'number': () => parseFloat(newValue) - }[Objects.types[objType].properties()[propertyY]]() - let obj = Objects.currentObjectsByName[objName] // Objects.getObjectByName(objName, objType) + obj[propertyX] = newValueX + obj[propertyY] = newValueY + } else if(parent.pickX) { history.addToHistory(new HistoryLib.EditedProperty( - objName, objType, propertyY, obj[propertyY], newValue + objName, objType, propertyX, obj[propertyX], newValueX )) - obj[propertyY] = newValue - obj.update() - objectLists.update() + obj[propertyX] = newValueX + } else if(parent.pickY) { + history.addToHistory(new HistoryLib.EditedProperty( + objName, objType, propertyY, obj[propertyY], newValueY + )) + obj[propertyY] = newValueY } + obj.update() + objectLists.update() } pickerRoot.visible = false; } @@ -214,4 +209,14 @@ Item { } + /*! + \qmlmethod void History::parseValue(string value, string objType, string propertyName) + Parses a given \c value as an expression or a number depending on the type of \c propertyName of all \c objType. + */ + function parseValue(value, objType, propertyName) { + return { + 'Expression': () => new MathLib.Expression(value), + 'number': () => parseFloat(value) + }[Objects.types[objType].properties()[propertyName]]() + } } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js index 16f9c6e..92811d9 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/common.js @@ -18,14 +18,27 @@ .pragma library +.import "../math/latex.js" as Latex + var themeTextColor; +var imageDepth = 2; +var fontSize = 14; class Action { - // Type of the action done. + /** + * Type of the action. + * + * @returns {string} + */ type(){return 'Unknown'} - // Icon associated with the item + /** + * Icon associated with the action. + * + * @returns {string} + */ + icon(){return 'position'} // TargetName is the name of the object that's targeted by the event. constructor(targetName = "", targetType = "Point") { @@ -33,25 +46,67 @@ class Action { this.targetType = targetType } + /** + * Undoes the action. + * + * @returns {string} + */ undo() {} + /** + * Redoes the action. + * + * @returns {string} + */ redo() {} + /** + * Export the action to a serializable format. + * NOTE: These arguments will be reinputed in the constructor in this order. + * + * @returns {string} + */ export() { return [this.targetName, this.targetType] } - // String used in the toolkit + /** + * Returns a string with the human readable description of the action. + * + * @returns {string} + */ getReadableString() { return 'Unknown action' } - // Returns an HTML tag containing the icon of a type + /** + * Returns a string containing an HTML tag describing the icon of a type + * + * @param {string} type - Name of the icon to put in rich text. + * @returns {string} + */ getIconRichText(type) { return `` } - // String used in the preview + /** + * Renders a LaTeX-formatted string to an image and wraps it in an HTML tag in a string. + * + * @param {string} latexString - Source string of the latex. + * @returns {string} + */ + renderLatexAsHtml(latexString) { + if(!Latex.enabled) + throw new Error("Cannot render an item as LaTeX when LaTeX is disabled.") + let latexInfo = Latex.Renderer.render(latexString, imageDepth*fontSize+4, themeTextColor).split(",") + return `` + } + + /** + * Returns a string with the HTML-formated description of the action. + * + * @returns {string} + */ getHTMLString() { return this.getReadableString() } diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js index 9641967..3fca7b6 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/editproperty.js @@ -94,8 +94,8 @@ class EditedProperty extends C.Action { this.next = this.newValue.name.join(",") break; case "Dict": - this.prev = JSON.stringify(this.previousValue).replace("'", "\\'").replace('"', "'") - this.next = JSON.stringify(this.newValue).replace("'", "\\'").replace('"', "'") + this.prev = JSON.stringify(this.previousValue) + this.next = JSON.stringify(this.newValue) break; } } else { diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.js new file mode 100644 index 0000000..d33ad71 --- /dev/null +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/history/position.js @@ -0,0 +1,95 @@ +/** + * LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions. + * Copyright (C) 2022 Ad5001 + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +.pragma library + +.import "../objects.js" as Objects +.import "../mathlib.js" as MathLib +.import "../math/latex.js" as Latex +.import "../utils.js" as Utils +.import "../objs/common.js" as Common +.import "common.js" as C + +class EditedPosition extends C.Action { + // Action used for objects that have a X and Y expression properties (points, texts...) + type(){return 'EditedPosition'} + + icon(){return 'position'} + + color(darkVer=false){ + return darkVer ? 'seagreen' : 'lightseagreen'; + } + + constructor(targetName = "", targetType = "Point", previousXValue = "", newXValue = "", previousYValue = "", newYValue = "") { + super(targetName, targetType) + let imports = { + 'previousXValue': previousXValue, + 'previousYValue': previousYValue, + 'newXValue': newXValue, + 'newYValue': newYValue + } + for(let name in imports) + this[name] = (typeof imports[name]) == 'string' ? new MathLib.Expression(imports[name]) : imports[name] + this.setReadableValues() + } + + undo() { + Objects.currentObjectsByName[this.targetName].x = this.previousXValue + Objects.currentObjectsByName[this.targetName].y = this.previousYValue + Objects.currentObjectsByName[this.targetName].update() + } + + redo() { + Objects.currentObjectsByName[this.targetName].x = this.newXValue + Objects.currentObjectsByName[this.targetName].y = this.newYValue + Objects.currentObjectsByName[this.targetName].update() + } + + setReadableValues() { + this.prevString = `(${this.previousXValue.toString()},${this.previousYValue.toString()})` + this.nextString = `(${this.newXValue.toString()},${this.newYValue.toString()})` + // Render as LaTeX + if(Latex.enabled) { + this.prevHTML = this.renderLatexAsHtml(`\\left(${this.previousXValue.latexMarkup},${this.previousYValue.latexMarkup}\\right)`) + this.nextHTML = this.renderLatexAsHtml(`\\left(${this.newXValue.latexMarkup},${this.newYValue.latexMarkup}\\right)`) + } else { + this.prevHTML = ' '+Utils.escapeHTML(this.prevString)+' ' + this.nextHTML = ' '+Utils.escapeHTML(this.nextString)+' ' + } + + } + + export() { + return [this.targetName, this.targetType, this.targetProperty, + this.previousXValue.toEditableString(), this.newXValue.toEditableString(), + this.previousYValue.toEditableString(), this.newYValue.toEditableString()] + } + + getReadableString() { + return qsTr('Position of %1 %2 set from "%3" to "%4".') + .arg(Objects.types[this.targetType].displayType()) + .arg(this.targetName).arg(this.prevString).arg(this.nextString) + } + + getHTMLString() { + return qsTr('Position of %1 set from %2 to %3.') + .arg(' ' + this.targetName + ' ') + .arg(this.prevHTML) + .arg(this.nextHTML) + } +} diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js index c360cb7..70542af 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/historylib.js @@ -24,6 +24,7 @@ .import "history/create.js" as Create .import "history/delete.js" as Delete .import "history/editproperty.js" as EP +.import "history/position.js" as Pos .import "history/visibility.js" as V .import "history/name.js" as Name .import "history/color.js" as Color @@ -35,6 +36,7 @@ var Action = Common.Action var CreateNewObject = Create.CreateNewObject var DeleteObject = Delete.DeleteObject var EditedProperty = EP.EditedProperty +var EditedPosition = Pos.EditedPosition var EditedVisibility = V.EditedVisibility var NameChanged = Name.NameChanged var ColorChanged = Color.ColorChanged @@ -44,6 +46,7 @@ var Actions = { "CreateNewObject": CreateNewObject, "DeleteObject": DeleteObject, "EditedProperty": EditedProperty, + "EditedPosition": EditedPosition, "EditedVisibility": EditedVisibility, "NameChanged": NameChanged, "ColorChanged": ColorChanged, diff --git a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js index 4c57b07..06d0bfa 100644 --- a/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js +++ b/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/js/math/latex.js @@ -25,6 +25,14 @@ * true if latex has been enabled by the user, false otherwise. */ var enabled = false +/** + * LaTeX python backend QObject. + */ +var Renderer = null +/** + * Default window color used to render LaTeX formulas. + */ +var defaultColor = "black" /** * Puts element within parenthesis.