Skip to content

Commit

Permalink
tracker: the chart now shows the mouse coordinates and the video size…
Browse files Browse the repository at this point in the history
… can be configured
  • Loading branch information
wwmm committed Jun 1, 2024
1 parent 975a551 commit 707c885
Show file tree
Hide file tree
Showing 4 changed files with 183 additions and 102 deletions.
12 changes: 12 additions & 0 deletions src/contents/kcfg/eyeofsauron_db.kcfg
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,17 @@
<min>2</min>
<max>1000</max>
</entry>
<entry name="videoWidth" type="Int">
<label>Video Preview Width</label>
<default>800</default>
<min>640</min>
<max>1920</max>
</entry>
<entry name="videoHeight" type="Int">
<label>Video Preview Height</label>
<default>600</default>
<min>480</min>
<max>1080</max>
</entry>
</group>
</kcfg>
26 changes: 26 additions & 0 deletions src/contents/ui/PreferencesPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

}

}
231 changes: 129 additions & 102 deletions src/contents/ui/Tracker.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`;
}
}

Expand Down
16 changes: 16 additions & 0 deletions src/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,22 @@ Backend::Backend(QObject* parent)
Q_EMIT playerDurationChanged();
});

connect(db::Main::self(), &db::Main::videoWidthChanged, [this]() {
std::lock_guard<std::mutex> trackers_lock_guard(trackers_mutex);

_frameWidth = db::Main::videoWidth();

Q_EMIT frameWidthChanged();
});

connect(db::Main::self(), &db::Main::videoHeightChanged, [this]() {
std::lock_guard<std::mutex> trackers_lock_guard(trackers_mutex);

_frameHeight = db::Main::videoHeight();

Q_EMIT frameHeightChanged();
});

capture_session->setCamera(camera.get());
capture_session->setVideoSink(camera_video_sink.get());

Expand Down

0 comments on commit 707c885

Please sign in to comment.