Switching a lot of stuff to new Settings module
+ Fixing a bug that did not load the showygrad setting properly.
This commit is contained in:
parent
f4920aadb6
commit
d1ac70a946
11 changed files with 148 additions and 229 deletions
|
@ -30,104 +30,15 @@ import Qt.labs.platform as Native
|
|||
*/
|
||||
Canvas {
|
||||
id: canvas
|
||||
anchors.top: separator.bottom
|
||||
anchors.top: parent.top
|
||||
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 = {}
|
||||
|
@ -155,7 +66,7 @@ Canvas {
|
|||
Object.keys(imageLoaders).forEach((key) => {
|
||||
if(isImageLoaded(key)) {
|
||||
// Calling callback
|
||||
imageLoaders[key][0](canvas, ctx, imageLoaders[key][1])
|
||||
imageLoaders[key][0](imageLoaders[key][1])
|
||||
delete imageLoaders[key]
|
||||
}
|
||||
})
|
||||
|
|
|
@ -145,20 +145,6 @@ ApplicationWindow {
|
|||
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) {
|
||||
|
|
|
@ -175,17 +175,17 @@ Item {
|
|||
Icon {
|
||||
id: iconLabel
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: icon == "" ? 0 : 3
|
||||
source: control.visible && icon != "" ? "../icons/" + control.icon : ""
|
||||
anchors.topMargin: parent.icon == "" ? 0 : 3
|
||||
source: control.visible && parent.icon != "" ? "../icons/" + control.icon : ""
|
||||
width: height
|
||||
height: icon == "" || !visible ? 0 : 24
|
||||
height: parent.icon == "" || !visible ? 0 : 24
|
||||
color: sysPalette.windowText
|
||||
}
|
||||
|
||||
Label {
|
||||
id: labelItem
|
||||
anchors.left: iconLabel.right
|
||||
anchors.leftMargin: icon == "" ? 0 : 5
|
||||
anchors.leftMargin: parent.icon == "" ? 0 : 5
|
||||
anchors.top: parent.top
|
||||
height: parent.height
|
||||
width: Math.max(85, implicitWidth)
|
||||
|
@ -231,8 +231,8 @@ Item {
|
|||
onEditingFinished: {
|
||||
if(insertButton.focus || insertPopup.focus) return
|
||||
let value = text
|
||||
if(value != "" && value.toString() != defValue) {
|
||||
let expr = parse(value)
|
||||
if(value != "" && value.toString() != parent.defValue) {
|
||||
let expr = parent.parse(value)
|
||||
if(expr != null) {
|
||||
control.changed(expr)
|
||||
defValue = expr.toEditableString()
|
||||
|
@ -280,10 +280,10 @@ Item {
|
|||
acPopupContent.itemSelected = 0
|
||||
|
||||
|
||||
if(event.text in openAndCloseMatches && autoClosing) {
|
||||
if(event.text in parent.openAndCloseMatches && autoClosing) {
|
||||
let start = selectionStart
|
||||
insert(selectionStart, event.text)
|
||||
insert(selectionEnd, openAndCloseMatches[event.text])
|
||||
insert(selectionEnd, parent.openAndCloseMatches[event.text])
|
||||
cursorPosition = start+1
|
||||
event.accepted = true
|
||||
}
|
||||
|
|
|
@ -17,8 +17,6 @@
|
|||
*/
|
||||
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import eu.ad5001.LogarithmPlotter.Setting 1.0 as Setting
|
||||
|
||||
/*!
|
||||
\qmltype ViewPositionChangeOverlay
|
||||
|
@ -81,7 +79,7 @@ Item {
|
|||
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).
|
||||
How much should the zoom be multiplied/scrolled by for one scroll step (120° on the mouse wheel).
|
||||
*/
|
||||
property double baseZoomMultiplier: 0.1
|
||||
|
||||
|
@ -91,15 +89,15 @@ Item {
|
|||
cursorShape: pressed ? Qt.ClosedHandCursor : Qt.OpenHandCursor
|
||||
property int positionChangeTimer: 0
|
||||
|
||||
function updatePosition(deltaX, deltaY) {
|
||||
function updatePosition(deltaX, deltaY, isEnd) {
|
||||
const unauthorized = [NaN, Infinity, -Infinity]
|
||||
const xmin = (Modules.Canvas.px2x(Modules.Canvas.x2px(settingsInstance.xmin)-deltaX))
|
||||
const ymax = settingsInstance.ymax + deltaY/canvas.yzoom
|
||||
const xmin = (Modules.Canvas.px2x(Modules.Canvas.x2px(Modules.Settings.xmin)-deltaX))
|
||||
const ymax = Modules.Settings.ymax + deltaY/Modules.Settings.yzoom
|
||||
if(!unauthorized.includes(xmin))
|
||||
settingsInstance.xmin = xmin
|
||||
Modules.Settings.set("xmin", xmin, isEnd)
|
||||
if(!unauthorized.includes(ymax))
|
||||
settingsInstance.ymax = ymax.toFixed(4)
|
||||
settingsInstance.changed()
|
||||
Modules.Settings.set("ymax", ymax.toDecimalPrecision(6), isEnd)
|
||||
Modules.Canvas.requestPaint()
|
||||
parent.positionChanged(deltaX, deltaY)
|
||||
|
||||
}
|
||||
|
@ -113,9 +111,9 @@ Item {
|
|||
onPositionChanged: function(mouse) {
|
||||
positionChangeTimer++
|
||||
if(positionChangeTimer == 3) {
|
||||
let deltaX = mouse.x - prevX
|
||||
let deltaY = mouse.y - prevY
|
||||
updatePosition(deltaX, deltaY)
|
||||
let deltaX = mouse.x - parent.prevX
|
||||
let deltaY = mouse.y - parent.prevY
|
||||
updatePosition(deltaX, deltaY, false)
|
||||
prevX = mouse.x
|
||||
prevY = mouse.y
|
||||
positionChangeTimer = 0
|
||||
|
@ -123,35 +121,35 @@ Item {
|
|||
}
|
||||
|
||||
onReleased: function(mouse) {
|
||||
let deltaX = mouse.x - prevX
|
||||
let deltaY = mouse.y - prevY
|
||||
updatePosition(deltaX, deltaY)
|
||||
let deltaX = mouse.x - parent.prevX
|
||||
let deltaY = mouse.y - parent.prevY
|
||||
updatePosition(deltaX, deltaY, true)
|
||||
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))
|
||||
let zoomMultiplier = Math.pow(1+parent.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)
|
||||
let xZoomDelta = (Modules.Settings.xzoom*zoomMultiplier - Modules.Settings.xzoom)
|
||||
let yZoomDelta = (Modules.Settings.yzoom*zoomMultiplier - Modules.Settings.yzoom)
|
||||
if(scrollSteps < 0) { // Negative scroll
|
||||
xZoomDelta *= -1
|
||||
yZoomDelta *= -1
|
||||
}
|
||||
let newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(0)
|
||||
let newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(0)
|
||||
let newXZoom = (Modules.Settings.xzoom+xZoomDelta).toDecimalPrecision(0)
|
||||
let newYZoom = (Modules.Settings.yzoom+yZoomDelta).toDecimalPrecision(0)
|
||||
// Check if we need to have more precision
|
||||
if(newXZoom < 10)
|
||||
newXZoom = (settingsInstance.xzoom+xZoomDelta).toFixed(4)
|
||||
newXZoom = (Modules.Settings.xzoom+xZoomDelta).toDecimalPrecision(4)
|
||||
if(newYZoom < 10)
|
||||
newYZoom = (settingsInstance.yzoom+yZoomDelta).toFixed(4)
|
||||
newYZoom = (Modules.Settings.yzoom+yZoomDelta).toDecimalPrecision(4)
|
||||
if(newXZoom > 0.5)
|
||||
settingsInstance.xzoom = newXZoom
|
||||
Modules.Settings.set("xzoom", newXZoom)
|
||||
if(newYZoom > 0.5)
|
||||
settingsInstance.yzoom = newYZoom
|
||||
settingsInstance.changed()
|
||||
Modules.Settings.set("yzoom", newYZoom)
|
||||
Modules.Canvas.requestPaint()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue