lumina/src/qml/presenter/Slide.qml
2024-09-26 05:43:39 -05:00

245 lines
6.4 KiB
QML

import QtQuick 2.15
import QtQuick.Controls 2.15 as Controls
import QtQuick.Layouts 1.15
import QtMultimedia
/* import QtAudioEngine 1.15 */
import QtWebEngine 1.10
import Qt5Compat.GraphicalEffects
import org.kde.kirigami 2.13 as Kirigami
import "./" as Presenter
import org.presenter 1.0
Item {
id: root
// Let's make this slide editable
property bool editMode: false
// These properties are for the slides visuals
property real textSize: 50
property bool dropShadow: false
property url imageSource
property url webSource
property bool htmlVisible: false
property url videoSource
property url audioSource
property bool vidLoop
property real vidStartTime
property real vidEndTime
property int pdfIndex
property string chosenFont: "Quicksand"
property string text
property string audioError
property color backgroundColor
property var hTextAlignment: Text.AlignHCenter
property var vTextAlignment: Text.AlignVCenter
//these properties are for giving video info to parents
property int videoPosition: video.position
property int videoDuration: video.duration
property var videoLoop: video.loops
property bool videoIsPlaying: video.playbackState
// These propees help to determine the state of the slide
property string itemType
property bool preview: false
implicitWidth: 1920
implicitHeight: 1080
Rectangle {
id: basePrColor
anchors.fill: parent
color: "black"
Image {
id: backgroundImage
anchors.fill: parent
source: imageSource
fillMode: itemType == "song" ? Image.PreserveAspectCrop : Image.PreserveAspectFit
clip: true
visible: webSource.length == 0
currentFrame: pdfIndex
}
Rectangle {
id: black
color: "Black"
anchors.fill: parent
visible: false
}
Video {
id: video
anchors.fill: parent
muted: preview
Component.onCompleted: mpvLoadingTimer.start()
loops: itemType == "song" ? MediaPlayer.Infinite : vidLoop ? MediaPlayer.Infinite : 1
source: videoSource
MouseArea {
id: playArea
anchors.fill: parent
enabled: editMode
/* onPressed: mpv.playPause(); */
cursorShape: preview ? Qt.ArrowCursor : Qt.BlankCursor
}
}
Timer {
id: pauseTimer
interval: 300
onTriggered: mpv.pause()
}
Timer {
id: blackTimer
interval: 400
onTriggered: {
black.visible = false;
}
}
MediaPlayer {
id: audio
audioOutput: AudioOutput {}
source: audioSource
}
FastBlur {
id: imageBlue
anchors.fill: parent
source: imageSource === "" ? mpv : backgroundImage
radius: blurRadius
Controls.Label {
id: lyrics
text: root.text
/* text: root.textSize */
/* text: root.width / 1000 * root.textSize */
font.pixelSize: Math.max(root.width, 1000) / 1000 * Math.max(root.textSize, 50)
/* minimumPointSize: 5 */
fontSizeMode: Text.Fit
font.family: chosenFont
horizontalAlignment: hTextAlignment
verticalAlignment: vTextAlignment
style: Text.Raised
wrapMode: Text.WordWrap
anchors.fill: parent
anchors.topMargin: 10
anchors.bottomMargin: 10
anchors.leftMargin: 10
anchors.rightMargin: 10
clip: true
layer.enabled: true
layer.effect: DropShadow {
horizontalOffset: 5
verticalOffset: 5
radius: 11.0
samples: 24
color: "#80000000"
}
}
}
WebEngineView {
id: web
anchors.fill: parent
url: webSource
visible: htmlVisible
enabled: htmlVisible
zoomFactor: preview ? 0.25 : 1.0
backgroundColor: Kirigami.Theme.backgroundColor
onLoadingChanged: {
if (loadRequest.status == 2)
showPassiveNotification("yahoo?");
}
settings.playbackRequiresUserGesture: false
audioMuted: root.preview
/* function moveToSlideIndex(index) { */
/* web.runJavaScript(" */
/* const index */
/* for (let i = 0; i < index; i++) { */
/* Reveal.next(); */
/* }") */
/* } */
}
}
Connections {
target: SlideObject
function onRevealNext() {
console.log("revealNext")
web.runJavaScript("Reveal.next()")
}
function onRevealPrev() {
console.log("revealPrev")
web.runJavaScript("Reveal.prev()")
}
}
function changeText(text) {
lyrics.text = text
}
function loopVideo() {
if (mpv.getProperty("loop") === "inf") {
showPassiveNotification("already looping");
mpv.setProperty("loop", "no");
}
else {
mpv.setProperty("loop", "inf");
showPassiveNotification("looping video");
}
}
function loadVideo() {
video.seek(0)
video.play()
}
function playAudio() {
audio.play();
showPassiveNotification("Audio should change");
}
function stopAudio() {
audio.stop();
}
function stopVideo() {
video.stop();
black.visible = true;
console.log("Stopped video");
}
function seek(pos) {
video.seek(pos);
}
function quitMpv() {
mpv.quit();
}
function pauseVideo() {
video.pause();
}
function playPauseVideo() {
video.playbackState == MediaPlayer.PlayingState ? video.pause() : video.play()
}
function playVideo() {
video.play();
}
function revealNext() {
web.runJavaScript("Reveal.next()")
}
function revealPrev() {
web.runJavaScript("Reveal.prev()")
}
}