LogarithmPlotter/LogarithmPlotter/qml/eu/ad5001/LogarithmPlotter/LogarithmPlotter.qml

261 lines
7.7 KiB
QML
Raw Normal View History

/**
* LogarithmPlotter - 2D plotter software to make BODE plots, sequences and distribution functions.
2024-01-10 23:11:09 +00:00
* 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/>.
*/
2023-05-21 22:15:09 +00:00
import QtQml
import QtQuick.Controls
import eu.ad5001.MixedMenu 1.1
import QtQuick.Layouts 1.12
2023-05-21 22:15:09 +00:00
import QtQuick
// Auto loading all modules.
2024-03-29 00:55:13 +00:00
import "js/autoload.js" as ModulesAutoload
2022-01-30 00:22:33 +00:00
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 {}
2022-01-27 21:59:02 +00:00
Popup.Changelog {id: changelog}
Popup.About {id: about}
2022-04-02 16:17:09 +00:00
Popup.ThanksTo {id: thanksTo}
Popup.Alert {
id: alert
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
z: 3
}
Item {
id: sidebar
2020-12-22 22:19:00 +00:00
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
2021-03-14 18:03:58 +00:00
anchors.top: parent.top
TabButton {
2024-03-29 16:53:10 +00:00
text: qsTranslate('io', "Objects")
icon.name: 'polygon-add-nodes'
icon.color: sysPalette.windowText
//height: 24
}
TabButton {
2024-03-29 16:53:10 +00:00
text: qsTranslate('io', "Settings")
2021-07-31 22:49:44 +00:00
icon.name: 'preferences-system-symbolic'
icon.color: sysPalette.windowText
//height: 24
}
2021-04-07 12:51:48 +00:00
TabButton {
2024-03-29 16:53:10 +00:00
text: qsTranslate('io', "History")
2021-07-31 22:49:44 +00:00
icon.name: 'view-history'
icon.color: sysPalette.windowText
//height: 24
2021-04-07 12:51:48 +00:00
}
}
StackLayout {
2021-03-09 19:37:12 +00:00
id: sidebarContents
anchors.top: sidebarSelector.bottom
2020-12-22 22:19:00 +00:00
anchors.left: parent.left
anchors.topMargin: 5
anchors.leftMargin: 5
2021-03-31 22:29:05 +00:00
anchors.bottom: parent.bottom
//anchors.bottomMargin: sidebarSelector.height
width: parent.width - 5
2020-12-22 22:19:00 +00:00
currentIndex: sidebarSelector.currentIndex
2020-12-22 17:22:38 +00:00
z: -1
clip: true
ObjectLists {
id: objectLists
onChanged: drawCanvas.requestPaint()
}
2020-12-22 22:19:00 +00:00
Settings {
id: settings
canvas: drawCanvas
2020-12-22 22:19:00 +00:00
onChanged: drawCanvas.requestPaint()
}
2021-04-07 12:51:48 +00:00
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
2021-03-31 22:29:05 +00:00
linewidth: settings.linewidth
textsize: settings.textsize
2021-01-26 17:36:21 +00:00
showxgrad: settings.showxgrad
showygrad: settings.showygrad
property bool firstDrawDone: false
2024-03-29 16:53:10 +00:00
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()
}
}
2021-08-14 20:17:17 +00:00
2023-10-07 17:11:19 +00:00
ViewPositionChangeOverlay {
id: viewPositionChanger
anchors.fill: parent
canvas: parent
settingsInstance: settings
}
2021-08-14 20:17:17 +00:00
PickLocationOverlay {
id: positionPicker
2021-08-14 20:17:17 +00:00
anchors.fill: parent
canvas: parent
}
}
2020-12-22 22:19:00 +00:00
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
}
2023-05-21 22:15:09 +00:00
onClosing: function(close) {
if(!history.saved) {
close.accepted = false
2023-05-21 22:15:09 +00:00
appMenu.openSaveUnsavedChangesDialog()
}
}
2024-03-29 16:53:10 +00:00
/*!
\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()
2024-03-29 16:53:10 +00:00
alert.show(qsTranslate('io', "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
2024-03-29 16:53:10 +00:00
title: qsTranslate('io', "&Update")
Action {
2024-03-29 16:53:10 +00:00
text: qsTranslate('io', "&Update LogarithmPlotter")
icon.name: 'update'
2024-03-29 16:53:10 +00:00
onTriggered: Qt.openUrlExternally("https://apps.ad5001.eu/logarithmplotter/")
}
}
/*!
\qmlmethod void LogarithmPlotter::showUpdateMenu()
Shows the update menu in the AppMenuBar.
*/
function showUpdateMenu() {
appMenu.addMenu(updateMenu)
}
}