-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMediaComponent.qml
More file actions
345 lines (299 loc) · 11 KB
/
MediaComponent.qml
File metadata and controls
345 lines (299 loc) · 11 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
import QtQuick
import QtQuick.Effects
import QtMultimedia
import gavqml
Item {
property alias audioOutput: audioOutput
property bool controlsAreVisible: true
property bool isPlaying: false
property bool isVideo: customMediaPlayer.hasVideo
property bool isVideoAndPlaying: isVideo && isPlaying
property bool mediaLoaded: customMediaPlayer.mediaLoaded
property alias mediaPlayer: customMediaPlayer
required property string path
property alias videoOutput: videoOutput
signal stopped
signal fullscreenToggleRequested
height: parent.height
width: parent.width
CustomMediaPlayer {
id: customMediaPlayer
audioOutput: audioOutput
source: path
videoOutput: videoOutput
onErrorOccurred: function (errorString) {
console.log("MediaPlayer error:", errorString);
playbackErrorDialog.open();
}
onPlaybackStateChanged: function (state) {
if (state === MediaPlayer.PlayingState) {
isPlaying = true;
hideControlsTimer.start();
} else if (state === MediaPlayer.PausedState) {
isPlaying = true; // We still want to show the video when paused
} else {
// Stopped state - reset everything
controlsAreVisible = true;
isPlaying = false;
hideControlsTimer.stop();
// Reset zoom and pan
videoOutput.zoomLevel = 1.0;
videoOutput.panX = 0;
videoOutput.panY = 0;
videoOutput.zoomOriginX = videoOutput.width / 2;
videoOutput.zoomOriginY = videoOutput.height / 2;
// Reset brightness and contrast
videoOutput.brightnessLevel = AppConstants.defaultBrightness;
videoOutput.contrastLevel = AppConstants.defaultContrast;
// Notify parent to reset path and title
stopped();
}
}
onVideoVisibilityChanged: function (visible) {
videoOutput.visible = visible;
}
}
// Vertical volume display
Column {
id: volumeColumn
anchors.right: parent.right
anchors.rightMargin: 20
anchors.verticalCenter: parent.verticalCenter
opacity: 0.7
spacing: 10
visible: false
z: 100
Text {
id: volumeText
color: "white"
font.bold: true
font.pixelSize: 25
horizontalAlignment: Text.AlignHCenter
style: Text.Outline
styleColor: "black"
text: Math.round(audioOutput.volume * 100) + "%"
width: 50
}
Rectangle {
id: volumeViz
border.color: "white"
border.width: 2
clip: true
color: "#2a2a2a"
height: 250
radius: 5
width: 50
Rectangle {
anchors.bottom: parent.bottom
anchors.left: parent.left
anchors.right: parent.right
color: "#4CAF50"
height: parent.height * audioOutput.volume
radius: 5
}
}
Timer {
id: volumeDisplayTimer
interval: AppConstants.volumeDisplayDuration
repeat: false
onTriggered: volumeColumn.visible = false
}
}
// Zoom level indicator
Rectangle {
id: zoomIndicator
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 20
border.color: "white"
border.width: 2
color: "#2a2a2a"
height: zoomText.height + 20
opacity: 0.8
radius: 8
visible: videoOutput.zoomLevel > 1.0
width: zoomText.width + 30
z: 100
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
Text {
id: zoomText
anchors.centerIn: parent
color: "white"
font.bold: true
font.pixelSize: 18
text: "Zoom: " + Math.round(videoOutput.zoomLevel * 100) + "%"
}
// Auto-hide after zoom changes
Timer {
id: zoomDisplayTimer
interval: AppConstants.zoomDisplayDuration
repeat: false
running: videoOutput.zoomLevel > 1.0
onTriggered: {
if (videoOutput.zoomLevel <= 1.0) {
zoomIndicator.visible = false;
}
}
}
}
AudioOutput {
id: audioOutput
volume: AppConstants.defaultVolume
}
VideoOutput {
id: videoOutput
// Brightness and contrast properties
property real brightnessLevel: AppConstants.defaultBrightness
property real contrastLevel: AppConstants.defaultContrast
property real panX: 0
property real panY: 0
// Zoom and pan properties
property real zoomLevel: 1.0
// Zoom origin point (where the mouse was when zooming)
property real zoomOriginX: width / 2
property real zoomOriginY: height / 2
anchors.fill: parent
visible: false
// Apply brightness/contrast effect via layer
layer.enabled: brightnessLevel !== AppConstants.defaultBrightness || contrastLevel !== AppConstants.defaultContrast
layer.effect: MultiEffect {
brightness: videoOutput.brightnessLevel
contrast: videoOutput.contrastLevel
}
Behavior on panX {
NumberAnimation {
duration: 100
easing.type: Easing.OutQuad
}
}
Behavior on panY {
NumberAnimation {
duration: 100
easing.type: Easing.OutQuad
}
}
transform: [
Scale {
id: videoScale
origin.x: videoOutput.zoomOriginX
origin.y: videoOutput.zoomOriginY
xScale: videoOutput.zoomLevel
yScale: videoOutput.zoomLevel
},
Translate {
id: videoTranslate
x: videoOutput.panX
y: videoOutput.panY
}
]
Behavior on zoomLevel {
NumberAnimation {
duration: 50
easing.type: Easing.OutQuad
}
}
}
MouseArea {
id: mouseArea
property point dragStartPos: Qt.point(0, 0)
property bool isDragging: false
property point lastPos: Qt.point(mouseX, mouseY)
property real startPanX: 0
property real startPanY: 0
acceptedButtons: Qt.LeftButton | Qt.RightButton
anchors.fill: parent
cursorShape: {
if (isDragging) {
return Qt.ClosedHandCursor;
} else if (videoOutput.zoomLevel > 1.0) {
return Qt.OpenHandCursor;
} else {
return Qt.ArrowCursor;
}
}
hoverEnabled: true
onDoubleClicked: function (mouse) {
// Only toggle fullscreen when video is playing or paused
if (customMediaPlayer.playbackState !== MediaPlayer.StoppedState) {
fullscreenToggleRequested();
}
}
onPositionChanged: {
if (isDragging && videoOutput.zoomLevel > 1.0) {
// Calculate drag delta
var deltaX = mouseX - dragStartPos.x;
var deltaY = mouseY - dragStartPos.y;
// Update pan position with constraints
var maxPanX = videoOutput.width * (videoOutput.zoomLevel - 1) / 2;
var maxPanY = videoOutput.height * (videoOutput.zoomLevel - 1) / 2;
videoOutput.panX = Math.max(-maxPanX, Math.min(maxPanX, startPanX + deltaX));
videoOutput.panY = Math.max(-maxPanY, Math.min(maxPanY, startPanY + deltaY));
} else if (mouseX !== lastPos.x || mouseY !== lastPos.y) {
controlsAreVisible = true;
if (customMediaPlayer.playbackState === MediaPlayer.PlayingState) {
hideControlsTimer.restart();
}
lastPos = Qt.point(mouseX, mouseY);
}
}
onPressed: function (mouse) {
if (videoOutput.zoomLevel > 1.0) {
isDragging = true;
dragStartPos = Qt.point(mouseX, mouseY);
startPanX = videoOutput.panX;
startPanY = videoOutput.panY;
cursorShape = Qt.ClosedHandCursor;
}
}
onReleased: function (mouse) {
isDragging = false;
cursorShape = videoOutput.zoomLevel > 1.0 ? Qt.OpenHandCursor : Qt.ArrowCursor;
}
onWheel: function (wheel) {
// Only handle scroll when video is playing or paused (not stopped)
var isActive = customMediaPlayer.playbackState !== MediaPlayer.StoppedState;
// Ctrl + Scroll = Zoom (Chrome-like multiplicative scaling)
if (wheel.modifiers & Qt.ControlModifier && videoOutput.visible && isActive) {
// Each scroll step multiplies/divides by zoom factor
var zoomFactor = wheel.angleDelta.y > 0 ? AppConstants.zoomFactor : (1 / AppConstants.zoomFactor);
var newZoom = Math.max(AppConstants.zoomMin, Math.min(AppConstants.zoomMax, videoOutput.zoomLevel * zoomFactor));
// Reset when zooming back to minimum
if (newZoom === AppConstants.zoomMin) {
videoOutput.panX = 0;
videoOutput.panY = 0;
videoOutput.zoomOriginX = videoOutput.width / 2;
videoOutput.zoomOriginY = videoOutput.height / 2;
} else {
// Set zoom origin to mouse position for zoom-to-cursor effect
videoOutput.zoomOriginX = mouseX;
videoOutput.zoomOriginY = mouseY;
}
videoOutput.zoomLevel = newZoom;
// Regular Scroll = Volume
} else if (wheel.angleDelta.y > 0 && videoOutput.visible && isActive) {
audioOutput.volume = Math.min(audioOutput.volume + AppConstants.volumeStep, 1.0);
volumeColumn.visible = true;
volumeDisplayTimer.restart();
} else if (wheel.angleDelta.y < 0 && videoOutput.visible && isActive) {
audioOutput.volume = Math.max(audioOutput.volume - AppConstants.volumeStep, 0.0);
volumeColumn.visible = true;
volumeDisplayTimer.restart();
}
}
}
Timer {
id: hideControlsTimer
interval: AppConstants.controlsHideDelay
repeat: false
onTriggered: {
if (!mainWindow.mediaControlsContainsMouse) {
controlsAreVisible = false;
mouseArea.lastPos = Qt.point(-1, -1); // Reset position detector
}
}
}
}