1
0
mirror of https://gitlab.com/kelteseth/ScreenPlay.git synced 2024-11-06 19:12:30 +01:00

Add automatic qml plugin generation...

We still need a way to register the enums in the plugin
This commit is contained in:
Elias Steurer 2021-11-09 09:22:10 +01:00
parent b1abd38b28
commit fbb4d80817
14 changed files with 38 additions and 55 deletions

View File

@ -203,7 +203,8 @@ target_link_libraries(
Qt6::WebSockets
Qt6::Svg
Qt6::WebEngineQuick
Qt6::WebEngineCore)
Qt6::WebEngineCore
SteamSDK)
if(${TESTS_ENABLED})
add_executable(tst_ScreenPlay tests/tst_main.cpp)

View File

@ -1,5 +1,7 @@
#include "app.h"
#include "steam/steam_qt_enums_generated.h"
namespace ScreenPlay {
/*!
\module ScreenPlay
@ -96,6 +98,16 @@ App::App()
qRegisterMetaType<MonitorListModel*>();
qRegisterMetaType<ProfileListModel*>();
// TODO: This is a workaround because I don't know how to
// init this in the ScreenPlayWorkshop plugin.
// Move to workshop plugin.
qmlRegisterUncreatableMetaObject(ScreenPlayWorkshopSteamEnums::staticMetaObject,
"WorkshopEnums",
1, 0,
"SteamEnums",
"Error: only enums");
// Registers the enums from globalvariables.
// Apparently this is the only way for qml to work
// https://www.kdab.com/new-qt-5-8-meta-object-support-namespaces/

View File

@ -1,6 +1,5 @@
import QtQuick
import Qt5Compat.GraphicalEffects
import Workshop 1.0
Rectangle {
id: root

View File

@ -4,6 +4,7 @@ import QtQuick.Controls.Material
import Qt5Compat.GraphicalEffects
import QtQuick.Layouts
import Workshop 1.0
import WorkshopEnums 1.0
import ScreenPlay 1.0
import "upload/"

View File

@ -4,6 +4,7 @@ import QtQuick.Controls.Material
import Qt5Compat.GraphicalEffects
import QtQuick.Layouts
import Workshop 1.0
import WorkshopEnums 1.0
import ScreenPlay 1.0
import "upload/"
import "../Common" as Common

View File

@ -4,7 +4,8 @@ import Qt5Compat.GraphicalEffects
import QtQuick.Controls.Material
import QtQuick.Layouts
import QtQuick.Controls.Material.impl
import Workshop
import Workshop 1.0
import WorkshopEnums 1.0
Page {

View File

@ -1,4 +1,4 @@
project(workshopplugin LANGUAGES CXX)
project(ScreenPlayWorkshop LANGUAGES CXX)
add_subdirectory(SteamSDK)
@ -16,7 +16,6 @@ set(SOURCES
src/steamworkshopitem.cpp
src/workshop.cpp
src/installedlistmodel.cpp
src/screenplayworkshop_plugin.cpp
src/steamworkshop.cpp
src/steamworkshoplistmodel.cpp
src/steamaccount.cpp
@ -31,19 +30,22 @@ set(HEADER
src/workshop.h
src/workshopitem.h
src/installedlistmodel.h
src/screenplayworkshop_plugin.h
src/steamworkshop.h
src/steamaccount.h
src/steamqmlimageprovider.h)
add_library(${PROJECT_NAME} SHARED ${SOURCES} ${HEADER})
qt_add_qml_module(
${PROJECT_NAME}
OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin/Workshop
URI "Workshop"
SOURCES ${SOURCES} ${HEADER}
VERSION
1.0)
set(WORKSHOP_PLUGIN_DIR ${CMAKE_BINARY_DIR}/bin/workshop)
file(MAKE_DIRECTORY ${WORKSHOP_PLUGIN_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${WORKSHOP_PLUGIN_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${WORKSHOP_PLUGIN_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${WORKSHOP_PLUGIN_DIR})
# Needed by the automatic generated target missing includes
# https://github.com/qt/qtdeclarative/blob/7a7064e14f094e843e1ee832cc927e86f887621a/src/qml/Qt6QmlMacros.cmake#L2042
target_include_directories(${PROJECT_NAME} PUBLIC src/)
set(STEAM_LIB_PATH "${CMAKE_CURRENT_SOURCE_DIR}/SteamSDK/redistributable_bin/")

View File

@ -19,6 +19,7 @@
#include <QVariantList>
#include <QVector>
#include <QtConcurrent/QtConcurrent>
#include <QtQml>
#include "ScreenPlayUtil/projectfile.h"
#include "ScreenPlayUtil/util.h"
@ -33,6 +34,7 @@ namespace ScreenPlayWorkshop {
class InstalledListModel : public QAbstractListModel {
Q_OBJECT
QML_NAMED_ELEMENT(InstalledListModel)
Q_PROPERTY(QUrl absoluteStoragePath READ absoluteStoragePath WRITE setabsoluteStoragePath NOTIFY absoluteStoragePathChanged)
public:

View File

@ -1,19 +0,0 @@
#include "screenplayworkshop_plugin.h"
void ScreenPlayWorkshopPlugin::registerTypes(const char* uri)
{
qRegisterMetaType<ScreenPlayWorkshop::SteamQMLImageProvider*>("SteamQMLImageProvider*");
qmlRegisterType<ScreenPlayWorkshop::SteamQMLImageProvider>("Workshop", 1, 0, "SteamImage");
qmlRegisterUncreatableMetaObject(ScreenPlayWorkshopSteamEnums::staticMetaObject,
"Workshop",
1, 0,
"SteamEnums",
"Error: only enums");
qRegisterMetaType<ScreenPlayWorkshop::SteamAccount*>("SteamAccount*");
qRegisterMetaType<ScreenPlayWorkshop::InstalledListModel*>("InstalledListModel*");
qmlRegisterType<ScreenPlayWorkshop::SteamWorkshop>("Workshop", 1, 0, "SteamWorkshop");
qmlRegisterType<ScreenPlayWorkshop::Workshop>("Workshop", 1, 0, "ScreenPlayWorkshop");
}

View File

@ -1,21 +0,0 @@
#pragma once
#include <QQmlContext>
#include <QQmlEngine>
#include <QQmlExtensionPlugin>
#include <QSettings>
#include <QtQml>
#include "steam/steam_qt_enums_generated.h"
#include "workshop.h"
#include "steamqmlimageprovider.h"
class ScreenPlayWorkshopPlugin : public QQmlExtensionPlugin {
Q_OBJECT
Q_PLUGIN_METADATA(IID QQmlExtensionInterface_iid)
public:
void registerTypes(const char* uri) override;
};

View File

@ -7,6 +7,7 @@
#include <QString>
#include <QTimer>
#include <QtGlobal>
#include <QtQml>
#include <memory>
#include <steam/steam_api.h>
@ -15,7 +16,7 @@ namespace ScreenPlayWorkshop {
class SteamAccount : public QObject {
Q_OBJECT
QML_NAMED_ELEMENT(SteamAccount)
Q_PROPERTY(QString username READ username WRITE setUsername NOTIFY usernameChanged)
Q_PROPERTY(quint32 accountID READ accountID WRITE setAccountID NOTIFY accountIDChanged)
Q_PROPERTY(QImage avatar READ avatar WRITE setAvatar NOTIFY avatarChanged)

View File

@ -5,10 +5,12 @@
#include <QSGNode>
#include <QSGSimpleTextureNode>
#include <QSGTexture>
#include <QtQml>
namespace ScreenPlayWorkshop {
class SteamQMLImageProvider : public QQuickItem {
Q_OBJECT
QML_NAMED_ELEMENT(SteamImage)
public:
SteamQMLImageProvider(QQuickItem* parent);
@ -28,7 +30,6 @@ public:
node->setRect(boundingRect());
return node;
}
public slots:
void setImage(QImage image)
{

View File

@ -13,6 +13,7 @@
#include <QTimer>
#include <QUrl>
#include <QtConcurrent/QtConcurrent>
#include <QtQml>
// Steam
#include "cstring"
@ -40,6 +41,7 @@ struct SteamItemUpdate {
class SteamWorkshop : public QObject {
Q_OBJECT
QML_NAMED_ELEMENT(SteamWorkshop)
Q_PROPERTY(bool online READ online WRITE setOnline NOTIFY onlineChanged)
Q_PROPERTY(unsigned long long itemProcessed READ itemProcessed WRITE setItemProcessed NOTIFY itemProcessedChanged)
Q_PROPERTY(unsigned long long bytesTotal READ bytesTotal WRITE setBytesTotal NOTIFY bytesTotalChanged)

View File

@ -14,7 +14,7 @@ namespace ScreenPlayWorkshop {
class Workshop : public QQuickItem {
Q_OBJECT
QML_NAMED_ELEMENT(ScreenPlayWorkshop)
Q_PROPERTY(InstalledListModel* installedListModel READ installedListModel NOTIFY installedListModelChanged)
Q_PROPERTY(SteamWorkshop* steamWorkshop READ steamWorkshop NOTIFY steamWorkshopChanged)