From c6694afa1a7e283069a03843ffa422d98c9bacb8 Mon Sep 17 00:00:00 2001 From: kelteseth Date: Sun, 18 Feb 2018 17:02:03 +0100 Subject: [PATCH] Add fade in and out transitions --- ScreenPlayWindow/ScreenVideo.qml | 80 ++++++++--------------------- ScreenPlayWindow/main.cpp | 1 - ScreenPlayWindow/main.qml | 38 ++++++-------- ScreenPlayWindow/src/mainwindow.cpp | 39 ++++++-------- 4 files changed, 54 insertions(+), 104 deletions(-) diff --git a/ScreenPlayWindow/ScreenVideo.qml b/ScreenPlayWindow/ScreenVideo.qml index 89642d66..7acfb710 100644 --- a/ScreenPlayWindow/ScreenVideo.qml +++ b/ScreenPlayWindow/ScreenVideo.qml @@ -8,72 +8,27 @@ Rectangle { property string videoPath onVideoPathChanged: { player.source = Qt.resolvedUrl("file:///" + videoPath) - print("######### " + player.source) - state = "playing" player.play() } property bool isPlaying: true - - // onIsPlayingChanged: { - // if(isPlaying){ - // player.play() - // state = "playing" - // } else { - // player.pause() - // state = "" - // } - // } - // Connections{ - // target: wallpaper - // onPrepareDestroy:{ - // player.stop(); - // wallpaper.destroyWindow() - // } - // onVolumeChanged:{ - // player.volume = wallpaper.volume - // } - // onIsPlayingChanged:{ - // if(wallpaper.isPlaying){ - // player.play() - // } else { - // player.pause() - // } - // } - // onDecoderChanged:{ - // player.videoCodecPriority = [decoder] - // } - // onFillModeChanged:{ - // if(fillMode === "Stretch"){ - // videoOut.fillMode = VideoOutput2.Stretch - // } else if(fillMode === "PreserveAspectFit"){ - // videoOut.fillMode = VideoOutput2.PreserveAspectFit - // }else if(fillMode === "PreserveAspectCrop"){ - // videoOut.fillMode = VideoOutput2.PreserveAspectCrop - // } - // } - // } - VideoOutput2 { id: videoOut anchors.fill: parent source: player - opacity: 0 opengl: true fillMode: VideoOutput.Stretch } MediaPlayer { id: player - videoCodecPriority: ["CUDA", "VAAPI", "D3D11", "DXVA", "FFmpeg"] loops: MediaPlayer.Infinite volume: 0 onStatusChanged: { - print("STATUS: " + player.status) - if(player.status === MediaPlayer.Loaded){ - print("init") + if (player.status === MediaPlayer.Loaded) { + state = "playing" mainwindow.init() } } @@ -82,31 +37,40 @@ Rectangle { states: [ State { name: "playing" - PropertyChanges { - target: videoOut - opacity: 1 - } PropertyChanges { target: player volume: 1 } + }, + State { + name: "destroy" + PropertyChanges { + target: player + volume: 0 + } } ] transitions: [ Transition { - from: "" + from: "*" to: "playing" reversible: true - OpacityAnimator { - target: videoOut - duration: 300 - easing.type: Easing.InOutQuad - } NumberAnimation { target: player property: "volume" - duration: 300 + duration: 1000 + } + }, + Transition { + from: "playing" + to: "destroy" + reversible: true + + NumberAnimation { + target: player + property: "volume" + duration: 450 } } ] diff --git a/ScreenPlayWindow/main.cpp b/ScreenPlayWindow/main.cpp index 137e75b2..9c42bef6 100644 --- a/ScreenPlayWindow/main.cpp +++ b/ScreenPlayWindow/main.cpp @@ -24,7 +24,6 @@ int main(int argc, char* argv[]) } MainWindow w(monitor,argumentList.at(2)); - //MainWindow w(0,"D:/672870/786361026"); return a.exec(); } diff --git a/ScreenPlayWindow/main.qml b/ScreenPlayWindow/main.qml index 7f0a08f9..c37eba89 100644 --- a/ScreenPlayWindow/main.qml +++ b/ScreenPlayWindow/main.qml @@ -1,35 +1,29 @@ import QtQuick 2.9 -//import net.aimber.screenplaysdk 1.0 +import net.aimber.screenplaysdk 1.0 Rectangle { color: "gray" anchors.fill: parent property string tmpVideoPath -// ScreenPlaySDK { -// contentType: "wallpaper" + ScreenPlaySDK { + contentType: "wallpaper" -// onIncommingMessageError: { -// name.text = msg -// } + onIncommingMessageError: { + //name.text = msg + } -// onSdkConnected: { -// name.text = "connected" -// } + onSdkConnected: { + //name.text = "connected" + } -// onSdkDisconnected: { -// name.text = "disconnected" -// mainwindow.destroyThis() -// } -// } + onSdkDisconnected: { + //name.text = "disconnected" + screenVideo.state = "destroy" + mainwindow.destroyThis() + } + } -// Text { -// id: name -// text: qsTr("text") -// anchors.centerIn: parent -// font.pixelSize: 64 -// color: "orange" -// } Connections { target: mainwindow @@ -38,8 +32,6 @@ Rectangle { } } - - ScreenVideo { id:screenVideo } diff --git a/ScreenPlayWindow/src/mainwindow.cpp b/ScreenPlayWindow/src/mainwindow.cpp index 9ce7eef8..1ad984ec 100644 --- a/ScreenPlayWindow/src/mainwindow.cpp +++ b/ScreenPlayWindow/src/mainwindow.cpp @@ -102,30 +102,33 @@ MainWindow::MainWindow(int i, QString projectPath, QScreen* parent) m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView); m_quickRenderer.data()->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint); + if (m_project.contains("type")) { + if (m_project.value("type") == "video") { + QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; + emit playVideo(tmpPath); + } else if (m_project.value("type") == "scene") { + return; + } + } +} +void MainWindow::init() +{ + ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT); + ShowWindow(m_hwnd, SW_SHOWDEFAULT); + m_quickRenderer.data()->show(); + this->setVisible(true); + setOpacity(0); QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); animation->setDuration(250); animation->setEasingCurve(QEasingCurve::OutCubic); animation->setStartValue(0); animation->setEndValue(1); - animation->start(); - - QObject::connect(animation, &QPropertyAnimation::finished, [&]() { - if (m_project.contains("type")) { - if (m_project.value("type") == "video") { - QString tmpPath = m_projectPath.toString() + "/" + m_projectFile; - emit playVideo(tmpPath); - } else if (m_project.value("type") == "scene") { - return; - } - } - }); } - void MainWindow::destroyThis() { QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity"); - animation->setDuration(5000); + animation->setDuration(500); animation->setStartValue(1); animation->setEndValue(0); animation->start(); @@ -137,14 +140,6 @@ void MainWindow::destroyThis() }); } -void MainWindow::init() -{ - ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT); - ShowWindow(m_hwnd, SW_SHOWDEFAULT); - m_quickRenderer.data()->show(); - this->show(); -} - QUrl MainWindow::projectPath() const { return m_projectPath;