2024-01-25 12:33:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <qdir.h>
|
|
|
|
#include <qlogging.h>
|
|
|
|
#include <qobject.h>
|
|
|
|
#include <qqmlcomponent.h>
|
|
|
|
#include <qqmlengine.h>
|
|
|
|
#include <qqmlintegration.h>
|
|
|
|
#include <qqmllist.h>
|
|
|
|
#include <qqmlparserstatus.h>
|
|
|
|
|
|
|
|
extern QString CONFIG_PATH; // NOLINT
|
|
|
|
|
|
|
|
class ShellComponent;
|
|
|
|
|
|
|
|
class QtShell: public QObject, public QQmlParserStatus {
|
|
|
|
Q_OBJECT;
|
|
|
|
Q_INTERFACES(QQmlParserStatus);
|
|
|
|
Q_PROPERTY(QQmlListProperty<ShellComponent> components READ components FINAL);
|
|
|
|
Q_CLASSINFO("DefaultProperty", "components");
|
|
|
|
QML_ELEMENT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit QtShell();
|
|
|
|
|
2024-02-01 01:43:18 +00:00
|
|
|
void classBegin() override {}
|
2024-01-25 12:33:02 +00:00
|
|
|
void componentComplete() override;
|
|
|
|
|
|
|
|
QQmlListProperty<ShellComponent> components();
|
|
|
|
|
2024-02-01 01:43:18 +00:00
|
|
|
public slots:
|
|
|
|
void reload();
|
|
|
|
|
2024-01-25 12:33:02 +00:00
|
|
|
private:
|
|
|
|
static void appendComponent(QQmlListProperty<ShellComponent>* list, ShellComponent* component);
|
|
|
|
|
|
|
|
QList<ShellComponent*> mComponents;
|
|
|
|
QString path;
|
|
|
|
QDir dir;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ShellComponent: public QObject {
|
|
|
|
Q_OBJECT;
|
|
|
|
Q_PROPERTY(QString source WRITE setSource);
|
|
|
|
Q_PROPERTY(QQmlComponent* component MEMBER mComponent WRITE setComponent);
|
|
|
|
Q_CLASSINFO("DefaultProperty", "component");
|
|
|
|
QML_ELEMENT;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit ShellComponent(QObject* parent = nullptr): QObject(parent) {}
|
|
|
|
|
|
|
|
void setSource(QString source);
|
|
|
|
void setComponent(QQmlComponent* component);
|
|
|
|
void prepare(const QDir& basePath);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void ready();
|
|
|
|
|
|
|
|
private:
|
|
|
|
QString mSource;
|
|
|
|
QQmlComponent* mComponent = nullptr;
|
|
|
|
};
|