1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-22 10:42:29 +01:00

Implement basic installed screens and remove steam api for now

This commit is contained in:
kelteseth 2017-04-03 18:48:34 +02:00
parent 0e564a34c6
commit a65a1f85a4
14 changed files with 427 additions and 42 deletions

View File

@ -5,7 +5,9 @@ CONFIG += c++14
SOURCES += main.cpp \
src/screenplay.cpp \
src/steamworkshop.cpp
src/steamworkshop.cpp \
src/installedlistmodel.cpp \
src/screenplayitem.cpp
RESOURCES += qml.qrc
@ -33,7 +35,9 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
HEADERS += \
src/screenplay.h \
src/steamworkshop.h
src/steamworkshop.h \
src/installedlistmodel.h \
src/screenplayitem.h
INCLUDEPATH += $$PWD/ThirdParty/Steam/
INCLUDEPATH += $$PWD/src/

View File

@ -8,8 +8,12 @@
#include <QUrl>
#include <QWindow>
#include <qt_windows.h>
#include <QQmlContext>
#include <QModelIndex>
#include <QVariant>
#include "screenplay.h"
#include "installedlistmodel.h"
int main(int argc, char* argv[])
{
@ -20,9 +24,20 @@ int main(int argc, char* argv[])
QCoreApplication::setApplicationName("ScreenPlay");
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QQmlApplicationEngine mainWindow(QUrl(QStringLiteral("qrc:/qml/main.qml")));
InstalledListModel ilm;
ilm.setData(QModelIndex(),QVariant("ascb"),0);
QQmlApplicationEngine mainWindow;
mainWindow.rootContext()->setContextProperty("installedListModel", &ilm);
mainWindow.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
//ScreenPlay sp(GetSystemMetrics(SM_CXSCREEN),GetSystemMetrics(SM_CYSCREEN));
return app.exec();
int status = app.exec();
//Shutdown
return status;
}

View File

@ -20,5 +20,7 @@
<file>assets/icons/icon_share.svg</file>
<file>assets/icons/icon_volume.svg</file>
<file>assets/icons/icon_workshop.svg</file>
<file>qml/Components/ScreenPlayItem.qml</file>
<file>qml/Components/Sidebar.qml</file>
</qresource>
</RCC>

View File

@ -1,6 +1,27 @@
import QtQuick 2.0
import QtQuick 2.7
import QtQml.Models 2.2
Page {
id:pageInstalled
pageName: "Installed"
GridView {
id: gridView
anchors.fill: parent
cellWidth: 320
cellHeight: 200
anchors.margins: 20
focus: true
delegate: ScreenPlayItem {
customTitle: title
}
model: installedListModel
}
}

View File

@ -4,6 +4,7 @@ import QtQuick.Controls 2.2
Rectangle {
id:navigation
height:60
clip: true
width: 1366
signal changeTab(string name)
@ -38,7 +39,7 @@ Rectangle {
NavigationItem {
id: navWorkshop
state: "active"
state: "inactive"
name: "Workshop"
iconSource: "qrc:/assets/icons/icon_workshop.svg"
onTabClicked: navigation.onTabChanged(name)
@ -46,7 +47,7 @@ Rectangle {
NavigationItem {
id: navInstalled
state: "inactive"
state: "active"
name: "Installed"
iconSource: "qrc:/assets/icons/icon_installed.svg"
onTabClicked: navigation.onTabChanged(name)
@ -63,27 +64,5 @@ Rectangle {
}
}
Item {
id:createScreenPlay
width: txtcreateScreenPlay.contentWidth
anchors{
top:parent.top
right: parent.right
rightMargin: 20
bottom: parent.bottom
}
MouseArea {
anchors.fill: parent
Text {
id: txtcreateScreenPlay
text: qsTr("+ Create ScreenPlay")
anchors.centerIn: parent
}
}
}
}

View File

@ -44,7 +44,7 @@ Item {
anchors.left: icon.right
anchors.leftMargin: 10
text: name
font.pointSize: 16
font.pointSize: 14
color: "#626262"
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
@ -136,6 +136,7 @@ Item {
NumberAnimation {
properties: "anchors.bottomMargin"
duration: 100
easing.type: Easing.InOutQuad
}
},
Transition {
@ -144,6 +145,7 @@ Item {
NumberAnimation {
properties: "anchors.bottomMargin"
duration: 100
easing.type: Easing.InOutQuad
}
}
]

View File

@ -0,0 +1,31 @@
import QtQuick 2.0
Item {
id:screenPlayItem
width: 320
height: 180
property string customTitle: "name here"
Rectangle
{
id: rectangle
color: "white"
radius: 23
anchors {
fill: parent
margins:5
}
Text {
id: text1
text: customTitle
renderType: Text.QtRendering
wrapMode: Text.WrapAnywhere
anchors.fill: parent
font.pixelSize: 18
anchors.margins: 10
}
}
}

107
qml/Components/Sidebar.qml Normal file
View File

@ -0,0 +1,107 @@
import QtQuick 2.0
import QtGraphicalEffects 1.0
import QtQuick.Controls 2.2
Item {
id:sidebar
height: 768
width:400
state: "inactive"
Item {
id: sidebarWrapper
anchors {
top:sidebar.top
right:sidebar.right
bottom:sidebar.bottom
left:sidebar.left
}
Rectangle {
id:sidebarBackground
color: "grey"
anchors {
top:parent.top
right:parent.right
bottom:parent.bottom
left:parent.left
leftMargin: 5
}
Button {
id: button
text: qsTr("Button")
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
onClicked: {
sidebar.state = sidebar.state == "active" ? "inactive" : "active"
}
}
}
Rectangle {
id:shadow
anchors {
top:parent.top
right:sidebarBackground.left
bottom:parent.bottom
left:parent.left
}
LinearGradient {
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(5, 0)
gradient: Gradient {
GradientStop { position: 0.0; color: "#00000000" }
GradientStop { position: 1.0; color: "#22000000" }
}
}
}
}
states: [
State {
name: "active"
PropertyChanges {
target: sidebarWrapper
anchors.leftMargin: 0
}
},
State {
name: "inactive"
PropertyChanges {
target: sidebarWrapper
anchors.leftMargin: sidebar.width
}
}
]
transitions: [
Transition {
to: "active"
NumberAnimation {
properties: "anchors.leftMargin"
duration: 500
easing.type: Easing.InOutQuad
}
},
Transition {
to: "inactive"
NumberAnimation {
properties: "anchors.leftMargin"
duration: 500
easing.type: Easing.InOutQuad
}
}
]
}

View File

@ -12,6 +12,31 @@ Window {
visible: true
width: 1366
height: 768
Component.onCompleted: installedListModel.loadDrives()
Loader {
id: pageLoader
anchors {
top: nav.bottom
right: parent.right
bottom: parent.bottom
left: parent.left
}
source: "qrc:/qml/Components/Installed.qml"
}
Sidebar {
id: sidebar
width:400
anchors {
top:parent.top
right:parent.right
bottom:parent.bottom
}
}
Navigation {
id: nav
@ -22,15 +47,4 @@ Window {
}
onChangeTab: pageLoader.setSource("qrc:/qml/Components/"+name+".qml")
}
Loader {
id: pageLoader
anchors {
top: nav.bottom
right: parent.right
bottom: parent.bottom
left: parent.left
}
source: "qrc:/qml/Components/Workshop.qml"
}
}

View File

@ -0,0 +1,90 @@
#include "installedlistmodel.h"
InstalledListModel::InstalledListModel(QObject* parent)
: QAbstractListModel(parent)
{
}
int InstalledListModel::rowCount(const QModelIndex& parent) const
{
// For list models only the root node (an invalid parent) should return the
// list's size. For all
// other (valid) parents, rowCount() should return 0 so that it does not
// become a tree model.
return _screenPlayFiles.count();
}
QVariant InstalledListModel::data(const QModelIndex& index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() < rowCount())
switch (role) {
case TitleRole:
return _screenPlayFiles.at(index.row())._title;
case ImageRole:
return _screenPlayFiles.at(index.row())._description;
default:
return QVariant();
}
return QVariant();
}
QHash<int, QByteArray> InstalledListModel::roleNames() const
{
static const QHash<int, QByteArray> roles{
{ TitleRole, "title" },
{ ImageRole, "image" },
};
return roles;
}
void InstalledListModel::append(const QJsonObject obj)
{
int row = 0;
beginInsertRows(QModelIndex(), row, row);
ScreenPlayFile tmpFile(obj);
_screenPlayFiles.append(tmpFile);
endInsertRows();
}
void InstalledListModel::loadDrives()
{
QString writablePath = QStandardPaths::writableLocation(QStandardPaths::StandardLocation::DataLocation);
if (!QDir(writablePath).exists()) {
if (!QDir().mkdir(writablePath)) {
qWarning("ERROR: Cloud not create install dir");
return;
}
}
QString tmp(writablePath + "/Installed/");
QJsonDocument jsonProject;
QJsonParseError parseError;
QFileInfoList list = QDir(tmp).entryInfoList(QDir::NoDotAndDotDot | QDir::AllDirs);
QString tmpPath;
for (auto&& item : list) {
tmpPath = tmp + item.baseName() + "/project.json";
if (!QFile(tmpPath).exists())
continue;
QFile projectConfig;
projectConfig.setFileName(tmpPath);
projectConfig.open(QIODevice::ReadOnly | QIODevice::Text);
QString projectConfigData = projectConfig.readAll();
jsonProject = QJsonDocument::fromJson(projectConfigData.toUtf8(), &parseError);
if (!(parseError.error == QJsonParseError::NoError))
continue;
append(jsonProject.object());
}
}

75
src/installedlistmodel.h Normal file
View File

@ -0,0 +1,75 @@
#ifndef INSTALLEDLISTMODEL_H
#define INSTALLEDLISTMODEL_H
#include <QAbstractListModel>
#include <QByteArray>
#include <QDebug>
#include <QDir>
#include <QDirIterator>
#include <QFile>
#include <QJsonArray>
#include <QJsonDocument>
#include <QJsonObject>
#include <QList>
#include <QStandardPaths>
#include <QString>
#include <QUrl>
#include <QtConcurrent/QtConcurrent>
class ScreenPlayFile;
class InstalledListModel : public QAbstractListModel {
Q_OBJECT
public:
explicit InstalledListModel(QObject* parent = 0);
// Basic functionality:
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const override;
void append(const QJsonObject);
QHash<int, QByteArray> roleNames() const;
Q_INVOKABLE void loadDrives();
enum InstalledRole {
TitleRole,
ImageRole,
};
Q_ENUM(InstalledRole)
private:
QList<ScreenPlayFile> _screenPlayFiles;
};
class ScreenPlayFile {
public:
ScreenPlayFile();
ScreenPlayFile(QJsonObject obj)
{
if (obj.contains("description"))
_description = obj.value("description");
if (obj.contains("file"))
_file = obj.value("file");
if (obj.contains("preview"))
_preview = obj.value("preview");
if (obj.contains("title"))
_title = obj.value("title");
}
QVariant _description = "as";
QVariant _file;
QVariant _preview;
QVariant _title= "aass";
QUrl _absolutePath;
QVariantList _tags; //TODO: Implement me!
};
#endif // INSTALLEDLISTMODEL_H

View File

@ -21,7 +21,7 @@ ScreenPlay::ScreenPlay(QWindow* parent)
ScreenPlay::ScreenPlay(int width, int height)
{
this->setHeight(height);
this->setHeight(height);
this->setWidth(width);
this->hwnd = (HWND)this->winId();

6
src/screenplayitem.cpp Normal file
View File

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

39
src/screenplayitem.h Normal file
View File

@ -0,0 +1,39 @@
#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