1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-09-15 06:52:34 +02:00

Fix window positioning FINALLY

This commit is contained in:
kelteseth 2018-02-14 10:21:15 +01:00
parent 245c28314e
commit b675c4dd97
8 changed files with 234 additions and 46 deletions

View File

@ -106,7 +106,11 @@ void Settings::setWallpaper(int monitorIndex, QUrl absoluteStoragePath)
}
}
increaseActiveWallpaperCounter();
m_windows.append(new QProcess());
auto pro = new QProcess();
QStringList proArgs;
proArgs.append(absoluteStoragePath.toString());
m_windows.append(pro);
m_windows.last()->start(m_screenPlayWindowPath.toString());
}

View File

@ -1,5 +1,6 @@
<RCC>
<qresource prefix="/">
<file>main.qml</file>
<file>ScreenVideo.qml</file>
</qresource>
</RCC>

View File

@ -1,5 +1,5 @@
TEMPLATE = app
QT += qml quick av widgets quickcontrols2
QT += qml quick av widgets quickcontrols2 widgets
CONFIG += c++17

View File

@ -0,0 +1,101 @@
import QtQuick 2.9
import QtAV 1.7
Rectangle {
color: "black"
id: screenVideoPlayer
anchors.fill: parent
property string videoPath
property bool isPlaying: false
Component.onCompleted: screenVideoPlayer.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
source: "d:/672870/860170953/horde_1980.mp4"
}
states: [
State {
name: "playing"
PropertyChanges {
target: videoOut
opacity: 1
}
PropertyChanges {
target: player
volume: 1
}
}
]
transitions: [
Transition {
from: ""
to: "playing"
reversible: true
OpacityAnimator {
target: videoOut
duration: 300
easing.type: Easing.InOutQuad
}
NumberAnimation {
target: player
property: "volume"
duration: 300
}
}
]
}

View File

@ -7,6 +7,12 @@ int main(int argc, char *argv[])
//QCoreApplication::addLibraryPath("C:/msys64/mingw64/bin");
QApplication a(argc, argv);
MainWindow w;
QStringList argumentList = a.arguments();
//MainWindow w(argumentList.at(0));
//MainWindow w(0,"D:/672870/860170953");
//MainWindow w1(1,"D:/672870/818696361");
MainWindow w2(2,"D:/672870/860170953");
return a.exec();
}

View File

@ -19,35 +19,29 @@ Rectangle {
onSdkDisconnected: {
name.text = "disconnected"
mainwindow.destroyThis()
//mainwindow.destroyThis()
}
}
Text {
id: name
text: qsTr("text")
anchors {
horizontalCenter: parent.horizontalCenter
}
y:-100
Connections {
target: mainwindow
onPlayVideo:{
loaderVideo.active = true
print(path)
//loaderVideo.item.videoPath = path
font.pixelSize: 36
SequentialAnimation {
loops: SequentialAnimation.Infinite
running: true
NumberAnimation {
target: name
property: "y"
duration: 2000
easing.type: Easing.InOutQuad
to:500
}
NumberAnimation {
target: name
property: "y"
duration: 2000
easing.type: Easing.InOutQuad
to:300
}
}
Loader {
id:loaderVideo
anchors.fill: parent
asynchronous: true
active: false
source: "qrc:/ScreenVideo.qml"
onStateChanged: {
if(status == Loader.Ready){
loaderVideo.item.isPlaying = true
}
}
}

View File

@ -1,5 +1,7 @@
#include "mainwindow.h"
#include <QJsonDocument>
BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam)
{
// 0xXXXXXXX "" WorkerW
@ -13,20 +15,60 @@ BOOL WINAPI SearchForWorkerWindow(HWND hwnd, LPARAM lparam)
return TRUE;
}
MainWindow::MainWindow(QScreen* parent)
MainWindow::MainWindow(int i, QString projectPath, QScreen* parent)
: QWindow(parent)
{
// for (int var = 0; var < QApplication::screens().count(); ++var) {
// QScreen* screen = QApplication::screens().at(i);
// }
setOpacity(0);
m_projectPath = projectPath;
QFile configTmp;
QJsonDocument configJsonDocument;
QJsonParseError parseError;
configTmp.setFileName(projectPath + "/project.json");
configTmp.open(QIODevice::ReadOnly | QIODevice::Text);
QString config = configTmp.readAll();
configJsonDocument = QJsonDocument::fromJson(config.toUtf8(), &parseError);
if (!(parseError.error == QJsonParseError::NoError)) {
qWarning("Settings Json Parse Error ");
return;
}
m_project = configJsonDocument.object();
//Some settings dont have a file type
if (!m_project.contains("type")) {
if (m_project.contains("file")) {
QString fileEnding = m_project.value("file").toString();
if (fileEnding.endsWith(".mp4") || fileEnding.endsWith(".vp9")) {
m_project.insert("type", "video");
}
}
}
if (m_project.contains("file"))
m_projectFile = m_project.value("file").toString();
this->m_hwnd = (HWND)this->winId();
QScreen* screen = QApplication::screens().at(0);
// Recalculate window coordiantes because of point (0,0)
// Is at the origin monitor or the most left
QScreen* screen = QApplication::screens().at(i);
int offsetX = 0;
int offsetY = 0;
setScreen(screen);
for (int i = 0; i < QApplication::screens().count(); i++) {
QScreen* screen = QApplication::screens().at(i);
qDebug() << screen->availableGeometry().x();
if (screen->availableGeometry().x() < 0) {
offsetX += (screen->availableGeometry().x() * -1);
}
if (screen->availableGeometry().y() < 0) {
offsetY += (screen->availableGeometry().y() * -1);
}
}
HWND progman_hwnd = FindWindowW(L"Progman", L"Program Manager");
@ -39,13 +81,13 @@ MainWindow::MainWindow(QScreen* parent)
1000, nullptr);
EnumWindows(SearchForWorkerWindow, reinterpret_cast<LPARAM>(&m_worker_hwnd));
//Hide first to avoid flickering
ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE);
SetParent(m_hwnd, m_worker_hwnd);
SetWindowPos(m_worker_hwnd, HWND_BOTTOM, screen->geometry().x(), screen->geometry().y(), screen->geometry().width(), screen->geometry().height(), SWP_SHOWWINDOW);
SetWindowPos(m_hwnd, HWND_BOTTOM, screen->geometry().x(), screen->geometry().y(), screen->size().width(), screen->size().height(), SWP_SHOWWINDOW);
MoveWindow(m_hwnd, screen->geometry().x() + offsetX, screen->geometry().y() + offsetY, screen->size().width(), screen->size().height(), true);
SetParent(m_hwnd, m_worker_hwnd);
SetWindowLongPtr(m_hwnd, GWL_STYLE,
WS_CAPTION | WS_THICKFRAME | WS_MINIMIZE | WS_MAXIMIZE | WS_SYSMENU);
SetWindowLongPtr(m_hwnd, GWL_EXSTYLE,
@ -53,14 +95,11 @@ MainWindow::MainWindow(QScreen* parent)
Qt::WindowFlags flags = this->flags();
this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
this->show();
m_quickRenderer = QSharedPointer<QQuickView>(new QQuickView(this));
//m_quickRenderer.data()->engine()->addImportPath("C:/msys64/mingw64/share/qt5/qml");
//m_quickRenderer.data()->engine()->addImportPath("C:/msys64/mingw64/share/qt5");
m_quickRenderer.data()->rootContext()->setContextProperty("mainwindow", this);
m_quickRenderer.data()->setGeometry(screen->geometry());
m_quickRenderer.data()->setGeometry(0,0, screen->size().width(), screen->size().height());
m_quickRenderer.data()->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
m_quickRenderer.data()->setSource(QUrl("qrc:/main.qml"));
@ -69,21 +108,52 @@ MainWindow::MainWindow(QScreen* parent)
animation->setEasingCurve(QEasingCurve::OutCubic);
animation->setStartValue(0);
animation->setEndValue(1);
m_quickRenderer.data()->show();
show();
ShowWindow(m_worker_hwnd, SW_SHOWDEFAULT);
ShowWindow(m_hwnd, SW_SHOWDEFAULT);
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;
tmpPath.replace("/", "\\\\");
emit playVideo(tmpPath);
} else if (m_project.value("type") == "scene") {
return;
}
}
});
}
void MainWindow::destroyThis()
{
ShowWindow(m_worker_hwnd, SW_HIDE);
ShowWindow(m_hwnd, SW_HIDE);
QCoreApplication::quit();
/*
QPropertyAnimation* animation = new QPropertyAnimation(this, "opacity");
animation->setDuration(5000);
animation->setStartValue(1);
animation->setEndValue(0);
animation->start();
QObject::connect(animation,&QPropertyAnimation::finished, [&]() {
});*/
}
QUrl MainWindow::projectPath() const
{
return m_projectPath;
}
void MainWindow::setProjectPath(const QUrl& projectPath)
{
m_projectPath = projectPath;
}
MainWindow::~MainWindow()

View File

@ -2,6 +2,7 @@
#include <QApplication>
#include <QEasingCurve>
#include <QObject>
#include <QPropertyAnimation>
#include <QQmlContext>
#include <QQmlEngine>
@ -10,6 +11,7 @@
#include <QWindow>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickWindow>
#include <QJsonObject>
#include "qt_windows.h"
@ -17,14 +19,24 @@ class MainWindow : public QWindow {
Q_OBJECT
public:
explicit MainWindow(QScreen* parent = 0);
explicit MainWindow(int i, QString projectPath, QScreen* parent = 0);
void init();
~MainWindow();
QUrl projectPath() const;
void setProjectPath(const QUrl &projectPath);
public slots:
void destroyThis();
signals:
void playVideo(QString path);
private:
HWND m_hwnd;
HWND m_worker_hwnd;
QSharedPointer<QQuickView> m_quickRenderer = nullptr;
QUrl m_projectPath;
QString m_projectFile;
QJsonObject m_project;
};