AddVideoFormat.qml
5.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/* Webcamoid, webcam capture application.
* Copyright (C) 2020 Gonzalo Exequiel Pedone
*
* Webcamoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Webcamoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Ak
Dialog {
id: addFormat
standardButtons: Dialog.Ok | Dialog.Cancel
width: AkUnit.create(450 * AkTheme.controlScale, "dp").pixels
height: AkUnit.create(350 * AkTheme.controlScale, "dp").pixels
modal: true
property int formatIndex: -1
signal addFormat(variant caps)
signal changeFormat(int index, variant caps)
signal removeFormat(int index)
onVisibleChanged: pixelFormats.forceActiveFocus()
function openOptions(formatIndex=-1, caps={})
{
addFormat.formatIndex = formatIndex
title = formatIndex < 0?
qsTr("Add Video Format"):
qsTr("Change Video Format")
pixelFormats.model.clear()
let pixFormats = videoLayer.supportedOutputPixelFormats
let index = -1
for (let i in pixFormats) {
if (pixFormats[i] == videoLayer.defaultOutputPixelFormat)
index = i
pixelFormats.model.append({
format: Number(pixFormats[i]),
description: AkVideoCaps.pixelFormatToString(pixFormats[i])
})
}
removeFormat.visible = formatIndex >= 0
if (formatIndex < 0) {
pixelFormats.currentIndex = index
frameWidth.value = 640
frameHeight.value = 480
frameRate.value = 30
} else {
index = -1
for (let i in pixFormats)
if (pixFormats[i] == caps.format)
index = i
let fps = AkFrac.create(caps.fps)
pixelFormats.currentIndex = index
frameWidth.value = caps.width
frameHeight.value = caps.height
frameRate.value = fps.value
}
open()
}
ScrollView {
id: formatView
anchors.fill: parent
contentHeight: formatControls.height
clip: true
GridLayout {
id: formatControls
columns: 2
width: formatView.width
Button {
id: removeFormat
text: qsTr("Remove format")
icon.source: "image://icons/no"
flat: true
Layout.columnSpan: 2
onClicked: {
addFormat.removeFormat(addFormat.formatIndex)
addFormat.reject()
}
}
Label {
id: txtFormat
text: qsTr("Format")
}
ComboBox {
id: pixelFormats
Accessible.description: txtFormat.text
textRole: "description"
model: ListModel {}
Layout.fillWidth: true
}
Label {
id: txtWidth
text: qsTr("Width")
}
SpinBox {
id: frameWidth
value: 640
from: 1
to: 4096
stepSize: 1
editable: true
Accessible.name: txtWidth.text
}
Label {
id: txtHeight
text: qsTr("Height")
}
SpinBox {
id: frameHeight
value: 480
from: 1
to: 4096
stepSize: 1
editable: true
Accessible.name: txtHeight.text
}
Label {
id: txtFrameRate
text: qsTr("Frame rate")
}
SpinBox {
id: frameRate
value: 30
from: 1
to: 250
stepSize: 1
editable: true
Accessible.name: txtFrameRate.text
}
}
}
onAccepted: {
let element = pixelFormats.model.get(pixelFormats.currentIndex)
let fps = AkFrac.create(frameRate.value, 1).toVariant()
let caps = AkVideoCaps.create(element.format,
frameWidth.value,
frameHeight.value,
fps)
if (addFormat.formatIndex < 0)
addFormat.addFormat(caps)
else
addFormat.changeFormat(addFormat.formatIndex, caps)
}
}