1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#ifndef SVGMANAGER_H
#define SVGMANAGER_H
#include <QObject>
#include <QUrl>
#include <QQmlEngine>
class SvgManager : public QObject
{
Q_OBJECT
QML_ELEMENT
QML_SINGLETON
Q_PROPERTY(QUrl currentSource READ currentSource NOTIFY currentSourceChanged)
Q_PROPERTY(QString qmlSource READ qmlSource NOTIFY currentSourceChanged)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(int sourceCount READ sourceCount NOTIFY sourcesChanged)
Q_PROPERTY(QString currentDirectory READ currentDirectory WRITE setCurrentDirectory NOTIFY currentDirectoryChanged)
Q_PROPERTY(QList<QUrl> sources READ sources NOTIFY sourcesChanged)
Q_PROPERTY(qreal scale READ scale WRITE setScale NOTIFY scaleChanged)
public:
SvgManager(QObject *parent);
~SvgManager() override;
static SvgManager *create(QQmlEngine *, QJSEngine *)
{
return g_manager;
}
QUrl currentSource() const
{
if (m_currentIndex < 0)
return QUrl{};
return m_sources.at(m_currentIndex);
}
int currentIndex() const
{
return m_currentIndex;
}
void setCurrentIndex(int newCurrentIndex);
int sourceCount() const
{
return m_sources.size();
}
QList<QUrl> sources() const;
QString currentDirectory() const;
void setCurrentDirectory(const QString &newCurrentDirectory);
QString qmlSource() const;
qreal scale() const;
public slots:
void setScale(int newScale);
signals:
void currentSourceChanged();
void currentIndexChanged();
void sourcesChanged();
void currentDirectoryChanged();
void scaleChanged();
private:
static SvgManager *g_manager;
int m_currentIndex = -1;
QList<QUrl> m_sources;
QString m_currentDirectory;
QString m_qmlSource;
qreal m_scale = 10.0;
};
#endif // SVGMANAGER_H
|