Various changes have been made as a result of the discussion of the first version
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import QtQuick 2.12
|
||||
import QtCharts 2.3
|
||||
import QtQuick.Shapes 1.12
|
||||
|
||||
import Controls 1.0 as Controls
|
||||
import Utils 1.0
|
||||
|
||||
ChartView {
|
||||
@@ -20,6 +22,7 @@ ChartView {
|
||||
property int defaultXMax: 10
|
||||
property int defaultYMax: 1
|
||||
property bool autoScaling: true
|
||||
property int selectedSeriesIndex: 0
|
||||
|
||||
ValueAxis {
|
||||
id: valueAxisX
|
||||
@@ -45,10 +48,47 @@ ChartView {
|
||||
titleVisible: false
|
||||
}
|
||||
|
||||
Shape {
|
||||
id: currentPointLine
|
||||
implicitWidth: 1
|
||||
implicitHeight: chart.plotArea.height
|
||||
x: chart.plotArea.x
|
||||
y: chart.plotArea.y
|
||||
|
||||
ShapePath {
|
||||
strokeColor: Palette.borderColor
|
||||
strokeStyle: ShapePath.SolidLine
|
||||
startX: 0
|
||||
startY: 0
|
||||
PathLine { x: 0; y: currentPointLine.height }
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: currentPointInfo
|
||||
|
||||
width: currentPointInfoLabel.width
|
||||
height: currentPointInfoLabel.height
|
||||
color: Palette.backgroundColor
|
||||
border.width: 1
|
||||
border.color: Palette.borderColor
|
||||
opacity: 0.9
|
||||
radius: 6
|
||||
visible: false
|
||||
|
||||
Controls.SubtitleLabel {
|
||||
id: currentPointInfoLabel
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
anchors.centerIn: parent
|
||||
padding: 10
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: chartMouseAreaA
|
||||
id: chartMouseArea
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.LeftButton
|
||||
hoverEnabled: true
|
||||
|
||||
property real lastMouseX: 0
|
||||
property real lastMouseY: 0
|
||||
@@ -59,27 +99,28 @@ ChartView {
|
||||
if ((mouse.buttons & Qt.LeftButton) == Qt.LeftButton) {
|
||||
if (mouseX - lastMouseX > scrollThreshold) {
|
||||
chart.scrollLeft(mouseX - lastMouseX)
|
||||
lastMouseX = mouseX
|
||||
chart.autoScaling = false
|
||||
} else if (mouseX - lastMouseX < scrollThreshold) {
|
||||
chart.scrollRight(lastMouseX - mouseX)
|
||||
lastMouseX = mouseX
|
||||
chart.autoScaling = false
|
||||
}
|
||||
lastMouseX = mouseX
|
||||
chart.autoScaling = false
|
||||
}
|
||||
|
||||
updatePointInfo()
|
||||
}
|
||||
onMouseYChanged: {
|
||||
|
||||
if ((mouse.buttons & Qt.LeftButton) == Qt.LeftButton) {
|
||||
if (mouseY - lastMouseY > scrollThreshold) {
|
||||
chart.scrollUp(mouseY - lastMouseY)
|
||||
lastMouseY = mouseY
|
||||
chart.autoScaling = false
|
||||
} else if (mouseY - lastMouseY < scrollThreshold) {
|
||||
chart.scrollDown(lastMouseY - mouseY)
|
||||
lastMouseY = mouseY
|
||||
chart.autoScaling = false
|
||||
}
|
||||
lastMouseY = mouseY
|
||||
chart.autoScaling = false
|
||||
}
|
||||
|
||||
updatePointInfo()
|
||||
}
|
||||
onPressed: {
|
||||
if (mouse.button === Qt.LeftButton) {
|
||||
@@ -88,13 +129,71 @@ ChartView {
|
||||
}
|
||||
}
|
||||
onWheel: {
|
||||
if (wheel.angleDelta.y > 0) {
|
||||
chart.zoomIn()
|
||||
chart.autoScaling = false
|
||||
} else {
|
||||
chart.zoomOut()
|
||||
chart.autoScaling = false
|
||||
var scaleFactor = 0.75
|
||||
var area = chart.plotArea
|
||||
chart.autoScaling = false
|
||||
|
||||
var yAxisPosition = mouseX <= chart.plotArea.x
|
||||
if (yAxisPosition) {
|
||||
if (wheel.angleDelta.y > 0) {
|
||||
chart.zoomIn(Qt.rect(area.x, area.y + Math.round(area.height * (1 - scaleFactor) / 2), area.width, Math.round(area.height * scaleFactor)))
|
||||
} else {
|
||||
chart.zoomIn(Qt.rect(area.x, area.y - Math.round((area.height / scaleFactor) * (1 - scaleFactor) / 2), area.width, Math.round(area.height / scaleFactor)))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var xAxisPosition = mouseY >= (chart.plotArea.y + chart.plotArea.height)
|
||||
if (xAxisPosition) {
|
||||
if (wheel.angleDelta.y > 0) {
|
||||
chart.zoomIn(Qt.rect(area.x + area.width * (1 - scaleFactor) / 2, area.y, Math.round(area.width * scaleFactor), area.height))
|
||||
} else {
|
||||
chart.zoomIn(Qt.rect(area.x - (area.width / scaleFactor) * (1 - scaleFactor) / 2, area.y, Math.round(area.width / scaleFactor), area.height))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if (wheel.angleDelta.y > 0) {
|
||||
let zoomedInArea = Qt.rect(area.x + Math.round((mouseX - area.x) * (1 - scaleFactor)),
|
||||
area.y + Math.round((mouseY - area.y) * (1 - scaleFactor)),
|
||||
Math.round(area.width * scaleFactor),
|
||||
Math.round(area.height * scaleFactor))
|
||||
chart.zoomIn(zoomedInArea)
|
||||
} else {
|
||||
let zoomedOutArea = Qt.rect(area.x - Math.floor((mouseX - area.x) * (1 - scaleFactor)),
|
||||
area.y - Math.floor((mouseY - area.y) * (1 - scaleFactor)),
|
||||
Math.round(area.width * (1 + (1 - scaleFactor))),
|
||||
Math.round(area.height * (1 + (1 - scaleFactor))))
|
||||
chart.zoomIn(zoomedOutArea)
|
||||
}
|
||||
|
||||
updatePointInfo()
|
||||
}
|
||||
|
||||
function updatePointInfo() {
|
||||
var currentPointVisibility = mouseX >= chart.plotArea.x && mouseX <= chart.plotArea.x + chart.plotArea.width &&
|
||||
mouseY >= chart.plotArea.y && mouseY <= chart.plotArea.y + chart.plotArea.height
|
||||
|
||||
currentPointInfo.visible = currentPointVisibility
|
||||
currentPointInfo.x = mouseX + 5
|
||||
currentPointInfo.y = mouseY - currentPointInfo.height - 5
|
||||
|
||||
var currentX = Math.ceil(mapToValue(Qt.point(mouseX, mouseY), chart.series(selectedSeriesIndex)).x)
|
||||
var selectedPoint = Qt.point(0, 0)
|
||||
|
||||
if (currentX < chart.series(selectedSeriesIndex).count && currentX > 0) {
|
||||
selectedPoint = chart.series(selectedSeriesIndex).at(currentX)
|
||||
currentPointInfoLabel.text = selectedPoint.x + ", " +selectedPoint.y
|
||||
} else {
|
||||
currentPointInfo.visible = false
|
||||
}
|
||||
|
||||
currentPointLine.visible = currentPointVisibility
|
||||
currentPointLine.x = mouseX
|
||||
}
|
||||
}
|
||||
|
||||
onSeriesAdded: if (count === 1) {
|
||||
series.pointAdded.connect(function (index){ chartMouseArea.updatePointInfo() })
|
||||
}
|
||||
}
|
||||
|
||||
27
qml/Controls/ImageButton.qml
Normal file
27
qml/Controls/ImageButton.qml
Normal file
@@ -0,0 +1,27 @@
|
||||
import QtQuick 2.12
|
||||
import QtQuick.Controls 2.12
|
||||
|
||||
import Utils 1.0
|
||||
|
||||
Button {
|
||||
id: control
|
||||
|
||||
icon.width: 24
|
||||
icon.height: 24
|
||||
|
||||
contentItem: Image {
|
||||
source: control.icon.source
|
||||
sourceSize.width: control.icon.width
|
||||
sourceSize.height: control.icon.height
|
||||
fillMode: Image.PreserveAspectFit
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
implicitWidth: 44
|
||||
implicitHeight: 44
|
||||
opacity: enabled ? 1 : 0.3
|
||||
color: control.pressed ? Palette.pressedButtonColor :
|
||||
control.hovered ? Palette.hoveredButtonColor : Palette.buttonColor
|
||||
radius: 5
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,8 @@ TextField {
|
||||
color: Palette.textColor
|
||||
selectByMouse: true
|
||||
selectionColor: Palette.selectedTextBackgroundColor
|
||||
leftPadding: 16
|
||||
rightPadding: 16
|
||||
|
||||
background: Rectangle {
|
||||
color: enabled ? Palette.backgroundColor : Palette.hoveredBackgroundColor
|
||||
|
||||
@@ -24,3 +24,4 @@ BusyIndicator 1.0 BusyIndicator.qml
|
||||
MenuItemDelegate 1.0 MenuItemDelegate.qml
|
||||
ScrollIndicator 1.0 ScrollIndicator.qml
|
||||
OutlineImageButton 1.0 OutlineImageButton.qml
|
||||
ImageButton 1.0 ImageButton.qml
|
||||
|
||||
Reference in New Issue
Block a user