2021-06-14 19:09:53 +02:00
|
|
|
|
// SPDX-License-Identifier: Unlicense
|
|
|
|
|
|
|
|
|
|
import QtQuick 2.12
|
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
|
import QtQuick.Layouts 1.6
|
|
|
|
|
import Qt.labs.platform 1.1
|
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
import fuzbal 1
|
2021-09-07 19:25:32 +02:00
|
|
|
|
import 'util.js' as Util
|
2021-09-01 17:13:51 +02:00
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Page {
|
|
|
|
|
id: control
|
|
|
|
|
|
2021-09-07 19:25:32 +02:00
|
|
|
|
required property Video video
|
2021-06-14 19:09:53 +02:00
|
|
|
|
property bool modified: false
|
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
EventList {
|
|
|
|
|
id: eventList
|
|
|
|
|
onDataChanged: modified = true
|
|
|
|
|
onRowsInserted: modified = true
|
|
|
|
|
onRowsRemoved: modified = true
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-05 21:16:46 +02:00
|
|
|
|
EventFilter {
|
|
|
|
|
id: eventFilter
|
|
|
|
|
sourceModel: eventList
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
FileDialog {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
id: dialog
|
|
|
|
|
|
2021-09-16 20:52:01 +02:00
|
|
|
|
title: qsTr('Load video or tags')
|
|
|
|
|
nameFilters: [qsTr('all files (*)'), qsTr('events and tags (*.events *.json)')]
|
2021-09-07 19:25:32 +02:00
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
onAccepted: {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
const path = file.toString()
|
|
|
|
|
if (path.endsWith('.json')) {
|
|
|
|
|
eventList.load({ 'tags': JSON.parse(io.read(file)) })
|
|
|
|
|
modified = true
|
|
|
|
|
} else {
|
|
|
|
|
video.source = path.endsWith('.events') ? path.substr(0, path.length-7) : path
|
|
|
|
|
const json = JSON.parse(io.read(video.source+'.events') || '{}')
|
|
|
|
|
eventList.load(json)
|
|
|
|
|
description.text = json['description'] || ''
|
|
|
|
|
modified = false
|
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-12 19:34:10 +02:00
|
|
|
|
Keys.forwardTo: [video, tags]
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-07 19:25:32 +02:00
|
|
|
|
// Save / load buttons.
|
2021-06-14 19:09:53 +02:00
|
|
|
|
header: ToolBar {
|
|
|
|
|
horizontalPadding: 0
|
|
|
|
|
RowLayout {
|
|
|
|
|
anchors.fill: parent
|
2021-09-07 19:25:32 +02:00
|
|
|
|
spacing: 0
|
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Label {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
text: video.loaded ? video.source : qsTr('(no video)')
|
2021-06-14 19:09:53 +02:00
|
|
|
|
elide: Text.ElideLeft
|
2021-09-07 19:25:32 +02:00
|
|
|
|
leftPadding: 5
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
2021-09-07 19:25:32 +02:00
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
ToolButton {
|
|
|
|
|
action: Action {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
icon.name: 'document-save'
|
|
|
|
|
shortcut: StandardKey.Save
|
|
|
|
|
enabled: video.loaded && control.modified
|
2021-09-01 17:13:51 +02:00
|
|
|
|
onTriggered: {
|
|
|
|
|
var json = eventList.save()
|
|
|
|
|
json['description'] = description.text
|
|
|
|
|
json['video'] = video.source
|
|
|
|
|
json['version'] = Qt.application.version
|
|
|
|
|
io.write(video.source+'.events', JSON.stringify(json))
|
|
|
|
|
modified = false
|
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
visible: video.loaded
|
|
|
|
|
opacity: enabled ? 1 : 0.25
|
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
|
}
|
2021-09-07 19:25:32 +02:00
|
|
|
|
|
|
|
|
|
ToolButton {
|
|
|
|
|
action: Action {
|
|
|
|
|
icon.name: 'document-open'
|
|
|
|
|
shortcut: StandardKey.Open
|
|
|
|
|
onTriggered: dialog.open()
|
|
|
|
|
}
|
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
// Description box.
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Rectangle {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.maximumHeight: 100
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Layout.preferredHeight: description.implicitHeight
|
2021-09-16 20:02:49 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
border.color: description.activeFocus ? palette.highlight : palette.dark
|
|
|
|
|
color: palette.base
|
|
|
|
|
radius: 2
|
2021-09-16 20:02:49 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
ScrollView {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
|
padding: 0
|
2021-09-16 20:02:49 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
TextArea {
|
|
|
|
|
id: description
|
2021-09-16 20:02:49 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
placeholderText: qsTr('Description')
|
|
|
|
|
padding: filter.padding
|
|
|
|
|
leftPadding: filter.leftPadding
|
|
|
|
|
selectByMouse: true
|
|
|
|
|
wrapMode: Text.Wrap
|
2021-09-16 20:02:49 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
onTextChanged: modified = true
|
|
|
|
|
KeyNavigation.priority: KeyNavigation.BeforeItem
|
|
|
|
|
KeyNavigation.tab: nextItemInFocusChain()
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-16 20:24:07 +02:00
|
|
|
|
|
|
|
|
|
Hotkey {
|
|
|
|
|
control: description
|
2021-09-16 20:52:01 +02:00
|
|
|
|
sequence: qsTr('Ctrl+D')
|
2021-09-16 20:24:07 +02:00
|
|
|
|
anchors { right: parent.right; bottom: parent.bottom; margins: 4 }
|
|
|
|
|
font.pixelSize: description.font.pixelSize * 0.75
|
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-15 22:21:20 +02:00
|
|
|
|
// Filter box.
|
2021-09-07 19:25:32 +02:00
|
|
|
|
TextField {
|
|
|
|
|
id: filter
|
2021-09-16 20:24:07 +02:00
|
|
|
|
|
2021-09-07 19:25:32 +02:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
placeholderText: qsTr('Filter')
|
2021-09-16 20:24:07 +02:00
|
|
|
|
background: Rectangle {
|
|
|
|
|
border.color: parent.activeFocus ? palette.highlight : palette.dark
|
|
|
|
|
color: palette.base
|
|
|
|
|
radius: 2
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-07 19:25:32 +02:00
|
|
|
|
onTextChanged: eventFilter.setFilter(text)
|
|
|
|
|
Keys.onEscapePressed: text = ''
|
2021-09-12 20:14:06 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Hotkey {
|
|
|
|
|
control: filter
|
|
|
|
|
sequence: StandardKey.Find
|
2021-09-12 20:14:06 +02:00
|
|
|
|
anchors { right: parent.right; bottom: parent.bottom; margins: 4 }
|
|
|
|
|
font.pixelSize: filter.font.pixelSize * 0.75
|
|
|
|
|
}
|
2021-09-07 19:25:32 +02:00
|
|
|
|
}
|
2021-09-05 21:16:46 +02:00
|
|
|
|
|
2021-09-15 22:21:20 +02:00
|
|
|
|
// Event list.
|
2021-09-15 22:03:11 +02:00
|
|
|
|
Frame {
|
2021-09-07 19:25:32 +02:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: true
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Layout.rightMargin: -control.padding // fill to window edge for easier scrolling
|
2021-09-05 21:16:46 +02:00
|
|
|
|
|
2021-09-16 16:57:45 +02:00
|
|
|
|
focusPolicy: Qt.StrongFocus
|
2021-09-16 20:24:07 +02:00
|
|
|
|
|
2021-09-15 22:03:11 +02:00
|
|
|
|
padding: 1
|
|
|
|
|
rightPadding: 0
|
|
|
|
|
background: Rectangle {
|
2021-09-16 20:24:07 +02:00
|
|
|
|
border.color: parent.activeFocus ? palette.highlight : palette.dark
|
2021-09-15 22:03:11 +02:00
|
|
|
|
color: 'transparent'
|
|
|
|
|
radius: 2
|
2021-09-07 19:25:32 +02:00
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-15 22:03:11 +02:00
|
|
|
|
Events {
|
|
|
|
|
id: events
|
2021-09-12 20:14:06 +02:00
|
|
|
|
|
2021-09-15 22:03:11 +02:00
|
|
|
|
model: eventFilter
|
|
|
|
|
tags: eventList.tags
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
focus: true
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-15 22:03:11 +02:00
|
|
|
|
onEditingChanged: video.pause(editing)
|
|
|
|
|
onSelected: {
|
|
|
|
|
video.pause(true)
|
|
|
|
|
video.seek(event.time)
|
|
|
|
|
}
|
|
|
|
|
Keys.forwardTo: control
|
2021-09-16 20:24:07 +02:00
|
|
|
|
}
|
2021-09-15 22:03:11 +02:00
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Hotkey {
|
|
|
|
|
control: events
|
2021-09-16 20:52:01 +02:00
|
|
|
|
sequence: qsTr('Ctrl+E')
|
2021-09-16 20:24:07 +02:00
|
|
|
|
anchors {
|
|
|
|
|
right: parent.right
|
|
|
|
|
top: parent.top
|
|
|
|
|
margins: 4
|
|
|
|
|
rightMargin: control.padding + anchors.margins
|
2021-09-15 22:03:11 +02:00
|
|
|
|
}
|
2021-09-16 20:24:07 +02:00
|
|
|
|
font.pixelSize: filter.font.pixelSize * 0.75
|
2021-09-07 19:25:32 +02:00
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-15 22:21:20 +02:00
|
|
|
|
// Tags box.
|
2021-09-07 19:25:32 +02:00
|
|
|
|
Flow {
|
|
|
|
|
id: tags
|
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Layout.fillWidth: true
|
2021-09-07 19:25:32 +02:00
|
|
|
|
enabled: video.loaded && !events.editing
|
|
|
|
|
|
2021-09-16 20:24:07 +02:00
|
|
|
|
// Try passing key to each tag button in order.
|
2021-09-07 19:25:32 +02:00
|
|
|
|
Keys.forwardTo: Array.from({ length: buttons.count }, (_, i) => buttons.itemAt(i))
|
2021-09-16 20:24:07 +02:00
|
|
|
|
Keys.enabled: enabled
|
2021-09-07 19:25:32 +02:00
|
|
|
|
|
|
|
|
|
spacing: 5
|
|
|
|
|
|
|
|
|
|
Label {
|
|
|
|
|
text: qsTr('(no tags)')
|
|
|
|
|
visible: buttons.count === 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Repeater {
|
|
|
|
|
id: buttons
|
|
|
|
|
model: eventList.tagsOrder.map(name => eventList.tags[name])
|
|
|
|
|
delegate: Button {
|
|
|
|
|
readonly property string name: modelData.name || modelData.tag
|
|
|
|
|
|
|
|
|
|
text: Util.addShortcut(name, modelData.key)
|
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
|
implicitWidth: implicitContentWidth + 2*padding
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
onClicked: {
|
2021-09-16 20:24:07 +02:00
|
|
|
|
// Create a new event with this tag and current time.
|
2021-09-07 19:25:32 +02:00
|
|
|
|
const index = eventList.insert(name, video.time)
|
2021-09-05 21:16:46 +02:00
|
|
|
|
// Reset filter if new event doesn’t match.
|
|
|
|
|
var row = eventFilter.mapFromSource(eventList.index(index, 0)).row
|
2021-09-07 19:25:32 +02:00
|
|
|
|
if (row === -1) {
|
2021-09-05 21:16:46 +02:00
|
|
|
|
filter.text = ''
|
|
|
|
|
row = index
|
|
|
|
|
}
|
|
|
|
|
events.currentIndex = row
|
2021-09-01 17:13:51 +02:00
|
|
|
|
const event = events.currentItem
|
|
|
|
|
if (event.fields.length > 0)
|
|
|
|
|
events.editing = true
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
2021-09-07 19:25:32 +02:00
|
|
|
|
|
|
|
|
|
Keys.onPressed: {
|
|
|
|
|
if (event.text === modelData.key) {
|
|
|
|
|
clicked()
|
|
|
|
|
event.accepted = true
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|