Reorganizing paths
This commit is contained in:
parent
e9d204daab
commit
34cb856dd4
249 changed files with 118 additions and 294 deletions
41
runtime-pyside6/LogarithmPlotter/__init__.py
Normal file
41
runtime-pyside6/LogarithmPlotter/__init__.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from shutil import which
|
||||
|
||||
__VERSION__ = "0.6.0"
|
||||
is_release = False
|
||||
|
||||
# Check if development version, if so get the date of the latest git patch
|
||||
# and append it to the version string.
|
||||
if not is_release and which('git') is not None:
|
||||
from os.path import realpath, join, dirname, exists
|
||||
from subprocess import check_output
|
||||
from datetime import datetime
|
||||
|
||||
# Command to check date of latest git commit
|
||||
cmd = ['git', 'log', '--format=%ci', '-n 1']
|
||||
cwd = realpath(join(dirname(__file__), '..')) # Root AccountFree directory.
|
||||
if exists(join(cwd, '.git')):
|
||||
date_str = check_output(cmd, cwd=cwd).decode('utf-8').split(' ')[0]
|
||||
try:
|
||||
date = datetime.fromisoformat(date_str)
|
||||
__VERSION__ += '.dev0+git' + date.strftime('%Y%m%d')
|
||||
except ValueError:
|
||||
# Date cannot be parsed, not git root?
|
||||
pass
|
||||
|
199
runtime-pyside6/LogarithmPlotter/logarithmplotter.py
Normal file
199
runtime-pyside6/LogarithmPlotter/logarithmplotter.py
Normal file
|
@ -0,0 +1,199 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from os import getcwd, chdir, environ, path
|
||||
from platform import release as os_release
|
||||
from sys import path as sys_path
|
||||
from sys import platform, argv, exit
|
||||
from tempfile import TemporaryDirectory
|
||||
from time import time
|
||||
|
||||
from PySide6.QtCore import QTranslator, QLocale
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
from PySide6.QtQuickControls2 import QQuickStyle
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
start_time = time()
|
||||
|
||||
# Create the temporary directory for saving copied screenshots and latex files
|
||||
tempdir = TemporaryDirectory()
|
||||
tmpfile = path.join(tempdir.name, 'graph.png')
|
||||
pwd = getcwd()
|
||||
|
||||
logarithmplotter_path = path.dirname(path.realpath(__file__))
|
||||
chdir(logarithmplotter_path)
|
||||
|
||||
if path.realpath(path.join(getcwd(), "..")) not in sys_path:
|
||||
sys_path.append(path.realpath(path.join(getcwd(), "..")))
|
||||
|
||||
from LogarithmPlotter import __VERSION__
|
||||
from LogarithmPlotter.util import config, native, debug
|
||||
from LogarithmPlotter.util.update import check_for_updates
|
||||
from LogarithmPlotter.util.helper import Helper
|
||||
from LogarithmPlotter.util.latex import Latex
|
||||
from LogarithmPlotter.util.js import PyJSValue
|
||||
|
||||
LINUX_THEMES = { # See https://specifications.freedesktop.org/menu-spec/latest/onlyshowin-registry.html
|
||||
"COSMIC": "Basic",
|
||||
"GNOME": "Basic",
|
||||
"GNOME-Classic": "Basic",
|
||||
"GNOME-Flashback": "Basic",
|
||||
"KDE": "Fusion",
|
||||
"LXDE": "Basic",
|
||||
"LXQt": "Fusion",
|
||||
"MATE": "Fusion",
|
||||
"TDE": "Fusion",
|
||||
"Unity": "Basic",
|
||||
"XFCE": "Basic",
|
||||
"Cinnamon": "Fusion",
|
||||
"Pantheon": "Basic",
|
||||
"DDE": "Basic",
|
||||
"EDE": "Fusion",
|
||||
"Endless": "Basic",
|
||||
"Old": "Fusion",
|
||||
}
|
||||
|
||||
|
||||
def get_linux_theme() -> str:
|
||||
if "XDG_SESSION_DESKTOP" in environ:
|
||||
if environ["XDG_SESSION_DESKTOP"] in LINUX_THEMES:
|
||||
return LINUX_THEMES[environ["XDG_SESSION_DESKTOP"]]
|
||||
return "Fusion"
|
||||
else:
|
||||
# Android
|
||||
return "Material"
|
||||
|
||||
|
||||
def get_platform_qt_style(os) -> str:
|
||||
return {
|
||||
"linux": get_linux_theme(),
|
||||
"freebsd": get_linux_theme(),
|
||||
"win32": "Universal" if os_release() in ["10", "11", "12", "13", "14"] else "Windows",
|
||||
"cygwin": "Fusion",
|
||||
"darwin": "macOS"
|
||||
}[os]
|
||||
|
||||
|
||||
def register_icon_directories() -> None:
|
||||
icon_fallbacks = QIcon.fallbackSearchPaths()
|
||||
base_icon_path = path.join(logarithmplotter_path, "qml", "eu", "ad5001", "LogarithmPlotter", "icons")
|
||||
paths = [["common"], ["objects"], ["history"], ["settings"], ["settings", "custom"]]
|
||||
for p in paths:
|
||||
icon_fallbacks.append(path.realpath(path.join(base_icon_path, *p)))
|
||||
QIcon.setFallbackSearchPaths(icon_fallbacks)
|
||||
|
||||
|
||||
def create_qapp() -> QApplication:
|
||||
app = QApplication(argv)
|
||||
app.setApplicationName("LogarithmPlotter")
|
||||
app.setApplicationDisplayName("LogarithmPlotter")
|
||||
app.setApplicationVersion(f"v{__VERSION__}")
|
||||
app.setDesktopFileName("eu.ad5001.LogarithmPlotter")
|
||||
app.setOrganizationName("Ad5001")
|
||||
app.styleHints().setShowShortcutsInContextMenus(True)
|
||||
app.setWindowIcon(QIcon(path.realpath(path.join(logarithmplotter_path, "logarithmplotter.svg"))))
|
||||
return app
|
||||
|
||||
|
||||
def install_translation(app: QApplication) -> QTranslator:
|
||||
# Installing translators
|
||||
translator = QTranslator()
|
||||
# Check if lang is forced.
|
||||
forcedlang = [p for p in argv if p[:7] == "--lang="]
|
||||
i18n_path = path.realpath(path.join(logarithmplotter_path, "i18n"))
|
||||
locale = QLocale(forcedlang[0][7:]) if len(forcedlang) > 0 else QLocale()
|
||||
if not translator.load(locale, "lp", "_", i18n_path):
|
||||
# Load default translation
|
||||
print("Loading default language en...")
|
||||
translator.load(QLocale("en"), "lp", "_", i18n_path)
|
||||
app.installTranslator(translator)
|
||||
return translator
|
||||
|
||||
|
||||
def create_engine(helper: Helper, latex: Latex, dep_time: float) -> tuple[QQmlApplicationEngine, PyJSValue]:
|
||||
global tmpfile
|
||||
engine = QQmlApplicationEngine()
|
||||
js_globals = PyJSValue(engine.globalObject())
|
||||
js_globals.globalThis = engine.globalObject()
|
||||
js_globals.Helper = engine.newQObject(helper)
|
||||
js_globals.Latex = engine.newQObject(latex)
|
||||
engine.rootContext().setContextProperty("TestBuild", "--test-build" in argv)
|
||||
engine.rootContext().setContextProperty("StartTime", dep_time)
|
||||
|
||||
qml_path = path.realpath(path.join(logarithmplotter_path, "qml"))
|
||||
engine.addImportPath(qml_path)
|
||||
engine.load(path.join(qml_path, "eu", "ad5001", "LogarithmPlotter", "LogarithmPlotter.qml"))
|
||||
|
||||
return engine, js_globals
|
||||
|
||||
|
||||
def run():
|
||||
config.init()
|
||||
|
||||
if not 'QT_QUICK_CONTROLS_STYLE' in environ:
|
||||
QQuickStyle.setStyle(get_platform_qt_style(platform))
|
||||
|
||||
dep_time = time()
|
||||
print("Loaded dependencies in " + str((dep_time - start_time) * 1000) + "ms.")
|
||||
|
||||
register_icon_directories()
|
||||
app = create_qapp()
|
||||
translator = install_translation(app)
|
||||
debug.setup()
|
||||
|
||||
# Installing macOS file handler.
|
||||
macos_file_open_handler = None
|
||||
if platform == "darwin":
|
||||
macos_file_open_handler = native.MacOSFileOpenHandler()
|
||||
app.installEventFilter(macos_file_open_handler)
|
||||
|
||||
helper = Helper(pwd, tmpfile)
|
||||
latex = Latex(tempdir)
|
||||
engine, js_globals = create_engine(helper, latex, dep_time)
|
||||
|
||||
if len(engine.rootObjects()) == 0: # No root objects loaded
|
||||
print("No root object", path.realpath(path.join(getcwd(), "qml")))
|
||||
exit(-1)
|
||||
|
||||
# Open the current diagram
|
||||
chdir(pwd)
|
||||
if len(argv) > 0 and path.exists(argv[-1]) and argv[-1].split('.')[-1] in ['lpf']:
|
||||
js_globals.Modules.IO.loadDiagram(argv[-1])
|
||||
chdir(path.dirname(path.realpath(__file__)))
|
||||
|
||||
if platform == "darwin":
|
||||
macos_file_open_handler.init_io(js_globals.Modules.IO)
|
||||
|
||||
# Check for LaTeX installation if LaTeX support is enabled
|
||||
if config.getSetting("enable_latex"):
|
||||
latex.checkLatexInstallation()
|
||||
|
||||
# Check for updates
|
||||
if config.getSetting("check_for_updates"):
|
||||
check_for_updates(__VERSION__, engine.rootObjects()[0])
|
||||
|
||||
exit_code = app.exec()
|
||||
|
||||
tempdir.cleanup()
|
||||
config.save()
|
||||
exit(exit_code)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run()
|
64
runtime-pyside6/LogarithmPlotter/logarithmplotter.svg
Normal file
64
runtime-pyside6/LogarithmPlotter/logarithmplotter.svg
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<svg
|
||||
width="24.0px"
|
||||
height="24.0px"
|
||||
viewBox="0 0 24.0 24.0"
|
||||
version="1.1"
|
||||
id="SVGRoot"
|
||||
xml:space="preserve"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"><title
|
||||
id="title836">LogarithmPlotter Icon v1.0</title><defs
|
||||
id="defs833" /><metadata
|
||||
id="metadata836"><rdf:RDF><cc:Work
|
||||
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title>LogarithmPlotter Icon v1.0</dc:title><cc:license
|
||||
rdf:resource="http://creativecommons.org/licenses/by-nc-sa/4.0/" /><dc:date>2021</dc:date><dc:creator><cc:Agent><dc:title>Ad5001</dc:title></cc:Agent></dc:creator><dc:rights><cc:Agent><dc:title>(c) Ad5001 2021 - All rights reserved</dc:title></cc:Agent></dc:rights></cc:Work><cc:License
|
||||
rdf:about="http://creativecommons.org/licenses/by-nc-sa/4.0/"><cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Reproduction" /><cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#Distribution" /><cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Notice" /><cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#Attribution" /><cc:prohibits
|
||||
rdf:resource="http://creativecommons.org/ns#CommercialUse" /><cc:permits
|
||||
rdf:resource="http://creativecommons.org/ns#DerivativeWorks" /><cc:requires
|
||||
rdf:resource="http://creativecommons.org/ns#ShareAlike" /></cc:License></rdf:RDF></metadata><g
|
||||
id="layer2"
|
||||
transform="matrix(1,0,0,0.94444444,0,1.1666667)"
|
||||
style="fill:#666666"><rect
|
||||
style="fill:#666666;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect1546"
|
||||
width="18"
|
||||
height="18"
|
||||
x="3"
|
||||
y="3"
|
||||
ry="2.25" /></g><g
|
||||
id="layer2-6"
|
||||
transform="matrix(1,0,0,0.94444444,0,0.16666668)"
|
||||
style="fill:#f9f9f9"><rect
|
||||
style="fill:#f9f9f9;fill-opacity:1;fill-rule:evenodd;stroke:none;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="rect1546-7"
|
||||
width="18"
|
||||
height="18"
|
||||
x="3"
|
||||
y="3"
|
||||
ry="2.25" /></g><g
|
||||
id="layer1"
|
||||
style="stroke-width:2;stroke-dasharray:none"><rect
|
||||
style="fill:#000000;fill-rule:evenodd;stroke-width:1.86898;stroke-dasharray:none;stroke-opacity:0"
|
||||
id="rect1410"
|
||||
width="14"
|
||||
height="2"
|
||||
x="5"
|
||||
y="15.5" /><rect
|
||||
style="fill:#000000;fill-rule:evenodd;stroke-width:2;stroke-dasharray:none;stroke-opacity:0"
|
||||
id="rect1412"
|
||||
width="2"
|
||||
height="15"
|
||||
x="9"
|
||||
y="3.9768662" /><path
|
||||
style="fill:none;fill-rule:evenodd;stroke:#ff0000;stroke-width:2;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path1529"
|
||||
d="M 18,4 C 18,10.017307 13.40948,15.5 5,15.5" /></g></svg>
|
After Width: | Height: | Size: 3.1 KiB |
|
@ -0,0 +1,183 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import Qt.labs.platform as Native
|
||||
//import QtQuick.Controls 2.15
|
||||
import eu.ad5001.MixedMenu 1.1
|
||||
import "js/index.mjs" as JS
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype AppMenuBar
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief MenuBar for LogarithmPlotter.
|
||||
|
||||
Makes use of eu.ad5001.LogarithmPlotter.
|
||||
|
||||
\sa LogarithmPlotter
|
||||
*/
|
||||
MenuBar {
|
||||
|
||||
Menu {
|
||||
title: qsTr("&File")
|
||||
Action {
|
||||
text: qsTr("&Load...")
|
||||
shortcut: StandardKey.Open
|
||||
onTriggered: settings.load()
|
||||
icon.name: 'document-open'
|
||||
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Save")
|
||||
shortcut: StandardKey.Save
|
||||
onTriggered: settings.save()
|
||||
icon.name: 'document-save'
|
||||
}
|
||||
Action {
|
||||
text: qsTr("Save &As...")
|
||||
shortcut: StandardKey.SaveAs
|
||||
onTriggered: settings.saveAs()
|
||||
icon.name: 'document-save-as'
|
||||
|
||||
}
|
||||
MenuSeparator { }
|
||||
Action {
|
||||
text: qsTr("&Quit")
|
||||
shortcut: StandardKey.Quit
|
||||
onTriggered: {
|
||||
if(settings.saved)
|
||||
Qt.quit()
|
||||
else
|
||||
saveUnsavedChangesDialog.visible = true;
|
||||
}
|
||||
|
||||
icon.name: 'application-exit'
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
title: qsTr("&Edit")
|
||||
Action {
|
||||
text: qsTr("&Undo")
|
||||
shortcut: StandardKey.Undo
|
||||
onTriggered: history.undo()
|
||||
icon.name: 'edit-undo'
|
||||
icon.color: enabled ? sysPalette.windowText : sysPaletteIn.windowText
|
||||
enabled: history.undoCount > 0
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Redo")
|
||||
shortcut: StandardKey.Redo
|
||||
onTriggered: history.redo()
|
||||
icon.name: 'edit-redo'
|
||||
icon.color: enabled ? sysPalette.windowText : sysPaletteIn.windowText
|
||||
enabled: history.redoCount > 0
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Copy plot")
|
||||
shortcut: StandardKey.Copy
|
||||
onTriggered: root.copyDiagramToClipboard()
|
||||
icon.name: 'edit-copy'
|
||||
}
|
||||
MenuSeparator { }
|
||||
Action {
|
||||
text: qsTr("&Preferences")
|
||||
shortcut: StandardKey.Copy
|
||||
onTriggered: preferences.open()
|
||||
icon.name: 'settings'
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
title: qsTr("&Create")
|
||||
// Services repeater
|
||||
Repeater {
|
||||
model: Object.keys(Modules.Objects.types)
|
||||
|
||||
MenuItem {
|
||||
text: Modules.Objects.types[modelData].displayType()
|
||||
visible: Modules.Objects.types[modelData].createable()
|
||||
height: visible ? implicitHeight : 0
|
||||
icon.name: modelData
|
||||
icon.source: './icons/objects/' + modelData + '.svg'
|
||||
icon.color: sysPalette.buttonText
|
||||
onTriggered: {
|
||||
var newObj = Modules.Objects.createNewRegisteredObject(modelData)
|
||||
history.addToHistory(new JS.HistoryLib.CreateNewObject(newObj.name, modelData, newObj.export()))
|
||||
objectLists.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Menu {
|
||||
title: qsTr("&Help")
|
||||
Action {
|
||||
text: qsTr("&Source code")
|
||||
icon.name: 'software-sources'
|
||||
onTriggered: Qt.openUrlExternally("https://git.ad5001.eu/Ad5001/LogarithmPlotter")
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Report a bug")
|
||||
icon.name: 'tools-report-bug'
|
||||
onTriggered: Qt.openUrlExternally("https://git.ad5001.eu/Ad5001/LogarithmPlotter/issues")
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&User manual")
|
||||
icon.name: 'documentation'
|
||||
onTriggered: Qt.openUrlExternally("https://git.ad5001.eu/Ad5001/LogarithmPlotter/wiki/_Sidebar")
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Changelog")
|
||||
icon.name: 'state-information'
|
||||
onTriggered: changelog.open()
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&Help translating!")
|
||||
icon.name: 'translator'
|
||||
onTriggered: Qt.openUrlExternally("https://hosted.weblate.org/engage/logarithmplotter/")
|
||||
}
|
||||
MenuSeparator { }
|
||||
Action {
|
||||
text: qsTr("&Thanks")
|
||||
icon.name: 'about'
|
||||
onTriggered: thanksTo.open()
|
||||
}
|
||||
Action {
|
||||
text: qsTr("&About")
|
||||
shortcut: StandardKey.HelpContents
|
||||
icon.name: 'about'
|
||||
onTriggered: about.open()
|
||||
}
|
||||
}
|
||||
|
||||
Native.MessageDialog {
|
||||
id: saveUnsavedChangesDialog
|
||||
title: qsTr("Save unsaved changes?")
|
||||
text: qsTr("This plot contains unsaved changes. By doing this, all unsaved data will be lost. Continue?")
|
||||
buttons: Native.MessageDialog.Save | Native.MessageDialog.Discard | Native.MessageDialog.Cancel
|
||||
|
||||
onSaveClicked: settings.save()
|
||||
onDiscardClicked: Qt.quit()
|
||||
}
|
||||
|
||||
function openSaveUnsavedChangesDialog() {
|
||||
saveUnsavedChangesDialog.open()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,222 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQml
|
||||
import QtQuick.Window
|
||||
import "../js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype History
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.History
|
||||
\brief QObject holding persistantly for undo & redo stacks.
|
||||
|
||||
\sa HistoryBrowser, HistoryLib
|
||||
*/
|
||||
Item {
|
||||
// Using a QtObject is necessary in order to have proper property propagation in QML
|
||||
id: historyObj
|
||||
|
||||
/*!
|
||||
\qmlproperty int History::undoCount
|
||||
Count of undo actions.
|
||||
*/
|
||||
property int undoCount: 0
|
||||
/*!
|
||||
\qmlproperty int History::redoCount
|
||||
Count of redo actions.
|
||||
*/
|
||||
property int redoCount: 0
|
||||
/*!
|
||||
\qmlproperty var History::undoStack
|
||||
Stack of undo actions.
|
||||
*/
|
||||
property var undoStack: []
|
||||
/*!
|
||||
\qmlproperty var History::redoStack
|
||||
Stack of redo actions.
|
||||
*/
|
||||
property var redoStack: []
|
||||
/*!
|
||||
\qmlproperty bool History::saved
|
||||
true when no modification was done to the current working file, false otherwise.
|
||||
*/
|
||||
property bool saved: true
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::clear()
|
||||
Clears both undo and redo stacks completly.
|
||||
*/
|
||||
function clear() {
|
||||
undoCount = 0
|
||||
redoCount = 0
|
||||
undoStack = []
|
||||
redoStack = []
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmethod var History::serialize()
|
||||
Serializes history into JSON-able content.
|
||||
*/
|
||||
function serialize() {
|
||||
let undoSt = [], redoSt = [];
|
||||
for(let i = 0; i < undoCount; i++)
|
||||
undoSt.push([
|
||||
undoStack[i].type(),
|
||||
undoStack[i].export()
|
||||
]);
|
||||
for(let i = 0; i < redoCount; i++)
|
||||
redoSt.push([
|
||||
redoStack[i].type(),
|
||||
redoStack[i].export()
|
||||
]);
|
||||
return [undoSt, redoSt]
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::unserialize(var undoSt, var redoSt)
|
||||
Unserializes both \c undoSt stack and \c redoSt stack from serialized content.
|
||||
*/
|
||||
function unserialize(undoSt, redoSt) {
|
||||
clear();
|
||||
for(let i = 0; i < undoSt.length; i++)
|
||||
undoStack.push(new JS.HistoryLib.Actions[undoSt[i][0]](...undoSt[i][1]))
|
||||
for(let i = 0; i < redoSt.length; i++)
|
||||
redoStack.push(new JS.HistoryLib.Actions[redoSt[i][0]](...redoSt[i][1]))
|
||||
undoCount = undoSt.length;
|
||||
redoCount = redoSt.length;
|
||||
objectLists.update()
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::addToHistory(var action)
|
||||
Adds an instance of HistoryLib.Action to history.
|
||||
*/
|
||||
function addToHistory(action) {
|
||||
if(action instanceof JS.HistoryLib.Action) {
|
||||
console.log("Added new entry to history: " + action.getReadableString())
|
||||
undoStack.push(action)
|
||||
undoCount++;
|
||||
if(Helper.getSettingBool("reset_redo_stack")) {
|
||||
redoStack = []
|
||||
redoCount = 0
|
||||
}
|
||||
saved = false
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::undo(bool updateObjectList = true)
|
||||
Undoes the HistoryLib.Action at the top of the undo stack and pushes it to the top of the redo stack.
|
||||
By default, will update the graph and the object list. This behavior can be disabled by setting the \c updateObjectList to false.
|
||||
*/
|
||||
function undo(updateObjectList = true) {
|
||||
if(undoStack.length > 0) {
|
||||
var action = undoStack.pop()
|
||||
action.undo()
|
||||
if(updateObjectList)
|
||||
objectLists.update()
|
||||
redoStack.push(action)
|
||||
undoCount--;
|
||||
redoCount++;
|
||||
saved = false
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::redo(bool updateObjectList = true)
|
||||
Redoes the HistoryLib.Action at the top of the redo stack and pushes it to the top of the undo stack.
|
||||
By default, will update the graph and the object list. This behavior can be disabled by setting the \c updateObjectList to false.
|
||||
*/
|
||||
function redo(updateObjectList = true) {
|
||||
if(redoStack.length > 0) {
|
||||
var action = redoStack.pop()
|
||||
action.redo()
|
||||
if(updateObjectList)
|
||||
objectLists.update()
|
||||
undoStack.push(action)
|
||||
undoCount++;
|
||||
redoCount--;
|
||||
saved = false
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::undoMultipleDefered(int toUndoCount)
|
||||
Undoes several HistoryLib.Action at the top of the undo stack and pushes them to the top of the redo stack.
|
||||
It undoes them deferedly to avoid overwhelming the computer while creating a cool short accelerated summary of all changes.
|
||||
*/
|
||||
function undoMultipleDefered(toUndoCount) {
|
||||
undoTimer.toUndoCount = toUndoCount;
|
||||
undoTimer.start()
|
||||
if(toUndoCount > 0)
|
||||
saved = false
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmethod void History::redoMultipleDefered(int toRedoCount)
|
||||
Redoes several HistoryLib.Action at the top of the redo stack and pushes them to the top of the undo stack.
|
||||
It redoes them deferedly to avoid overwhelming the computer while creating a cool short accelerated summary of all changes.
|
||||
*/
|
||||
function redoMultipleDefered(toRedoCount) {
|
||||
redoTimer.toRedoCount = toRedoCount;
|
||||
redoTimer.start()
|
||||
if(toRedoCount > 0)
|
||||
saved = false
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: undoTimer
|
||||
interval: 5; running: false; repeat: true
|
||||
property int toUndoCount: 0
|
||||
onTriggered: {
|
||||
if(toUndoCount > 0) {
|
||||
historyObj.undo(toUndoCount % 4 == 1) // Only redraw once every 4 changes.
|
||||
toUndoCount--;
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: redoTimer
|
||||
interval: 5; running: false; repeat: true
|
||||
property int toRedoCount: 0
|
||||
onTriggered: {
|
||||
if(toRedoCount > 0) {
|
||||
historyObj.redo(toRedoCount % 4 == 1) // Only redraw once every 4 changes.
|
||||
toRedoCount--;
|
||||
} else {
|
||||
running = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
Modules.History.initialize({
|
||||
historyObj,
|
||||
themeTextColor: sysPalette.windowText.toString(),
|
||||
imageDepth: Screen.devicePixelRatio,
|
||||
fontSize: 14
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick.Controls
|
||||
import QtQuick
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype HistoryBrowser
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.History
|
||||
\brief Tab of the drawer that allows to navigate through the undo and redo history.
|
||||
|
||||
Creates a scrollable view containing a list of history actions based on the redo stack, then a "Now" indicator
|
||||
followed by the entirety of the saved undo stack. Each action can be click to restore a state of the graph at
|
||||
some point of the history.
|
||||
|
||||
\sa LogarithmPlotter, Settings, ObjectLists
|
||||
*/
|
||||
Item {
|
||||
id: historyBrowser
|
||||
|
||||
/*!
|
||||
\qmlproperty int HistoryBrowser::actionWidth
|
||||
Width of the actions.
|
||||
*/
|
||||
property int actionWidth: width-20
|
||||
|
||||
/*!
|
||||
\qmlproperty int HistoryBrowser::darkTheme
|
||||
true when the system is running with a dark theme, false otherwise.
|
||||
*/
|
||||
property bool darkTheme: isDarkTheme()
|
||||
|
||||
Setting.TextSetting {
|
||||
id: filterInput
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
anchors.rightMargin: 5
|
||||
placeholderText: qsTr("Filter...")
|
||||
category: "all"
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
anchors.left: parent.left
|
||||
anchors.right: parent.right
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.top: filterInput.bottom
|
||||
|
||||
ScrollBar.horizontal.visible: false
|
||||
clip: true
|
||||
|
||||
Flickable {
|
||||
width: parent.width
|
||||
height: parent.height
|
||||
contentHeight: redoColumn.height + nowRect.height + undoColumn.height
|
||||
contentWidth: parent.width
|
||||
|
||||
Column {
|
||||
id: redoColumn
|
||||
anchors.right: parent.right
|
||||
anchors.top: parent.top
|
||||
width: actionWidth
|
||||
|
||||
Repeater {
|
||||
model: history.redoCount
|
||||
|
||||
HistoryItem {
|
||||
id: redoButton
|
||||
width: actionWidth
|
||||
//height: actionHeight
|
||||
isRedo: true
|
||||
idx: index
|
||||
darkTheme: historyBrowser.darkTheme
|
||||
hidden: !(filterInput.value == "" || content.includes(filterInput.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.bottom: nowRect.top
|
||||
text: qsTr("Redo >")
|
||||
color: sysPaletteIn.windowText
|
||||
transform: Rotation { origin.x: 30; origin.y: 30; angle: 270}
|
||||
height: 70
|
||||
width: 20
|
||||
visible: history.redoCount > 0
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: nowRect
|
||||
anchors.right: parent.right
|
||||
anchors.top: redoColumn.bottom
|
||||
width: actionWidth
|
||||
height: 40
|
||||
color: sysPalette.highlight
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 5
|
||||
text: qsTr("> Now")
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
id: undoColumn
|
||||
anchors.right: parent.right
|
||||
anchors.top: nowRect.bottom
|
||||
width: actionWidth
|
||||
|
||||
Repeater {
|
||||
model: history.undoCount
|
||||
|
||||
|
||||
HistoryItem {
|
||||
id: undoButton
|
||||
width: actionWidth
|
||||
//height: actionHeight
|
||||
isRedo: false
|
||||
idx: index
|
||||
darkTheme: historyBrowser.darkTheme
|
||||
hidden: !(filterInput.value == "" || content.includes(filterInput.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.left: parent.left
|
||||
anchors.top: undoColumn.top
|
||||
text: qsTr("< Undo")
|
||||
color: sysPaletteIn.windowText
|
||||
transform: Rotation { origin.x: 30; origin.y: 30; angle: 270}
|
||||
height: 60
|
||||
width: 20
|
||||
visible: history.undoCount > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod bool HistoryBrowser::isDarkTheme()
|
||||
Checks whether the system is running with a light or dark theme.
|
||||
*/
|
||||
function isDarkTheme() {
|
||||
let hex = sysPalette.windowText.toString()
|
||||
// We only check the first parameter, as on all normal OSes, text color is grayscale.
|
||||
return parseInt(hex.substr(1,2), 16) > 128
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick.Controls
|
||||
import QtQuick
|
||||
import Qt5Compat.GraphicalEffects
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype HistoryItem
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.History
|
||||
\brief Item representing an history action.
|
||||
|
||||
Creates a scrollable view containing a list of history actions based on the redo stack, then a "Now" indicator
|
||||
followed by the entirety of the saved undo stack. Each action can be click to restore a state of the graph at
|
||||
some point of the history.
|
||||
|
||||
\sa HistoryBrowser
|
||||
*/
|
||||
Button {
|
||||
id: redoButton
|
||||
flat: true
|
||||
|
||||
/*!
|
||||
\qmlproperty bool HistoryItem::isRedo
|
||||
true if the action is in the redo stack, false othewise.
|
||||
*/
|
||||
property bool isRedo
|
||||
/*!
|
||||
\qmlproperty int HistoryItem::idx
|
||||
Index of the item within the HistoryBrowser list.
|
||||
*/
|
||||
property int idx
|
||||
/*!
|
||||
\qmlproperty bool HistoryItem::darkTheme
|
||||
true when the system is running with a dark theme, false otherwise.
|
||||
*/
|
||||
property bool darkTheme
|
||||
/*!
|
||||
\qmlproperty bool HistoryItem::hidden
|
||||
true when the item is filtered out, false otherwise.
|
||||
*/
|
||||
property bool hidden: false
|
||||
/*!
|
||||
\qmlproperty int HistoryItem::historyAction
|
||||
Associated history action.
|
||||
*/
|
||||
readonly property var historyAction: isRedo ? history.redoStack[idx] : history.undoStack[history.undoCount-idx-1]
|
||||
|
||||
/*!
|
||||
\qmlproperty int HistoryItem::actionHeight
|
||||
Base height of the action.
|
||||
*/
|
||||
readonly property int actionHeight: 40
|
||||
/*!
|
||||
\qmlproperty color HistoryItem::clr
|
||||
Color of the history action.
|
||||
*/
|
||||
readonly property color clr: historyAction.color(darkTheme)
|
||||
/*!
|
||||
\qmlproperty string HistoryItem::clr
|
||||
Label description of the history item.
|
||||
*/
|
||||
readonly property string content: historyAction.getReadableString()
|
||||
|
||||
height: hidden ? 8 : Math.max(actionHeight, label.height + 15)
|
||||
|
||||
|
||||
LinearGradient {
|
||||
anchors.fill: parent
|
||||
//opacity: hidden ? 0.6 : 1
|
||||
start: Qt.point(0, 0)
|
||||
end: Qt.point(parent.width, 0)
|
||||
gradient: Gradient {
|
||||
GradientStop { position: 0.1; color: "transparent" }
|
||||
GradientStop { position: 1.5; color: clr }
|
||||
}
|
||||
}
|
||||
|
||||
Setting.Icon {
|
||||
id: icon
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 6
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: !hidden
|
||||
width: 18
|
||||
height: 18
|
||||
|
||||
color: sysPalette.windowText
|
||||
source: `../icons/history/${historyAction.icon()}.svg`
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors.left: icon.right
|
||||
anchors.right: parent.right
|
||||
anchors.leftMargin: 6
|
||||
anchors.rightMargin: 20
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
visible: !hidden
|
||||
font.pixelSize: 14
|
||||
text: ""
|
||||
textFormat: Text.RichText
|
||||
clip: true
|
||||
wrapMode: Text.WordWrap
|
||||
|
||||
Component.onCompleted: function() {
|
||||
// Render HTML, might be string, but could also be a promise
|
||||
const html = historyAction.getHTMLString()
|
||||
if(typeof html === "string") {
|
||||
label.text = html.replace(/\$\{tag_color\}/g, clr)
|
||||
} else {
|
||||
// Promise! We need to way to wait for it to be completed.
|
||||
html.then(rendered => {
|
||||
label.text = rendered.replace(/\$\{tag_color\}/g, clr)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: hiddenDot
|
||||
anchors.centerIn: parent
|
||||
visible: hidden
|
||||
width: 5
|
||||
height: 5
|
||||
radius: 5
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.delay: 200
|
||||
ToolTip.text: content
|
||||
|
||||
onClicked: {
|
||||
if(isRedo)
|
||||
history.redoMultipleDefered(history.redoCount-idx)
|
||||
else
|
||||
history.undoMultipleDefered(+idx+1)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
module eu.ad5001.LogarithmPlotter.History
|
||||
|
||||
History 1.0 History.qml
|
||||
HistoryBrowser 1.0 HistoryBrowser.qml
|
||||
HistoryItem 1.0 HistoryItem.qml
|
|
@ -0,0 +1,163 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import Qt.labs.platform as Native
|
||||
|
||||
/*!
|
||||
\qmltype LogGraphCanvas
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief Canvas used to display the diagram.
|
||||
|
||||
Provides a customized canvas with several helper methods to be used by objects.
|
||||
|
||||
\sa LogarithmPlotter, PickLocationOverlay
|
||||
*/
|
||||
Canvas {
|
||||
id: canvas
|
||||
anchors.top: separator.bottom
|
||||
anchors.left: parent.left
|
||||
height: parent.height - 90
|
||||
width: parent.width
|
||||
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::xmin
|
||||
Minimum x of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double xmin: 0
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::ymax
|
||||
Maximum y of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double ymax: 0
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::xzoom
|
||||
Zoom on the x axis of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double xzoom: 10
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::yzoom
|
||||
Zoom on the y axis of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double yzoom: 10
|
||||
/*!
|
||||
\qmlproperty string LogGraphCanvas::xaxisstep
|
||||
Step of the x axis graduation, provided from settings.
|
||||
\note: Only available in non-logarithmic mode.
|
||||
\sa Settings
|
||||
*/
|
||||
property string xaxisstep: "4"
|
||||
/*!
|
||||
\qmlproperty string LogGraphCanvas::yaxisstep
|
||||
Step of the y axis graduation, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string yaxisstep: "4"
|
||||
/*!
|
||||
\qmlproperty string LogGraphCanvas::xlabel
|
||||
Label used on the x axis, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string xlabel: ""
|
||||
/*!
|
||||
\qmlproperty string LogGraphCanvas::ylabel
|
||||
Label used on the y axis, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string ylabel: ""
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::linewidth
|
||||
Width of lines that will be drawn into the canvas, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double linewidth: 1
|
||||
/*!
|
||||
\qmlproperty double LogGraphCanvas::textsize
|
||||
Font size of the text that will be drawn into the canvas, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double textsize: 14
|
||||
/*!
|
||||
\qmlproperty bool LogGraphCanvas::logscalex
|
||||
true if the canvas should be in logarithmic mode, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool logscalex: false
|
||||
/*!
|
||||
\qmlproperty bool LogGraphCanvas::showxgrad
|
||||
true if the x graduation should be shown, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool showxgrad: false
|
||||
/*!
|
||||
\qmlproperty bool LogGraphCanvas::showygrad
|
||||
true if the y graduation should be shown, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool showygrad: false
|
||||
|
||||
/*!
|
||||
\qmlproperty var LogGraphCanvas::imageLoaders
|
||||
Dictionary of format {image: [callback.image data]} containing data for defered image loading.
|
||||
*/
|
||||
property var imageLoaders: {}
|
||||
/*!
|
||||
\qmlproperty var LogGraphCanvas::ctx
|
||||
Cache for the 2D context so that it may be used asynchronously.
|
||||
*/
|
||||
property var ctx
|
||||
|
||||
Component.onCompleted: {
|
||||
imageLoaders = {}
|
||||
Modules.Canvas.initialize({ canvas, drawingErrorDialog })
|
||||
}
|
||||
|
||||
Native.MessageDialog {
|
||||
id: drawingErrorDialog
|
||||
title: qsTranslate("expression", "LogarithmPlotter - Drawing error")
|
||||
text: ""
|
||||
function show(objType, objName, error) {
|
||||
text = qsTranslate("error", "Error while attempting to draw %1 %2:\n%3\n\nUndoing last change.").arg(objType).arg(objName).arg(error)
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
onPaint: function(rect) {
|
||||
//console.log('Redrawing')
|
||||
if(rect.width == canvas.width) { // Redraw full canvas
|
||||
Modules.Canvas.redraw()
|
||||
}
|
||||
}
|
||||
|
||||
onImageLoaded: {
|
||||
Object.keys(imageLoaders).forEach((key) => {
|
||||
if(isImageLoaded(key)) {
|
||||
// Calling callback
|
||||
imageLoaders[key][0](canvas, ctx, imageLoaders[key][1])
|
||||
delete imageLoaders[key]
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -0,0 +1,268 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQml
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.MixedMenu 1.1
|
||||
import QtQuick.Layouts 1.12
|
||||
import QtQuick
|
||||
|
||||
// Auto loading all modules.
|
||||
import "js/index.mjs" as JS
|
||||
|
||||
import eu.ad5001.LogarithmPlotter.History 1.0
|
||||
import eu.ad5001.LogarithmPlotter.ObjectLists 1.0
|
||||
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
|
||||
|
||||
/*!
|
||||
\qmltype LogarithmPlotter
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief Main window of LogarithmPlotter
|
||||
|
||||
\sa AppMenuBar, History, GreetScreen, Changelog, Alert, ObjectLists, Settings, HistoryBrowser, LogGraphCanvas, PickLocationOverlay.
|
||||
*/
|
||||
ApplicationWindow {
|
||||
id: root
|
||||
visible: true
|
||||
width: 1000
|
||||
height: 500
|
||||
color: sysPalette.window
|
||||
title: "LogarithmPlotter " + (settings.saveFilename != "" ? " - " + settings.saveFilename.split('/').pop() : "") + (history.saved ? "" : "*")
|
||||
|
||||
SystemPalette { id: sysPalette; colorGroup: SystemPalette.Active }
|
||||
SystemPalette { id: sysPaletteIn; colorGroup: SystemPalette.Disabled }
|
||||
|
||||
menuBar: appMenu.trueItem
|
||||
|
||||
AppMenuBar {id: appMenu}
|
||||
|
||||
History { id: history }
|
||||
|
||||
Popup.GreetScreen {}
|
||||
|
||||
Popup.Preferences {id: preferences}
|
||||
|
||||
Popup.Changelog {id: changelog}
|
||||
|
||||
Popup.About {id: about}
|
||||
|
||||
Popup.ThanksTo {id: thanksTo}
|
||||
|
||||
Popup.Alert {
|
||||
id: alert
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 5
|
||||
z: 3
|
||||
}
|
||||
|
||||
Item {
|
||||
id: sidebar
|
||||
width: 300
|
||||
height: parent.height
|
||||
//y: root.menuBar.height
|
||||
readonly property bool inPortrait: root.width < root.height
|
||||
/*modal: true// inPortrait
|
||||
interactive: inPortrait
|
||||
position: inPortrait ? 0 : 1
|
||||
*/
|
||||
visible: !inPortrait
|
||||
|
||||
|
||||
TabBar {
|
||||
id: sidebarSelector
|
||||
width: parent.width
|
||||
anchors.top: parent.top
|
||||
TabButton {
|
||||
text: qsTr("Objects")
|
||||
icon.name: 'polygon-add-nodes'
|
||||
icon.color: sysPalette.windowText
|
||||
//height: 24
|
||||
}
|
||||
TabButton {
|
||||
text: qsTr("Settings")
|
||||
icon.name: 'preferences-system-symbolic'
|
||||
icon.color: sysPalette.windowText
|
||||
//height: 24
|
||||
}
|
||||
TabButton {
|
||||
text: qsTr("History")
|
||||
icon.name: 'view-history'
|
||||
icon.color: sysPalette.windowText
|
||||
//height: 24
|
||||
}
|
||||
}
|
||||
|
||||
StackLayout {
|
||||
id: sidebarContents
|
||||
anchors.top: sidebarSelector.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.topMargin: 5
|
||||
anchors.leftMargin: 5
|
||||
anchors.bottom: parent.bottom
|
||||
//anchors.bottomMargin: sidebarSelector.height
|
||||
width: parent.width - 5
|
||||
currentIndex: sidebarSelector.currentIndex
|
||||
z: -1
|
||||
clip: true
|
||||
|
||||
ObjectLists {
|
||||
id: objectLists
|
||||
onChanged: drawCanvas.requestPaint()
|
||||
}
|
||||
|
||||
Settings {
|
||||
id: settings
|
||||
canvas: drawCanvas
|
||||
onChanged: drawCanvas.requestPaint()
|
||||
}
|
||||
|
||||
HistoryBrowser {
|
||||
id: historyBrowser
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LogGraphCanvas {
|
||||
id: drawCanvas
|
||||
anchors.top: parent.top
|
||||
anchors.left: sidebar.inPortrait ? parent.left : sidebar.right
|
||||
height: parent.height
|
||||
width: sidebar.inPortrait ? parent.width : parent.width - sidebar.width//*sidebar.position
|
||||
x: sidebar.width//*sidebar.position
|
||||
|
||||
xmin: settings.xmin
|
||||
ymax: settings.ymax
|
||||
xzoom: settings.xzoom
|
||||
yzoom: settings.yzoom
|
||||
xlabel: settings.xlabel
|
||||
ylabel: settings.ylabel
|
||||
yaxisstep: settings.yaxisstep
|
||||
xaxisstep: settings.xaxisstep
|
||||
logscalex: settings.logscalex
|
||||
linewidth: settings.linewidth
|
||||
textsize: settings.textsize
|
||||
showxgrad: settings.showxgrad
|
||||
showygrad: settings.showygrad
|
||||
|
||||
property bool firstDrawDone: false
|
||||
|
||||
onPainted: if(!firstDrawDone) {
|
||||
firstDrawDone = true;
|
||||
console.info("First paint done in " + (new Date().getTime()-(StartTime*1000)) + "ms")
|
||||
if(TestBuild == true) {
|
||||
console.log("Plot drawn in canvas, terminating test of build in 100ms.")
|
||||
testBuildTimer.start()
|
||||
}
|
||||
}
|
||||
|
||||
ViewPositionChangeOverlay {
|
||||
id: viewPositionChanger
|
||||
anchors.fill: parent
|
||||
canvas: parent
|
||||
settingsInstance: settings
|
||||
}
|
||||
|
||||
PickLocationOverlay {
|
||||
id: positionPicker
|
||||
anchors.fill: parent
|
||||
canvas: parent
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: delayRefreshTimer
|
||||
repeat: false
|
||||
interval: 1
|
||||
onTriggered: sidebarSelector.currentIndex = 0
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: testBuildTimer
|
||||
repeat: false
|
||||
interval: 100
|
||||
onTriggered: Qt.quit() // Quit after paint on test build
|
||||
}
|
||||
|
||||
onClosing: function(close) {
|
||||
if(!history.saved) {
|
||||
close.accepted = false
|
||||
appMenu.openSaveUnsavedChangesDialog()
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogarithmPlotter::updateObjectsLists()
|
||||
Updates the objects lists when loading a file.
|
||||
*/
|
||||
function updateObjectsLists() {
|
||||
if(sidebarSelector.currentIndex === 0) {
|
||||
// For some reason, if we load a file while the tab is on object,
|
||||
// we get stuck in a Qt-side loop? Qt bug or side-effect here, I don't know.
|
||||
sidebarSelector.currentIndex = 1
|
||||
objectLists.update()
|
||||
delayRefreshTimer.start()
|
||||
} else {
|
||||
objectLists.update()
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogarithmPlotter::copyDiagramToClipboard()
|
||||
Copies the current diagram image to the clipboard.
|
||||
*/
|
||||
function copyDiagramToClipboard() {
|
||||
var file = Helper.gettmpfile()
|
||||
drawCanvas.save(file)
|
||||
Helper.copyImageToClipboard()
|
||||
alert.show(qsTr("Copied plot screenshot to clipboard!"))
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogarithmPlotter::showAlert(string alertText)
|
||||
Shows an alert on the diagram.
|
||||
*/
|
||||
function showAlert(alertText) {
|
||||
// This function is called from the backend and is used to show alerts from there.
|
||||
alert.show(alertText)
|
||||
}
|
||||
|
||||
|
||||
Menu {
|
||||
id: updateMenu
|
||||
title: qsTr("&Update")
|
||||
Action {
|
||||
text: qsTr("&Update LogarithmPlotter")
|
||||
icon.name: 'update'
|
||||
onTriggered: Qt.openUrlExternally("https://apps.ad5001.eu/logarithmplotter/")
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogarithmPlotter::showUpdateMenu()
|
||||
Shows the update menu in the AppMenuBar.
|
||||
*/
|
||||
function showUpdateMenu() {
|
||||
appMenu.addMenu(updateMenu)
|
||||
}
|
||||
|
||||
// Initializing modules
|
||||
Component.onCompleted: {
|
||||
Modules.IO.initialize({ root, settings, alert })
|
||||
Modules.Latex.initialize({ latex: Latex, helper: Helper })
|
||||
}
|
||||
}
|
|
@ -0,0 +1,339 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import Qt.labs.platform as Native
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import "../../js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype CustomPropertyList
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists.Editor
|
||||
\brief Lists all custom properties editors inside a repeater and allow for edition.
|
||||
|
||||
This class repeats all of the custom properties and loads the appropriate editor for each kind of property.
|
||||
|
||||
\sa Dialog
|
||||
*/
|
||||
Repeater {
|
||||
id: root
|
||||
|
||||
signal changed()
|
||||
|
||||
/*!
|
||||
\qmlproperty var CustomPropertyList::obj
|
||||
Object whose properties to list and edit.
|
||||
*/
|
||||
property var obj
|
||||
/*!
|
||||
\qmlproperty var CustomPropertyList::positionPicker
|
||||
Reference to the global PositionPicker QML object.
|
||||
*/
|
||||
property var positionPicker
|
||||
|
||||
readonly property var textTypes: ['Domain', 'string', 'number', 'int']
|
||||
readonly property var comboBoxTypes: ['ObjectType', 'Enum']
|
||||
readonly property var listTypes: ['List', 'Dict']
|
||||
|
||||
|
||||
// NOTE: All components have the declared properties 'propertyLabel', 'propertyIcon', propertyName' and 'propertyType' to access the object in question.
|
||||
Component {
|
||||
id: commentComponent
|
||||
|
||||
// Item for comments.
|
||||
// NOTE: propertyType here is the content of the comment (yes, it's a bit backwards, but it's more clear on the properties side).
|
||||
Label {
|
||||
// Translated text with object name.
|
||||
property string trText: qsTranslate('comment', propertyType).toString()
|
||||
text: (trText.includes("%1") ? trText.arg(obj.name) : trText).toString()
|
||||
//color: sysPalette.windowText
|
||||
wrapMode: Text.WordWrap
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: expressionEditorComponent
|
||||
|
||||
// Setting for expressions
|
||||
Setting.ExpressionEditor {
|
||||
height: 30
|
||||
label: propertyLabel
|
||||
icon: `settings/custom/${propertyIcon}.svg`
|
||||
defValue: JS.Utils.simplifyExpression(obj[propertyName].toEditableString())
|
||||
self: obj.name
|
||||
variables: propertyType.variables
|
||||
onChanged: function(newExpr) {
|
||||
if(obj[propertyName].toString() != newExpr.toString()) {
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], newExpr
|
||||
))
|
||||
obj[propertyName] = newExpr
|
||||
root.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Component {
|
||||
id: textEditorComponent
|
||||
|
||||
// Setting for text & number settings as well as domains
|
||||
Setting.TextSetting {
|
||||
height: 30
|
||||
label: propertyLabel
|
||||
icon: `settings/custom/${propertyIcon}.svg`
|
||||
min: propertyType == "int" ? 0 : -Infinity
|
||||
isInt: propertyType == "int"
|
||||
isDouble: propertyType == "number"
|
||||
defValue: obj[propertyName] == null ? '' : obj[propertyName].toString()
|
||||
category: {
|
||||
return {
|
||||
"Domain": "domain",
|
||||
"string": "all",
|
||||
"number": "all",
|
||||
"int": "all",
|
||||
}[propertyType]
|
||||
}
|
||||
onChanged: function(newValue) {
|
||||
try {
|
||||
var newValueParsed = {
|
||||
"Domain": () => JS.MathLib.parseDomain(newValue),
|
||||
"string": () => newValue,
|
||||
"number": () => newValue,
|
||||
"int": () => newValue
|
||||
}[propertyType]()
|
||||
|
||||
// Ensuring old and new values are different to prevent useless adding to history.
|
||||
if(obj[propertyName] != newValueParsed) {
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], newValueParsed
|
||||
))
|
||||
obj[propertyName] = newValueParsed
|
||||
root.changed()
|
||||
}
|
||||
} catch(e) {
|
||||
// Error in expression or domain
|
||||
console.trace()
|
||||
parsingErrorDialog.showDialog(propertyName, newValue, e.message)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Native.MessageDialog {
|
||||
id: parsingErrorDialog
|
||||
title: qsTranslate("expression", "LogarithmPlotter - Parsing error")
|
||||
text: ""
|
||||
function showDialog(propName, propValue, error) {
|
||||
text = qsTranslate("error", "Error while parsing expression for property %1:\n%2\n\nEvaluated expression: %3")
|
||||
.arg(qsTranslate('prop', propName))
|
||||
.arg(error).arg(propValue)
|
||||
open()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: checkboxComponent
|
||||
|
||||
// Setting for boolean
|
||||
CheckBox {
|
||||
height: 20
|
||||
text: propertyLabel
|
||||
//icon: `settings/custom/${propertyIcon}.svg`
|
||||
|
||||
checked: {
|
||||
//if(obj[propertyName] == null) {
|
||||
// return false
|
||||
//}
|
||||
return obj[propertyName]
|
||||
}
|
||||
onClicked: {
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], this.checked
|
||||
))
|
||||
obj[propertyName] = this.checked
|
||||
root.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: comboBoxComponent
|
||||
|
||||
// Setting when selecting data from an enum, or an object of a certain type.
|
||||
Setting.ComboBoxSetting {
|
||||
height: 30
|
||||
label: propertyLabel
|
||||
icon: `settings/custom/${propertyIcon}.svg`
|
||||
// True to select an object of type, false for enums.
|
||||
property bool selectObjMode: paramTypeIn(propertyType, ['ObjectType'])
|
||||
property bool isRealObject: !selectObjMode || (propertyType.objType != "ExecutableObject" && propertyType.objType != "DrawableObject")
|
||||
|
||||
// Base, untranslated version of the model.
|
||||
property var baseModel: selectObjMode ?
|
||||
Modules.Objects.getObjectsName(propertyType.objType).concat(
|
||||
isRealObject ? [qsTr("+ Create new %1").arg(Modules.Objects.types[propertyType.objType].displayType())] : [])
|
||||
: propertyType.values
|
||||
// Translated version of the model.
|
||||
model: selectObjMode ? baseModel : propertyType.translatedValues
|
||||
currentIndex: baseModel.indexOf(selectObjMode ? obj[propertyName].name : obj[propertyName])
|
||||
|
||||
onActivated: function(newIndex) {
|
||||
if(selectObjMode) {
|
||||
// This is only done when what we're selecting are Objects.
|
||||
// Setting object property.
|
||||
var selectedObj = Modules.Objects.currentObjectsByName[baseModel[newIndex]]
|
||||
if(newIndex != 0) {
|
||||
// Make sure we don't set the object to null.
|
||||
if(selectedObj == null) {
|
||||
// Creating new object.
|
||||
selectedObj = Modules.Objects.createNewRegisteredObject(propertyType.objType)
|
||||
history.addToHistory(new JS.HistoryLib.CreateNewObject(selectedObj.name, propertyType.objType, selectedObj.export()))
|
||||
baseModel = Modules.Objects.getObjectsName(propertyType.objType).concat(
|
||||
isRealObject ? [qsTr("+ Create new %1").arg(Modules.Objects.types[propertyType.objType].displayType())] :
|
||||
[])
|
||||
currentIndex = baseModel.indexOf(selectedObj.name)
|
||||
}
|
||||
selectedObj.requiredBy.push(Modules.Objects.currentObjects[objType][objIndex])
|
||||
//Modules.Objects.currentObjects[objType][objIndex].requiredBy = obj[propertyName].filter((obj) => obj.name != obj.name)
|
||||
}
|
||||
obj.requiredBy = obj.requiredBy.filter((obj) => obj.name != obj.name)
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], selectedObj
|
||||
))
|
||||
obj[propertyName] = selectedObj
|
||||
} else if(baseModel[newIndex] != obj[propertyName]) {
|
||||
// Ensuring new property is different to not add useless history entries.
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], baseModel[newIndex]
|
||||
))
|
||||
obj[propertyName] = baseModel[newIndex]
|
||||
}
|
||||
// Refreshing
|
||||
root.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
// Setting to edit lists or dictionaries (e.g sequences & repartition function values)
|
||||
id: listDictEditorComponent
|
||||
|
||||
Setting.ListSetting {
|
||||
label: propertyLabel
|
||||
//icon: `settings/custom/${propertyIcon}.svg`
|
||||
dictionaryMode: paramTypeIn(propertyType, ['Dict'])
|
||||
keyType: dictionaryMode ? propertyType.keyType : 'string'
|
||||
valueType: propertyType.valueType
|
||||
preKeyLabel: (dictionaryMode ? propertyType.preKeyLabel : propertyType.label).replace(/\{name\}/g, obj.name).replace(/\{name_\}/g, obj.name.substring(obj.name.indexOf("_")+1))
|
||||
postKeyLabel: (dictionaryMode ? propertyType.postKeyLabel : '').replace(/\{name\}/g, obj.name).replace(/\{name_\}/g, obj.name.substring(obj.name.indexOf("_")+1))
|
||||
keyRegexp: dictionaryMode ? propertyType.keyFormat : /^.+$/
|
||||
valueRegexp: propertyType.format
|
||||
forbidAdding: propertyType.forbidAdding
|
||||
|
||||
onChanged: {
|
||||
var exported = exportModel()
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
obj.name, objType, propertyName,
|
||||
obj[propertyName], exported
|
||||
))
|
||||
obj[propertyName] = exported
|
||||
root.changed()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
importModel(obj[propertyName])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Component {
|
||||
Row {
|
||||
width: dlgProperties.width
|
||||
spacing: 5
|
||||
|
||||
Loader {
|
||||
id: propertyEditor
|
||||
width: dlgProperties.width - pointerButton.width
|
||||
property string propertyName: modelData[0]
|
||||
property var propertyType: modelData[1]
|
||||
property string propertyLabel: qsTranslate('prop',propertyName)
|
||||
property string propertyIcon: JS.Utils.camelCase2readable(propertyName)
|
||||
|
||||
sourceComponent: {
|
||||
if(propertyName.startsWith('comment'))
|
||||
return commentComponent
|
||||
else if(propertyType == 'boolean')
|
||||
return checkboxComponent
|
||||
else if(paramTypeIn(propertyType, ['Expression']))
|
||||
return expressionEditorComponent
|
||||
else if(paramTypeIn(propertyType, textTypes))
|
||||
return textEditorComponent
|
||||
else if(paramTypeIn(propertyType, comboBoxTypes))
|
||||
return comboBoxComponent
|
||||
else if(paramTypeIn(propertyType, listTypes))
|
||||
return listDictEditorComponent
|
||||
else
|
||||
return {}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: pointerButton
|
||||
height: parent.height
|
||||
width: visible ? height : 0
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
property bool isXProp: ['labelX', 'x'].includes(propertyEditor.propertyName)
|
||||
property bool isYProp: ['y'].includes(propertyEditor.propertyName)
|
||||
visible: isXProp || isYProp
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Pick on graph")
|
||||
|
||||
Setting.Icon {
|
||||
id: icon
|
||||
width: 18
|
||||
height: 18
|
||||
anchors.centerIn: parent
|
||||
|
||||
color: sysPalette.windowText
|
||||
source: '../icons/common/position.svg'
|
||||
}
|
||||
|
||||
onClicked: {
|
||||
positionPicker.objType = objType
|
||||
positionPicker.objName = obj.name
|
||||
positionPicker.pickX = isXProp
|
||||
positionPicker.pickY = isYProp
|
||||
positionPicker.propertyX = propertyEditor.propertyName
|
||||
positionPicker.propertyY = propertyEditor.propertyName
|
||||
positionPicker.visible = true
|
||||
objEditor.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Dialogs as D
|
||||
import Qt.labs.platform as Native
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
|
||||
import "../../js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype Dialog
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists.Editor
|
||||
\brief Dialog used to edit properties of objects.
|
||||
|
||||
This class contains the dialog that allows to edit all properties of objects.
|
||||
\todo In the future, this class should be optimized so that each property doesn't instanciate one instance of each setting type.
|
||||
|
||||
\sa Loader, ObjectLists
|
||||
*/
|
||||
Popup.BaseDialog {
|
||||
id: objEditor
|
||||
/*!
|
||||
\qmlproperty string EditorDialog::objType
|
||||
Type of object being edited by the dialog.
|
||||
*/
|
||||
property string objType: 'Point'
|
||||
/*!
|
||||
\qmlproperty int EditorDialog::objIndex
|
||||
Index of the objects amongst the ones of it's type.
|
||||
*/
|
||||
property int objIndex: 0
|
||||
/*!
|
||||
\qmlproperty var EditorDialog::obj
|
||||
Instance of the object being edited.
|
||||
*/
|
||||
property var obj: Modules.Objects.currentObjects[objType][objIndex]
|
||||
/*!
|
||||
\qmlproperty var EditorDialog::posPicker
|
||||
Reference to the global PositionPicker QML object.
|
||||
*/
|
||||
property var posPicker
|
||||
|
||||
title: "LogarithmPlotter"
|
||||
width: 350
|
||||
minimumHeight: Math.max(450,dlgProperties.height + margin*4 + 30)
|
||||
maximumHeight: minimumHeight
|
||||
|
||||
Item {
|
||||
anchors {
|
||||
top: parent.top;
|
||||
left: parent.left;
|
||||
bottom: parent.bottom;
|
||||
right: parent.right;
|
||||
topMargin: margin;
|
||||
leftMargin: margin;
|
||||
bottomMargin: margin + 30;
|
||||
rightMargin: margin;
|
||||
}
|
||||
|
||||
Column {
|
||||
id: dlgProperties
|
||||
anchors.top: parent.top
|
||||
width: objEditor.width - 20
|
||||
spacing: 10
|
||||
|
||||
Label {
|
||||
id: dlgTitle
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: qsTr("Edit properties of %1 %2").arg(Modules.Objects.types[objEditor.objType].displayType()).arg(objEditor.obj.name)
|
||||
font.pixelSize: 20
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Native.MessageDialog {
|
||||
id: invalidNameDialog
|
||||
title: qsTr("LogarithmPlotter - Invalid object name")
|
||||
text: ""
|
||||
function showDialog(objectName) {
|
||||
text = qsTr("An object with the name '%1' already exists.").arg(objectName)
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: nameProperty
|
||||
height: 30
|
||||
label: qsTr("Name")
|
||||
icon: "common/label.svg"
|
||||
category: "name"
|
||||
width: dlgProperties.width
|
||||
value: objEditor.obj.name
|
||||
onChanged: function(newValue) {
|
||||
let newName = JS.Utils.parseName(newValue)
|
||||
if(newName != '' && objEditor.obj.name != newName) {
|
||||
if(newName in Modules.Objects.currentObjectsByName) {
|
||||
invalidNameDialog.showDialog(newName)
|
||||
} else {
|
||||
history.addToHistory(new JS.HistoryLib.NameChanged(
|
||||
objEditor.obj.name, objEditor.objType, newName
|
||||
))
|
||||
Modules.Objects.renameObject(obj.name, newName)
|
||||
objEditor.obj = Modules.Objects.currentObjects[objEditor.objType][objEditor.objIndex]
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Setting.ComboBoxSetting {
|
||||
id: labelContentProperty
|
||||
height: 30
|
||||
width: dlgProperties.width
|
||||
label: qsTr("Label content")
|
||||
model: [qsTr("null"), qsTr("name"), qsTr("name + value")]
|
||||
property var idModel: ["null", "name", "name + value"]
|
||||
icon: "common/label.svg"
|
||||
currentIndex: idModel.indexOf(objEditor.obj.labelContent)
|
||||
onActivated: function(newIndex) {
|
||||
if(idModel[newIndex] != objEditor.obj.labelContent) {
|
||||
objEditor.obj.labelContent = idModel[newIndex]
|
||||
objEditor.obj.update()
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dynamic properties
|
||||
CustomPropertyList {
|
||||
id: dlgCustomProperties
|
||||
obj: objEditor.obj
|
||||
positionPicker: posPicker
|
||||
|
||||
onChanged: {
|
||||
obj.update()
|
||||
objectListList.update()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void EditorDialog::open()
|
||||
Shows the editor after the object to be edited is set.
|
||||
*/
|
||||
function open() {
|
||||
dlgCustomProperties.model = [] // Reset
|
||||
let objProps = Modules.Objects.types[objEditor.objType].properties()
|
||||
dlgCustomProperties.model = Object.keys(objProps).map(prop => [prop, objProps[prop]]) // Converted to 2-dimentional array.
|
||||
objEditor.show()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
module eu.ad5001.LogarithmPlotter.ObjectLists.Editor
|
||||
|
||||
Dialog 1.0 Dialog.qml
|
||||
CustomPropertyList 1.0 CustomPropertyList.qml
|
||||
|
|
@ -0,0 +1,130 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import "../js/index.mjs" as JS
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype ObjectCreationGrid
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists
|
||||
\brief Grid with buttons to create objects.
|
||||
|
||||
\sa LogarithmPlotter, ObjectLists
|
||||
*/
|
||||
Column {
|
||||
id: createRow
|
||||
property var objectEditor
|
||||
property var objectLists
|
||||
property var posPicker
|
||||
|
||||
/*!
|
||||
\qmlmethod int ObjectCreationGrid::openEditorDialog(var obj)
|
||||
Opens the editor dialog for an object \c obj.
|
||||
*/
|
||||
function openEditorDialog(obj) {
|
||||
// Open editor
|
||||
objectEditor.obj = obj
|
||||
objectEditor.objType = obj.type
|
||||
objectEditor.objIndex = Modules.Objects.currentObjects[obj.type].indexOf(obj)
|
||||
objectEditor.open()
|
||||
// Disconnect potential link
|
||||
posPicker.picked.disconnect(openEditorDialog)
|
||||
}
|
||||
|
||||
Label {
|
||||
id: createTitle
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: qsTr('+ Create new:')
|
||||
font.pixelSize: 20
|
||||
}
|
||||
|
||||
Grid {
|
||||
width: parent.width
|
||||
columns: 3
|
||||
Repeater {
|
||||
model: Object.keys(Modules.Objects.types)
|
||||
|
||||
Button {
|
||||
id: createBtn
|
||||
width: 96
|
||||
visible: Modules.Objects.types[modelData].createable()
|
||||
height: visible ? width*0.8 : 0
|
||||
// The KDE SDK is kinda buggy, so it respects neither specified color nor display propreties.
|
||||
//display: AbstractButton.TextUnderIcon
|
||||
|
||||
Setting.Icon {
|
||||
id: icon
|
||||
width: 24
|
||||
height: 24
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: (parent.width-width)/2
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: (label.y-height)/2
|
||||
|
||||
color: sysPalette.windowText
|
||||
source: '../icons/objects/'+modelData+'.svg'
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 5
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 4
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 4
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font.pixelSize: 14
|
||||
text: Modules.Objects.types[modelData].displayType()
|
||||
wrapMode: Text.WordWrap
|
||||
clip: true
|
||||
}
|
||||
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.delay: 200
|
||||
ToolTip.text: label.text
|
||||
|
||||
onClicked: {
|
||||
let newObj = Modules.Objects.createNewRegisteredObject(modelData)
|
||||
history.addToHistory(new JS.HistoryLib.CreateNewObject(newObj.name, modelData, newObj.export()))
|
||||
objectLists.update()
|
||||
|
||||
let hasXProp = newObj.constructor.properties().hasOwnProperty('x')
|
||||
let hasYProp = newObj.constructor.properties().hasOwnProperty('y')
|
||||
if(hasXProp || hasYProp) {
|
||||
// Open picker
|
||||
posPicker.objType = newObj.type
|
||||
posPicker.objName = newObj.name
|
||||
posPicker.pickX = hasXProp
|
||||
posPicker.pickY = hasYProp
|
||||
posPicker.propertyX = 'x'
|
||||
posPicker.propertyY = 'y'
|
||||
posPicker.visible = true
|
||||
posPicker.picked.connect(openEditorDialog)
|
||||
} else {
|
||||
// Open editor
|
||||
openEditorDialog(newObj)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,147 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
// import QtQuick.Dialogs 1.3 as D
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import eu.ad5001.LogarithmPlotter.ObjectLists.Editor 1.0 as Editor
|
||||
|
||||
/*!
|
||||
\qmltype ObjectLists
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists
|
||||
\brief Tab of the drawer that allows the user to manage the objects.
|
||||
|
||||
This item allows the user to synthetically see all objects, while giving the user the ability
|
||||
to show, hide, delete, change the location and color, as well as opening the editor dialog
|
||||
for each object.
|
||||
|
||||
\sa LogarithmPlotter, ObjectCreationGrid, ObjectLists
|
||||
*/
|
||||
ScrollView {
|
||||
id: objectListList
|
||||
|
||||
signal changed()
|
||||
|
||||
property var listViews: {'':''} // Needs to be initialized or will be undefined -_-
|
||||
|
||||
|
||||
ScrollBar.horizontal.visible: false
|
||||
ScrollBar.vertical.visible: true
|
||||
|
||||
ListView {
|
||||
id: objectsListView
|
||||
model: Object.keys(Modules.Objects.types)
|
||||
//width: implicitWidth //objectListList.width - (implicitHeight > objectListList.parent.height ? 20 : 0)
|
||||
implicitHeight: contentItem.childrenRect.height + footerItem.height + 10
|
||||
|
||||
delegate: ListView {
|
||||
id: objTypeList
|
||||
property string objType: objectsListView.model[index]
|
||||
property var editingRows: []
|
||||
model: Modules.Objects.currentObjects[objType]
|
||||
width: objectsListView.width
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
visible: model != undefined && model.length > 0
|
||||
interactive: false
|
||||
|
||||
Component.onCompleted: objectListList.listViews[objType] = objTypeList // Listing in order to be refreshed
|
||||
|
||||
header: Row {
|
||||
width: typeHeaderText.width + typeVisibilityCheckBox.visible
|
||||
height: visible ? 20 : 0
|
||||
visible: objTypeList.visible
|
||||
|
||||
CheckBox {
|
||||
id: typeVisibilityCheckBox
|
||||
checked: Modules.Objects.currentObjects[objType] != undefined ? Modules.Objects.currentObjects[objType].every(obj => obj.visible) : true
|
||||
onClicked: {
|
||||
for(var obj of Modules.Objects.currentObjects[objType]) obj.visible = this.checked
|
||||
for(var obj of objTypeList.editingRows) obj.objVisible = this.checked
|
||||
objectListList.changed()
|
||||
}
|
||||
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: checked ?
|
||||
qsTr("Hide all %1").arg(Modules.Objects.types[objType].displayTypeMultiple()) :
|
||||
qsTr("Show all %1").arg(Modules.Objects.types[objType].displayTypeMultiple())
|
||||
}
|
||||
|
||||
Label {
|
||||
id: typeHeaderText
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: qsTranslate("control", "%1: ").arg(Modules.Objects.types[objType].displayTypeMultiple())
|
||||
font.pixelSize: 20
|
||||
}
|
||||
}
|
||||
|
||||
delegate: ObjectRow {
|
||||
id: controlRow
|
||||
width: objTypeList.width
|
||||
obj: Modules.Objects.currentObjects[objType][index]
|
||||
posPicker: positionPicker
|
||||
|
||||
onChanged: {
|
||||
obj = Modules.Objects.currentObjects[objType][index]
|
||||
objectListList.update()
|
||||
}
|
||||
|
||||
Component.onCompleted: objTypeList.editingRows.push(controlRow)
|
||||
}
|
||||
}
|
||||
|
||||
// Create items
|
||||
footer: ObjectCreationGrid {
|
||||
id: createRow
|
||||
width: objectsListView.width
|
||||
objectEditor: objEditor
|
||||
objectLists: objectListList
|
||||
posPicker: positionPicker
|
||||
}
|
||||
}
|
||||
|
||||
// Object editor
|
||||
Editor.Dialog {
|
||||
id: objEditor
|
||||
|
||||
posPicker: positionPicker
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void ObjectLists::update()
|
||||
Updates the view of the ObjectLists.
|
||||
*/
|
||||
function update() {
|
||||
objectListList.changed()
|
||||
for(var objType in objectListList.listViews) {
|
||||
objectListList.listViews[objType].model = Modules.Objects.currentObjects[objType]
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void ObjectLists::paramTypeIn(var parameter, var types)
|
||||
Checks if the type of the provided \c parameter is in \c types.
|
||||
\note The type can be normal string types ('boolean', 'string', 'number'...) or object types (Enum, Dictionay, Object types...). If the latter, only the type of object type should be provided in \c types. E.g: if you want to check if the parameter is an enum, add "Enum" to types.
|
||||
*/
|
||||
function paramTypeIn(parameter, types = []) {
|
||||
if(types.includes(parameter.toString())) return true
|
||||
if(typeof parameter == 'object' && 'type' in parameter)
|
||||
return types.includes(parameter.type)
|
||||
return false
|
||||
}
|
||||
}
|
|
@ -0,0 +1,240 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Dialogs
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Window
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import "../js/index.mjs" as JS
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype ObjectRow
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.ObjectLists
|
||||
\brief Row describing an object.
|
||||
|
||||
This item allows the user to see, control, and modify a graph object.
|
||||
It includes the visibility checkbox, the description label (optionally latex if enabled),
|
||||
the reposition and delete buttons, and the color picker.
|
||||
|
||||
\sa LogarithmPlotter, ObjectCreationGrid, ObjectLists
|
||||
*/
|
||||
Item {
|
||||
id: objectRow
|
||||
|
||||
signal changed()
|
||||
|
||||
/*!
|
||||
\qmlproperty var ObjectRow::obj
|
||||
Object to show.
|
||||
*/
|
||||
property var obj
|
||||
/*!
|
||||
\qmlproperty var ObjectRow::posPicker
|
||||
Reference to the global PositionPicker QML object.
|
||||
*/
|
||||
property var posPicker
|
||||
|
||||
/*!
|
||||
\qmlproperty bool ObjectRow::objVisible
|
||||
True if the object should be visible, false otherwise.
|
||||
*/
|
||||
property alias objVisible: objVisibilityCheckBox.checked
|
||||
/*!
|
||||
\qmlproperty bool ObjectRow::minHeight
|
||||
Minimum height of the row.
|
||||
*/
|
||||
readonly property int minHeight: 40
|
||||
|
||||
height: objDescription.height
|
||||
width: obj.typeList.width
|
||||
|
||||
CheckBox {
|
||||
id: objVisibilityCheckBox
|
||||
checked: obj.visible
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 5
|
||||
onClicked: {
|
||||
history.addToHistory(new JS.HistoryLib.EditedVisibility(
|
||||
obj.name, obj.type, this.checked
|
||||
))
|
||||
obj.visible = this.checked
|
||||
changed()
|
||||
}
|
||||
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: checked ?
|
||||
qsTr("Hide %1 %2").arg(obj.constructor.displayType()).arg(obj.name) :
|
||||
qsTr("Show %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
|
||||
}
|
||||
|
||||
Label {
|
||||
id: objDescription
|
||||
anchors.left: objVisibilityCheckBox.right
|
||||
anchors.right: deleteButton.left
|
||||
height: Modules.Latex.enabled ? Math.max(parent.minHeight, latexDescription.height+4) : parent.minHeight
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: Modules.Latex.enabled ? "" : obj.getReadableString()
|
||||
font.pixelSize: 14
|
||||
|
||||
Image {
|
||||
id: latexDescription
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
visible: Modules.Latex.enabled
|
||||
property double depth: Screen.devicePixelRatio
|
||||
source: ""
|
||||
width: 0/depth
|
||||
height: 0/depth
|
||||
|
||||
Component.onCompleted: function() {
|
||||
if(Modules.Latex.enabled) {
|
||||
const args = [obj.getLatexString(), depth*(parent.font.pixelSize+2), parent.color]
|
||||
const prerendered = Modules.Latex.findPrerendered(...args)
|
||||
if(prerendered !== null) {
|
||||
source = prerendered.source
|
||||
width = prerendered.width/depth
|
||||
height = prerendered.height/depth
|
||||
} else
|
||||
Modules.Latex.requestAsyncRender(...args).then(info => {
|
||||
source = info.source
|
||||
width = info.width/depth
|
||||
height = info.height/depth
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: {
|
||||
objEditor.obj = Modules.Objects.currentObjects[obj.type][index]
|
||||
objEditor.objType = obj.type
|
||||
objEditor.objIndex = index
|
||||
//objEditor.editingRow = objectRow
|
||||
objEditor.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: pointerButton
|
||||
width: parent.height - 10
|
||||
height: width
|
||||
anchors.right: deleteButton.left
|
||||
anchors.rightMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
|
||||
Setting.Icon {
|
||||
id: icon
|
||||
width: 18
|
||||
height: 18
|
||||
anchors.centerIn: parent
|
||||
|
||||
color: sysPalette.windowText
|
||||
source: '../icons/common/position.svg'
|
||||
}
|
||||
|
||||
property bool hasXProp: obj.constructor.properties().hasOwnProperty('x')
|
||||
property bool hasYProp: obj.constructor.properties().hasOwnProperty('y')
|
||||
visible: hasXProp || hasYProp
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Set %1 %2 position").arg(obj.constructor.displayType()).arg(obj.name)
|
||||
|
||||
onClicked: {
|
||||
posPicker.objType = obj.type
|
||||
posPicker.objName = obj.name
|
||||
posPicker.pickX = hasXProp
|
||||
posPicker.pickY = hasYProp
|
||||
posPicker.propertyX = 'x'
|
||||
posPicker.propertyY = 'y'
|
||||
posPicker.visible = true
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: deleteButton
|
||||
width: parent.minHeight - 10
|
||||
height: width
|
||||
anchors.right: colorPickRect.left
|
||||
anchors.rightMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
icon.name: 'delete'
|
||||
icon.source: '../icons/common/delete.svg'
|
||||
icon.color: sysPalette.buttonText
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.text: qsTr("Delete %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
|
||||
|
||||
onClicked: {
|
||||
deleteRecursively(obj)
|
||||
changed()
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: colorPickRect
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: obj.color
|
||||
width: parent.minHeight - 10
|
||||
height: width
|
||||
radius: Math.min(width, height)
|
||||
border.width: 2
|
||||
border.color: sysPalette.windowText
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: pickColor.open()
|
||||
}
|
||||
}
|
||||
|
||||
ColorDialog {
|
||||
id: pickColor
|
||||
selectedColor: obj.color
|
||||
title: qsTr("Pick new color for %1 %2").arg(obj.constructor.displayType()).arg(obj.name)
|
||||
onAccepted: {
|
||||
history.addToHistory(new JS.HistoryLib.ColorChanged(
|
||||
obj.name, obj.type, obj.color, selectedColor.toString()
|
||||
))
|
||||
obj.color = selectedColor.toString()
|
||||
changed()
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void ObjectRow::deleteRecursively(var object)
|
||||
Deletes an object and it's dependencies recursively.
|
||||
*/
|
||||
function deleteRecursively(object) {
|
||||
for(let toRemove of object.requiredBy)
|
||||
deleteRecursively(toRemove)
|
||||
if(Modules.Objects.currentObjectsByName[object.name] != undefined) {
|
||||
// Object still exists
|
||||
// Temporary fix for objects require not being propertly updated.
|
||||
object.requiredBy = []
|
||||
history.addToHistory(new JS.HistoryLib.DeleteObject(
|
||||
object.name, object.type, object.export()
|
||||
))
|
||||
Modules.Objects.deleteObject(object.name)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
module eu.ad5001.LogarithmPlotter.ObjectLists
|
||||
|
||||
ObjectLists 1.0 ObjectLists.qml
|
||||
ObjectCreationGrid 1.0 ObjectCreationGrid.qml
|
||||
ObjectRow 1.0 ObjectRow.qml
|
|
@ -0,0 +1,331 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import "js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype PickLocationOverlay
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief Overlay used to pick a new location for an object.
|
||||
|
||||
Provides an overlay over the canvas that can be shown when the user clicks the "Set position" button
|
||||
on a specific object. It allows the user to pick a new location on the canvas to place the object at.
|
||||
This overlay allows to set the precision of the pick as well as whether the pick should be on the plot grid.
|
||||
|
||||
\sa LogarithmPlotter, LogGraphCanvas
|
||||
*/
|
||||
Item {
|
||||
id: pickerRoot
|
||||
visible: false
|
||||
clip: true
|
||||
|
||||
/*!
|
||||
\qmlsignal PickLocationOverlay::picked(var obj)
|
||||
|
||||
Emitted when a location has been picked
|
||||
The corresponding handler is \c onPicked.
|
||||
*/
|
||||
signal picked(var obj)
|
||||
|
||||
/*!
|
||||
\qmlproperty var PickLocationOverlay::canvas
|
||||
logGraphCanvas instance.
|
||||
*/
|
||||
property var canvas
|
||||
/*!
|
||||
\qmlproperty string PickLocationOverlay::objType
|
||||
Type of object whose position the user is picking.
|
||||
*/
|
||||
property string objType: 'Point'
|
||||
/*!
|
||||
\qmlproperty string PickLocationOverlay::objType
|
||||
Name of the object whose position the user is picking.
|
||||
*/
|
||||
property string objName: 'A'
|
||||
/*!
|
||||
\qmlproperty bool PickLocationOverlay::pickX
|
||||
true if the property in propertyX is pickable.
|
||||
*/
|
||||
property bool pickX: true
|
||||
/*!
|
||||
\qmlproperty bool PickLocationOverlay::pickY
|
||||
true if the property in propertyY is pickable.
|
||||
*/
|
||||
property bool pickY: true
|
||||
/*!
|
||||
\qmlproperty string PickLocationOverlay::propertyX
|
||||
Name of the object's property whose x value is being changed.
|
||||
*/
|
||||
property string propertyX: 'x'
|
||||
/*!
|
||||
\qmlproperty string PickLocationOverlay::propertyY
|
||||
Name of the object's property whose y value is being changed.
|
||||
*/
|
||||
property string propertyY: 'y'
|
||||
/*!
|
||||
\qmlproperty int PickLocationOverlay::precision
|
||||
Precision of the picked value (post-dot precision).
|
||||
*/
|
||||
property alias precision: precisionSlider.value
|
||||
/*!
|
||||
\qmlproperty bool PickLocationOverlay::userPickX
|
||||
true if the user can and wants to be picking a position on the x axis.
|
||||
*/
|
||||
readonly property bool userPickX: pickX && pickXCheckbox.checked
|
||||
/*!
|
||||
\qmlproperty bool PickLocationOverlay::userPickY
|
||||
true if the user can and wants to be picking a position on the y axis.
|
||||
*/
|
||||
readonly property bool userPickY: pickY && pickYCheckbox.checked
|
||||
|
||||
Rectangle {
|
||||
color: sysPalette.window
|
||||
opacity: 0.35
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: picker
|
||||
anchors.fill: parent
|
||||
hoverEnabled: parent.visible
|
||||
cursorShape: Qt.CrossCursor
|
||||
acceptedButtons: Qt.LeftButton | Qt.RightButton
|
||||
onClicked: function(mouse) {
|
||||
if(mouse.button == Qt.LeftButton) { // Validate
|
||||
let newValueX = !parent.userPickX ? null : parseValue(picked.mouseX.toString(), objType, propertyX)
|
||||
let newValueY = !parent.userPickY ? null : parseValue(picked.mouseY.toString(), objType, propertyY)
|
||||
let obj = Modules.Objects.currentObjectsByName[objName]
|
||||
// Set values
|
||||
if(parent.userPickX && parent.userPickY) {
|
||||
history.addToHistory(new JS.HistoryLib.EditedPosition(
|
||||
objName, objType, obj[propertyX], newValueX, obj[propertyY], newValueY
|
||||
))
|
||||
obj[propertyX] = newValueX
|
||||
obj[propertyY] = newValueY
|
||||
obj.update()
|
||||
objectLists.update()
|
||||
pickerRoot.picked(obj)
|
||||
} else if(parent.userPickX) {
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
objName, objType, propertyX, obj[propertyX], newValueX
|
||||
))
|
||||
obj[propertyX] = newValueX
|
||||
obj.update()
|
||||
objectLists.update()
|
||||
pickerRoot.picked(obj)
|
||||
} else if(parent.userPickY) {
|
||||
history.addToHistory(new JS.HistoryLib.EditedProperty(
|
||||
objName, objType, propertyY, obj[propertyY], newValueY
|
||||
))
|
||||
obj[propertyY] = newValueY
|
||||
obj.update()
|
||||
objectLists.update()
|
||||
pickerRoot.picked(obj)
|
||||
}
|
||||
}
|
||||
pickerRoot.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Rectangle {
|
||||
id: pickerSettings
|
||||
radius: 15
|
||||
color: sysPalette.window
|
||||
width: pickerSettingsColumn.width + 30;
|
||||
height: pickerSettingsColumn.height + 20
|
||||
property bool folded: false;
|
||||
x: -15 - ((width-55) * folded);
|
||||
y: 10
|
||||
z: 2
|
||||
|
||||
Row {
|
||||
id: pickerSettingsColumn
|
||||
anchors {
|
||||
left: parent.left
|
||||
top: parent.top
|
||||
leftMargin: 20
|
||||
topMargin: 10
|
||||
}
|
||||
spacing: 15
|
||||
property int cellHeight: 15
|
||||
|
||||
Column {
|
||||
spacing: 5
|
||||
// width: 100
|
||||
|
||||
Text {
|
||||
text: qsTr("Pointer precision:")
|
||||
color: sysPalette.windowText
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
}
|
||||
|
||||
Text {
|
||||
text: qsTr("Snap to grid:")
|
||||
color: sysPalette.windowText
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: pickXCheckbox
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
text: qsTr("Pick X")
|
||||
checked: pickX
|
||||
visible: pickX
|
||||
}
|
||||
}
|
||||
|
||||
Column {
|
||||
spacing: 5
|
||||
|
||||
Slider {
|
||||
id: precisionSlider
|
||||
from: 0
|
||||
value: 2
|
||||
to: 10
|
||||
stepSize: 1
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
|
||||
ToolTip {
|
||||
parent: precisionSlider.handle
|
||||
visible: precisionSlider.pressed
|
||||
text: precisionSlider.value.toFixed(0)
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: snapToGridCheckbox
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
// text: qsTr("Snap to grid")
|
||||
checked: false
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: pickYCheckbox
|
||||
height: pickerSettingsColumn.cellHeight
|
||||
text: qsTr("Pick Y")
|
||||
checked: pickY
|
||||
visible: pickY
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
width: 24
|
||||
anchors.top: parent.top
|
||||
anchors.bottom: parent.bottom
|
||||
flat: true
|
||||
|
||||
onClicked: pickerSettings.folded = !pickerSettings.folded
|
||||
|
||||
ToolTip.visible: hovered
|
||||
ToolTip.delay: 200
|
||||
ToolTip.text: pickerSettings.folded ? qsTr("Open picker settings") : qsTr("Hide picker settings")
|
||||
|
||||
Setting.Icon {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
width: 18
|
||||
height: 18
|
||||
color: sysPalette.windowText
|
||||
source: `../icons/common/settings.svg`
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: xCursor
|
||||
width: 1
|
||||
height: parent.height
|
||||
color: 'black'
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: Modules.Canvas.x2px(picked.mouseX)
|
||||
visible: parent.userPickX
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: yCursor
|
||||
width: parent.width
|
||||
height: 1
|
||||
color: 'black'
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
anchors.topMargin: Modules.Canvas.y2px(picked.mouseY)
|
||||
visible: parent.userPickY
|
||||
}
|
||||
|
||||
Text {
|
||||
id: picked
|
||||
x: picker.mouseX - width - 5
|
||||
y: picker.mouseY - height - 5
|
||||
color: 'black'
|
||||
property double mouseX: {
|
||||
const axisX = Modules.Canvas.axesSteps.x.value
|
||||
const xpos = Modules.Canvas.px2x(picker.mouseX)
|
||||
if(snapToGridCheckbox.checked) {
|
||||
if(canvas.logscalex) {
|
||||
// Calculate the logged power
|
||||
let pow = Math.pow(10, Math.floor(Math.log10(xpos)))
|
||||
return pow*Math.round(xpos/pow)
|
||||
} else {
|
||||
return axisX*Math.round(xpos/axisX)
|
||||
}
|
||||
} else {
|
||||
return xpos.toFixed(parent.precision)
|
||||
}
|
||||
}
|
||||
property double mouseY: {
|
||||
const axisY = Modules.Canvas.axesSteps.y.value
|
||||
const ypos = Modules.Canvas.px2y(picker.mouseY)
|
||||
if(snapToGridCheckbox.checked) {
|
||||
return axisY*Math.round(ypos/axisY)
|
||||
} else {
|
||||
return ypos.toFixed(parent.precision)
|
||||
}
|
||||
}
|
||||
text: {
|
||||
if(parent.userPickX && parent.userPickY)
|
||||
return `(${mouseX}, ${mouseY})`
|
||||
else if(parent.userPickX)
|
||||
return `X = ${mouseX}`
|
||||
else if(parent.userPickY)
|
||||
return `Y = ${mouseY}`
|
||||
else
|
||||
return qsTr('(no pick selected)')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\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) {
|
||||
if(Modules.Objects.types[objType].properties()[propertyName] == 'number')
|
||||
return parseFloat(value)
|
||||
else
|
||||
return new JS.MathLib.Expression(value)
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype About
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief About popup of LogarithmPlotter.
|
||||
|
||||
\sa LogarithmPlotter
|
||||
*/
|
||||
BaseDialog {
|
||||
id: about
|
||||
title: qsTr("About LogarithmPlotter")
|
||||
width: 400
|
||||
minimumHeight: 600
|
||||
|
||||
Item {
|
||||
anchors {
|
||||
top: parent.top;
|
||||
left: parent.left;
|
||||
bottom: parent.bottom;
|
||||
right: parent.right;
|
||||
topMargin: margin;
|
||||
leftMargin: margin;
|
||||
bottomMargin: margin;
|
||||
rightMargin: margin;
|
||||
}
|
||||
|
||||
Image {
|
||||
id: logo
|
||||
source: "../icons/logarithmplotter.svg"
|
||||
sourceSize.width: 64
|
||||
sourceSize.height: 64
|
||||
width: 64
|
||||
height: 64
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.rightMargin: width/2
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 10
|
||||
}
|
||||
|
||||
Label {
|
||||
id: appName
|
||||
anchors.top: logo.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.topMargin: 10
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 25
|
||||
text: qsTr("LogarithmPlotter v%1").arg(Helper.getVersion())
|
||||
}
|
||||
|
||||
Label {
|
||||
id: description
|
||||
anchors.top: appName.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.topMargin: 10
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 18
|
||||
text: qsTr("2D plotter software to make BODE plots, sequences and repartition functions.")
|
||||
}
|
||||
|
||||
Label {
|
||||
id: debugInfos
|
||||
anchors.top: description.bottom
|
||||
anchors.left: parent.left
|
||||
anchors.topMargin: 10
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
width: parent.width
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 14
|
||||
text: Helper.getDebugInfos()
|
||||
}
|
||||
|
||||
Label {
|
||||
id: copyrightInfos
|
||||
anchors.top: debugInfos.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.topMargin: 10
|
||||
width: Math.min(410, parent.width)
|
||||
wrapMode: Text.WordWrap
|
||||
textFormat: Text.RichText
|
||||
font.pixelSize: 13
|
||||
text: "Copyright © 2021-2024 Ad5001 <mail@ad5001.eu><br>
|
||||
<br>
|
||||
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.<br>
|
||||
<br>
|
||||
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.<br>
|
||||
<br>
|
||||
You should have received a copy of the GNU General Public License along with this program. If not, see <a href='http://www.gnu.org/licenses/'>http://www.gnu.org/licenses/</a>."
|
||||
onLinkActivated: Qt.openUrlExternally(link)
|
||||
}
|
||||
|
||||
Row {
|
||||
id: buttonsRow
|
||||
anchors.top: copyrightInfos.bottom
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.topMargin: 10
|
||||
spacing: 5
|
||||
|
||||
Button {
|
||||
id: openIssueButton
|
||||
text: qsTr('Report a bug')
|
||||
icon.name: 'tools-report-bug'
|
||||
onClicked: Qt.openUrlExternally('https://git.ad5001.eu/Ad5001/LogarithmPlotter')
|
||||
}
|
||||
|
||||
Button {
|
||||
id: officialWebsiteButton
|
||||
text: qsTr('Official website')
|
||||
icon.name: 'web-browser'
|
||||
onClicked: Qt.openUrlExternally('https://apps.ad5001.eu/logarithmplotter/')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,98 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
/*!
|
||||
\qmltype Alert
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Alert used to show status messages to the user.
|
||||
|
||||
This class (only one instance) allows messages to be displayed to the user that will fade in time.
|
||||
|
||||
\sa LogarithmPlotter
|
||||
*/
|
||||
Rectangle {
|
||||
id: alert
|
||||
color: "black"
|
||||
radius: 5
|
||||
x: fadingAnimation.running ? fadingX : parent.width - width - 10
|
||||
visible: false;
|
||||
width: textItem.width + 10
|
||||
height: textItem.height + 10
|
||||
|
||||
/*!
|
||||
\qmlproperty int Alert::fadingX
|
||||
X of the object that is being animated.
|
||||
*/
|
||||
property int fadingX: parent.width - width - 10
|
||||
/*!
|
||||
\qmlproperty int Alert::fadeTime
|
||||
Length in millisecond of the animation.
|
||||
*/
|
||||
property int fadeTime: 200
|
||||
/*!
|
||||
\qmlproperty string Alert::text
|
||||
Text of the alert.
|
||||
*/
|
||||
property alias text: textItem.text
|
||||
|
||||
Text {
|
||||
id: textItem
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
color: "white"
|
||||
font.pixelSize: 18
|
||||
}
|
||||
|
||||
|
||||
ParallelAnimation {
|
||||
id: fadingAnimation
|
||||
running: false
|
||||
NumberAnimation { target: alert; property: "fadingX"; to: alert.parent.width; duration: alert.fadeTime }
|
||||
NumberAnimation { target: alert; property: "opacity"; to: 0; duration: alert.fadeTime }
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: fadeTimer
|
||||
interval: 1000 + text.length * 45
|
||||
onTriggered: {
|
||||
hideTimer.start()
|
||||
fadingAnimation.start()
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: hideTimer
|
||||
interval: alert.fadeTime
|
||||
onTriggered: {
|
||||
alert.visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void Alert::show(string alertText)
|
||||
Show an alert with a certain \c alertText.
|
||||
*/
|
||||
function show(alertText) {
|
||||
visible = true
|
||||
fadeTimer.restart()
|
||||
text = alertText
|
||||
opacity = 0.75
|
||||
fadingX = parent.width - width - 10
|
||||
}
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype BaseDialog
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Base dialog window in replacement of Dialog Popup from Qt 5.
|
||||
|
||||
\sa LogarithmPlotter
|
||||
*/
|
||||
|
||||
Window {
|
||||
id: base
|
||||
color: sysPalette.window
|
||||
visible: false;
|
||||
flags: Qt.Dialog | Qt.Popup | Qt.MSWindowsFixedSizeDialogHint
|
||||
modality: Qt.WindowModal
|
||||
minimumWidth: width
|
||||
maximumWidth: width
|
||||
height: minimumHeight
|
||||
property int margin: 10
|
||||
|
||||
Button {
|
||||
id: closeButton
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.right: parent.right
|
||||
anchors.bottomMargin: margin
|
||||
anchors.rightMargin: margin
|
||||
text: qsTr('Close')
|
||||
onClicked: close()
|
||||
}
|
||||
|
||||
Shortcut {
|
||||
sequence: "Esc"
|
||||
onActivated: base.close()
|
||||
}
|
||||
|
||||
function open() {
|
||||
show()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype Changelog
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Overlay used to display the current changelog to the user.
|
||||
|
||||
\note The changelog is either fetched from https://api.ad5001.eu/changelog/logarithmplotter/ or taken locally when a file named CHANGELOG.md exists within the main source code.
|
||||
|
||||
\sa LogarithmPlotter, GreetScreen
|
||||
*/
|
||||
Popup {
|
||||
id: changelogPopup
|
||||
x: (parent.width-width)/2
|
||||
y: Math.max(20, (parent.height-height)/2)
|
||||
width: 800
|
||||
height: Math.min(parent.height-40, 500)
|
||||
modal: true
|
||||
focus: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
/*!
|
||||
\qmlproperty string Changelog::changelogNeedsFetching
|
||||
true when the changelog has yet to be loaded, set to false the moment it's loaded.
|
||||
*/
|
||||
property bool changelogNeedsFetching: true
|
||||
|
||||
onAboutToShow: if(changelogNeedsFetching) {
|
||||
Helper.fetchChangelog()
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: Helper
|
||||
function onChangelogFetched(chl) {
|
||||
changelogNeedsFetching = false;
|
||||
changelog.text = chl
|
||||
changelogView.contentItem.implicitHeight = changelog.height
|
||||
// console.log(changelog.height, changelogView.contentItem.implicitHeight)
|
||||
}
|
||||
}
|
||||
|
||||
ScrollView {
|
||||
id: changelogView
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 10
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 10
|
||||
anchors.bottom: doneBtn.top
|
||||
anchors.bottomMargin: 10
|
||||
clip: true
|
||||
|
||||
|
||||
Label {
|
||||
id: changelog
|
||||
color: sysPalette.windowText
|
||||
width: 760
|
||||
wrapMode: Text.WordWrap
|
||||
textFormat: TextEdit.MarkdownText
|
||||
|
||||
text: qsTr("Fetching changelog...")
|
||||
onLinkActivated: Qt.openUrlExternally(link)
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: bottomSeparator
|
||||
opacity: 0.3
|
||||
color: sysPalette.windowText
|
||||
width: parent.width * 2 / 3
|
||||
height: 1
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.bottom: doneBtn.top
|
||||
anchors.bottomMargin: 7
|
||||
}
|
||||
|
||||
Button {
|
||||
id: doneBtn
|
||||
text: qsTr("Close")
|
||||
font.pixelSize: 18
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 7
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
onClicked: changelogPopup.close()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import Qt.labs.platform
|
||||
|
||||
/*!
|
||||
\qmltype FileDialog
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Dialog used to prompt the user to save or load Logarithm Plot Files.
|
||||
|
||||
\sa LogarithmPlotter, Settings
|
||||
*/
|
||||
FileDialog {
|
||||
id: fileDialog
|
||||
|
||||
property bool exportMode: false
|
||||
|
||||
title: exportMode ? qsTr("Export Logarithm Plot file") : qsTr("Import Logarithm Plot file")
|
||||
nameFilters: ["Logarithm Plot File (*.lpf)", "All files (*)"]
|
||||
|
||||
defaultSuffix: 'lpf'
|
||||
fileMode: exportMode ? FileDialog.SaveFile : FileDialog.OpenFile
|
||||
}
|
|
@ -0,0 +1,156 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
|
||||
/*!
|
||||
\qmltype GreetScreen
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Overlay displayed when LogarithmPlotter is launched for the first time or when it was just updated.
|
||||
|
||||
It contains several settings as well as an easy access to the changelog
|
||||
|
||||
\sa LogarithmPlotter, Settings, AppMenuBar, Changelog
|
||||
*/
|
||||
Popup {
|
||||
id: greetingPopup
|
||||
x: (parent.width-width)/2
|
||||
y: Math.max(20, (parent.height-height)/2)
|
||||
width: greetingLayout.width+20
|
||||
height: Math.min(parent.height-40, 700)
|
||||
modal: true
|
||||
focus: true
|
||||
clip: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
Column {
|
||||
id: greetingLayout
|
||||
width: 600
|
||||
spacing: 10
|
||||
clip: true
|
||||
topPadding: 35
|
||||
|
||||
Row {
|
||||
id: welcome
|
||||
height: logo.height
|
||||
spacing: 10
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
Image {
|
||||
id: logo
|
||||
source: "../icons/logarithmplotter.svg"
|
||||
sourceSize.width: 48
|
||||
sourceSize.height: 48
|
||||
width: 48
|
||||
height: 48
|
||||
}
|
||||
|
||||
Label {
|
||||
id: welcomeText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 32
|
||||
text: qsTr("Welcome to LogarithmPlotter")
|
||||
}
|
||||
}
|
||||
|
||||
Label {
|
||||
id: versionText
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
wrapMode: Text.WordWrap
|
||||
width: implicitWidth
|
||||
font.pixelSize: 18
|
||||
font.italic: true
|
||||
text: qsTr("Version %1").arg(Helper.getVersion())
|
||||
}
|
||||
}
|
||||
|
||||
Grid {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: greetingLayout.bottom
|
||||
anchors.topMargin: 50
|
||||
columns: 2
|
||||
spacing: 10
|
||||
|
||||
Repeater {
|
||||
model: [{
|
||||
name: qsTr("Changelog"),
|
||||
icon: 'common/new.svg',
|
||||
onClicked: () => changelog.open()
|
||||
},{
|
||||
name: qsTr("Preferences"),
|
||||
icon: 'common/settings.svg',
|
||||
onClicked: () => preferences.open()
|
||||
},{
|
||||
name: qsTr("User manual"),
|
||||
icon: 'common/manual.svg',
|
||||
onClicked: () => Qt.openUrlExternally("https://git.ad5001.eu/Ad5001/LogarithmPlotter/wiki/_Sidebar")
|
||||
},{
|
||||
name: qsTr("Close"),
|
||||
icon: 'common/close.svg',
|
||||
onClicked: () => greetingPopup.close()
|
||||
}]
|
||||
|
||||
Button {
|
||||
id: createBtn
|
||||
width: 96
|
||||
height: 96
|
||||
onClicked: modelData.onClicked()
|
||||
|
||||
Setting.Icon {
|
||||
id: icon
|
||||
width: 24
|
||||
height: 24
|
||||
anchors {
|
||||
left: parent.left
|
||||
leftMargin: (parent.width-width)/2
|
||||
top: parent.top
|
||||
topMargin: (label.y-height)/2
|
||||
}
|
||||
color: sysPalette.windowText
|
||||
source: '../icons/' + modelData.icon
|
||||
}
|
||||
|
||||
Label {
|
||||
id: label
|
||||
anchors {
|
||||
bottom: parent.bottom
|
||||
bottomMargin: 5
|
||||
left: parent.left
|
||||
leftMargin: 4
|
||||
right: parent.right
|
||||
rightMargin: 4
|
||||
}
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
font.pixelSize: 14
|
||||
text: modelData.name
|
||||
wrapMode: Text.WordWrap
|
||||
clip: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: if(Helper.getSetting("last_install_greet") != Helper.getVersion()+1) {
|
||||
greetingPopup.open()
|
||||
}
|
||||
|
||||
onClosed: Helper.setSetting("last_install_greet", Helper.getVersion())
|
||||
}
|
|
@ -0,0 +1,106 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick.Controls
|
||||
import QtQuick
|
||||
|
||||
/*!
|
||||
\qmltype InsertCharacter
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Popup to insert special character.
|
||||
|
||||
\sa TextSetting, ExpressionEditor
|
||||
*/
|
||||
Popup {
|
||||
id: insertPopup
|
||||
|
||||
signal selected(string character)
|
||||
|
||||
/*!
|
||||
\qmlproperty string InsertCharacter::category
|
||||
Type of special character to insert.
|
||||
Possible values:
|
||||
- expression
|
||||
- domain
|
||||
- name
|
||||
- all
|
||||
*/
|
||||
property string category: 'all'
|
||||
|
||||
width: 280
|
||||
height: Math.ceil(insertGrid.insertChars.length/insertGrid.columns)*(width/insertGrid.columns)+5
|
||||
modal: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutsideParent
|
||||
|
||||
Grid {
|
||||
id: insertGrid
|
||||
width: parent.width
|
||||
columns: 7
|
||||
|
||||
property var insertCharsExpression: [
|
||||
"∞","π","¹","²","³","⁴","⁵",
|
||||
"⁶","⁷","⁸","⁹","⁰"
|
||||
]
|
||||
|
||||
property var insertCharsDomain: [
|
||||
"∅","∪","∩","∖","ℝ","ℕ","ℤ",
|
||||
"⁺","⁻",...insertCharsExpression
|
||||
]
|
||||
|
||||
property var insertCharsName: [
|
||||
"α","β","γ","δ","ε","ζ","η",
|
||||
"π","θ","κ","λ","μ","ξ","ρ",
|
||||
"ς","σ","τ","φ","χ","ψ","ω",
|
||||
"Γ","Δ","Θ","Λ","Ξ","Π","Σ",
|
||||
"Φ","Ψ","Ω","ₐ","ₑ","ₒ","ₓ",
|
||||
"ₕ","ₖ","ₗ","ₘ","ₙ","ₚ","ₛ",
|
||||
"ₜ","₁","₂","₃","₄","₅","₆",
|
||||
"₇","₈","₉","₀"
|
||||
]
|
||||
|
||||
property var insertCharsAll: [
|
||||
...insertCharsName, ...insertCharsDomain
|
||||
]
|
||||
|
||||
property var insertChars: {
|
||||
return {
|
||||
"expression": insertCharsExpression,
|
||||
"domain": insertCharsDomain,
|
||||
"name": insertCharsName,
|
||||
"all": insertCharsAll
|
||||
}[insertPopup.category]
|
||||
}
|
||||
|
||||
Repeater {
|
||||
model: parent.insertChars.length
|
||||
|
||||
Button {
|
||||
id: insertBtn
|
||||
width: insertGrid.width/insertGrid.columns
|
||||
height: width
|
||||
text: insertGrid.insertChars[modelData]
|
||||
flat: text == " "
|
||||
font.pixelSize: 18
|
||||
|
||||
onClicked: {
|
||||
selected(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,255 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQuick.Layouts
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import "../js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype Preferences
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Popup to change global application preferences.
|
||||
|
||||
\sa LogarithmPlotter, GreetScreen
|
||||
*/
|
||||
Popup {
|
||||
id: preferencesPopup
|
||||
x: (parent.width-width)/2
|
||||
y: Math.max(20, (parent.height-height)/2)
|
||||
width: settingPopupRow.width + 30
|
||||
height: settingPopupRow.height + 20
|
||||
modal: true
|
||||
focus: true
|
||||
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
|
||||
|
||||
// Components for the preferences
|
||||
Component {
|
||||
id: boolSettingComponent
|
||||
|
||||
CheckBox {
|
||||
height: 20
|
||||
text: setting.name
|
||||
checked: setting.value()
|
||||
onClicked: setting.set(this.checked)
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: enumIntSettingComponent
|
||||
|
||||
// Setting when selecting data from an enum, or an object of a certain type.
|
||||
Setting.ComboBoxSetting {
|
||||
height: 30
|
||||
label: setting.name
|
||||
icon: `settings/${setting.icon}.svg`
|
||||
currentIndex: setting.value()
|
||||
model: setting.values
|
||||
onActivated: function(newIndex) { setting.set(newIndex) }
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: stringSettingComponent
|
||||
|
||||
Setting.ComboBoxSetting {
|
||||
height: 30
|
||||
label: setting.name
|
||||
icon: `settings/${setting.icon}.svg`
|
||||
editable: true
|
||||
currentIndex: find(setting.value())
|
||||
model: setting.defaultValues
|
||||
onAccepted: function() {
|
||||
editText = JS.Utils.parseName(editText, false)
|
||||
if(find(editText) === -1) model.append(editText)
|
||||
setting.set(editText)
|
||||
}
|
||||
onActivated: function(selectedId) {
|
||||
setting.set(model[selectedId])
|
||||
}
|
||||
Component.onCompleted: editText = setting.value()
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: numberSettingComponent
|
||||
|
||||
Setting.TextSetting {
|
||||
height: 30
|
||||
isDouble: true
|
||||
label: setting.name
|
||||
min: setting.min()
|
||||
icon: `settings/${setting.icon}.svg`
|
||||
value: setting.value()
|
||||
onChanged: function(newValue) {
|
||||
if(newValue < setting.max())
|
||||
setting.set(newValue)
|
||||
else {
|
||||
value = setting.max()
|
||||
setting.set(setting.max())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: expressionSettingComponent
|
||||
|
||||
Setting.ExpressionEditor {
|
||||
height: 30
|
||||
label: setting.name
|
||||
icon: `settings/${setting.icon}.svg`
|
||||
defValue: JS.Utils.simplifyExpression(setting.value())
|
||||
variables: setting.variables
|
||||
allowGraphObjects: false
|
||||
property string propertyName: setting.name
|
||||
onChanged: function(newExpr) {
|
||||
try {
|
||||
setting.set(newExpr)
|
||||
} catch(e) {
|
||||
errorDialog.showDialog(propertyName, newExpr, e.message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Row {
|
||||
id: settingPopupRow
|
||||
height: 300
|
||||
width: categories.width + categorySeparator.width + settingView.width + 70
|
||||
spacing: 15
|
||||
|
||||
anchors {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
topMargin: 10
|
||||
bottomMargin: 10
|
||||
rightMargin: 15
|
||||
leftMargin: 15
|
||||
}
|
||||
|
||||
ColumnLayout {
|
||||
id: categories
|
||||
width: 150
|
||||
height: parent.height
|
||||
spacing: 0
|
||||
clip: true
|
||||
|
||||
Repeater {
|
||||
model: Object.keys(Modules.Preferences.categories)
|
||||
|
||||
Button {
|
||||
// width: 150
|
||||
Layout.fillWidth: true
|
||||
text: qsTranslate('settingCategory', modelData)
|
||||
|
||||
onClicked: {
|
||||
settingView.modelName = modelData
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
Layout.fillHeight: true
|
||||
Layout.fillWidth: true
|
||||
|
||||
Button {
|
||||
id: closeButton
|
||||
anchors {
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
bottom: parent.bottom
|
||||
}
|
||||
text: qsTr('Close')
|
||||
onClicked: preferencesPopup.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: categorySeparator
|
||||
anchors {
|
||||
top: parent.top
|
||||
topMargin: 5
|
||||
}
|
||||
opacity: 0.3
|
||||
color: sysPalette.windowText
|
||||
height: parent.height - 10
|
||||
width: 1
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: settingView
|
||||
clip: true
|
||||
width: 500
|
||||
spacing: 10
|
||||
model: Modules.Preferences.categories[modelName]
|
||||
anchors {
|
||||
top: parent.top
|
||||
bottom: parent.bottom
|
||||
}
|
||||
ScrollBar.vertical: ScrollBar { }
|
||||
property string modelName: 'general'
|
||||
|
||||
|
||||
header: Text {
|
||||
id: settingCategoryName
|
||||
font.pixelSize: 32
|
||||
height: 48
|
||||
color: sysPalette.windowText
|
||||
text: qsTranslate('settingCategory', settingView.modelName)
|
||||
|
||||
Rectangle {
|
||||
id: bottomSeparator
|
||||
anchors.bottom: parent.bottom
|
||||
anchors.bottomMargin: 8
|
||||
opacity: 0.3
|
||||
color: sysPalette.windowText
|
||||
width: settingView.width
|
||||
height: 1
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Component {
|
||||
Loader {
|
||||
width: settingView.width - 20
|
||||
property var setting: Modules.Preferences.categories[settingView.modelName][index]
|
||||
sourceComponent: {
|
||||
if(setting.type === "bool")
|
||||
return boolSettingComponent
|
||||
else if(setting.type === "enum")
|
||||
return enumIntSettingComponent
|
||||
else if(setting.type === "number")
|
||||
return numberSettingComponent
|
||||
else if(setting.type === "expression")
|
||||
return expressionSettingComponent
|
||||
else if(setting.type === "string")
|
||||
return stringSettingComponent
|
||||
else
|
||||
console.log('Unknown setting type!', setting.constructor.nameInConfig, setting.constructor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Component.onCompleted: open()
|
||||
}
|
|
@ -0,0 +1,357 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Dialogs
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype ThanksTo
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Popup
|
||||
\brief Thanks to popup of LogarithmPlotter.
|
||||
|
||||
\sa LogarithmPlotter
|
||||
*/
|
||||
BaseDialog {
|
||||
id: thanks
|
||||
title: qsTr("Thanks and Contributions - LogarithmPlotter")
|
||||
width: 450
|
||||
minimumHeight: 600
|
||||
|
||||
ScrollView {
|
||||
|
||||
anchors {
|
||||
top: parent.top;
|
||||
left: parent.left;
|
||||
bottom: parent.bottom;
|
||||
right: parent.right;
|
||||
topMargin: margin;
|
||||
leftMargin: margin;
|
||||
bottomMargin: margin+30;
|
||||
}
|
||||
|
||||
Column {
|
||||
|
||||
anchors {
|
||||
left: parent.left;
|
||||
}
|
||||
|
||||
width: thanks.width - 2*margin
|
||||
spacing: 10
|
||||
|
||||
ListView {
|
||||
id: librariesListView
|
||||
anchors.left: parent.left
|
||||
width: parent.width
|
||||
//height: parent.height
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
interactive: false
|
||||
|
||||
model: ListModel {
|
||||
Component.onCompleted: {
|
||||
append({
|
||||
libName: 'expr-eval',
|
||||
license: 'MIT',
|
||||
licenseLink: 'https://raw.githubusercontent.com/silentmatt/expr-eval/master/LICENSE.txt',
|
||||
linkName: qsTr('Source code'),
|
||||
link: 'https://github.com/silentmatt/expr-eval',
|
||||
authors: [{
|
||||
authorLine: qsTr('Original library by Raphael Graf'),
|
||||
email: 'r@undefined.ch',
|
||||
website: 'https://web.archive.org/web/20111023001618/http://www.undefined.ch/mparser/index.html',
|
||||
websiteName: qsTr('Source')
|
||||
}, {
|
||||
authorLine: qsTr('Ported to Javascript by Matthew Crumley'),
|
||||
email: 'email@matthewcrumley.com',
|
||||
website: 'https://silentmatt.com/',
|
||||
websiteName: qsTr('Website')
|
||||
}, {
|
||||
authorLine: qsTr('Ported to QMLJS by Ad5001'),
|
||||
email: 'mail@ad5001.eu',
|
||||
website: 'https://ad5001.eu/',
|
||||
websiteName: qsTr('Website')
|
||||
}]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
header: Label {
|
||||
id: librariesUsedHeader
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 25
|
||||
text: qsTr("Libraries included")
|
||||
height: implicitHeight + 10
|
||||
}
|
||||
|
||||
delegate: Column {
|
||||
id: libClmn
|
||||
width: librariesListView.width
|
||||
spacing: 10
|
||||
|
||||
Item {
|
||||
height: libraryHeader.height
|
||||
width: parent.width
|
||||
|
||||
Label {
|
||||
id: libraryHeader
|
||||
anchors.left: parent.left
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 18
|
||||
text: libName
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.right: parent.right
|
||||
height: parent.height
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
height: parent.height
|
||||
text: license
|
||||
icon.name: 'license'
|
||||
onClicked: Qt.openUrlExternally(licenseLink)
|
||||
}
|
||||
|
||||
Button {
|
||||
height: parent.height
|
||||
text: linkName
|
||||
icon.name: 'web-browser'
|
||||
onClicked: Qt.openUrlExternally(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: libAuthors
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
model: authors
|
||||
width: parent.width - 10
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
interactive: false
|
||||
|
||||
delegate: Item {
|
||||
id: libAuthor
|
||||
width: librariesListView.width - 10
|
||||
height: 50
|
||||
|
||||
Label {
|
||||
id: libAuthorName
|
||||
anchors.left: parent.left
|
||||
anchors.right: buttons.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 14
|
||||
text: authorLine
|
||||
}
|
||||
|
||||
Row {
|
||||
id: buttons
|
||||
anchors.right: parent.right
|
||||
height: parent.height
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: websiteName
|
||||
icon.name: 'web-browser'
|
||||
height: parent.height - 10
|
||||
onClicked: Qt.openUrlExternally(website)
|
||||
}
|
||||
|
||||
Button {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: qsTr('Email')
|
||||
icon.name: 'email'
|
||||
height: parent.height - 10
|
||||
onClicked: Qt.openUrlExternally('mailto:' + email)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: libSeparator
|
||||
opacity: 0.3
|
||||
color: sysPalette.windowText
|
||||
width: parent.width
|
||||
height: 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: translationsListView
|
||||
anchors.left: parent.left
|
||||
width: parent.width
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
interactive: false
|
||||
spacing: 3
|
||||
|
||||
|
||||
model: ListModel {
|
||||
Component.onCompleted: {
|
||||
const authors = {
|
||||
Ad5001: {
|
||||
authorLine: 'Ad5001',
|
||||
email: 'mail@ad5001.eu',
|
||||
website: 'https://ad5001.eu',
|
||||
websiteName: qsTr('Website')
|
||||
},
|
||||
Ovari: {
|
||||
authorLine: 'Óvári',
|
||||
website: 'https://github.com/ovari',
|
||||
websiteName: qsTr('Github')
|
||||
},
|
||||
comradekingu: {
|
||||
authorLine: 'Allan Nordhøy',
|
||||
website: 'https://github.com/comradekingu',
|
||||
websiteName: qsTr('Github')
|
||||
},
|
||||
IngrownMink4: {
|
||||
authorLine: 'IngrownMink4',
|
||||
website: 'https://github.com/IngrownMink4',
|
||||
websiteName: qsTr('Github')
|
||||
},
|
||||
gallegonovato: {
|
||||
authorLine: 'gallegonovato',
|
||||
website: '',
|
||||
websiteName: ''
|
||||
}
|
||||
}
|
||||
|
||||
append({
|
||||
tranName: '🇬🇧 ' + qsTr('English'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/en/',
|
||||
authors: [authors.Ad5001]
|
||||
})
|
||||
append({
|
||||
tranName: '🇫🇷 ' + qsTr('French'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/fr/',
|
||||
authors: [authors.Ad5001]
|
||||
})
|
||||
append({
|
||||
tranName: '🇩🇪 ' + qsTr('German'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/de/',
|
||||
authors: [authors.Ad5001]
|
||||
})
|
||||
append({
|
||||
tranName: '🇭🇺 ' + qsTr('Hungarian'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/hu/',
|
||||
authors: [authors.Ovari]
|
||||
})
|
||||
append({
|
||||
tranName: '🇳🇴 ' + qsTr('Norwegian'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/no/',
|
||||
authors: [authors.comradekingu, authors.Ad5001]
|
||||
})
|
||||
append({
|
||||
tranName: '🇪🇸 ' + qsTr('Spanish'),
|
||||
link: 'https://hosted.weblate.org/projects/logarithmplotter/logarithmplotter/es/',
|
||||
authors: [authors.IngrownMink4, authors.gallegonovato]
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
header: Label {
|
||||
id: translationsHeader
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 25
|
||||
text: qsTr("Translations included")
|
||||
height: implicitHeight + 10
|
||||
}
|
||||
|
||||
delegate: Column {
|
||||
id: tranClmn
|
||||
width: translationsListView.width
|
||||
|
||||
Item {
|
||||
width: parent.width
|
||||
height: translationHeader.height + 10
|
||||
|
||||
Label {
|
||||
id: translationHeader
|
||||
anchors.left: parent.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 18
|
||||
text: tranName
|
||||
}
|
||||
|
||||
Row {
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
height: 30
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
height: parent.height
|
||||
text: qsTr('Improve')
|
||||
icon.name: 'web-browser'
|
||||
onClicked: Qt.openUrlExternally(link)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ListView {
|
||||
id: tranAuthors
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 10
|
||||
model: authors
|
||||
width: parent.width - 10
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
interactive: false
|
||||
|
||||
delegate: Item {
|
||||
id: tranAuthor
|
||||
width: tranAuthors.width
|
||||
height: 40
|
||||
|
||||
Label {
|
||||
id: tranAuthorName
|
||||
anchors.left: parent.left
|
||||
//anchors.right: buttons.left
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
wrapMode: Text.WordWrap
|
||||
font.pixelSize: 14
|
||||
text: authorLine
|
||||
}
|
||||
|
||||
Row {
|
||||
id: buttons
|
||||
anchors.left: tranAuthorName.right
|
||||
anchors.leftMargin: 10
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
height: 30
|
||||
spacing: 10
|
||||
|
||||
Button {
|
||||
text: websiteName
|
||||
visible: websiteName !== ""
|
||||
icon.name: 'web-browser'
|
||||
height: parent.height
|
||||
onClicked: Qt.openUrlExternally(website)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
module eu.ad5001.LogarithmPlotter.Popup
|
||||
|
||||
BaseDialog 1.0 BaseDialog.qml
|
||||
About 1.0 About.qml
|
||||
Alert 1.0 Alert.qml
|
||||
FileDialog 1.0 FileDialog.qml
|
||||
GreetScreen 1.0 GreetScreen.qml
|
||||
Changelog 1.0 Changelog.qml
|
||||
ThanksTo 1.0 ThanksTo.qml
|
||||
InsertCharacter 1.0 InsertCharacter.qml
|
||||
Preferences 1.0 Preferences.qml
|
|
@ -0,0 +1,125 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype AutocompletionCategory
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief ListView representing a category of autocompletion.
|
||||
|
||||
\sa ExpressionEditor
|
||||
*/
|
||||
ListView {
|
||||
id: listFiltered
|
||||
/*!
|
||||
\qmlproperty int AutocompletionCategory::itemStartIndex
|
||||
Start index of the first element in this list compared to the global autocompletion index.
|
||||
*/
|
||||
property int itemStartIndex: 0
|
||||
/*!
|
||||
\qmlproperty int AutocompletionCategory::itemSelected
|
||||
The global autocompletion index.
|
||||
*/
|
||||
property int itemSelected: 0
|
||||
|
||||
/*!
|
||||
\qmlproperty string AutocompletionCategory::category
|
||||
Name of the category.
|
||||
*/
|
||||
property string category: ""
|
||||
|
||||
/*!
|
||||
\qmlproperty var AutocompletionCategory::categoryItems
|
||||
List of items in this category. To be filtered by the autocomplete to filters.
|
||||
*/
|
||||
property var categoryItems: []
|
||||
|
||||
/*!
|
||||
\qmlproperty var AutocompletionCategory::autocompleteGenerator
|
||||
Javascript function taking the name of the item to create an autocompletion item (dictionary with
|
||||
a 'text', 'annotation' 'autocomplete', and 'cursorFinalOffset' keys.
|
||||
*/
|
||||
property var autocompleteGenerator: (item) => {return {'text': item, 'autocomplete': item, 'annotation': '', 'cursorFinalOffset': 0}}
|
||||
|
||||
/*!
|
||||
\qmlproperty string AutocompletionCategory::baseText
|
||||
Text to autocomplete.
|
||||
*/
|
||||
property string baseText: ""
|
||||
|
||||
/*!
|
||||
\qmlproperty bool AutocompletionCategory::visbilityCondition
|
||||
Condition to be met for the category to be visible.
|
||||
*/
|
||||
property bool visbilityCondition: true
|
||||
|
||||
width: parent.width
|
||||
visible: model.length > 0
|
||||
implicitHeight: contentItem.childrenRect.height
|
||||
model: visbilityCondition ? categoryItems.filter((item) => item.includes(baseText)).map(autocompleteGenerator) : []
|
||||
|
||||
header: Column {
|
||||
width: listFiltered.width
|
||||
spacing: 2
|
||||
topPadding: 5
|
||||
bottomPadding: 5
|
||||
|
||||
Text {
|
||||
leftPadding: 5
|
||||
text: listFiltered.category
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
height: 1
|
||||
color: 'gray'
|
||||
width: parent.width
|
||||
}
|
||||
}
|
||||
|
||||
delegate: Rectangle {
|
||||
property bool selected: index + listFiltered.itemStartIndex == listFiltered.itemSelected
|
||||
|
||||
width: listFiltered.width
|
||||
height: Math.max(autocompleteText.height, annotationText.height)
|
||||
color: selected ? sysPalette.highlight : 'transparent'
|
||||
|
||||
Text {
|
||||
id: autocompleteText
|
||||
topPadding: 2
|
||||
bottomPadding: 2
|
||||
leftPadding: 15
|
||||
text: listFiltered.model[index].text
|
||||
color: parent.selected ? sysPalette.highlightedText : sysPalette.windowText
|
||||
}
|
||||
|
||||
Text {
|
||||
id: annotationText
|
||||
anchors.right: parent.right
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
topPadding: 2
|
||||
bottomPadding: 2
|
||||
rightPadding: 15
|
||||
font.pixelSize: autocompleteText.font.pixelSize - 2
|
||||
text: listFiltered.model[index].annotation
|
||||
color: parent.selected ? sysPaletteIn.highlightedText : sysPaletteIn.windowText
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,134 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
|
||||
/*!
|
||||
\qmltype ComboBoxSetting
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Combo box with an icon and label to make a proper setting.
|
||||
|
||||
\sa EditorDialog, Settings, Icon
|
||||
*/
|
||||
Item {
|
||||
id: control
|
||||
height: 30
|
||||
|
||||
/*!
|
||||
\qmlsignal ComboBoxSetting::activated(int newIndex)
|
||||
|
||||
Alias of ComboBox.activated.
|
||||
The corresponding handler is \c onActivated.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#activated-signal
|
||||
*/
|
||||
signal activated(int newIndex)
|
||||
/*!
|
||||
\qmlsignal ComboBoxSetting::accepted()
|
||||
|
||||
Alias of ComboBox.accepted.
|
||||
The corresponding handler is \c onAccepted.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#accepted-signal
|
||||
*/
|
||||
signal accepted()
|
||||
|
||||
/*!
|
||||
\qmlproperty string ComboBoxSetting::label
|
||||
Label of the setting.
|
||||
*/
|
||||
property string label: ''
|
||||
/*!
|
||||
\qmlproperty string ComboBoxSetting::icon
|
||||
Icon path of the setting.
|
||||
*/
|
||||
property string icon: ""
|
||||
|
||||
/*!
|
||||
\qmlproperty var ComboBoxSetting::model
|
||||
Model of the combo box.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#model-prop
|
||||
*/
|
||||
property alias model: combox.model
|
||||
/*!
|
||||
\qmlproperty bool ComboBoxSetting::editable
|
||||
Whether the combo box accepts user-inputed values.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#editable-prop
|
||||
*/
|
||||
property alias editable: combox.editable
|
||||
/*!
|
||||
\qmlproperty string ComboBoxSetting::editText
|
||||
Text in the text field of an editable combo box.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#editText-prop
|
||||
*/
|
||||
property alias editText: combox.editText
|
||||
/*!
|
||||
\qmlproperty string ComboBoxSetting::currentIndex
|
||||
Index of the current item in the combo box.
|
||||
The default value is -1 when count is 0, and 0 otherwise
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#currentIndex-prop
|
||||
*/
|
||||
property alias currentIndex: combox.currentIndex
|
||||
/*!
|
||||
\qmlproperty string ComboBoxSetting::currentIndex
|
||||
Input text validator for an editable combo box
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#validator-prop
|
||||
*/
|
||||
property alias validator: combox.validator
|
||||
|
||||
/*!
|
||||
\qmlmethod int ComboBoxSetting::find(string elementName)
|
||||
Returns the index of the specified \a elementName, or -1 if no match is found.
|
||||
\sa https://doc.qt.io/qt-5/qml-qtquick-controls2-combobox.html#find-method
|
||||
*/
|
||||
function find(elementName) {
|
||||
return combox.find(elementName)
|
||||
}
|
||||
|
||||
Icon {
|
||||
id: iconLabel
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: icon == "" ? 0 : 3
|
||||
source: control.visible ? "../icons/" + control.icon : ""
|
||||
width: height
|
||||
height: icon == "" && visible ? 0 : 24
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Label {
|
||||
id: labelItem
|
||||
anchors.left: iconLabel.right
|
||||
anchors.leftMargin: icon == "" ? 0 : 5
|
||||
height: 30
|
||||
width: Math.max(85, implicitWidth)
|
||||
anchors.top: parent.top
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: qsTranslate("control", "%1: ").arg(control.label)
|
||||
}
|
||||
|
||||
ComboBox {
|
||||
id: combox
|
||||
height: 30
|
||||
anchors.left: labelItem.right
|
||||
anchors.leftMargin: 5
|
||||
width: control.width - labelItem.width - iconLabel.width - 10
|
||||
onActivated: function(newIndex) {
|
||||
control.activated(newIndex)
|
||||
}
|
||||
onAccepted: control.accepted()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,634 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick.Controls
|
||||
import QtQuick
|
||||
import Qt.labs.platform as Native
|
||||
import eu.ad5001.LogarithmPlotter.Popup 1.0 as P
|
||||
import "../js/index.mjs" as JS
|
||||
|
||||
|
||||
/*!
|
||||
\qmltype ExpressionEditor
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Setting to edit strings and numbers.
|
||||
|
||||
\sa EditorDialog, AutocompletionCategory
|
||||
*/
|
||||
Item {
|
||||
id: control
|
||||
height: 30
|
||||
|
||||
/*!
|
||||
\qmlsignal ExpressionEditor::changed(var newValue)
|
||||
|
||||
Emitted when the value of the expression has been changed.
|
||||
The corresponding handler is \c onChanged.
|
||||
*/
|
||||
signal changed(var newValue)
|
||||
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::defValue
|
||||
Default editable expression value of the editor.
|
||||
*/
|
||||
property string defValue
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::value
|
||||
Value of the editor.
|
||||
*/
|
||||
property alias value: editor.text
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::self
|
||||
Object or context of the expression to be edited.
|
||||
Used to prevent circular dependency.
|
||||
*/
|
||||
property string self: ""
|
||||
/*!
|
||||
\qmlproperty var ExpressionEditor::variables
|
||||
Accepted variables for the expression.
|
||||
*/
|
||||
property var variables: []
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::placeholderText
|
||||
Value of the editor.
|
||||
*/
|
||||
property alias placeholderText: editor.placeholderText
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::label
|
||||
Label of the editor.
|
||||
*/
|
||||
property string label
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::icon
|
||||
Icon path of the editor.
|
||||
*/
|
||||
property string icon: ""
|
||||
/*!
|
||||
\qmlproperty bool ExpressionEditor::allowGraphObjects
|
||||
If true, allows graph objects to be used as part of the expression.
|
||||
*/
|
||||
property bool allowGraphObjects: true
|
||||
|
||||
/*!
|
||||
\qmlproperty var ExpressionEditor::errorDialog
|
||||
Allows to summon the error dialog when using additional external parsing.
|
||||
*/
|
||||
readonly property alias errorDialog: parsingErrorDialog
|
||||
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::openAndCloseMatches
|
||||
Characters that when pressed, should be immediately followed up by their closing character.
|
||||
TODO: Make it configurable.
|
||||
*/
|
||||
readonly property var openAndCloseMatches: {
|
||||
"(": ")",
|
||||
"[": "]",
|
||||
"'": "'",
|
||||
'"': '"'
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlproperty string ExpressionEditor::colorSchemes
|
||||
Color schemes of the editor.
|
||||
*/
|
||||
readonly property var colorSchemes: [
|
||||
{ // Breeze Light
|
||||
'NORMAL': "#1F1C1B",
|
||||
'VARIABLE': "#0057AE",
|
||||
'CONSTANT': "#006E28",
|
||||
'FUNCTION': "#644A9B",
|
||||
'OPERATOR': "#CA60CA",
|
||||
'STRING': "#BF0303",
|
||||
'NUMBER': "#B08000"
|
||||
},
|
||||
{ // Breeze Dark
|
||||
'NORMAL': "#CFCFC2",
|
||||
'VARIABLE': "#2980B9",
|
||||
'CONSTANT': "#27AE60",
|
||||
'FUNCTION': "#8E44AD",
|
||||
'OPERATOR': "#A44EA4",
|
||||
'STRING': "#F44F4F",
|
||||
'NUMBER': "#F67400"
|
||||
},
|
||||
{ // Solarized
|
||||
'NORMAL': "#839496",
|
||||
'VARIABLE': "#B58900",
|
||||
'CONSTANT': "#859900",
|
||||
'FUNCTION': "#268BD2",
|
||||
'OPERATOR': "#859900",
|
||||
'STRING': "#2AA198",
|
||||
'NUMBER': "#2AA198"
|
||||
},
|
||||
{ // GitHub Light
|
||||
'NORMAL': "#24292E",
|
||||
'VARIABLE': "#D73A49",
|
||||
'CONSTANT': "#6F42C1",
|
||||
'FUNCTION': "#6F42C1",
|
||||
'OPERATOR': "#24292E",
|
||||
'STRING': "#032F62",
|
||||
'NUMBER': "#005CC5"
|
||||
},
|
||||
{ // GitHub Dark
|
||||
'NORMAL': "#E1E4E8",
|
||||
'VARIABLE': "#F97583",
|
||||
'CONSTANT': "#B392f0",
|
||||
'FUNCTION': "#B392f0",
|
||||
'OPERATOR': "#E1E4E8",
|
||||
'STRING': "#9ECBFF",
|
||||
'NUMBER': "#79B8FF"
|
||||
},
|
||||
{ // Nord
|
||||
'NORMAL': "#D8DEE9",
|
||||
'VARIABLE': "#81A1C1",
|
||||
'CONSTANT': "#8FBCBB",
|
||||
'FUNCTION': "#88C0D0",
|
||||
'OPERATOR': "#81A1C1",
|
||||
'STRING': "#A3BE8C",
|
||||
'NUMBER': "#B48EAD"
|
||||
},
|
||||
{ // Monokai
|
||||
'NORMAL': "#F8F8F2",
|
||||
'VARIABLE': "#66D9EF",
|
||||
'CONSTANT': "#F92672",
|
||||
'FUNCTION': "#A6E22E",
|
||||
'OPERATOR': "#F8F8F2",
|
||||
'STRING': "#E6DB74",
|
||||
'NUMBER': "#AE81FF"
|
||||
}
|
||||
]
|
||||
|
||||
Icon {
|
||||
id: iconLabel
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: icon == "" ? 0 : 3
|
||||
source: control.visible && icon != "" ? "../icons/" + control.icon : ""
|
||||
width: height
|
||||
height: icon == "" || !visible ? 0 : 24
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Label {
|
||||
id: labelItem
|
||||
anchors.left: iconLabel.right
|
||||
anchors.leftMargin: icon == "" ? 0 : 5
|
||||
anchors.top: parent.top
|
||||
height: parent.height
|
||||
width: Math.max(85, implicitWidth)
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
//color: sysPalette.windowText
|
||||
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""
|
||||
visible: control.label != ""
|
||||
}
|
||||
|
||||
Native.MessageDialog {
|
||||
id: parsingErrorDialog
|
||||
title: qsTranslate("expression", "LogarithmPlotter - Parsing error")
|
||||
text: ""
|
||||
function showDialog(propName, propValue, error) {
|
||||
text = qsTranslate("expression", "Error while parsing expression for property %1:\n%2\n\nEvaluated expression: %3")
|
||||
.arg(qsTranslate('prop', propName))
|
||||
.arg(error).arg(propValue)
|
||||
open()
|
||||
}
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: editor
|
||||
anchors.top: parent.top
|
||||
anchors.left: labelItem.right
|
||||
anchors.leftMargin: 5
|
||||
width: control.width - (labelItem.visible ? labelItem.width + 5 : 0) - iconLabel.width - 5
|
||||
height: parent.height
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter
|
||||
text: control.defValue
|
||||
color: syntaxHighlightingEnabled ? sysPalette.window : sysPalette.windowText
|
||||
focus: true
|
||||
selectByMouse: true
|
||||
|
||||
property bool autocompleteEnabled: Helper.getSettingBool("autocompletion.enabled")
|
||||
property bool syntaxHighlightingEnabled: Helper.getSettingBool("expression_editor.colorize")
|
||||
property bool autoClosing: Helper.getSettingBool("expression_editor.autoclose")
|
||||
property var tokens: autocompleteEnabled || syntaxHighlightingEnabled ? parent.tokens(text) : []
|
||||
|
||||
Keys.priority: Keys.BeforeItem // Required for knowing which key the user presses.
|
||||
|
||||
onEditingFinished: {
|
||||
if(insertButton.focus || insertPopup.focus) return
|
||||
let value = text
|
||||
if(value != "" && value.toString() != defValue) {
|
||||
let expr = parse(value)
|
||||
if(expr != null) {
|
||||
control.changed(expr)
|
||||
defValue = expr.toEditableString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onActiveFocusChanged: {
|
||||
if(activeFocus && autocompleteEnabled)
|
||||
autocompletePopup.open()
|
||||
else
|
||||
autocompletePopup.close()
|
||||
}
|
||||
|
||||
cursorDelegate: Rectangle {
|
||||
visible: editor.cursorVisible
|
||||
color: sysPalette.windowText
|
||||
width: editor.cursorRectangle.width
|
||||
}
|
||||
|
||||
Keys.onUpPressed: function(event) {
|
||||
if(autocompleteEnabled)
|
||||
if(acPopupContent.itemSelected == 0)
|
||||
acPopupContent.itemSelected = acPopupContent.itemCount-1
|
||||
else
|
||||
acPopupContent.itemSelected = acPopupContent.itemSelected-1
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
Keys.onDownPressed: function(event) {
|
||||
if(autocompleteEnabled)
|
||||
if(acPopupContent.itemSelected == Math.min(acPopupContent.itemCount-1))
|
||||
acPopupContent.itemSelected = 0
|
||||
else
|
||||
acPopupContent.itemSelected = acPopupContent.itemSelected+1
|
||||
event.accepted = true
|
||||
}
|
||||
|
||||
Keys.onPressed: function(event) {
|
||||
// Autocomplete popup events
|
||||
if(autocompleteEnabled && (event.key == Qt.Key_Enter || event.key == Qt.Key_Return) && acPopupContent.itemCount > 0) {
|
||||
acPopupContent.autocomplete()
|
||||
event.accepted = true
|
||||
} else
|
||||
acPopupContent.itemSelected = 0
|
||||
|
||||
|
||||
if(event.text in openAndCloseMatches && autoClosing) {
|
||||
let start = selectionStart
|
||||
insert(selectionStart, event.text)
|
||||
insert(selectionEnd, openAndCloseMatches[event.text])
|
||||
cursorPosition = start+1
|
||||
event.accepted = true
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: colorizedEditor
|
||||
anchors.fill: editor
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter
|
||||
textFormat: Text.StyledText
|
||||
text: parent.syntaxHighlightingEnabled ? colorize(parent.tokens) : ""
|
||||
color: sysPalette.windowText
|
||||
visible: parent.syntaxHighlightingEnabled
|
||||
//font.pixelSize: parent.font.pixelSize
|
||||
//opacity: editor.activeFocus ? 0 : 1
|
||||
}
|
||||
|
||||
Popup {
|
||||
id: autocompletePopup
|
||||
x: 0
|
||||
y: parent.height
|
||||
closePolicy: Popup.NoAutoClose
|
||||
|
||||
width: editor.width
|
||||
height: acPopupContent.height
|
||||
padding: 0
|
||||
|
||||
Column {
|
||||
id: acPopupContent
|
||||
width: parent.width
|
||||
|
||||
readonly property var identifierTokenTypes: [
|
||||
JS.Parsing.TokenType.VARIABLE,
|
||||
JS.Parsing.TokenType.FUNCTION,
|
||||
JS.Parsing.TokenType.CONSTANT
|
||||
]
|
||||
property var currentToken: generateTokenInformation(getTokenAt(editor.tokens, editor.cursorPosition))
|
||||
property var previousToken: generateTokenInformation(getPreviousToken(currentToken.token))
|
||||
property var previousToken2: generateTokenInformation(getPreviousToken(previousToken.token))
|
||||
property var previousToken3: generateTokenInformation(getPreviousToken(previousToken2.token))
|
||||
visible: currentToken.exists
|
||||
|
||||
// Focus handling.
|
||||
readonly property var lists: [objectPropertiesList, variablesList, constantsList, functionsList, executableObjectsList, objectsList]
|
||||
readonly property int itemCount: objectPropertiesList.model.length + variablesList.model.length + constantsList.model.length + functionsList.model.length + executableObjectsList.model.length + objectsList.model.length
|
||||
property int itemSelected: 0
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::generateTokenInformation(var token)
|
||||
Generates basic information about the given token (existence and type) used in autocompletion).
|
||||
*/
|
||||
function generateTokenInformation(token) {
|
||||
let exists = token != null
|
||||
return {
|
||||
'token': token,
|
||||
'exists': exists,
|
||||
'value': exists ? token.value : null,
|
||||
'type': exists ? token.type : null,
|
||||
'startPosition': exists ? token.startPosition : 0,
|
||||
'dot': exists ? (token.type == JS.Parsing.TokenType.PUNCT && token.value == ".") : false,
|
||||
'identifier': exists ? identifierTokenTypes.includes(token.type) : false
|
||||
}
|
||||
}
|
||||
/*!
|
||||
\qmlmethod void ExpressionEditor::autocompleteInfoAt(int idx)
|
||||
Returns the autocompletion text information at a given position.
|
||||
The information contains key 'text' (description text), 'autocomplete' (text to insert)
|
||||
and 'cursorFinalOffset' (amount to add to the cursor's position after the end of the autocomplete)
|
||||
*/
|
||||
function autocompleteInfoAt(idx) {
|
||||
if(idx >= itemCount) return ""
|
||||
let startIndex = 0
|
||||
for(let list of lists) {
|
||||
if(idx < startIndex + list.model.length)
|
||||
return list.model[idx-startIndex]
|
||||
startIndex += list.model.length
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void ExpressionEditor::autocomplete()
|
||||
Autocompletes with the current selected word.
|
||||
*/
|
||||
function autocomplete() {
|
||||
let autotext = autocompleteInfoAt(itemSelected)
|
||||
let startPos = currentToken.startPosition
|
||||
console.log("Replacing", currentToken.value, "at", startPos, "with", autotext.autocomplete)
|
||||
editor.remove(startPos, startPos+currentToken.value.length)
|
||||
editor.insert(startPos, autotext.autocomplete)
|
||||
editor.cursorPosition = startPos+autotext.autocomplete.length+autotext.cursorFinalOffset
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::getPreviousToken(var token)
|
||||
Returns the token before this one.
|
||||
*/
|
||||
function getPreviousToken(token) {
|
||||
let newToken = getTokenAt(editor.tokens, token.startPosition)
|
||||
if(newToken != null && newToken.type == JS.Parsing.TokenType.WHITESPACE)
|
||||
return getPreviousToken(newToken)
|
||||
return newToken
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: objectPropertiesList
|
||||
|
||||
category: qsTr("Object Properties")
|
||||
visbilityCondition: control.allowGraphObjects && doesObjectExist
|
||||
itemStartIndex: 0
|
||||
itemSelected: parent.itemSelected
|
||||
property bool isEnteringProperty: (
|
||||
// Current token is dot.
|
||||
(parent.currentToken.dot && parent.previousToken.identifier && !parent.previousToken2.dot) ||
|
||||
// Current token is property identifier
|
||||
(parent.currentToken.identifier && parent.previousToken.dot && parent.previousToken2.identifier && !parent.previousToken3.dot))
|
||||
property string objectName: isEnteringProperty ?
|
||||
(parent.currentToken.dot ? parent.previousToken.value : parent.previousToken2.value)
|
||||
: ""
|
||||
property bool doesObjectExist: isEnteringProperty && (objectName in Modules.Objects.currentObjectsByName)
|
||||
property var objectProperties: doesObjectExist ?
|
||||
Modules.Objects.currentObjectsByName[objectName].constructor.properties() :
|
||||
{}
|
||||
categoryItems: Object.keys(objectProperties)
|
||||
autocompleteGenerator: (item) => {
|
||||
let propType = objectProperties[item]
|
||||
return {
|
||||
'text': item, 'annotation': propType == null ? '' : propType.toString(),
|
||||
'autocomplete': parent.currentToken.dot ? `.${item} ` : `${item} `,
|
||||
'cursorFinalOffset': 0
|
||||
}
|
||||
|
||||
}
|
||||
baseText: parent.visible && !parent.currentToken.dot ? parent.currentToken.value : ""
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: variablesList
|
||||
|
||||
category: qsTr("Variables")
|
||||
visbilityCondition: parent.currentToken.identifier && !parent.previousToken.dot
|
||||
itemStartIndex: objectPropertiesList.model.length
|
||||
itemSelected: parent.itemSelected
|
||||
categoryItems: control.variables
|
||||
autocompleteGenerator: (item) => {return {
|
||||
'text': item, 'annotation': '',
|
||||
'autocomplete': item + " ", 'cursorFinalOffset': 0
|
||||
}}
|
||||
baseText: parent.visible ? parent.currentToken.value : ""
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: constantsList
|
||||
|
||||
category: qsTr("Constants")
|
||||
visbilityCondition: parent.currentToken.identifier && !parent.previousToken.dot
|
||||
itemStartIndex: variablesList.itemStartIndex + variablesList.model.length
|
||||
itemSelected: parent.itemSelected
|
||||
categoryItems: JS.Parsing.CONSTANTS_LIST
|
||||
autocompleteGenerator: (item) => {return {
|
||||
'text': item, 'annotation': JS.Parsing.CONSTANTS[item],
|
||||
'autocomplete': item + " ", 'cursorFinalOffset': 0
|
||||
}}
|
||||
baseText: parent.visible ? parent.currentToken.value : ""
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: functionsList
|
||||
|
||||
category: qsTr("Functions")
|
||||
visbilityCondition: parent.currentToken.identifier && !parent.previousToken.dot
|
||||
itemStartIndex: constantsList.itemStartIndex + constantsList.model.length
|
||||
itemSelected: parent.itemSelected
|
||||
categoryItems: JS.Parsing.FUNCTIONS_LIST
|
||||
autocompleteGenerator: (item) => {return {
|
||||
'text': item, 'annotation': JS.Parsing.FUNCTIONS_USAGE[item].join(', '),
|
||||
'autocomplete': item+'()', 'cursorFinalOffset': -1
|
||||
}}
|
||||
baseText: parent.visible ? parent.currentToken.value : ""
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: executableObjectsList
|
||||
|
||||
category: qsTr("Executable Objects")
|
||||
visbilityCondition: control.allowGraphObjects && parent.currentToken.identifier && !parent.previousToken.dot
|
||||
itemStartIndex: functionsList.itemStartIndex + functionsList.model.length
|
||||
itemSelected: parent.itemSelected
|
||||
categoryItems: Modules.Objects.getObjectsName("ExecutableObject").filter(obj => obj != self)
|
||||
autocompleteGenerator: (item) => {return {
|
||||
'text': item, 'annotation': Modules.Objects.currentObjectsByName[item] == null ? '' : Modules.Objects.currentObjectsByName[item].constructor.displayType(),
|
||||
'autocomplete': item+'()', 'cursorFinalOffset': -1
|
||||
}}
|
||||
baseText: parent.visible ? parent.currentToken.value : ""
|
||||
}
|
||||
|
||||
AutocompletionCategory {
|
||||
id: objectsList
|
||||
|
||||
category: qsTr("Objects")
|
||||
visbilityCondition: control.allowGraphObjects && parent.currentToken.identifier && !parent.previousToken.dot
|
||||
itemStartIndex: executableObjectsList.itemStartIndex + executableObjectsList.model.length
|
||||
itemSelected: parent.itemSelected
|
||||
categoryItems: Object.keys(Modules.Objects.currentObjectsByName).filter(obj => obj != self)
|
||||
autocompleteGenerator: (item) => {return {
|
||||
'text': item, 'annotation': `${Modules.Objects.currentObjectsByName[item].constructor.displayType()}`,
|
||||
'autocomplete': item+'.', 'cursorFinalOffset': 0
|
||||
}}
|
||||
baseText: parent.visible ? parent.currentToken.value : ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: insertButton
|
||||
text: "α"
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 20
|
||||
height: width
|
||||
onClicked: {
|
||||
insertPopup.open()
|
||||
insertPopup.focus = true
|
||||
}
|
||||
}
|
||||
|
||||
P.InsertCharacter {
|
||||
id: insertPopup
|
||||
|
||||
x: Math.round((parent.width - width) / 2)
|
||||
y: Math.round((parent.height - height) / 2)
|
||||
|
||||
category: "expression"
|
||||
|
||||
onSelected: function(c) {
|
||||
editor.insert(editor.cursorPosition, c)
|
||||
insertPopup.close()
|
||||
focus = false
|
||||
editor.focus = true
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::parse(string newExpression)
|
||||
Parses the \c newExpression as an expression, checks for errors, shows them if any.
|
||||
Returns the parsed expression if possible, null otherwise..
|
||||
*/
|
||||
function parse(newExpression) {
|
||||
let expr = null
|
||||
try {
|
||||
expr = new JS.MathLib.Expression(value.toString())
|
||||
// Check if the expression is valid, throws error otherwise.
|
||||
if(!expr.allRequirementsFulfilled()) {
|
||||
let undefVars = expr.undefinedVariables()
|
||||
if(undefVars.length > 1)
|
||||
throw new Error(qsTranslate('error', 'No object found with names %1.').arg(undefVars.join(', ')))
|
||||
else
|
||||
throw new Error(qsTranslate('error', 'No object found with name %1.').arg(undefVars.join(', ')))
|
||||
}
|
||||
if(expr.requiredObjects().includes(control.self))
|
||||
throw new Error(qsTranslate('error', 'Object cannot be dependent on itself.'))
|
||||
// Recursive dependencies
|
||||
let dependentOnSelfObjects = expr.requiredObjects().filter(
|
||||
(obj) => Modules.Objects.currentObjectsByName[obj].getDependenciesList()
|
||||
.includes(Modules.Objects.currentObjectsByName[control.self])
|
||||
)
|
||||
if(dependentOnSelfObjects.length == 1)
|
||||
throw new Error(qsTranslate('error', 'Circular dependency detected. Object %1 depends on %2.').arg(dependentOnSelfObjects[0].toString()).arg(control.self))
|
||||
else if(dependentOnSelfObjects.length > 1)
|
||||
throw new Error(qsTranslate('error', 'Circular dependency detected. Objects %1 depend on %2.').arg(dependentOnSelfObjects.map(obj => obj.toString()).join(', ')).arg(control.self))
|
||||
//console.log(control.self, propertyName, expr.execute())
|
||||
return expr
|
||||
} catch(e) {
|
||||
// Error in expression
|
||||
parsingErrorDialog.showDialog(propertyName, newExpression, e.message)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::tokens(string expressionText)
|
||||
Generates a list of tokens from the given.
|
||||
*/
|
||||
function tokens(text) {
|
||||
let tokenizer = new JS.Parsing.Tokenizer(new JS.Parsing.Input(text), true, false)
|
||||
let tokenList = []
|
||||
let token
|
||||
while((token = tokenizer.next()) != null)
|
||||
tokenList.push(token)
|
||||
return tokenList
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::getTokenAt(var tokens, int position)
|
||||
Gets the token at the given position within the text.
|
||||
Returns null if out of bounds.
|
||||
*/
|
||||
function getTokenAt(tokenList, position) {
|
||||
let currentPosition = 0
|
||||
for(let token of tokenList)
|
||||
if(position <= (currentPosition + token.value.length))
|
||||
return token
|
||||
else
|
||||
currentPosition += token.value.length
|
||||
return null
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod var ExpressionEditor::colorize(var tokenList)
|
||||
Creates an HTML colorized string of the given tokens.
|
||||
Returns the colorized and escaped expression if possible, null otherwise..
|
||||
*/
|
||||
function colorize(tokenList) {
|
||||
let parsedText = ""
|
||||
let scheme = colorSchemes[Helper.getSettingInt("expression_editor.color_scheme")]
|
||||
for(let token of tokenList) {
|
||||
switch(token.type) {
|
||||
case JS.Parsing.TokenType.VARIABLE:
|
||||
parsedText += `<font color="${scheme.VARIABLE}">${token.value}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.CONSTANT:
|
||||
parsedText += `<font color="${scheme.CONSTANT}">${token.value}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.FUNCTION:
|
||||
parsedText += `<font color="${scheme.FUNCTION}">${JS.Utils.escapeHTML(token.value)}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.OPERATOR:
|
||||
parsedText += `<font color="${scheme.OPERATOR}">${JS.Utils.escapeHTML(token.value)}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.NUMBER:
|
||||
parsedText += `<font color="${scheme.NUMBER}">${JS.Utils.escapeHTML(token.value)}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.STRING:
|
||||
parsedText += `<font color="${scheme.STRING}">${token.limitator}${JS.Utils.escapeHTML(token.value)}${token.limitator}</font>`
|
||||
break;
|
||||
case JS.Parsing.TokenType.WHITESPACE:
|
||||
case JS.Parsing.TokenType.PUNCT:
|
||||
default:
|
||||
parsedText += JS.Utils.escapeHTML(token.value).replace(/ /g, ' ')
|
||||
break;
|
||||
}
|
||||
}
|
||||
return parsedText
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import QtQuick
|
||||
import QtQuick.Window
|
||||
import QtQuick.Controls.impl
|
||||
|
||||
/*!
|
||||
\qmltype Icon
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Colorable image.
|
||||
|
||||
\sa ComboBoxSetting, ListSetting, TextSetting
|
||||
*/
|
||||
Item {
|
||||
/*!
|
||||
\qmlproperty string Icon::color
|
||||
Overlay color of the icon.
|
||||
*/
|
||||
property color color: "#000000"
|
||||
/*!
|
||||
\qmlproperty string Icon::source
|
||||
Path of the icon image source.
|
||||
*/
|
||||
property alias source: img.source
|
||||
/*!
|
||||
\qmlproperty string Icon::source
|
||||
Path of the icon image source.
|
||||
*/
|
||||
property alias sourceSize: img.sourceS
|
||||
|
||||
ColorImage {
|
||||
id: img
|
||||
height: parent.height
|
||||
width: parent.width
|
||||
// visible: false
|
||||
property int sourceS: width*Screen.devicePixelRatio
|
||||
sourceSize.width: sourceS
|
||||
sourceSize.height: sourceS
|
||||
color: parent.color
|
||||
}
|
||||
}
|
|
@ -0,0 +1,275 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import QtQml.Models
|
||||
|
||||
/*!
|
||||
\qmltype ListSetting
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Setting to create and edit lists and dictionaries.
|
||||
|
||||
\sa EditorDialog, Settings, Icon
|
||||
*/
|
||||
Column {
|
||||
id: control
|
||||
|
||||
/*!
|
||||
\qmlsignal ListSetting::changed()
|
||||
|
||||
Emitted when an entry of the setting has been changed.
|
||||
The corresponding handler is \c onChanged.
|
||||
*/
|
||||
signal changed()
|
||||
|
||||
/*!
|
||||
\qmlproperty string ListSetting::label
|
||||
Label of the setting.
|
||||
*/
|
||||
property string label: ''
|
||||
/*!
|
||||
\qmlproperty string ListSetting::icon
|
||||
Icon path of the setting.
|
||||
*/
|
||||
property string icon: ''
|
||||
/*!
|
||||
\qmlproperty bool ListSetting::dictionaryMode
|
||||
true to set the export mode to dictionary, false for list.
|
||||
*/
|
||||
property bool dictionaryMode: false
|
||||
/*!
|
||||
\qmlproperty string ListSetting::keyType
|
||||
Type for keys for dictionary, can be either "string" or "number".
|
||||
*/
|
||||
property string keyType: "string"
|
||||
/*!
|
||||
\qmlproperty string ListSetting::keyType
|
||||
Type for values of the dictionary or list, can be either "string" or "number".
|
||||
*/
|
||||
property string valueType: "string"
|
||||
/*!
|
||||
\qmlproperty string ListSetting::preKeyLabel
|
||||
Text to be put before the key for each entry.
|
||||
*/
|
||||
property string preKeyLabel: ""
|
||||
/*!
|
||||
\qmlproperty string ListSetting::postKeyLabel
|
||||
Text to be put after the key for each entry. Only for dictionaries.
|
||||
*/
|
||||
property string postKeyLabel: ": "
|
||||
/*!
|
||||
\qmlproperty var ListSetting::keyRegexp
|
||||
Regular expression used in the validator for keys. Only for dictionaries.
|
||||
*/
|
||||
property var keyRegexp: /^.+$/
|
||||
/*!
|
||||
\qmlproperty var ListSetting::valueRegexp
|
||||
Regular expression used in the validator for values.
|
||||
*/
|
||||
property var valueRegexp: /^.+$/
|
||||
/*!
|
||||
\qmlproperty bool ListSetting::forbidAdding
|
||||
If true, prevents the user from adding or removing new entries.
|
||||
*/
|
||||
property bool forbidAdding: false
|
||||
|
||||
/*!
|
||||
\qmlproperty bool ListSetting::model
|
||||
Model of the list/dictionnary, in the form of [{key: < key >, val: < value > }].
|
||||
|
||||
Use the \a importModel method to set the model.
|
||||
*/
|
||||
property alias model: repeater.model
|
||||
|
||||
Row {
|
||||
height: 30
|
||||
width: parent.width;
|
||||
Icon {
|
||||
id: iconLabel
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: icon == "" ? 0 : 3
|
||||
source: control.visible ? "../icons/" + control.icon : ""
|
||||
width: height
|
||||
height: icon == "" || !visible ? 0 : 24
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
Label {
|
||||
id: labelItem
|
||||
height: 30
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
text: qsTranslate("control", "%1: ").arg(control.label)
|
||||
}
|
||||
}
|
||||
|
||||
Repeater {
|
||||
id: repeater
|
||||
width: control.width
|
||||
model: ListModel {}
|
||||
|
||||
Row {
|
||||
id: defRow
|
||||
height: addEntryBtn.height
|
||||
width: parent.width
|
||||
|
||||
Text {
|
||||
id: preKeyText
|
||||
height: parent.height
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: sysPalette.windowText
|
||||
text: control.preKeyLabel
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: keyInput
|
||||
visible: control.dictionaryMode
|
||||
height: parent.height
|
||||
width: visible ? 50 : 0
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: control.keyRegexp
|
||||
}
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
color: sysPalette.windowText
|
||||
text: visible ? control.model.get(index).key : false
|
||||
selectByMouse: true
|
||||
onEditingFinished: {
|
||||
var value = text
|
||||
if(control.keyType == 'int') {
|
||||
value = parseInt(value)
|
||||
if(value.toString()=="NaN")
|
||||
value = ""
|
||||
}
|
||||
if(control.keyType == 'double') {
|
||||
value = parseFloat(value)
|
||||
if(value.toString()=="NaN")
|
||||
value = ""
|
||||
}
|
||||
if(value !== "" && valueInput.acceptableInput) {
|
||||
control.model.setProperty(index, 'key', value)
|
||||
control.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Text {
|
||||
id: postKeyText
|
||||
visible: control.dictionaryMode
|
||||
height: parent.height
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
color: sysPalette.windowText
|
||||
text: control.postKeyLabel
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: valueInput
|
||||
height: parent.height
|
||||
width: parent.width - x - deleteButton.width - 5
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: control.valueRegexp
|
||||
}
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
color: sysPalette.windowText
|
||||
text: visible ? control.model.get(index).val : false
|
||||
selectByMouse: true
|
||||
onEditingFinished: {
|
||||
var value = text
|
||||
if(control.valueType == 'int') {
|
||||
value = parseInt(value)
|
||||
if(value.toString()=="NaN")
|
||||
value = ""
|
||||
}
|
||||
if(control.valueType == 'double') {
|
||||
value = parseFloat(value)
|
||||
if(value.toString()=="NaN")
|
||||
value = ""
|
||||
}
|
||||
if(value !== "" && keyInput.acceptableInput) {
|
||||
control.model.setProperty(index, 'val', value)
|
||||
control.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Item {
|
||||
width: 5
|
||||
height: parent.height
|
||||
}
|
||||
|
||||
Button {
|
||||
id: deleteButton
|
||||
width: visible ? parent.height : 0
|
||||
height: width
|
||||
icon.source: './icons/common/delete.svg'
|
||||
icon.name: 'delete'
|
||||
visible: !control.forbidAdding
|
||||
|
||||
onClicked: {
|
||||
control.model.remove(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: addEntryBtn
|
||||
visible: !control.forbidAdding
|
||||
text: qsTr('+ Add Entry')
|
||||
width: control.width
|
||||
|
||||
onClicked: {
|
||||
control.model.append({
|
||||
key: control.keyType == 'string' ? '' : model.count,
|
||||
val: control.valueType == 'string' ? '' : 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void ListSetting::importModel(var importer)
|
||||
Imports either a list or a dictionnary in the model.
|
||||
*/
|
||||
function importModel(importer) {
|
||||
model.clear()
|
||||
for(var key in importer)
|
||||
model.append({
|
||||
key: control.keyType == 'string' ? key.toString() : parseFloat(key),
|
||||
val: control.valueType == 'string' ? importer[key].toString() : parseFloat(importer[key])
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmethod void ListSetting::exportModel()
|
||||
Exports the model either a list or a dictionnary in the model depending on \a dictionaryMode.
|
||||
*/
|
||||
function exportModel() {
|
||||
if(dictionaryMode) {
|
||||
var ret = {}
|
||||
for(var i = 0; i < model.count; i++)
|
||||
ret[model.get(i).key] = model.get(i).val
|
||||
return ret
|
||||
} else {
|
||||
var ret = []
|
||||
for(var i = 0; i < model.count; i++)
|
||||
ret.push(model.get(i).val)
|
||||
return ret
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,173 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick.Controls
|
||||
import QtQuick
|
||||
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
|
||||
|
||||
/*!
|
||||
\qmltype TextSetting
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter.Setting
|
||||
\brief Setting to edit strings and numbers.
|
||||
|
||||
\sa EditorDialog, Settings, Icon
|
||||
*/
|
||||
Item {
|
||||
id: control
|
||||
height: 30
|
||||
|
||||
/*!
|
||||
\qmlsignal TextSetting::changed(string newValue)
|
||||
|
||||
Emitted when the value of the text has been changed.
|
||||
The corresponding handler is \c onChanged.
|
||||
*/
|
||||
signal changed(string newValue)
|
||||
|
||||
/*!
|
||||
\qmlproperty bool TextSetting::isInt
|
||||
If true, the input is being parsed an int before being emitting the \a changed signal.
|
||||
*/
|
||||
property bool isInt: false
|
||||
/*!
|
||||
\qmlproperty bool TextSetting::isDouble
|
||||
If true, the input is being parsed an double before being emitting the \a changed signal.
|
||||
*/
|
||||
property bool isDouble: false
|
||||
/*!
|
||||
\qmlproperty bool TextSetting::category
|
||||
Type of special character to insert from the popup.
|
||||
\sa InsertCharacter::category
|
||||
*/
|
||||
property alias category: insertPopup.category
|
||||
/*!
|
||||
\qmlproperty double TextSetting::min
|
||||
Minimum value for numbers that can be entered into the input.
|
||||
*/
|
||||
property double min: -1
|
||||
/*!
|
||||
\qmlproperty string TextSetting::defValue
|
||||
Default value of the input.
|
||||
*/
|
||||
property string defValue
|
||||
/*!
|
||||
\qmlproperty string TextSetting::value
|
||||
Value of the input.
|
||||
*/
|
||||
property alias value: input.text
|
||||
/*!
|
||||
\qmlproperty string TextSetting::placeholderText
|
||||
Value of the input.
|
||||
*/
|
||||
property alias placeholderText: input.placeholderText
|
||||
/*!
|
||||
\qmlproperty string TextSetting::label
|
||||
Label of the setting.
|
||||
*/
|
||||
property string label
|
||||
/*!
|
||||
\qmlproperty string TextSetting::icon
|
||||
Icon path of the setting.
|
||||
*/
|
||||
property string icon: ""
|
||||
|
||||
Icon {
|
||||
id: iconLabel
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: icon == "" ? 0 : 3
|
||||
source: control.visible && icon != "" ? "../icons/" + control.icon : ""
|
||||
width: height
|
||||
height: icon == "" || !visible ? 0 : 24
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Label {
|
||||
id: labelItem
|
||||
anchors.left: iconLabel.right
|
||||
anchors.leftMargin: icon == "" ? 0 : 5
|
||||
anchors.top: parent.top
|
||||
height: parent.height
|
||||
width: visible ? Math.max(85, implicitWidth) : 0
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
//color: sysPalette.windowText
|
||||
text: visible ? qsTranslate("control", "%1: ").arg(control.label) : ""
|
||||
visible: control.label != ""
|
||||
}
|
||||
|
||||
TextField {
|
||||
id: input
|
||||
anchors.top: parent.top
|
||||
anchors.left: labelItem.right
|
||||
anchors.leftMargin: 5
|
||||
width: control.width - (labelItem.visible ? labelItem.width + 5 : 0) - iconLabel.width - 5
|
||||
height: parent.height
|
||||
verticalAlignment: TextInput.AlignVCenter
|
||||
horizontalAlignment: control.label == "" ? TextInput.AlignLeft : TextInput.AlignHCenter
|
||||
color: sysPalette.windowText
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: control.isInt ? /-?[0-9]+/ : control.isDouble ? /-?[0-9]+(\.[0-9]+)?/ : /.+/
|
||||
}
|
||||
focus: true
|
||||
text: control.defValue
|
||||
selectByMouse: true
|
||||
onEditingFinished: function() {
|
||||
if(insertButton.focus || insertPopup.focus) return
|
||||
let value = text
|
||||
if(control.isInt) {
|
||||
let parsed = parseInt(value)
|
||||
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
|
||||
} else if(control.isDouble) {
|
||||
let parsed = parseFloat(value)
|
||||
value = isNaN(parsed) ? control.min : Math.max(control.min,parsed)
|
||||
}
|
||||
if(value !== "" && value.toString() != defValue) {
|
||||
control.changed(value)
|
||||
defValue = value.toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: insertButton
|
||||
text: "α"
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 5
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
width: 20
|
||||
height: width
|
||||
visible: !isInt && !isDouble
|
||||
onClicked: {
|
||||
insertPopup.open()
|
||||
insertPopup.focus = true
|
||||
}
|
||||
}
|
||||
|
||||
Popup.InsertCharacter {
|
||||
id: insertPopup
|
||||
|
||||
x: Math.round((parent.width - width) / 2)
|
||||
y: Math.round((parent.height - height) / 2)
|
||||
|
||||
onSelected: function(c) {
|
||||
input.insert(input.cursorPosition, c)
|
||||
insertPopup.close()
|
||||
focus = false
|
||||
input.focus = true
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
module eu.ad5001.LogarithmPlotter.Setting
|
||||
|
||||
ComboBoxSetting 1.0 ComboBoxSetting.qml
|
||||
Icon 1.0 Icon.qml
|
||||
ListSetting 1.0 ListSetting.qml
|
||||
TextSetting 1.0 TextSetting.qml
|
||||
ExpressionEditor 1.0 ExpressionEditor.qml
|
||||
AutocompletionCategory 1.0 AutocompletionCategory.qml
|
|
@ -0,0 +1,467 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
import eu.ad5001.LogarithmPlotter.Popup 1.0 as Popup
|
||||
import "js/index.mjs" as JS
|
||||
|
||||
/*!
|
||||
\qmltype Settings
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief Tab of the drawer that allows the user to customize how the diagram looks.
|
||||
|
||||
All canvas settings can found in this scrollable view, as well as buttons to copy and save the graph.
|
||||
|
||||
\sa LogarithmPlotter, LogGraphCanvas
|
||||
*/
|
||||
ScrollView {
|
||||
id: settings
|
||||
|
||||
signal changed()
|
||||
|
||||
property int settingWidth: settings.width - ScrollBar.vertical.width
|
||||
property Canvas canvas
|
||||
|
||||
/*!
|
||||
\qmlproperty double Settings::xzoom
|
||||
Zoom on the x axis of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double xzoom: Helper.getSettingInt('default_graph.xzoom')
|
||||
/*!
|
||||
\qmlproperty double Settings::yzoom
|
||||
Zoom on the y axis of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double yzoom: Helper.getSettingInt('default_graph.yzoom')
|
||||
/*!
|
||||
\qmlproperty double Settings::xmin
|
||||
Minimum x of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double xmin: Helper.getSettingInt('default_graph.xmin')
|
||||
/*!
|
||||
\qmlproperty double Settings::ymax
|
||||
Maximum y of the diagram, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double ymax: Helper.getSettingInt('default_graph.ymax')
|
||||
/*!
|
||||
\qmlproperty string Settings::xaxisstep
|
||||
Step of the x axis graduation, provided from settings.
|
||||
\note: Only available in non-logarithmic mode.
|
||||
\sa Settings
|
||||
*/
|
||||
property string xaxisstep: Helper.getSetting('default_graph.xaxisstep')
|
||||
/*!
|
||||
\qmlproperty string Settings::yaxisstep
|
||||
Step of the y axis graduation, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string yaxisstep: Helper.getSetting('default_graph.yaxisstep')
|
||||
/*!
|
||||
\qmlproperty string Settings::xlabel
|
||||
Label used on the x axis, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string xlabel: Helper.getSetting('default_graph.xlabel')
|
||||
/*!
|
||||
\qmlproperty string Settings::ylabel
|
||||
Label used on the y axis, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property string ylabel: Helper.getSetting('default_graph.ylabel')
|
||||
/*!
|
||||
\qmlproperty double Settings::linewidth
|
||||
Width of lines that will be drawn into the canvas, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double linewidth: Helper.getSettingInt('default_graph.linewidth')
|
||||
/*!
|
||||
\qmlproperty double Settings::textsize
|
||||
Font size of the text that will be drawn into the canvas, provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property double textsize: Helper.getSettingInt('default_graph.textsize')
|
||||
/*!
|
||||
\qmlproperty bool Settings::logscalex
|
||||
true if the canvas should be in logarithmic mode, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool logscalex: Helper.getSettingBool('default_graph.logscalex')
|
||||
/*!
|
||||
\qmlproperty bool Settings::showxgrad
|
||||
true if the x graduation should be shown, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool showxgrad: Helper.getSettingBool('default_graph.showxgrad')
|
||||
/*!
|
||||
\qmlproperty bool Settings::showygrad
|
||||
true if the y graduation should be shown, false otherwise.
|
||||
Provided from settings.
|
||||
\sa Settings
|
||||
*/
|
||||
property bool showygrad: Helper.getSettingBool('default_graph.showygrad')
|
||||
/*!
|
||||
\qmlproperty bool Settings::saveFilename
|
||||
Path of the currently opened file. Empty if no file is opened.
|
||||
*/
|
||||
property string saveFilename: ""
|
||||
|
||||
Column {
|
||||
spacing: 10
|
||||
width: parent.width
|
||||
bottomPadding: 20
|
||||
|
||||
Popup.FileDialog {
|
||||
id: fdiag
|
||||
onAccepted: {
|
||||
var filePath = fdiag.currentFile.toString().substr(7)
|
||||
settings.saveFilename = filePath
|
||||
if(exportMode) {
|
||||
Modules.IO.saveDiagram(filePath)
|
||||
} else {
|
||||
Modules.IO.loadDiagram(filePath)
|
||||
if(xAxisLabel.find(settings.xlabel) == -1) xAxisLabel.model.append({text: settings.xlabel})
|
||||
xAxisLabel.editText = settings.xlabel
|
||||
if(yAxisLabel.find(settings.ylabel) == -1) yAxisLabel.model.append({text: settings.ylabel})
|
||||
yAxisLabel.editText = settings.ylabel
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Zoom
|
||||
Setting.TextSetting {
|
||||
id: zoomX
|
||||
height: 30
|
||||
isDouble: true
|
||||
label: qsTr("X Zoom")
|
||||
min: 0.1
|
||||
icon: "settings/xzoom.svg"
|
||||
width: settings.settingWidth
|
||||
value: settings.xzoom.toFixed(2)
|
||||
onChanged: function(newValue) {
|
||||
settings.xzoom = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: zoomY
|
||||
height: 30
|
||||
isDouble: true
|
||||
min: 0.1
|
||||
label: qsTr("Y Zoom")
|
||||
icon: "settings/yzoom.svg"
|
||||
width: settings.settingWidth
|
||||
value: settings.yzoom.toFixed(2)
|
||||
onChanged: function(newValue) {
|
||||
settings.yzoom = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
// Positioning the graph
|
||||
Setting.TextSetting {
|
||||
id: minX
|
||||
height: 30
|
||||
isDouble: true
|
||||
min: -Infinity
|
||||
label: qsTr("Min X")
|
||||
icon: "settings/xmin.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.xmin
|
||||
onChanged: function(newValue) {
|
||||
if(parseFloat(maxX.value) > newValue) {
|
||||
settings.xmin = newValue
|
||||
settings.changed()
|
||||
} else {
|
||||
alert.show("Minimum x value must be inferior to maximum.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: maxY
|
||||
height: 30
|
||||
isDouble: true
|
||||
min: -Infinity
|
||||
label: qsTr("Max Y")
|
||||
icon: "settings/ymax.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.ymax
|
||||
onChanged: function(newValue) {
|
||||
settings.ymax = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: maxX
|
||||
height: 30
|
||||
isDouble: true
|
||||
min: -Infinity
|
||||
label: qsTr("Max X")
|
||||
icon: "settings/xmax.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: Modules.Canvas.px2x(canvas.width).toFixed(2)
|
||||
onChanged: function(xvaluemax) {
|
||||
if(xvaluemax > settings.xmin) {
|
||||
settings.xzoom = settings.xzoom * canvas.width/(Modules.Canvas.x2px(xvaluemax)) // Adjusting zoom to fit. = (end)/(px of current point)
|
||||
settings.changed()
|
||||
} else {
|
||||
alert.show("Maximum x value must be superior to minimum.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: minY
|
||||
height: 30
|
||||
isDouble: true
|
||||
min: -Infinity
|
||||
label: qsTr("Min Y")
|
||||
icon: "settings/ymin.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: Modules.Canvas.px2y(canvas.height).toFixed(2)
|
||||
onChanged: function(yvaluemin) {
|
||||
if(yvaluemin < settings.ymax) {
|
||||
settings.yzoom = settings.yzoom * canvas.height/(Modules.Canvas.y2px(yvaluemin)) // Adjusting zoom to fit. = (end)/(px of current point)
|
||||
settings.changed()
|
||||
} else {
|
||||
alert.show("Minimum y value must be inferior to maximum.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: xAxisStep
|
||||
height: 30
|
||||
category: "expression"
|
||||
label: qsTr("X Axis Step")
|
||||
icon: "settings/xaxisstep.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.xaxisstep
|
||||
visible: !settings.logscalex
|
||||
onChanged: function(newValue) {
|
||||
settings.xaxisstep = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: yAxisStep
|
||||
height: 30
|
||||
category: "expression"
|
||||
label: qsTr("Y Axis Step")
|
||||
icon: "settings/yaxisstep.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.yaxisstep
|
||||
onChanged: function(newValue) {
|
||||
settings.yaxisstep = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: lineWidth
|
||||
height: 30
|
||||
isDouble: true
|
||||
label: qsTr("Line width")
|
||||
min: 1
|
||||
icon: "settings/linewidth.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.linewidth
|
||||
onChanged: function(newValue) {
|
||||
settings.linewidth = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.TextSetting {
|
||||
id: textSize
|
||||
height: 30
|
||||
isDouble: true
|
||||
label: qsTr("Text size (px)")
|
||||
min: 1
|
||||
icon: "settings/textsize.svg"
|
||||
width: settings.settingWidth
|
||||
defValue: settings.textsize
|
||||
onChanged: function(newValue) {
|
||||
settings.textsize = newValue
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Setting.ComboBoxSetting {
|
||||
id: xAxisLabel
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
label: qsTr('X Label')
|
||||
icon: "settings/xlabel.svg"
|
||||
model: ListModel {
|
||||
ListElement { text: "" }
|
||||
ListElement { text: "x" }
|
||||
ListElement { text: "ω (rad/s)" }
|
||||
}
|
||||
currentIndex: find(settings.xlabel)
|
||||
editable: true
|
||||
onAccepted: function(){
|
||||
editText = JS.Utils.parseName(editText, false)
|
||||
if (find(editText) === -1) model.append({text: editText})
|
||||
settings.xlabel = editText
|
||||
settings.changed()
|
||||
}
|
||||
onActivated: function(selectedId) {
|
||||
settings.xlabel = model.get(selectedId).text
|
||||
settings.changed()
|
||||
}
|
||||
Component.onCompleted: editText = settings.xlabel
|
||||
}
|
||||
|
||||
Setting.ComboBoxSetting {
|
||||
id: yAxisLabel
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
label: qsTr('Y Label')
|
||||
icon: "settings/ylabel.svg"
|
||||
model: ListModel {
|
||||
ListElement { text: "" }
|
||||
ListElement { text: "y" }
|
||||
ListElement { text: "G (dB)" }
|
||||
ListElement { text: "φ (°)" }
|
||||
ListElement { text: "φ (deg)" }
|
||||
ListElement { text: "φ (rad)" }
|
||||
}
|
||||
currentIndex: find(settings.ylabel)
|
||||
editable: true
|
||||
onAccepted: function(){
|
||||
editText = JS.Utils.parseName(editText, false)
|
||||
if (find(editText) === -1) model.append({text: editText, yaxisstep: root.yaxisstep})
|
||||
settings.ylabel = editText
|
||||
settings.changed()
|
||||
}
|
||||
onActivated: function(selectedId) {
|
||||
settings.ylabel = model.get(selectedId).text
|
||||
settings.changed()
|
||||
}
|
||||
Component.onCompleted: editText = settings.ylabel
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: logScaleX
|
||||
checked: settings.logscalex
|
||||
text: qsTr('X Log scale')
|
||||
onClicked: {
|
||||
settings.logscalex = checked
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: showXGrad
|
||||
checked: settings.showxgrad
|
||||
text: qsTr('Show X graduation')
|
||||
onClicked: {
|
||||
settings.showxgrad = checked
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
CheckBox {
|
||||
id: showYGrad
|
||||
checked: settings.showygrad
|
||||
text: qsTr('Show Y graduation')
|
||||
onClicked: {
|
||||
settings.showygrad = checked
|
||||
settings.changed()
|
||||
}
|
||||
}
|
||||
|
||||
Button {
|
||||
id: copyToClipboard
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
text: qsTr("Copy to clipboard")
|
||||
icon.name: 'editcopy'
|
||||
onClicked: root.copyDiagramToClipboard()
|
||||
}
|
||||
|
||||
Button {
|
||||
id: saveDiagram
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
text: qsTr("Save plot")
|
||||
icon.name: 'document-save'
|
||||
onClicked: save()
|
||||
}
|
||||
|
||||
Button {
|
||||
id: saveDiagramAs
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
text: qsTr("Save plot as")
|
||||
icon.name: 'document-save-as'
|
||||
onClicked: saveAs()
|
||||
}
|
||||
|
||||
Button {
|
||||
id: loadDiagram
|
||||
height: 30
|
||||
width: settings.settingWidth
|
||||
text: qsTr("Load plot")
|
||||
icon.name: 'document-open'
|
||||
onClicked: load()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogGraphCanvas::save()
|
||||
Saves the current canvas in the opened file. If no file is currently opened, prompts to pick a save location.
|
||||
*/
|
||||
function save() {
|
||||
if(settings.saveFilename == "") {
|
||||
saveAs()
|
||||
} else {
|
||||
Modules.IO.saveDiagram(settings.saveFilename)
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogGraphCanvas::saveAs()
|
||||
Prompts the user to pick a new save location.
|
||||
*/
|
||||
function saveAs() {
|
||||
fdiag.exportMode = true
|
||||
fdiag.open()
|
||||
}
|
||||
|
||||
/*!
|
||||
\qmlmethod void LogGraphCanvas::saveAs()
|
||||
Prompts the user to pick a diagram to load.
|
||||
*/
|
||||
function load() {
|
||||
fdiag.exportMode = false
|
||||
fdiag.open()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,158 @@
|
|||
/**
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
|
||||
/*!
|
||||
\qmltype ViewPositionChangeOverlay
|
||||
\inqmlmodule eu.ad5001.LogarithmPlotter
|
||||
\brief Overlay used allow the user to drag the canvas' position and change the zoom level.
|
||||
|
||||
Provides an overlay over the canvas that detects mouse movements and changes the canvas view position
|
||||
accordingly by providing new signals.
|
||||
|
||||
\sa LogarithmPlotter, LogGraphCanvas, Settings
|
||||
*/
|
||||
Item {
|
||||
id: viewChangeRoot
|
||||
visible: true
|
||||
clip: true
|
||||
|
||||
/*!
|
||||
\qmlsignal ViewPositionChangeOverlay::positionChanged(int deltaX, int deltaY)
|
||||
|
||||
Emmited when the user dragged the canvas and the view should be refreshed.
|
||||
The corresponding handler is \c onPositionChanged.
|
||||
*/
|
||||
signal positionChanged(int deltaX, int deltaY)
|
||||
|
||||
/*!
|
||||
\qmlsignal ViewPositionChangeOverlay::beginPositionChange()
|
||||
|
||||
Emmited when the user starts dragging the canvas.
|
||||
The corresponding handler is \c onBeginPositionChange.
|
||||
*/
|
||||
signal beginPositionChange()
|
||||
|
||||
/*!
|
||||
\qmlsignal ViewPositionChangeOverlay::endPositionChange(int deltaX, int deltaY)
|
||||
|
||||
Emmited when the user stops dragging the canvas.
|
||||
The corresponding handler is \c onEndPositionChange.
|
||||
*/
|
||||
signal endPositionChange(int deltaX, int deltaY)
|
||||
|
||||
/*!
|
||||
\qmlproperty var ViewPositionChangeOverlay::canvas
|
||||
LogGraphCanvas instance.
|
||||
*/
|
||||
property var canvas
|
||||
/*!
|
||||
\qmlproperty var ViewPositionChangeOverlay::settingsInstance
|
||||
Settings instance.
|
||||
*/
|
||||
property var settingsInstance
|
||||
/*!
|
||||
\qmlproperty int ViewPositionChangeOverlay::prevX
|
||||
The x coordinate (on the mousearea) at the last change of the canvas position.
|
||||
*/
|
||||
property int prevX
|
||||
/*!
|
||||
\qmlproperty int ViewPositionChangeOverlay::prevY
|
||||
The y coordinate (on the mousearea) at the last change of the canvas position.
|
||||
*/
|
||||
property int prevY
|
||||
/*!
|
||||
\qmlproperty double ViewPositionChangeOverlay::baseZoomMultiplier
|
||||
How much should the zoom be mutliplied/scrolled by for one scroll step (120° on the mouse wheel).
|
||||
*/
|
||||
property double baseZoomMultiplier: 0.1
|
||||
|
||||
MouseArea {
|
||||
id: dragArea
|
||||
anchors.fill: parent
|
||||
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
|
||||
property int positionChangeTimer: 0
|
||||
|
||||
function updatePosition(deltaX, deltaY) {
|
||||
const unauthorized = [NaN, Infinity, -Infinity]
|
||||
const xmin = (Modules.Canvas.px2x(Modules.Canvas.x2px(settingsInstance.xmin)-deltaX))
|
||||
const ymax = settingsInstance.ymax + deltaY/canvas.yzoom
|
||||
if(!unauthorized.includes(xmin))
|
||||
settingsInstance.xmin = xmin
|
||||
if(!unauthorized.includes(ymax))
|
||||
settingsInstance.ymax = ymax.toFixed(4)
|
||||
settingsInstance.changed()
|
||||
parent.positionChanged(deltaX, deltaY)
|
||||
|
||||
}
|
||||
|
||||
onPressed: function(mouse) {
|
||||
prevX = mouse.x
|
||||
prevY = mouse.y
|
||||
parent.beginPositionChange()
|
||||
}
|
||||
|
||||
onPositionChanged: function(mouse) {
|
||||
positionChangeTimer++
|
||||
if(positionChangeTimer == 3) {
|
||||
let deltaX = mouse.x - prevX
|
||||
let deltaY = mouse.y - prevY
|
||||
updatePosition(deltaX, deltaY)
|
||||
prevX = mouse.x
|
||||
prevY = mouse.y
|
||||
positionChangeTimer = 0
|
||||
}
|
||||
}
|
||||
|
||||
onReleased: function(mouse) {
|
||||
let deltaX = mouse.x - prevX
|
||||
let deltaY = mouse.y - prevY
|
||||
updatePosition(deltaX, deltaY)
|
||||
parent.endPositionChange(deltaX, deltaY)
|
||||
}
|
||||
|
||||
onWheel: function(wheel) {
|
||||
// Scrolling
|
||||
let scrollSteps = Math.round(wheel.angleDelta.y / 120)
|
||||
let zoomMultiplier = Math.pow(1+baseZoomMultiplier, Math.abs(scrollSteps))
|
||||
// Avoid floating-point rounding errors by removing the zoom *after*
|
||||
let xZoomDelta = (settingsInstance.xzoom*zoomMultiplier - settingsInstance.xzoom)
|
||||
let yZoomDelta = (settingsInstance.yzoom*zoomMultiplier - settingsInstance.yzoom)
|
||||
if(scrollSteps < 0) { // Negative scroll
|
||||
xZoomDelta *= -1
|
||||
yZoomDelta *= -1
|
||||
}
|
||||
let newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(0)
|
||||
let newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(0)
|
||||
// Check if we need to have more precision
|
||||
if(newXZoom < 10)
|
||||
newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(4)
|
||||
if(newYZoom < 10)
|
||||
newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(4)
|
||||
if(newXZoom > 0.5)
|
||||
settingsInstance.xzoom = newXZoom
|
||||
if(newYZoom > 0.5)
|
||||
settingsInstance.yzoom = newYZoom
|
||||
settingsInstance.changed()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
module eu.ad5001.LogarithmPlotter
|
||||
|
||||
Settings 1.0 Settings.qml
|
||||
Alert 1.0 Alert.qml
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5c6e05b1e4fe20f5ad9b4e427dd91ae305fd26c6
|
1
runtime-pyside6/LogarithmPlotter/util/__init__.py
Normal file
1
runtime-pyside6/LogarithmPlotter/util/__init__.py
Normal file
|
@ -0,0 +1 @@
|
|||
|
128
runtime-pyside6/LogarithmPlotter/util/config.py
Normal file
128
runtime-pyside6/LogarithmPlotter/util/config.py
Normal file
|
@ -0,0 +1,128 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from os import path, environ, makedirs
|
||||
from platform import system
|
||||
from json import load, dumps
|
||||
from PySide6.QtCore import QLocale, QTranslator
|
||||
|
||||
DEFAULT_SETTINGS = {
|
||||
"check_for_updates": True,
|
||||
"reset_redo_stack": True,
|
||||
"last_install_greet": "0",
|
||||
"enable_latex": False,
|
||||
"expression_editor": {
|
||||
"autoclose": True,
|
||||
"colorize": True,
|
||||
"color_scheme": 0,
|
||||
},
|
||||
"autocompletion": {
|
||||
"enabled": True
|
||||
},
|
||||
"default_graph": {
|
||||
"xzoom": 100,
|
||||
"yzoom": 10,
|
||||
"xmin": 5 / 10,
|
||||
"ymax": 25,
|
||||
"xaxisstep": "4",
|
||||
"yaxisstep": "4",
|
||||
"xlabel": "",
|
||||
"ylabel": "",
|
||||
"linewidth": 1,
|
||||
"textsize": 18,
|
||||
"logscalex": True,
|
||||
"showxgrad": True,
|
||||
"showygrad": True
|
||||
}
|
||||
}
|
||||
|
||||
# Create config directory
|
||||
CONFIG_PATH = {
|
||||
"Linux": path.join(environ["XDG_CONFIG_HOME"], "LogarithmPlotter")
|
||||
if "XDG_CONFIG_HOME" in environ else
|
||||
path.join(path.expanduser("~"), ".config", "LogarithmPlotter"),
|
||||
"Windows": path.join(path.expandvars('%APPDATA%'), "LogarithmPlotter", "config"),
|
||||
"Darwin": path.join(path.expanduser("~"), "Library", "Application Support", "LogarithmPlotter"),
|
||||
}[system()]
|
||||
|
||||
CONFIG_FILE = path.join(CONFIG_PATH, "config.json")
|
||||
|
||||
current_config = DEFAULT_SETTINGS
|
||||
|
||||
|
||||
class UnknownNamespaceError(Exception): pass
|
||||
|
||||
|
||||
def init():
|
||||
"""
|
||||
Initializes the config and loads all possible settings from the file if needs be.
|
||||
"""
|
||||
global current_config
|
||||
current_config = DEFAULT_SETTINGS
|
||||
makedirs(CONFIG_PATH, exist_ok=True)
|
||||
|
||||
if path.exists(CONFIG_FILE):
|
||||
cfg_data = load(open(CONFIG_FILE, 'r', -1, 'utf8'))
|
||||
for setting_name in cfg_data:
|
||||
if type(cfg_data[setting_name]) == dict:
|
||||
for setting_name2 in cfg_data[setting_name]:
|
||||
setSetting(setting_name + "." + setting_name2, cfg_data[setting_name][setting_name2])
|
||||
else:
|
||||
setSetting(setting_name, cfg_data[setting_name])
|
||||
|
||||
|
||||
def save(file=CONFIG_FILE):
|
||||
"""
|
||||
Saves the config to the path.
|
||||
"""
|
||||
write_file = open(file, 'w', -1, 'utf8')
|
||||
write_file.write(dumps(current_config))
|
||||
write_file.close()
|
||||
|
||||
|
||||
def getSetting(namespace):
|
||||
"""
|
||||
Returns a setting from a namespace.
|
||||
E.g: if the config is {"test": {"foo": 1}}, you can access the "foo" setting
|
||||
by using the "test.foo" namespace.
|
||||
"""
|
||||
names = namespace.split(".")
|
||||
setting = current_config
|
||||
for name in names:
|
||||
if name in setting:
|
||||
setting = setting[name]
|
||||
else:
|
||||
# return namespace # Return original name
|
||||
raise UnknownNamespaceError(f"Setting {namespace} doesn't exist. Debug: {setting}, {name}")
|
||||
return setting
|
||||
|
||||
|
||||
def setSetting(namespace, data):
|
||||
"""
|
||||
Sets a setting at a namespace with data.
|
||||
E.g: if the config is {"test": {"foo": 1}}, you can access the "foo" setting
|
||||
by using the "test.foo" namespace.
|
||||
"""
|
||||
names = namespace.split(".")
|
||||
setting = current_config
|
||||
for name in names[:-1]:
|
||||
if name in setting:
|
||||
setting = setting[name]
|
||||
else:
|
||||
raise UnknownNamespaceError(f"Setting {namespace} doesn't exist. Debug: {setting}, {name}")
|
||||
setting[names[-1]] = data
|
102
runtime-pyside6/LogarithmPlotter/util/debug.py
Normal file
102
runtime-pyside6/LogarithmPlotter/util/debug.py
Normal file
|
@ -0,0 +1,102 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide6.QtCore import QtMsgType, qInstallMessageHandler, QMessageLogContext
|
||||
from math import ceil, log10
|
||||
from os import path
|
||||
|
||||
CURRENT_PATH = path.dirname(path.realpath(__file__))
|
||||
SOURCEMAP_PATH = path.realpath(f"{CURRENT_PATH}/../qml/eu/ad5001/LogarithmPlotter/js/index.mjs.map")
|
||||
SOURCEMAP_INDEX = None
|
||||
|
||||
|
||||
class LOG_COLORS:
|
||||
GRAY = "\033[90m"
|
||||
BLUE = "\033[94m"
|
||||
ORANGE = "\033[38;5;166m"
|
||||
RED = "\033[38;5;204m"
|
||||
INVERT = "\033[7m"
|
||||
RESET_INVERT = "\033[27m"
|
||||
RESET = "\033[0m"
|
||||
|
||||
|
||||
MODES = {
|
||||
QtMsgType.QtInfoMsg: ['info', LOG_COLORS.BLUE],
|
||||
QtMsgType.QtWarningMsg: ['warning', LOG_COLORS.ORANGE],
|
||||
QtMsgType.QtCriticalMsg: ['critical', LOG_COLORS.RED],
|
||||
QtMsgType.QtFatalMsg: ['critical', LOG_COLORS.RED]
|
||||
}
|
||||
|
||||
DEFAULT_MODE = ['debug', LOG_COLORS.GRAY]
|
||||
|
||||
|
||||
def map_javascript_source(source_file: str, line: str) -> tuple[str, str]:
|
||||
"""
|
||||
Maps a line from the compiled javascript to its source.
|
||||
"""
|
||||
try:
|
||||
if SOURCEMAP_INDEX is not None:
|
||||
token = SOURCEMAP_INDEX.lookup(line, 20)
|
||||
source_file = token.src.split("../")[-1]
|
||||
line = token.src_line
|
||||
except IndexError:
|
||||
pass # Unable to find source, leave as is.
|
||||
return source_file, line
|
||||
|
||||
|
||||
def create_log_terminal_message(mode: QtMsgType, context: QMessageLogContext, message: str):
|
||||
"""
|
||||
Parses a qt log message and returns it.
|
||||
"""
|
||||
mode = MODES[mode] if mode in MODES else DEFAULT_MODE
|
||||
line = context.line
|
||||
source_file = context.file
|
||||
# Remove source and line from message
|
||||
if source_file is not None:
|
||||
if message.startswith(source_file):
|
||||
message = message[len(source_file) + 1:]
|
||||
source_file = "LogarithmPlotter/qml/" + source_file.split("/qml/")[-1] # We're only interested in that part.
|
||||
if line is not None and message.startswith(str(line)):
|
||||
line_length = ceil(log10((line + 1) if line > 0 else 1))
|
||||
message = message[line_length + 2:]
|
||||
# Check MJS
|
||||
if line is not None and source_file is not None and source_file.endswith("index.mjs"):
|
||||
source_file, line = map_javascript_source(source_file, line)
|
||||
prefix = f"{LOG_COLORS.INVERT}{mode[1]}[{mode[0].upper()}]{LOG_COLORS.RESET_INVERT}"
|
||||
message = message + LOG_COLORS.RESET
|
||||
context = f"{context.function} at {source_file}:{line}"
|
||||
return f"{prefix} {message} ({context})"
|
||||
|
||||
|
||||
def log_qt_debug(mode: QtMsgType, context: QMessageLogContext, message: str):
|
||||
"""
|
||||
Parses and renders qt log messages.
|
||||
"""
|
||||
print(create_log_terminal_message(mode, context, message))
|
||||
|
||||
|
||||
def setup():
|
||||
global SOURCEMAP_INDEX
|
||||
try:
|
||||
with open(SOURCEMAP_PATH, "r") as f:
|
||||
from sourcemap import loads
|
||||
SOURCEMAP_INDEX = loads(f.read())
|
||||
except Exception as e:
|
||||
log_qt_debug(QtMsgType.QtWarningMsg, QMessageLogContext(),
|
||||
f"Could not setup JavaScript source mapper in logs: {repr(e)}")
|
||||
qInstallMessageHandler(log_qt_debug)
|
181
runtime-pyside6/LogarithmPlotter/util/helper.py
Normal file
181
runtime-pyside6/LogarithmPlotter/util/helper.py
Normal file
|
@ -0,0 +1,181 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide6.QtWidgets import QMessageBox, QApplication
|
||||
from PySide6.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, Slot, QCoreApplication
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
from PySide6.QtGui import QImage
|
||||
from PySide6 import __version__ as PySide6_version
|
||||
|
||||
from os import chdir, path
|
||||
from json import loads
|
||||
from sys import version as sys_version, argv
|
||||
from urllib.request import urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
|
||||
from LogarithmPlotter import __VERSION__
|
||||
from LogarithmPlotter.util import config
|
||||
|
||||
SHOW_GUI_MESSAGES = "--test-build" not in argv
|
||||
CHANGELOG_VERSION = __VERSION__
|
||||
|
||||
|
||||
class InvalidFileException(Exception): pass
|
||||
|
||||
def show_message(msg: str) -> None:
|
||||
"""
|
||||
Shows a GUI message if GUI messages are enabled
|
||||
"""
|
||||
if SHOW_GUI_MESSAGES:
|
||||
QMessageBox.warning(None, "LogarithmPlotter", msg, QMessageBox.OK)
|
||||
else:
|
||||
raise InvalidFileException(msg)
|
||||
|
||||
|
||||
|
||||
class ChangelogFetcher(QRunnable):
|
||||
def __init__(self, helper):
|
||||
QRunnable.__init__(self)
|
||||
self.helper = helper
|
||||
|
||||
def run(self):
|
||||
msg_text = "Unknown changelog error."
|
||||
try:
|
||||
# Fetching version
|
||||
r = urlopen("https://api.ad5001.eu/changelog/logarithmplotter/?version=" + CHANGELOG_VERSION)
|
||||
lines = r.readlines()
|
||||
r.close()
|
||||
msg_text = "".join(map(lambda x: x.decode('utf-8'), lines)).strip()
|
||||
except HTTPError as e:
|
||||
msg_text = QCoreApplication.translate("changelog", "Could not fetch changelog: Server error {}.").format(
|
||||
str(e.code))
|
||||
except URLError as e:
|
||||
msg_text = QCoreApplication.translate("changelog", "Could not fetch update: {}.").format(str(e.reason))
|
||||
self.helper.changelogFetched.emit(msg_text)
|
||||
|
||||
|
||||
class Helper(QObject):
|
||||
changelogFetched = Signal(str)
|
||||
|
||||
def __init__(self, cwd: str, tmpfile: str):
|
||||
QObject.__init__(self)
|
||||
self.cwd = cwd
|
||||
self.tmpfile = tmpfile
|
||||
|
||||
@Slot(str, str)
|
||||
def write(self, filename, filedata):
|
||||
chdir(self.cwd)
|
||||
if path.exists(path.dirname(path.realpath(filename))):
|
||||
if filename.split(".")[-1] == "lpf":
|
||||
# Add header to file
|
||||
filedata = "LPFv1" + filedata
|
||||
f = open(path.realpath(filename), 'w', -1, 'utf8')
|
||||
f.write(filedata)
|
||||
f.close()
|
||||
chdir(path.dirname(path.realpath(__file__)))
|
||||
|
||||
@Slot(str, result=str)
|
||||
def load(self, filename):
|
||||
chdir(self.cwd)
|
||||
data = '{}'
|
||||
if path.exists(path.realpath(filename)):
|
||||
f = open(path.realpath(filename), 'r', -1, 'utf8')
|
||||
data = f.read()
|
||||
f.close()
|
||||
try:
|
||||
if data[:5] == "LPFv1":
|
||||
# V1 version of the file
|
||||
data = data[5:]
|
||||
elif data[:3] == "LPF":
|
||||
# More recent version of LogarithmPlotter file, but incompatible with the current format
|
||||
msg = QCoreApplication.translate('main',
|
||||
"This file was created by a more recent version of LogarithmPlotter and cannot be backloaded in LogarithmPlotter v{}.\nPlease update LogarithmPlotter to open this file.")
|
||||
raise InvalidFileException(msg.format(__VERSION__))
|
||||
else:
|
||||
raise InvalidFileException("Invalid LogarithmPlotter file.")
|
||||
except InvalidFileException as e: # If file can't be loaded
|
||||
msg = QCoreApplication.translate('main', 'Could not open file "{}":\n{}')
|
||||
show_message(msg.format(filename, e)) # Cannot parse file
|
||||
else:
|
||||
msg = QCoreApplication.translate('main', 'Could not open file: "{}"\nFile does not exist.')
|
||||
show_message(msg.format(filename)) # Cannot parse file
|
||||
try:
|
||||
chdir(path.dirname(path.realpath(__file__)))
|
||||
except NotADirectoryError as e:
|
||||
# Triggered on bundled versions of MacOS when it shouldn't. Prevents opening files.
|
||||
# See more at https://git.ad5001.eu/Ad5001/LogarithmPlotter/issues/1
|
||||
pass
|
||||
return data
|
||||
|
||||
@Slot(result=str)
|
||||
def gettmpfile(self):
|
||||
return self.tmpfile
|
||||
|
||||
@Slot()
|
||||
def copyImageToClipboard(self):
|
||||
clipboard = QApplication.clipboard()
|
||||
clipboard.setImage(QImage(self.tmpfile))
|
||||
|
||||
@Slot(result=str)
|
||||
def getVersion(self):
|
||||
return __VERSION__
|
||||
|
||||
@Slot(str, result=str)
|
||||
def getSetting(self, namespace):
|
||||
return str(config.getSetting(namespace))
|
||||
|
||||
@Slot(str, result=float)
|
||||
def getSettingInt(self, namespace):
|
||||
return float(config.getSetting(namespace))
|
||||
|
||||
@Slot(str, result=bool)
|
||||
def getSettingBool(self, namespace):
|
||||
return bool(config.getSetting(namespace))
|
||||
|
||||
@Slot(str, str)
|
||||
def setSetting(self, namespace, value):
|
||||
return config.setSetting(namespace, str(value))
|
||||
|
||||
@Slot(str, bool)
|
||||
def setSettingBool(self, namespace, value):
|
||||
return config.setSetting(namespace, bool(value))
|
||||
|
||||
@Slot(str, float)
|
||||
def setSettingInt(self, namespace, value):
|
||||
return config.setSetting(namespace, float(value))
|
||||
|
||||
@Slot(result=str)
|
||||
def getDebugInfos(self):
|
||||
"""
|
||||
Returns the version info about Qt, PySide6 & Python
|
||||
"""
|
||||
msg = QCoreApplication.translate('main', "Built with PySide6 (Qt) v{} and python v{}")
|
||||
return msg.format(PySide6_version, sys_version.split("\n")[0])
|
||||
|
||||
@Slot()
|
||||
def fetchChangelog(self):
|
||||
changelog_cache_path = path.join(path.dirname(path.realpath(__file__)), "CHANGELOG.md")
|
||||
if path.exists(changelog_cache_path):
|
||||
# We have a cached version of the changelog, for env that don't have access to the internet.
|
||||
f = open(changelog_cache_path);
|
||||
self.changelogFetched.emit("".join(f.readlines()).strip())
|
||||
f.close()
|
||||
else:
|
||||
# Fetch it from the internet.
|
||||
runnable = ChangelogFetcher(self)
|
||||
QThreadPool.globalInstance().start(runnable)
|
106
runtime-pyside6/LogarithmPlotter/util/js.py
Normal file
106
runtime-pyside6/LogarithmPlotter/util/js.py
Normal file
|
@ -0,0 +1,106 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from re import Pattern
|
||||
from PySide6.QtCore import QMetaObject, QObject, QDateTime
|
||||
from PySide6.QtQml import QJSValue
|
||||
|
||||
class InvalidAttributeValueException(Exception): pass
|
||||
class NotAPrimitiveException(Exception): pass
|
||||
|
||||
class Function: pass
|
||||
class URL: pass
|
||||
|
||||
class PyJSValue:
|
||||
"""
|
||||
Wrapper to provide easy way to interact with JavaScript values in Python directly.
|
||||
"""
|
||||
|
||||
def __init__(self, js_value: QJSValue, parent: QJSValue = None):
|
||||
self.qjs_value = js_value
|
||||
self._parent = parent
|
||||
|
||||
def __getattr__(self, item):
|
||||
return PyJSValue(self.qjs_value.property(item), self.qjs_value)
|
||||
|
||||
def __setattr__(self, key, value):
|
||||
if key in ['qjs_value', '_parent']:
|
||||
# Fallback
|
||||
object.__setattr__(self, key, value)
|
||||
elif isinstance(value, PyJSValue):
|
||||
# Set property
|
||||
self.qjs_value.setProperty(key, value.qjs_value)
|
||||
elif isinstance(value, QJSValue):
|
||||
self.qjs_value.setProperty(key, value)
|
||||
elif type(value) in (int, float, str, bool):
|
||||
self.qjs_value.setProperty(key, QJSValue(value))
|
||||
else:
|
||||
raise InvalidAttributeValueException(f"Invalid value {value} of type {type(value)} being set to {key}.")
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, PyJSValue):
|
||||
return self.qjs_value.strictlyEquals(other.qjs_value)
|
||||
elif isinstance(other, QJSValue):
|
||||
return self.qjs_value.strictlyEquals(other)
|
||||
elif type(other) in (int, float, str, bool):
|
||||
return self.qjs_value.strictlyEquals(QJSValue(other))
|
||||
else:
|
||||
return False
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
value = None
|
||||
if self.qjs_value.isCallable():
|
||||
if self._parent is None:
|
||||
value = self.qjs_value.call(args)
|
||||
else:
|
||||
value = self.qjs_value.callWithInstance(self._parent, args)
|
||||
else:
|
||||
raise InvalidAttributeValueException('Cannot call non-function JS value.')
|
||||
if isinstance(value, QJSValue):
|
||||
value = PyJSValue(value)
|
||||
return value
|
||||
|
||||
def type(self) -> any:
|
||||
matcher = [
|
||||
(lambda: self.qjs_value.isArray(), list),
|
||||
(lambda: self.qjs_value.isBool(), bool),
|
||||
(lambda: self.qjs_value.isCallable(), Function),
|
||||
(lambda: self.qjs_value.isDate(), QDateTime),
|
||||
(lambda: self.qjs_value.isError(), Exception),
|
||||
(lambda: self.qjs_value.isNull(), None),
|
||||
(lambda: self.qjs_value.isNumber(), float),
|
||||
(lambda: self.qjs_value.isQMetaObject(), QMetaObject),
|
||||
(lambda: self.qjs_value.isQObject(), QObject),
|
||||
(lambda: self.qjs_value.isRegExp(), Pattern),
|
||||
(lambda: self.qjs_value.isUndefined(), None),
|
||||
(lambda: self.qjs_value.isUrl(), URL),
|
||||
(lambda: self.qjs_value.isString(), str),
|
||||
(lambda: self.qjs_value.isObject(), object),
|
||||
]
|
||||
for (test, value) in matcher:
|
||||
if test():
|
||||
return value
|
||||
return None
|
||||
|
||||
def primitive(self):
|
||||
"""
|
||||
Returns the pythonic value of the given primitive data.
|
||||
Raises a NotAPrimitiveException() if this JS value is not a primitive.
|
||||
"""
|
||||
if self.type() not in [bool, float, str, None]:
|
||||
raise NotAPrimitiveException()
|
||||
return self.qjs_value.toPrimitive().toVariant()
|
230
runtime-pyside6/LogarithmPlotter/util/latex.py
Normal file
230
runtime-pyside6/LogarithmPlotter/util/latex.py
Normal file
|
@ -0,0 +1,230 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide6.QtCore import QObject, Slot, Property, QCoreApplication
|
||||
from PySide6.QtGui import QImage, QColor
|
||||
from PySide6.QtWidgets import QMessageBox
|
||||
|
||||
from os import path, remove
|
||||
from string import Template
|
||||
from tempfile import TemporaryDirectory
|
||||
from subprocess import Popen, TimeoutExpired, PIPE
|
||||
from shutil import which
|
||||
from sys import argv
|
||||
|
||||
"""
|
||||
Searches for a valid Latex and DVIPNG (http://savannah.nongnu.org/projects/dvipng/)
|
||||
installation and collects the binary path in the DVIPNG_PATH variable.
|
||||
If not found, it will send an alert to the user.
|
||||
"""
|
||||
LATEX_PATH = which('latex')
|
||||
DVIPNG_PATH = which('dvipng')
|
||||
PACKAGES = ["calligra", "amsfonts", "inputenc"]
|
||||
SHOW_GUI_MESSAGES = "--test-build" not in argv
|
||||
|
||||
DEFAULT_LATEX_DOC = Template(r"""
|
||||
\documentclass[]{minimal}
|
||||
\usepackage[utf8]{inputenc}
|
||||
\usepackage{calligra}
|
||||
\usepackage{amsfonts}
|
||||
|
||||
\title{}
|
||||
\author{}
|
||||
|
||||
\begin{document}
|
||||
|
||||
$$$$ $markup $$$$
|
||||
|
||||
\end{document}
|
||||
""")
|
||||
|
||||
|
||||
def show_message(msg: str) -> None:
|
||||
"""
|
||||
Shows a GUI message if GUI messages are enabled
|
||||
"""
|
||||
if SHOW_GUI_MESSAGES:
|
||||
QMessageBox.warning(None, "LogarithmPlotter - Latex", msg)
|
||||
|
||||
|
||||
class MissingPackageException(Exception): pass
|
||||
|
||||
|
||||
class RenderError(Exception): pass
|
||||
|
||||
|
||||
class Latex(QObject):
|
||||
"""
|
||||
Base class to convert Latex equations into PNG images with custom font color and size.
|
||||
It doesn't have any python dependency, but requires a working latex installation and
|
||||
dvipng to be installed on the system.
|
||||
"""
|
||||
|
||||
def __init__(self, tempdir: TemporaryDirectory):
|
||||
QObject.__init__(self)
|
||||
self.tempdir = tempdir
|
||||
|
||||
@Property(bool)
|
||||
def latexSupported(self) -> bool:
|
||||
return LATEX_PATH is not None and DVIPNG_PATH is not None
|
||||
|
||||
@Slot(result=bool)
|
||||
def checkLatexInstallation(self) -> bool:
|
||||
"""
|
||||
Checks if the current latex installation is valid.
|
||||
"""
|
||||
valid_install = True
|
||||
if LATEX_PATH is None:
|
||||
print("No Latex installation found.")
|
||||
msg = QCoreApplication.translate("latex",
|
||||
"No Latex installation found.\nIf you already have a latex distribution installed, make sure it's installed on your path.\nOtherwise, you can download a Latex distribution like TeX Live at https://tug.org/texlive/.")
|
||||
show_message(msg)
|
||||
valid_install = False
|
||||
elif DVIPNG_PATH is None:
|
||||
print("DVIPNG not found.")
|
||||
msg = QCoreApplication.translate("latex",
|
||||
"DVIPNG was not found. Make sure you include it from your Latex distribution.")
|
||||
show_message(msg)
|
||||
valid_install = False
|
||||
else:
|
||||
try:
|
||||
self.render("", 14, QColor(0, 0, 0, 255))
|
||||
except MissingPackageException:
|
||||
valid_install = False # Should have sent an error message if failed to render
|
||||
return valid_install
|
||||
|
||||
@Slot(str, float, QColor, result=str)
|
||||
def render(self, latex_markup: str, font_size: float, color: QColor) -> str:
|
||||
"""
|
||||
Prepares and renders a latex string into a png file.
|
||||
"""
|
||||
markup_hash, export_path = self.create_export_path(latex_markup, font_size, color)
|
||||
if self.latexSupported and not path.exists(export_path + ".png"):
|
||||
print("Rendering", latex_markup, export_path)
|
||||
# Generating file
|
||||
latex_path = path.join(self.tempdir.name, str(markup_hash))
|
||||
# If the formula is just recolored or the font is just changed, no need to recreate the DVI.
|
||||
if not path.exists(latex_path + ".dvi"):
|
||||
self.create_latex_doc(latex_path, latex_markup)
|
||||
self.convert_latex_to_dvi(latex_path)
|
||||
self.cleanup(latex_path)
|
||||
# Creating four pictures of different sizes to better handle dpi.
|
||||
self.convert_dvi_to_png(latex_path, export_path, font_size, color)
|
||||
# self.convert_dvi_to_png(latex_path, export_path+"@2", font_size*2, color)
|
||||
# self.convert_dvi_to_png(latex_path, export_path+"@3", font_size*3, color)
|
||||
# self.convert_dvi_to_png(latex_path, export_path+"@4", font_size*4, color)
|
||||
img = QImage(export_path)
|
||||
# Small hack, not very optimized since we load the image twice, but you can't pass a QImage to QML and expect it to be loaded
|
||||
return f'{export_path}.png,{img.width()},{img.height()}'
|
||||
|
||||
@Slot(str, float, QColor, result=str)
|
||||
def findPrerendered(self, latex_markup: str, font_size: float, color: QColor) -> str:
|
||||
"""
|
||||
Finds a prerendered image and returns its data if possible, and an empty string if not.
|
||||
"""
|
||||
markup_hash, export_path = self.create_export_path(latex_markup, font_size, color)
|
||||
data = ""
|
||||
if path.exists(export_path + ".png"):
|
||||
img = QImage(export_path)
|
||||
data = f'{export_path}.png,{img.width()},{img.height()}'
|
||||
return data
|
||||
|
||||
def create_export_path(self, latex_markup: str, font_size: float, color: QColor):
|
||||
"""
|
||||
Standardizes export path for renders.
|
||||
"""
|
||||
markup_hash = "render" + str(hash(latex_markup))
|
||||
export_path = path.join(self.tempdir.name, f'{markup_hash}_{int(font_size)}_{color.rgb()}')
|
||||
return markup_hash, export_path
|
||||
|
||||
def create_latex_doc(self, export_path: str, latex_markup: str):
|
||||
"""
|
||||
Creates a temporary latex document with base file_hash as file name and a given expression markup latex_markup.
|
||||
"""
|
||||
f = open(export_path + ".tex", 'w')
|
||||
f.write(DEFAULT_LATEX_DOC.substitute(markup=latex_markup))
|
||||
f.close()
|
||||
|
||||
def convert_latex_to_dvi(self, export_path: str):
|
||||
"""
|
||||
Converts a TEX file to a DVI file.
|
||||
"""
|
||||
self.run([
|
||||
LATEX_PATH,
|
||||
export_path + ".tex"
|
||||
])
|
||||
|
||||
def convert_dvi_to_png(self, dvi_path: str, export_path: str, font_size: float, color: QColor):
|
||||
"""
|
||||
Converts a DVI file to a PNG file.
|
||||
Documentation: https://linux.die.net/man/1/dvipng
|
||||
"""
|
||||
fg = color.convertTo(QColor.Rgb)
|
||||
fg = f'rgb {fg.redF()} {fg.greenF()} {fg.blueF()}'
|
||||
depth = int(font_size * 72.27 / 100) * 10
|
||||
self.run([
|
||||
DVIPNG_PATH,
|
||||
'-T', 'tight', # Make sure image borders are as tight around the equation as possible to avoid blank space.
|
||||
'--truecolor', # Make sure it's rendered in 24 bit colors.
|
||||
'-D', f'{depth}', # Depth of the image
|
||||
'-bg', 'Transparent', # Transparent background
|
||||
'-fg', f'{fg}', # Foreground of the wanted color.
|
||||
f'{dvi_path}.dvi', # Input file
|
||||
'-o', f'{export_path}.png', # Output file
|
||||
])
|
||||
|
||||
def run(self, process: list):
|
||||
"""
|
||||
Runs a subprocess and handles exceptions and messages them to the user.
|
||||
"""
|
||||
cmd = " ".join(process)
|
||||
proc = Popen(process, stdout=PIPE, stderr=PIPE, cwd=self.tempdir.name)
|
||||
try:
|
||||
out, err = proc.communicate(timeout=2) # 2 seconds is already FAR too long.
|
||||
if proc.returncode != 0:
|
||||
# Process errored
|
||||
output = str(out, 'utf8') + "\n" + str(err, 'utf8')
|
||||
msg = QCoreApplication.translate("latex",
|
||||
"An exception occured within the creation of the latex formula.\nProcess '{}' ended with a non-zero return code {}:\n\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
||||
show_message(msg.format(cmd, proc.returncode, output))
|
||||
raise RenderError(
|
||||
f"{cmd} process exited with return code {str(proc.returncode)}:\n{str(out, 'utf8')}\n{str(err, 'utf8')}")
|
||||
except TimeoutExpired:
|
||||
# Process timed out
|
||||
proc.kill()
|
||||
out, err = proc.communicate()
|
||||
output = str(out, 'utf8') + "\n" + str(err, 'utf8')
|
||||
if 'not found' in output:
|
||||
for pkg in PACKAGES:
|
||||
if f'{pkg}.sty' in output:
|
||||
# Package missing.
|
||||
msg = QCoreApplication.translate("latex",
|
||||
"Your LaTeX installation does not include some required packages:\n\n- {} (https://ctan.org/pkg/{})\n\nMake sure said package is installed, or disable the LaTeX rendering in LogarithmPlotter.")
|
||||
show_message(msg.format(pkg, pkg))
|
||||
raise MissingPackageException("Latex: Missing package " + pkg)
|
||||
msg = QCoreApplication.translate("latex",
|
||||
"An exception occured within the creation of the latex formula.\nProcess '{}' took too long to finish:\n{}\nPlease make sure your latex installation is correct and report a bug if so.")
|
||||
show_message(msg.format(cmd, output))
|
||||
raise RenderError(f"{cmd} process timed out:\n{output}")
|
||||
|
||||
def cleanup(self, export_path):
|
||||
"""
|
||||
Removes auxiliary, logs and Tex temporary files.
|
||||
"""
|
||||
for i in [".tex", ".aux", ".log"]:
|
||||
remove(export_path + i)
|
51
runtime-pyside6/LogarithmPlotter/util/native.py
Normal file
51
runtime-pyside6/LogarithmPlotter/util/native.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
# This file contains stuff for native interactions with each OS.
|
||||
|
||||
from PySide6.QtCore import QObject, QEvent
|
||||
|
||||
|
||||
# On macOS, opening a file through finder can only be fetched through the
|
||||
# QFileOpenEvent and NOT through command line parameters.
|
||||
class MacOSFileOpenHandler(QObject):
|
||||
def __init__(self):
|
||||
self.initialized = False
|
||||
self.io_module = None
|
||||
self.opened_file = ""
|
||||
QObject.__init__(self)
|
||||
|
||||
def init_io(self, io_modules):
|
||||
self.io_module = io_modules
|
||||
self.initialized = True
|
||||
if self.opened_file != "":
|
||||
self.open_file()
|
||||
|
||||
def open_file(self):
|
||||
self.io_module.loadDiagram(self.opened_file)
|
||||
|
||||
def eventFilter(self, obj, event):
|
||||
if event.type() == QEvent.FileOpen:
|
||||
print("Got file", event.file(), self.initialized)
|
||||
self.opened_file = event.file()
|
||||
if self.initialized:
|
||||
self.open_file()
|
||||
return True
|
||||
else:
|
||||
# standard event processing
|
||||
return QObject.eventFilter(self, obj, event)
|
91
runtime-pyside6/LogarithmPlotter/util/update.py
Normal file
91
runtime-pyside6/LogarithmPlotter/util/update.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
"""
|
||||
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
|
||||
* Copyright (C) 2021-2024 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 <https://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
from PySide6.QtCore import QRunnable, QThreadPool, QThread, QObject, Signal, QCoreApplication
|
||||
from urllib.request import urlopen
|
||||
from urllib.error import HTTPError, URLError
|
||||
from sys import argv
|
||||
|
||||
|
||||
class UpdateInformation(QObject):
|
||||
got_update_info = Signal(bool, str, bool)
|
||||
|
||||
|
||||
class UpdateCheckerRunnable(QRunnable):
|
||||
def __init__(self, current_version, callback):
|
||||
QRunnable.__init__(self)
|
||||
self.current_version = current_version
|
||||
self.callback = callback
|
||||
|
||||
def run(self):
|
||||
msg_text = "Unknown update error."
|
||||
show_alert = True
|
||||
update_available = False
|
||||
try:
|
||||
# Fetching version
|
||||
r = urlopen("https://api.ad5001.eu/update/v1/LogarithmPlotter")
|
||||
lines = r.readlines()
|
||||
r.close()
|
||||
# Parsing version
|
||||
version = "".join(map(chr, lines[0])).strip() # Converts byte to string.
|
||||
version_tuple = version.split(".")
|
||||
is_version_newer = False
|
||||
if "dev" in self.current_version:
|
||||
# We're on a dev version
|
||||
current_version_tuple = self.current_version.split(".")[:-1] # Removing the dev0+git bit.
|
||||
is_version_newer = version_tuple >= current_version_tuple # If equals, that means we got out of testing phase.
|
||||
else:
|
||||
current_version_tuple = self.current_version.split(".")
|
||||
is_version_newer = version_tuple > current_version_tuple
|
||||
if is_version_newer:
|
||||
msg_text = QCoreApplication.translate("update", "An update for LogarithmPlotter (v{}) is available.")
|
||||
msg_text = msg_text.format(version)
|
||||
update_available = True
|
||||
else:
|
||||
show_alert = False
|
||||
msg_text = QCoreApplication.translate("update", "No update available.")
|
||||
|
||||
except HTTPError as e:
|
||||
msg_text = QCoreApplication.translate("update",
|
||||
"Could not fetch update information: Server error {}.")
|
||||
msg_text = msg_text.format(str(e.code))
|
||||
except URLError as e:
|
||||
msg_text = QCoreApplication.translate("update", "Could not fetch update information: {}.")
|
||||
msg_text = msg_text.format(str(e.reason))
|
||||
self.callback.got_update_info.emit(show_alert, msg_text, update_available)
|
||||
|
||||
|
||||
def check_for_updates(current_version, window):
|
||||
"""
|
||||
Checks for updates in the background, and sends an alert with information.
|
||||
"""
|
||||
if "--no-check-for-updates" in argv:
|
||||
return
|
||||
|
||||
def cb(show_alert, msg_text, update_available):
|
||||
if show_alert:
|
||||
window.showAlert(msg_text)
|
||||
if update_available:
|
||||
window.showUpdateMenu()
|
||||
|
||||
update_info = UpdateInformation()
|
||||
update_info.got_update_info.connect(cb)
|
||||
|
||||
runnable = UpdateCheckerRunnable(current_version, update_info)
|
||||
QThreadPool.globalInstance().start(runnable)
|
||||
return update_info
|
Loading…
Add table
Add a link
Reference in a new issue