-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
197 lines (171 loc) · 5.14 KB
/
main.qml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import QtQuick
import QtQuick.Window
import QtMultimedia
import Qt5Compat.GraphicalEffects
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Layouts
import QtQuick.Dialogs
import QtCore
Window {
id: mwin
width: parseInt(settingsDialog.sizeValue) + margins*2
height: parseInt(settingsDialog.sizeValue) + margins*2
visible: true
title: qsTr("Easy Camera")
color: "#00000000"
flags: Qt.FramelessWindowHint |
Qt.WindowStaysOnTopHint
Material.accent: Material.Cyan
readonly property real margins: 30
readonly property bool maximized: mwin.visibility == Window.Maximized
readonly property bool recording: recorder.recorderState === MediaRecorder.RecordingState
Settings {
id: settings
property alias size: settingsDialog.size
property alias camera: settingsDialog.camera
property alias audio: settingsDialog.audio
property alias windowX: mwin.x
property alias windowY: mwin.y
property alias output: settingsDialog.output
}
MediaDevices {
id: mediaDevices
}
CaptureSession {
screenCapture: ScreenCapture {
id: screenCapture
active: true
}
audioInput: AudioInput {
device: settingsDialog.audioValue
}
recorder: MediaRecorder {
id: recorder
}
}
CaptureSession {
camera: Camera {
cameraDevice: settingsDialog.cameraValue
whiteBalanceMode: Camera.WhiteBalanceAuto
exposureMode: Camera.ExposureAuto
active: true
}
videoOutput: videoOutput
}
VideoOutput {
id: videoOutput
anchors.margins: maximized? 0 : margins
anchors.fill: parent
fillMode: VideoOutput.PreserveAspectCrop
visible: false
}
Item {
id: mask
anchors.fill: videoOutput
visible: false
Rectangle {
width: mwin.maximized? mwin.width : Math.min(mask.width, mask.height)
height: mwin.maximized? mwin.height : width
radius: mwin.maximized? 0 : height / 2
anchors.centerIn: parent
}
}
DropShadow {
source: mask
anchors.fill: videoOutput
radius: 16
opacity: 0.3 * opacityMask.opacity
horizontalOffset: 4
verticalOffset: 4
}
OpacityMask {
id: opacityMask
anchors.fill: videoOutput
source: videoOutput
maskSource: mask
Behavior on opacity {
NumberAnimation { easing.type: Easing.OutCubic; duration: 300 }
}
}
MouseArea {
id: marea
anchors.fill: parent
cursorShape: pressed? Qt.ClosedHandCursor : Qt.OpenHandCursor
hoverEnabled: true
onPressed: {
moving = false;
pin = Qt.point(mouseX, mouseY);
}
onPositionChanged: {
if (mwin.maximized || !pressed)
return;
const dx = Math.abs(mouseX - pin.x);
const dy = Math.abs(mouseY - pin.y);
if (dx + dy < 20 && !moving)
return;
moving = true;
const globalPos = mapToGlobal(mouseX, mouseY);
mwin.x = globalPos.x - pin.x;
mwin.y = globalPos.y - pin.y;
}
onDoubleClicked: {
if (mwin.maximized)
mwin.showNormal()
else
mwin.showMaximized()
}
property point pin
property bool moving
}
MouseArea {
width: parent.width
height: 110
hoverEnabled: true
opacity: containsMouse? 1 : 0
Behavior on opacity {
NumberAnimation { easing.type: Easing.OutCubic; duration: 300 }
}
RowLayout {
anchors.centerIn: parent
Button {
text: qsTr("Menu")
onClicked: menu.open()
Menu {
id: menu
Material.theme: Material.Dark
MenuItem {
text: qsTr("Settings")
onClicked: settingsDialog.showNormal()
}
MenuSeparator {}
MenuItem {
text: qsTr("Exit")
onClicked: Qt.exit(0)
}
}
}
Button {
highlighted: true
text: recording? qsTr("Stop") : qsTr("Record")
Material.accent: recording? Material.Red : Material.Cyan
onClicked: {
if (recording) {
recorder.stop();
cursorWindow.close();
} else {
recorder.outputLocation = "file://" + settingsDialog.output + "/easy_camera-" + (new Date).getTime() + ".mp4"
recorder.record();
cursorWindow.showMaximized();
}
}
}
}
}
SettingsDialog {
id: settingsDialog
}
CursorWindow {
id: cursorWindow
}
}