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

Add ability to start video via gui

This commit is contained in:
kelteseth 2017-04-06 23:12:58 +02:00
parent 71ed839495
commit 26d40f4e7d
15 changed files with 159 additions and 61 deletions

View File

@ -7,7 +7,8 @@ SOURCES += main.cpp \
src/screenplay.cpp \
src/steamworkshop.cpp \
src/installedlistmodel.cpp \
src/screenplayitem.cpp
src/mainwindow.cpp \
RESOURCES += qml.qrc
@ -37,7 +38,7 @@ HEADERS += \
src/screenplay.h \
src/steamworkshop.h \
src/installedlistmodel.h \
src/screenplayitem.h
src/mainwindow.h
INCLUDEPATH += $$PWD/ThirdParty/Steam/
INCLUDEPATH += $$PWD/src/

View File

@ -14,6 +14,7 @@
#include "installedlistmodel.h"
#include "screenplay.h"
#include "mainwindow.h"
int main(int argc, char* argv[])
{
@ -28,10 +29,17 @@ int main(int argc, char* argv[])
QQmlApplicationEngine mainWindow;
mainWindow.rootContext()->setContextProperty("installedListModel", &ilm);
mainWindow.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
//ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
sp.context()->setContextProperty("installedListModel",&ilm);
sp.loadQQuickView(QUrl(QStringLiteral("qrc:/qml/Components/ScreenPlay.qml")));
sp.showQQuickView(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
QObject::connect(&ilm, &InstalledListModel::setScreenVisible,
&sp,&ScreenPlay::setVisible);
int status = app.exec();

View File

@ -23,5 +23,6 @@
<file>qml/Components/ScreenPlayItem.qml</file>
<file>qml/Components/Sidebar.qml</file>
<file>assets/images/Window.svg</file>
<file>qml/Components/Screens/ScreenVideo.qml</file>
</qresource>
</RCC>

View File

@ -1,14 +1,31 @@
import QtQuick 2.6
import QtQuick.Window 2.2
import QtCanvas3D 1.1
import QtQuick.Controls 2.1
import QtAV 1.07
Item {
id:empty
height: parent.height
width: parent.width
Rectangle {
color: "#f29f6a"
width: 2560
height: 1080
// Loader {
// anchors.fill: parent
// source: "qrc:/qml/Components/Screens/ScreenVideo.qml"
// }
Connections {
target: installedListModel
onSetScreenToVideo:{
installedListModel.setScreenVisibleFromQml(true)
video.stop()
video.source = absolutePath;
video.play();
}
}
Video {
id: video
anchors.fill: parent
implicitWidth: parent.width
fillMode: Qt.KeepAspectRatio
}
}

View File

@ -68,6 +68,7 @@ Item {
anchors.margins: 10
}
MouseArea {
anchors.fill: parent
onClicked: {

View File

@ -0,0 +1,24 @@
import QtQuick 2.0
import QtAV 1.07
Rectangle {
color: "orange"
height: parent.height
width: parent.width
Connections {
target: installedListModel
onSetScreenToVideo:{
installedListModel.setScreenVisibleFromQml(true)
video.stop()
video.source = absolutePath;
video.play();
}
}
Video {
id: video
anchors.fill: parent
}
}

View File

@ -84,7 +84,10 @@ Item {
anchors.bottom: parent.bottom
anchors.bottomMargin: 18
onClicked: {
print()
installedListModel.setScreenToVideoFromQml( Qt.resolvedUrl(
"file:///" + installedListModel._screensPath + activeScreen
+ "/" + installedListModel.get(activeScreen).screenFile));
}
}

View File

@ -36,6 +36,8 @@ QVariant InstalledListModel::data(const QModelIndex& index, int role) const
return _screenPlayFiles.at(index.row())._preview;
case FolderIdRole:
return _screenPlayFiles.at(index.row())._folderId;
case FileIdRole:
return _screenPlayFiles.at(index.row())._file;
default:
return QVariant();
}
@ -48,6 +50,7 @@ QHash<int, QByteArray> InstalledListModel::roleNames() const
{ TitleRole, "screenTitle" },
{ PreviewRole, "screenPreview" },
{ FolderIdRole, "screenFolderId" },
{ FileIdRole, "screenFile" },
};
return roles;
}
@ -103,8 +106,19 @@ QVariantMap InstalledListModel::get(QString folderId)
if (_screenPlayFiles[i]._folderId == folderId) {
map.insert("screenTitle", _screenPlayFiles[i]._title);
map.insert("screenPreview", _screenPlayFiles[i]._preview);
map.insert("screenFile", _screenPlayFiles[i]._file);
}
}
return map;
}
void InstalledListModel::setScreenVisibleFromQml(bool visible)
{
emit setScreenVisible(visible);
}
void InstalledListModel::setScreenToVideoFromQml(QString absolutePath)
{
emit setScreenToVideo(absolutePath);
}

View File

@ -33,12 +33,16 @@ public:
Q_INVOKABLE void loadScreens();
Q_INVOKABLE QVariantMap get(QString folderId);
Q_INVOKABLE void setScreenVisibleFromQml(bool visible);
Q_INVOKABLE void setScreenToVideoFromQml(QString absolutePath);
Q_PROPERTY(QString _screensPath READ name CONSTANT)
enum InstalledRole {
TitleRole,
PreviewRole,
FolderIdRole,
FileIdRole,
};
Q_ENUM(InstalledRole)
@ -47,6 +51,10 @@ public:
return _screensPath;
}
signals:
void setScreenVisible(bool visible);
void setScreenToVideo(QString absolutePath);
private:
QList<ScreenPlayFile> _screenPlayFiles;
QString _screensPath;

6
src/mainwindow.cpp Normal file
View File

@ -0,0 +1,6 @@
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
{
}

17
src/mainwindow.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
signals:
public slots:
};
#endif // MAINWINDOW_H

View File

@ -21,6 +21,9 @@ ScreenPlay::ScreenPlay(QWindow* parent)
ScreenPlay::ScreenPlay(int width, int height)
{
this->quickRenderer = new QQuickView(this);
_context = quickRenderer->rootContext();
this->setHeight(height);
this->setWidth(width);
@ -47,17 +50,45 @@ ScreenPlay::ScreenPlay(int width, int height)
SetWindowLongPtr(hwnd, GWL_EXSTYLE,
WS_EX_LEFT | WS_EX_LTRREADING | WS_EX_RIGHTSCROLLBAR | WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TRANSPARENT | WS_EX_TOOLWINDOW);
this->quickRenderer = new QQuickView(QUrl(QStringLiteral("qrc:/qml/ComponentScreenPlay.qml")), this);
Qt::WindowFlags flags = this->flags();
this->setFlags(flags | Qt::FramelessWindowHint | Qt::WindowStaysOnBottomHint);
this->show();
quickRenderer->show();
ShowWindow(hwnd, SW_SHOWDEFAULT);
// We do not want to display anything initially
setVisible(false);
}
ScreenPlay::~ScreenPlay()
{
qDebug() << "exit";
ShowWindow(worker_hwnd, SW_HIDE);
}
void ScreenPlay::loadQQuickView(QUrl path)
{
quickRenderer->setSource(path);
}
void ScreenPlay::showQQuickView(int width, int height)
{
quickRenderer->setWidth(width);
quickRenderer->setHeight(height);
quickRenderer->show();
}
void ScreenPlay::setVisible(bool visible)
{
if (visible)
ShowWindow(worker_hwnd, SW_SHOWDEFAULT);
else
ShowWindow(worker_hwnd, SW_HIDE);
}
QQmlContext *ScreenPlay::context() const
{
return _context;
}

View File

@ -3,7 +3,9 @@
#include <QQuickView>
#include <QWindow>
#include <QDebug>
#include <qt_windows.h>
#include <QQmlContext>
class ScreenPlay : public QWindow {
Q_OBJECT
@ -12,14 +14,24 @@ public:
ScreenPlay(int width, int height);
~ScreenPlay();
void loadQQuickView(QUrl path);
void showQQuickView(int width, int height);
QQmlContext *context() const;
signals:
public slots:
void setVisible(bool visible);
private:
HWND hwnd = nullptr;
HWND worker_hwnd = nullptr;
QQuickView* quickRenderer = nullptr;
QQmlContext* _context = nullptr;
};
#endif // SCREENPLAY_H

View File

@ -1,6 +0,0 @@
#include "screenplayitem.h"
ScreenPlayItem::ScreenPlayItem(QObject *parent) : QObject(parent)
{
}

View File

@ -1,39 +0,0 @@
#ifndef SCREENPLAYITEM_H
#define SCREENPLAYITEM_H
#include <QObject>
#include <QVariant>
class ScreenPlayItem : public QObject
{
Q_OBJECT
Q_PROPERTY(QVariant name READ name WRITE setName NOTIFY nameChanged);
QVariant m_name;
public:
explicit ScreenPlayItem(QObject *parent = 0);
QVariant name() const
{
return m_name;
}
signals:
void nameChanged(QVariant name);
public slots:
void setName(QVariant name)
{
if (m_name == name)
return;
m_name = name;
emit nameChanged(name);
}
};
#endif // SCREENPLAYITEM_H