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-06-14 19:09:53 +02:00
|
|
|
|
Page {
|
|
|
|
|
id: control
|
|
|
|
|
|
|
|
|
|
property bool modified: false
|
|
|
|
|
property Video video
|
|
|
|
|
|
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 {
|
|
|
|
|
id: videoDialog
|
|
|
|
|
title: qsTr('Open video')
|
|
|
|
|
onAccepted: {
|
|
|
|
|
video.source = currentFile
|
2021-09-01 17:13:51 +02:00
|
|
|
|
const json = JSON.parse(io.read(currentFile+'.events') || '{}')
|
|
|
|
|
eventList.load(json)
|
|
|
|
|
description.text = json['description'] || ''
|
|
|
|
|
modified = false
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileDialog {
|
|
|
|
|
id: tagsDialog
|
|
|
|
|
title: qsTr('Load tags')
|
|
|
|
|
nameFilters: [qsTr('JSON files (*.json)'), qsTr('All files (*)')]
|
2021-09-01 17:13:51 +02:00
|
|
|
|
onAccepted: eventList.load({ 'tags': JSON.parse(io.read(currentFile)) })
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Keys.forwardTo: [tags, video]
|
|
|
|
|
|
|
|
|
|
header: ToolBar {
|
|
|
|
|
horizontalPadding: 0
|
|
|
|
|
RowLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
ToolButton {
|
|
|
|
|
action: Action {
|
|
|
|
|
icon.name: 'document-open'
|
|
|
|
|
shortcut: StandardKey.Open
|
|
|
|
|
onTriggered: videoDialog.open()
|
|
|
|
|
}
|
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
|
}
|
|
|
|
|
Label {
|
|
|
|
|
text: video.loaded ? video.source : ''
|
|
|
|
|
elide: Text.ElideLeft
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
|
|
|
|
ToolButton {
|
|
|
|
|
action: Action {
|
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
|
|
|
|
shortcut: StandardKey.Save
|
|
|
|
|
icon.name: 'document-save'
|
|
|
|
|
enabled: video.loaded && control.modified
|
|
|
|
|
}
|
|
|
|
|
visible: video.loaded
|
|
|
|
|
opacity: enabled ? 1 : 0.25
|
|
|
|
|
focusPolicy: Qt.NoFocus
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
|
|
// Description box.
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
spacing: 0
|
|
|
|
|
RowLayout {
|
|
|
|
|
Label {
|
|
|
|
|
text: qsTr('Description')
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
|
|
|
|
Label { text: description.enabled ? qsTr('−') : qsTr('+') }
|
|
|
|
|
TapHandler { onTapped: description.enabled = !description.enabled }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ScrollView {
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.preferredHeight: 100
|
|
|
|
|
contentWidth: parent.availableWidth
|
|
|
|
|
padding: 1
|
|
|
|
|
|
|
|
|
|
visible: description.enabled
|
|
|
|
|
background: Frame { }
|
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
|
|
|
|
|
|
TextArea {
|
|
|
|
|
id: description
|
|
|
|
|
|
|
|
|
|
background: Rectangle { color: palette.base }
|
|
|
|
|
leftPadding: padding
|
|
|
|
|
selectByMouse: true
|
|
|
|
|
wrapMode: Text.Wrap
|
|
|
|
|
|
|
|
|
|
onTextChanged: modified = true
|
|
|
|
|
KeyNavigation.priority: KeyNavigation.BeforeItem
|
|
|
|
|
KeyNavigation.tab: events
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Events list.
|
|
|
|
|
ColumnLayout {
|
|
|
|
|
spacing: 0
|
2021-09-05 21:16:46 +02:00
|
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
|
Label {
|
|
|
|
|
text: qsTr('Events')
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
}
|
|
|
|
|
Label { text: qsTr('🔍') }
|
|
|
|
|
TapHandler { onTapped: filter.visible = !filter.visible }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TextField {
|
|
|
|
|
id: filter
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
placeholderText: qsTr('Filter…')
|
|
|
|
|
visible: false
|
|
|
|
|
onTextChanged: eventFilter.setFilter(text)
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Frame {
|
|
|
|
|
padding: 1
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
|
|
Events {
|
|
|
|
|
id: events
|
|
|
|
|
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
focus: true
|
2021-09-05 21:16:46 +02:00
|
|
|
|
model: eventFilter
|
2021-09-01 17:13:51 +02:00
|
|
|
|
tags: eventList.tags
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
|
|
|
|
onEditingChanged: video.pause(editing)
|
2021-09-01 17:13:51 +02:00
|
|
|
|
onCurrentItemChanged: {
|
|
|
|
|
if (currentItem)
|
|
|
|
|
video.seek(currentItem.time)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Keys.onPressed: {
|
|
|
|
|
switch (event.key) {
|
|
|
|
|
case Qt.Key_Home:
|
|
|
|
|
currentIndex = 0
|
|
|
|
|
break
|
|
|
|
|
case Qt.Key_End:
|
|
|
|
|
currentIndex = count-1
|
|
|
|
|
break
|
|
|
|
|
case Qt.Key_Enter:
|
|
|
|
|
case Qt.Key_Return:
|
|
|
|
|
if (editing) {
|
|
|
|
|
currentItem.store()
|
|
|
|
|
editing = false
|
|
|
|
|
} else {
|
|
|
|
|
if (currentItem.fields.length > 0)
|
|
|
|
|
editing = true
|
|
|
|
|
}
|
|
|
|
|
break
|
|
|
|
|
case Qt.Key_Escape:
|
|
|
|
|
if (editing) {
|
|
|
|
|
currentItem.reset()
|
|
|
|
|
editing = false
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
2021-09-01 17:13:51 +02:00
|
|
|
|
break
|
|
|
|
|
case Qt.Key_Delete:
|
|
|
|
|
editing = false
|
2021-09-05 21:16:46 +02:00
|
|
|
|
eventFilter.remove(currentIndex)
|
2021-09-01 17:13:51 +02:00
|
|
|
|
break
|
|
|
|
|
case Qt.Key_Tab:
|
|
|
|
|
case Qt.Key_Backtab:
|
|
|
|
|
// swallow tabs so we don’t lose focus when editing
|
|
|
|
|
break
|
|
|
|
|
default:
|
|
|
|
|
return
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
2021-09-01 17:13:51 +02:00
|
|
|
|
event.accepted = true
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
// Tag list.
|
|
|
|
|
Frame {
|
2021-06-14 19:09:53 +02:00
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.fillHeight: false
|
2021-09-01 17:13:51 +02:00
|
|
|
|
padding: 5
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
ColumnLayout {
|
2021-06-14 19:09:53 +02:00
|
|
|
|
width: parent.width
|
2021-09-01 17:13:51 +02:00
|
|
|
|
spacing: 0
|
2021-06-14 19:09:53 +02:00
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
RowLayout {
|
|
|
|
|
Label {
|
|
|
|
|
text: qsTr('Tags')
|
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
2021-09-01 17:13:51 +02:00
|
|
|
|
ToolButton {
|
|
|
|
|
icon.name: 'document-open'
|
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
|
onClicked: tagsDialog.open()
|
|
|
|
|
focusPolicy:Qt.NoFocus
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-01 17:13:51 +02:00
|
|
|
|
Tags {
|
|
|
|
|
id: tags
|
|
|
|
|
model: eventList.tagsOrder.map(tag => eventList.tags[tag])
|
|
|
|
|
enabled: video.loaded && !events.editing
|
|
|
|
|
onClicked: {
|
2021-09-05 21:16:46 +02:00
|
|
|
|
const index = eventList.insert(tag, video.time)
|
|
|
|
|
// Reset filter if new event doesn’t match.
|
|
|
|
|
var row = eventFilter.mapFromSource(eventList.index(index, 0)).row
|
|
|
|
|
if (eventFilter.mapFromSource(eventList.index(index, 0)).row === -1) {
|
|
|
|
|
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-01 17:13:51 +02:00
|
|
|
|
Layout.fillWidth: true
|
2021-06-14 19:09:53 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|