From 707c8855e950cb0f51e4d66c0c052f578f6bfc87 Mon Sep 17 00:00:00 2001 From: wwmm Date: Sat, 1 Jun 2024 12:50:38 -0300 Subject: [PATCH] tracker: the chart now shows the mouse coordinates and the video size can be configured --- src/contents/kcfg/eyeofsauron_db.kcfg | 12 ++ src/contents/ui/PreferencesPage.qml | 26 +++ src/contents/ui/Tracker.qml | 231 ++++++++++++++------------ src/tracker.cpp | 16 ++ 4 files changed, 183 insertions(+), 102 deletions(-) diff --git a/src/contents/kcfg/eyeofsauron_db.kcfg b/src/contents/kcfg/eyeofsauron_db.kcfg index 53b0be8..67c3025 100644 --- a/src/contents/kcfg/eyeofsauron_db.kcfg +++ b/src/contents/kcfg/eyeofsauron_db.kcfg @@ -54,5 +54,17 @@ 2 1000 + + + 800 + 640 + 1920 + + + + 600 + 480 + 1080 + \ No newline at end of file diff --git a/src/contents/ui/PreferencesPage.qml b/src/contents/ui/PreferencesPage.qml index b3cdf17..57f85a4 100644 --- a/src/contents/ui/PreferencesPage.qml +++ b/src/contents/ui/PreferencesPage.qml @@ -77,6 +77,32 @@ FormCard.FormCardPage { } } + EoSSpinBox { + label: i18n("Video Width") + unit: i18n("px") + decimals: 0 + stepSize: 1 + from: 640 + to: 1920 + value: EoSdb.videoWidth + onValueModified: (v) => { + EoSdb.videoWidth = v; + } + } + + EoSSpinBox { + label: i18n("Video Height") + unit: i18n("px") + decimals: 0 + stepSize: 1 + from: 480 + to: 1080 + value: EoSdb.videoHeight + onValueModified: (v) => { + EoSdb.videoHeight = v; + } + } + } } diff --git a/src/contents/ui/Tracker.qml b/src/contents/ui/Tracker.qml index f12df2e..5c32d5c 100644 --- a/src/contents/ui/Tracker.qml +++ b/src/contents/ui/Tracker.qml @@ -166,120 +166,147 @@ Kirigami.ScrollablePage { } - ChartView { - id: chart - - property real rangeMargin: 0.01 - - function addSeries(axisName) { - let name = i18n(axisName + Math.floor(chart.count / 2)); - let series = createSeries(ChartView.SeriesTypeLine, name, axisTime, axisPosition); - series.useOpenGL = true; - if (axisName === "x") - series.visible = Qt.binding(function() { - return actionViewXdata.showChart; - }); - else if (axisName === "y") - series.visible = Qt.binding(function() { - return actionViewYdata.showChart; - }); - } - - antialiasing: true - Layout.fillWidth: true - Layout.fillHeight: true - implicitHeight: 480 - implicitWidth: 640 - theme: EoSdb.darkChartTheme === true ? ChartView.ChartThemeDark : ChartView.ChartThemeLight - localizeNumbers: true - - ValueAxis { - id: axisPosition - - labelFormat: "%.1f" - min: EoSTrackerBackend.yAxisMin * (1 - chart.rangeMargin) - max: EoSTrackerBackend.yAxisMax * (1 + chart.rangeMargin) - titleText: i18n("Position [px]") - } - - ValueAxis { - id: axisTime + ColumnLayout { + ChartView { + id: chart + + property real rangeMargin: 0.01 + + function addSeries(axisName) { + let name = i18n(axisName + Math.floor(chart.count / 2)); + let series = createSeries(ChartView.SeriesTypeLine, name, axisTime, axisPosition); + series.useOpenGL = true; + if (axisName === "x") + series.visible = Qt.binding(function() { + return actionViewXdata.showChart; + }); + else if (axisName === "y") + series.visible = Qt.binding(function() { + return actionViewYdata.showChart; + }); + } - labelFormat: "%.1f" - min: EoSTrackerBackend.xAxisMin - max: EoSTrackerBackend.xAxisMax - titleText: i18n("Time [s]") - } + antialiasing: true + Layout.fillWidth: true + Layout.fillHeight: true + implicitHeight: 480 + implicitWidth: 640 + theme: EoSdb.darkChartTheme === true ? ChartView.ChartThemeDark : ChartView.ChartThemeLight + localizeNumbers: true + + ValueAxis { + id: axisPosition + + labelFormat: "%.1f" + min: EoSTrackerBackend.yAxisMin * (1 - chart.rangeMargin) + max: EoSTrackerBackend.yAxisMax * (1 + chart.rangeMargin) + titleText: i18n("Position [px]") + } - Rectangle { - id: zoomRect + ValueAxis { + id: axisTime - color: EoSdb.darkChartTheme === true ? "aquamarine" : "crimson" - opacity: 0.25 - visible: false - width: 0 - height: 0 - } + labelFormat: "%.1f" + min: EoSTrackerBackend.xAxisMin + max: EoSTrackerBackend.xAxisMax + titleText: i18n("Time [s]") + } - MouseArea { - property real x0: 0 - property real y0: 0 + Rectangle { + id: zoomRect - anchors.fill: parent - acceptedButtons: Qt.LeftButton | Qt.RightButton - preventStealing: true - onPressed: (event) => { - if (event.button == Qt.LeftButton) { - x0 = event.x; - y0 = event.y; - zoomRect.width = 0; - zoomRect.height = 0; - zoomRect.visible = true; - event.accepted = true; - } + color: EoSdb.darkChartTheme === true ? "aquamarine" : "crimson" + opacity: 0.25 + visible: false + width: 0 + height: 0 } - onReleased: (event) => { - if (event.button == Qt.LeftButton) { - let width = event.x - x0; - let height = event.y - y0; - if (Math.abs(width) === 0 || Math.abs(height) === 0) - return ; - if (width < 0) { - x0 = width + x0; - width *= -1; - } - if (height < 0) { - y0 = height + y0; - height *= -1; + MouseArea { + // console.log(chart.mapToValue(Qt.point(event.x, event.y))); + + id: chartMouseArea + + property real mouseX: 0 + property real mouseY: 0 + property real x0: 0 + property real y0: 0 + + anchors.fill: parent + acceptedButtons: Qt.LeftButton | Qt.RightButton + preventStealing: true + hoverEnabled: true + onPressed: (event) => { + if (event.button == Qt.LeftButton) { + x0 = event.x; + y0 = event.y; + zoomRect.width = 0; + zoomRect.height = 0; + zoomRect.visible = true; + event.accepted = true; } - chart.zoomIn(zoomRect); - zoomRect.visible = false; - event.accepted = true; } - } - onPositionChanged: (event) => { - if (event.buttons & Qt.LeftButton) { - let x = x0; - let y = y0; - let width = event.x - x; - let height = event.y - y; - if (Math.abs(width) === 0 || Math.abs(height) === 0) - return ; - - if (width < 0) { - x = width + x; - width *= -1; + onReleased: (event) => { + if (event.button == Qt.LeftButton) { + let width = event.x - x0; + let height = event.y - y0; + if (Math.abs(width) === 0 || Math.abs(height) === 0) + return ; + + if (width < 0) { + x0 = width + x0; + width *= -1; + } + if (height < 0) { + y0 = height + y0; + height *= -1; + } + chart.zoomIn(zoomRect); + zoomRect.visible = false; + event.accepted = true; } - if (height < 0) { - y = height + y; - height *= -1; + } + onPositionChanged: (event) => { + if (event.buttons & Qt.LeftButton) { + let x = x0; + let y = y0; + let width = event.x - x; + let height = event.y - y; + if (Math.abs(width) === 0 || Math.abs(height) === 0) + return ; + + if (width < 0) { + x = width + x; + width *= -1; + } + if (height < 0) { + y = height + y; + height *= -1; + } + zoomRect.x = x; + zoomRect.y = y; + zoomRect.width = width; + zoomRect.height = height; + } else if (chart.count > 0) { + let p = chart.mapToValue(Qt.point(event.x, event.y)); + mouseX = p.x; + mouseY = p.y; } - zoomRect.x = x; - zoomRect.y = y; - zoomRect.width = width; - zoomRect.height = height; } + onExited: { + mouseX = 0; + mouseY = 0; + } + } + + } + + Text { + Layout.fillWidth: true + horizontalAlignment: Text.AlignHCenter + color: Kirigami.Theme.textColor + text: { + return `t = ${chartMouseArea.mouseX.toFixed(1)} \t p = ${chartMouseArea.mouseY.toFixed(1)}`; } } diff --git a/src/tracker.cpp b/src/tracker.cpp index 75ddcc1..522885c 100644 --- a/src/tracker.cpp +++ b/src/tracker.cpp @@ -248,6 +248,22 @@ Backend::Backend(QObject* parent) Q_EMIT playerDurationChanged(); }); + connect(db::Main::self(), &db::Main::videoWidthChanged, [this]() { + std::lock_guard trackers_lock_guard(trackers_mutex); + + _frameWidth = db::Main::videoWidth(); + + Q_EMIT frameWidthChanged(); + }); + + connect(db::Main::self(), &db::Main::videoHeightChanged, [this]() { + std::lock_guard trackers_lock_guard(trackers_mutex); + + _frameHeight = db::Main::videoHeight(); + + Q_EMIT frameHeightChanged(); + }); + capture_session->setCamera(camera.get()); capture_session->setVideoSink(camera_video_sink.get());