Imported existing sources
This commit is contained in:
6
DbSketch.pro
Normal file
6
DbSketch.pro
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
TEMPLATE = subdirs
|
||||||
|
|
||||||
|
SUBDIRS += sketchlib \
|
||||||
|
sketchviewer
|
||||||
|
|
||||||
|
sketchviewer.depends += sketchlib
|
59
sketchlib/basecontainer.cpp
Normal file
59
sketchlib/basecontainer.cpp
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#include "basecontainer.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
const QHash<QJsonValue::Type, QString> BaseContainer::m_types {
|
||||||
|
{ QJsonValue::Null, QStringLiteral("Null") },
|
||||||
|
{ QJsonValue::Bool, QStringLiteral("Bool") },
|
||||||
|
{ QJsonValue::Double, QStringLiteral("Double") },
|
||||||
|
{ QJsonValue::String, QStringLiteral("String") },
|
||||||
|
{ QJsonValue::Array, QStringLiteral("Array") },
|
||||||
|
{ QJsonValue::Object, QStringLiteral("Object") },
|
||||||
|
{ QJsonValue::Undefined, QStringLiteral("Undefined") }
|
||||||
|
};
|
||||||
|
|
||||||
|
QMap<QString, int> BaseContainer::m_missing;
|
||||||
|
|
||||||
|
BaseContainer::BaseContainer(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &BaseContainer::do_objectID() const
|
||||||
|
{
|
||||||
|
return m_do_objectID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseContainer::parseFromJson(const QJsonObject &jsonObj)
|
||||||
|
{
|
||||||
|
for(auto iter = jsonObj.constBegin(); iter != jsonObj.constEnd(); iter++)
|
||||||
|
{
|
||||||
|
if(iter.key() == QStringLiteral("_class"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(!parseProperty(iter.key(), iter.value()))
|
||||||
|
{
|
||||||
|
m_missing[QStringLiteral("%0::%1").arg(metaObject()->className(), iter.key())]++;
|
||||||
|
|
||||||
|
//qWarning() << "unknown property" << metaObject()->className() << iter.key() << m_types.value(iter.value().type());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const QMap<QString, int> &BaseContainer::missing()
|
||||||
|
{
|
||||||
|
return m_missing;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BaseContainer::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("do_objectID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_do_objectID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
36
sketchlib/basecontainer.h
Normal file
36
sketchlib/basecontainer.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
#include <QHash>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
class QJsonValue;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT BaseContainer : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString do_objectID READ do_objectID CONSTANT)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit BaseContainer(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
public:
|
||||||
|
const QString &do_objectID() const;
|
||||||
|
|
||||||
|
void parseFromJson(const QJsonObject &jsonObj);
|
||||||
|
|
||||||
|
static const QMap<QString, int> &missing();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static const QHash<QJsonValue::Type, QString> m_types;
|
||||||
|
static QMap<QString, int> m_missing;
|
||||||
|
|
||||||
|
QString m_do_objectID;
|
||||||
|
};
|
44
sketchlib/container/artboard.cpp
Normal file
44
sketchlib/container/artboard.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "artboard.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
|
Artboard::Artboard(QObject *parent) :
|
||||||
|
Group(parent),
|
||||||
|
m_backgroundColor(Q_NULLPTR),
|
||||||
|
m_hasBackgroundColor(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *Artboard::backgroundColor() const
|
||||||
|
{
|
||||||
|
return m_backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Artboard::hasBackgroundColor() const
|
||||||
|
{
|
||||||
|
return m_hasBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Artboard::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("backgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_backgroundColor = ContainerFactory::createContainer<Color>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasBackgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasBackgroundColor = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Group::parseProperty(key, value);
|
||||||
|
}
|
25
sketchlib/container/artboard.h
Normal file
25
sketchlib/container/artboard.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "group.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Artboard : public Group
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Artboard(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Color *backgroundColor() const;
|
||||||
|
bool hasBackgroundColor() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_backgroundColor;
|
||||||
|
bool m_hasBackgroundColor;
|
||||||
|
};
|
72
sketchlib/container/assetcollection.cpp
Normal file
72
sketchlib/container/assetcollection.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include "assetcollection.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "imagecollection.h"
|
||||||
|
|
||||||
|
AssetCollection::AssetCollection(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_imageCollection(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<Color *> &AssetCollection::colors() const
|
||||||
|
{
|
||||||
|
return m_colors;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImageCollection *AssetCollection::imageCollection() const
|
||||||
|
{
|
||||||
|
return m_imageCollection;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssetCollection::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("colors"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto colorValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(colorValue.isObject());
|
||||||
|
m_colors.append(ContainerFactory::createContainer<Color>(colorValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("gradients"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto gradientValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "gradients not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("imageCollection"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_imageCollection = ContainerFactory::createContainer<ImageCollection>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("images"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto imageValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "images not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
32
sketchlib/container/assetcollection.h
Normal file
32
sketchlib/container/assetcollection.h
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
class ImageCollection;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT AssetCollection : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<Color*> colors READ colors CONSTANT)
|
||||||
|
Q_PROPERTY(ImageCollection* imageCollection READ imageCollection CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit AssetCollection(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<Color*> &colors() const;
|
||||||
|
ImageCollection *imageCollection() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Color*> m_colors;
|
||||||
|
//TODO gradients
|
||||||
|
ImageCollection *m_imageCollection;
|
||||||
|
//TODO images
|
||||||
|
};
|
31
sketchlib/container/bitmap.cpp
Normal file
31
sketchlib/container/bitmap.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include "bitmap.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "msjsonfilereference.h"
|
||||||
|
|
||||||
|
Bitmap::Bitmap(QObject *parent) :
|
||||||
|
Layer(parent),
|
||||||
|
m_image(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
MSJSONFileReference *Bitmap::image() const
|
||||||
|
{
|
||||||
|
return m_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Bitmap::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("image"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_image = ContainerFactory::createContainer<MSJSONFileReference>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
23
sketchlib/container/bitmap.h
Normal file
23
sketchlib/container/bitmap.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class MSJSONFileReference;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Bitmap : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Bitmap(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
MSJSONFileReference *image() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MSJSONFileReference *m_image;
|
||||||
|
};
|
73
sketchlib/container/blur.cpp
Normal file
73
sketchlib/container/blur.cpp
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
#include "blur.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
Blur::Blur(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Blur::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Blur::center() const
|
||||||
|
{
|
||||||
|
return m_center;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Blur::motionAngle() const
|
||||||
|
{
|
||||||
|
return m_motionAngle;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Blur::radius() const
|
||||||
|
{
|
||||||
|
return m_radius;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Blur::type() const
|
||||||
|
{
|
||||||
|
return m_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Blur::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("center"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_center = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("motionAngle"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_motionAngle = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("radius"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_radius = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("type"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_type = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
36
sketchlib/container/blur.h
Normal file
36
sketchlib/container/blur.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Blur : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(QString center READ center CONSTANT)
|
||||||
|
Q_PROPERTY(double motionAngle READ motionAngle CONSTANT)
|
||||||
|
Q_PROPERTY(double radius READ radius CONSTANT)
|
||||||
|
Q_PROPERTY(double type READ type CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Blur(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool isEnabled() const;
|
||||||
|
const QString ¢er() const;
|
||||||
|
double motionAngle() const;
|
||||||
|
double radius() const;
|
||||||
|
double type() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_isEnabled;
|
||||||
|
QString m_center;
|
||||||
|
double m_motionAngle;
|
||||||
|
double m_radius;
|
||||||
|
double m_type;
|
||||||
|
};
|
83
sketchlib/container/border.cpp
Normal file
83
sketchlib/container/border.cpp
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
#include "border.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
|
Border::Border(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_color(Q_NULLPTR),
|
||||||
|
m_fillType(FillType::FlatColor),
|
||||||
|
m_isEnabled(false),
|
||||||
|
m_position(Position::Inside),
|
||||||
|
m_thickness(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *Border::color() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
Border::FillType Border::fillType() const
|
||||||
|
{
|
||||||
|
return m_fillType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Border::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
Border::Position Border::position() const
|
||||||
|
{
|
||||||
|
return m_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Border::thickness() const
|
||||||
|
{
|
||||||
|
return m_thickness;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Border::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("color"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_color = ContainerFactory::createContainer<Color>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("fillType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_fillType = FillType(int(value.toDouble()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("position"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_position = Position(int(value.toDouble()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("thickness"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_thickness = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
53
sketchlib/container/border.h
Normal file
53
sketchlib/container/border.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Border : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Color* color READ color CONSTANT)
|
||||||
|
Q_PROPERTY(FillType fillType READ fillType CONSTANT)
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(Position position READ position CONSTANT)
|
||||||
|
Q_PROPERTY(double thickness READ thickness CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Border(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
enum class FillType {
|
||||||
|
FlatColor = 0,
|
||||||
|
LinearGradient = 1,
|
||||||
|
RadialGradient = 2,
|
||||||
|
AngularGradient = 3
|
||||||
|
};
|
||||||
|
Q_ENUM(FillType)
|
||||||
|
|
||||||
|
enum class Position {
|
||||||
|
Inside = 0,
|
||||||
|
Center = 1,
|
||||||
|
Outside = 2
|
||||||
|
};
|
||||||
|
Q_ENUM(Position)
|
||||||
|
|
||||||
|
Color *color() const;
|
||||||
|
FillType fillType() const;
|
||||||
|
bool isEnabled() const;
|
||||||
|
Position position() const;
|
||||||
|
double thickness() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_color;
|
||||||
|
FillType m_fillType;
|
||||||
|
bool m_isEnabled;
|
||||||
|
Position m_position;
|
||||||
|
double m_thickness;
|
||||||
|
};
|
66
sketchlib/container/borderoptions.cpp
Normal file
66
sketchlib/container/borderoptions.cpp
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#include "borderoptions.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
BorderOptions::BorderOptions(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<double> &BorderOptions::dashPattern() const
|
||||||
|
{
|
||||||
|
return m_dashPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BorderOptions::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
double BorderOptions::lineCapStyle() const
|
||||||
|
{
|
||||||
|
return m_lineCapStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
double BorderOptions::lineJoinStyle() const
|
||||||
|
{
|
||||||
|
return m_lineJoinStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BorderOptions::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("dashPattern"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto dashPatternValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(dashPatternValue.isDouble());
|
||||||
|
m_dashPattern.append(dashPatternValue.toDouble());
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("lineCapStyle"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_lineCapStyle = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("lineJoinStyle"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_lineJoinStyle = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
33
sketchlib/container/borderoptions.h
Normal file
33
sketchlib/container/borderoptions.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT BorderOptions : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<double> dashPattern READ dashPattern CONSTANT)
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(double lineCapStyle READ lineCapStyle CONSTANT)
|
||||||
|
Q_PROPERTY(double lineJoinStyle READ lineJoinStyle CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit BorderOptions(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<double> &dashPattern() const;
|
||||||
|
bool isEnabled() const;
|
||||||
|
double lineCapStyle() const;
|
||||||
|
double lineJoinStyle() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<double> m_dashPattern;
|
||||||
|
bool m_isEnabled;
|
||||||
|
double m_lineCapStyle;
|
||||||
|
double m_lineJoinStyle;
|
||||||
|
};
|
65
sketchlib/container/color.cpp
Normal file
65
sketchlib/container/color.cpp
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#include "color.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
Color::Color(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_alpha(0.),
|
||||||
|
m_blue(0.),
|
||||||
|
m_green(0.),
|
||||||
|
m_red(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double Color::alpha() const
|
||||||
|
{
|
||||||
|
return m_alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Color::blue() const
|
||||||
|
{
|
||||||
|
return m_blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Color::green() const
|
||||||
|
{
|
||||||
|
return m_green;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Color::red() const
|
||||||
|
{
|
||||||
|
return m_red;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Color::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("alpha"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_alpha = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("blue"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_blue = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("green"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_green = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("red"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_red = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
33
sketchlib/container/color.h
Normal file
33
sketchlib/container/color.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Color : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double alpha READ alpha CONSTANT)
|
||||||
|
Q_PROPERTY(double blue READ blue CONSTANT)
|
||||||
|
Q_PROPERTY(double green READ green CONSTANT)
|
||||||
|
Q_PROPERTY(double red READ red CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Color(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double alpha() const;
|
||||||
|
double blue() const;
|
||||||
|
double green() const;
|
||||||
|
double red() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_alpha;
|
||||||
|
double m_blue;
|
||||||
|
double m_green;
|
||||||
|
double m_red;
|
||||||
|
};
|
160
sketchlib/container/document.cpp
Normal file
160
sketchlib/container/document.cpp
Normal file
@@ -0,0 +1,160 @@
|
|||||||
|
#include "document.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "assetcollection.h"
|
||||||
|
#include "msimmutableforeignsymbol.h"
|
||||||
|
#include "sharedstylecontainer.h"
|
||||||
|
#include "symbolcontainer.h"
|
||||||
|
#include "sharedtextstylecontainer.h"
|
||||||
|
#include "msjsonfilereference.h"
|
||||||
|
|
||||||
|
Document::Document(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_assets(Q_NULLPTR),
|
||||||
|
m_colorSpace(0.),
|
||||||
|
m_currentPageIndex(0.),
|
||||||
|
m_enableLayerInteraction(false),
|
||||||
|
m_enableSliceInteraction(false),
|
||||||
|
m_layerStyles(Q_NULLPTR),
|
||||||
|
m_layerSymbols(Q_NULLPTR),
|
||||||
|
m_layerTextStyles(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
AssetCollection *Document::assets() const
|
||||||
|
{
|
||||||
|
return m_assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Document::colorSpace() const
|
||||||
|
{
|
||||||
|
return m_colorSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Document::currentPageIndex() const
|
||||||
|
{
|
||||||
|
return m_currentPageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::enableLayerInteraction() const
|
||||||
|
{
|
||||||
|
return m_enableLayerInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::enableSliceInteraction() const
|
||||||
|
{
|
||||||
|
return m_enableSliceInteraction;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<MSImmutableForeignSymbol *> &Document::foreignSymbols() const
|
||||||
|
{
|
||||||
|
return m_foreignSymbols;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedStyleContainer *Document::layerStyles() const
|
||||||
|
{
|
||||||
|
return m_layerStyles;
|
||||||
|
}
|
||||||
|
|
||||||
|
SymbolContainer *Document::layerSymbols() const
|
||||||
|
{
|
||||||
|
return m_layerSymbols;
|
||||||
|
}
|
||||||
|
|
||||||
|
SharedTextStyleContainer *Document::layerTextStyles() const
|
||||||
|
{
|
||||||
|
return m_layerTextStyles;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<MSJSONFileReference *> &Document::pages() const
|
||||||
|
{
|
||||||
|
return m_pages;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Document::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("assets"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_assets = ContainerFactory::createContainer<AssetCollection>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("colorSpace"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_colorSpace = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("currentPageIndex"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_currentPageIndex = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("enableLayerInteraction"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_enableLayerInteraction = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("enableSliceInteraction"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_enableSliceInteraction = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("foreignSymbols"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto pageValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(pageValue.isObject());
|
||||||
|
m_foreignSymbols.append(ContainerFactory::createContainer<MSImmutableForeignSymbol>(pageValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerStyles"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_layerStyles = ContainerFactory::createContainer<SharedStyleContainer>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerSymbols"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_layerSymbols = ContainerFactory::createContainer<SymbolContainer>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerTextStyles"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_layerTextStyles = ContainerFactory::createContainer<SharedTextStyleContainer>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("pages"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto pageValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(pageValue.isObject());
|
||||||
|
m_pages.append(ContainerFactory::createContainer<MSJSONFileReference>(pageValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
58
sketchlib/container/document.h
Normal file
58
sketchlib/container/document.h
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class AssetCollection;
|
||||||
|
class MSImmutableForeignSymbol;
|
||||||
|
class SharedStyleContainer;
|
||||||
|
class SymbolContainer;
|
||||||
|
class SharedTextStyleContainer;
|
||||||
|
class MSJSONFileReference;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Document : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(AssetCollection* assets READ assets CONSTANT)
|
||||||
|
Q_PROPERTY(double colorSpace READ colorSpace CONSTANT)
|
||||||
|
Q_PROPERTY(double currentPageIndex READ currentPageIndex CONSTANT)
|
||||||
|
Q_PROPERTY(bool enableLayerInteraction READ enableLayerInteraction CONSTANT)
|
||||||
|
Q_PROPERTY(bool enableSliceInteraction READ enableSliceInteraction CONSTANT)
|
||||||
|
Q_PROPERTY(QList<MSImmutableForeignSymbol*> foreignSymbols READ foreignSymbols CONSTANT)
|
||||||
|
Q_PROPERTY(SharedStyleContainer* layerStyles READ layerStyles CONSTANT)
|
||||||
|
Q_PROPERTY(SymbolContainer* layerSymbols READ layerSymbols CONSTANT)
|
||||||
|
Q_PROPERTY(SharedTextStyleContainer* layerTextStyles READ layerTextStyles CONSTANT)
|
||||||
|
Q_PROPERTY(QList<MSJSONFileReference*> pages READ pages CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Document(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
AssetCollection *assets() const;
|
||||||
|
double colorSpace() const;
|
||||||
|
double currentPageIndex() const;
|
||||||
|
bool enableLayerInteraction() const;
|
||||||
|
bool enableSliceInteraction() const;
|
||||||
|
const QList<MSImmutableForeignSymbol*> &foreignSymbols() const;
|
||||||
|
SharedStyleContainer *layerStyles() const;
|
||||||
|
SymbolContainer *layerSymbols() const;
|
||||||
|
SharedTextStyleContainer *layerTextStyles() const;
|
||||||
|
const QList<MSJSONFileReference*> &pages() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
AssetCollection *m_assets;
|
||||||
|
double m_colorSpace;
|
||||||
|
double m_currentPageIndex;
|
||||||
|
bool m_enableLayerInteraction;
|
||||||
|
bool m_enableSliceInteraction;
|
||||||
|
QList<MSImmutableForeignSymbol*> m_foreignSymbols;
|
||||||
|
SharedStyleContainer *m_layerStyles;
|
||||||
|
SymbolContainer *m_layerSymbols;
|
||||||
|
SharedTextStyleContainer *m_layerTextStyles;
|
||||||
|
QList<MSJSONFileReference*> m_pages;
|
||||||
|
};
|
85
sketchlib/container/exportformat.cpp
Normal file
85
sketchlib/container/exportformat.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
#include "exportformat.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
ExportFormat::ExportFormat(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double ExportFormat::absoluteSize() const
|
||||||
|
{
|
||||||
|
return m_absoluteSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &ExportFormat::fileFormat() const
|
||||||
|
{
|
||||||
|
return m_fileFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &ExportFormat::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ExportFormat::namingScheme() const
|
||||||
|
{
|
||||||
|
return m_namingScheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ExportFormat::scale() const
|
||||||
|
{
|
||||||
|
return m_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ExportFormat::visibleScaleType() const
|
||||||
|
{
|
||||||
|
return m_visibleScaleType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExportFormat::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("absoluteSize"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_absoluteSize = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("fileFormat"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_fileFormat = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("name"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_name = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("namingScheme"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_namingScheme = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("scale"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_scale = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("visibleScaleType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_visibleScaleType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
39
sketchlib/container/exportformat.h
Normal file
39
sketchlib/container/exportformat.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ExportFormat : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double absoluteSize READ absoluteSize CONSTANT)
|
||||||
|
Q_PROPERTY(QString fileFormat READ fileFormat CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(double namingScheme READ namingScheme CONSTANT)
|
||||||
|
Q_PROPERTY(double scale READ scale CONSTANT)
|
||||||
|
Q_PROPERTY(double visibleScaleType READ visibleScaleType CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit ExportFormat(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double absoluteSize() const;
|
||||||
|
const QString &fileFormat() const;
|
||||||
|
const QString &name() const;
|
||||||
|
double namingScheme() const;
|
||||||
|
double scale() const;
|
||||||
|
double visibleScaleType() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_absoluteSize;
|
||||||
|
QString m_fileFormat;
|
||||||
|
QString m_name;
|
||||||
|
double m_namingScheme;
|
||||||
|
double m_scale;
|
||||||
|
double m_visibleScaleType;
|
||||||
|
};
|
75
sketchlib/container/exportoptions.cpp
Normal file
75
sketchlib/container/exportoptions.cpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#include "exportoptions.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include <QJsonDocument>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "exportformat.h"
|
||||||
|
|
||||||
|
ExportOptions::ExportOptions(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_layerOptions(0.),
|
||||||
|
m_shouldTrim(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<ExportFormat *> &ExportOptions::exportFormats() const
|
||||||
|
{
|
||||||
|
return m_exportFormats;
|
||||||
|
}
|
||||||
|
|
||||||
|
double ExportOptions::layerOptions() const
|
||||||
|
{
|
||||||
|
return m_layerOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExportOptions::shouldTrim() const
|
||||||
|
{
|
||||||
|
return m_shouldTrim;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ExportOptions::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("exportFormats"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto colorValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(colorValue.isObject());
|
||||||
|
m_exportFormats.append(ContainerFactory::createContainer<ExportFormat>(colorValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("includedLayerIds"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto includedLayerIdValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "includedLayerIds not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerOptions"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_layerOptions = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldTrim"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldTrim = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
35
sketchlib/container/exportoptions.h
Normal file
35
sketchlib/container/exportoptions.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class ExportFormat;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ExportOptions : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<ExportFormat*> exportFormats READ exportFormats CONSTANT)
|
||||||
|
//TODO includedLayerIds
|
||||||
|
Q_PROPERTY(double layerOptions READ layerOptions CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldTrim READ shouldTrim CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit ExportOptions(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<ExportFormat*> &exportFormats() const;
|
||||||
|
//TODO includedLayerIds
|
||||||
|
double layerOptions() const;
|
||||||
|
bool shouldTrim() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<ExportFormat*> m_exportFormats;
|
||||||
|
//TODO includedLayerIds
|
||||||
|
double m_layerOptions;
|
||||||
|
bool m_shouldTrim;
|
||||||
|
};
|
144
sketchlib/container/fill.cpp
Normal file
144
sketchlib/container/fill.cpp
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
#include "fill.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "graphicscontextsettings.h"
|
||||||
|
#include "msjsonfilereference.h"
|
||||||
|
#include "gradient.h"
|
||||||
|
|
||||||
|
Fill::Fill(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_color(Q_NULLPTR),
|
||||||
|
m_fillType(0.),
|
||||||
|
m_gradient(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *Fill::color() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsContextSettings *Fill::contextSettings() const
|
||||||
|
{
|
||||||
|
return m_contextSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Fill::fillType() const
|
||||||
|
{
|
||||||
|
return m_fillType;
|
||||||
|
}
|
||||||
|
|
||||||
|
MSJSONFileReference *Fill::image() const
|
||||||
|
{
|
||||||
|
return m_image;
|
||||||
|
}
|
||||||
|
|
||||||
|
Gradient *Fill::gradient() const
|
||||||
|
{
|
||||||
|
return m_gradient;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Fill::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Fill::noiseIndex() const
|
||||||
|
{
|
||||||
|
return m_noiseIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Fill::noiseIntensity() const
|
||||||
|
{
|
||||||
|
return m_noiseIntensity;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Fill::patternFillType() const
|
||||||
|
{
|
||||||
|
return m_patternFillType;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Fill::patternTileScale() const
|
||||||
|
{
|
||||||
|
return m_patternTileScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Fill::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("color"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_color = ContainerFactory::createContainer<Color>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("contextSettings"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_contextSettings = ContainerFactory::createContainer<GraphicsContextSettings>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("fillType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_fillType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("image"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_image = ContainerFactory::createContainer<MSJSONFileReference>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("gradient"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_gradient = ContainerFactory::createContainer<Gradient>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("noiseIndex"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_noiseIndex = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("noiseIntensity"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_noiseIntensity = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("patternFillType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_patternFillType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("patternTileScale"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_patternTileScale = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
56
sketchlib/container/fill.h
Normal file
56
sketchlib/container/fill.h
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
class GraphicsContextSettings;
|
||||||
|
class MSJSONFileReference;
|
||||||
|
class Gradient;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Fill : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Color* color READ color CONSTANT)
|
||||||
|
Q_PROPERTY(GraphicsContextSettings* contextSettings READ contextSettings CONSTANT)
|
||||||
|
Q_PROPERTY(double fillType READ fillType CONSTANT)
|
||||||
|
Q_PROPERTY(MSJSONFileReference* image READ image CONSTANT)
|
||||||
|
Q_PROPERTY(Gradient* gradient READ gradient CONSTANT)
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(double noiseIndex READ noiseIndex CONSTANT)
|
||||||
|
Q_PROPERTY(double noiseIntensity READ noiseIntensity CONSTANT)
|
||||||
|
Q_PROPERTY(double patternFillType READ patternFillType CONSTANT)
|
||||||
|
Q_PROPERTY(double patternTileScale READ patternTileScale CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Fill(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Color *color() const;
|
||||||
|
GraphicsContextSettings *contextSettings() const;
|
||||||
|
double fillType() const;
|
||||||
|
MSJSONFileReference *image() const;
|
||||||
|
Gradient *gradient() const;
|
||||||
|
bool isEnabled() const;
|
||||||
|
double noiseIndex() const;
|
||||||
|
double noiseIntensity() const;
|
||||||
|
double patternFillType() const;
|
||||||
|
double patternTileScale() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_color;
|
||||||
|
GraphicsContextSettings *m_contextSettings;
|
||||||
|
double m_fillType;
|
||||||
|
MSJSONFileReference *m_image;
|
||||||
|
Gradient *m_gradient;
|
||||||
|
bool m_isEnabled;
|
||||||
|
double m_noiseIndex;
|
||||||
|
double m_noiseIntensity;
|
||||||
|
double m_patternFillType;
|
||||||
|
double m_patternTileScale;
|
||||||
|
};
|
98
sketchlib/container/gradient.cpp
Normal file
98
sketchlib/container/gradient.cpp
Normal file
@@ -0,0 +1,98 @@
|
|||||||
|
#include "gradient.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "gradientstop.h"
|
||||||
|
|
||||||
|
Gradient::Gradient(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_elipseLength(0.),
|
||||||
|
m_gradientType(0.),
|
||||||
|
m_shouldSmoothenOpacity(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double Gradient::elipseLength() const
|
||||||
|
{
|
||||||
|
return m_elipseLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Gradient::from() const
|
||||||
|
{
|
||||||
|
return m_from;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Gradient::gradientType() const
|
||||||
|
{
|
||||||
|
return m_gradientType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Gradient::shouldSmoothenOpacity() const
|
||||||
|
{
|
||||||
|
return m_shouldSmoothenOpacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<GradientStop *> &Gradient::stops() const
|
||||||
|
{
|
||||||
|
return m_stops;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Gradient::to() const
|
||||||
|
{
|
||||||
|
return m_to;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Gradient::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("elipseLength"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_elipseLength = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("from"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_from = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("gradientType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_gradientType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldSmoothenOpacity"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldSmoothenOpacity = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("stops"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto gradientStopValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(gradientStopValue.isObject());
|
||||||
|
m_stops.append(ContainerFactory::createContainer<GradientStop>(gradientStopValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("to"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_to = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
41
sketchlib/container/gradient.h
Normal file
41
sketchlib/container/gradient.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class GradientStop;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Gradient : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double elipseLength READ elipseLength CONSTANT)
|
||||||
|
Q_PROPERTY(QString from READ from CONSTANT)
|
||||||
|
Q_PROPERTY(double gradientType READ gradientType CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldSmoothenOpacity READ shouldSmoothenOpacity CONSTANT)
|
||||||
|
Q_PROPERTY(QList<GradientStop*> stops READ stops CONSTANT)
|
||||||
|
Q_PROPERTY(QString to READ to CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Gradient(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double elipseLength() const;
|
||||||
|
const QString &from() const;
|
||||||
|
double gradientType() const;
|
||||||
|
bool shouldSmoothenOpacity() const;
|
||||||
|
const QList<GradientStop*> &stops() const;
|
||||||
|
const QString &to() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_elipseLength;
|
||||||
|
QString m_from;
|
||||||
|
double m_gradientType;
|
||||||
|
bool m_shouldSmoothenOpacity;
|
||||||
|
QList<GradientStop*> m_stops;
|
||||||
|
QString m_to;
|
||||||
|
};
|
42
sketchlib/container/gradientstop.cpp
Normal file
42
sketchlib/container/gradientstop.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "gradientstop.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
|
GradientStop::GradientStop(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *GradientStop::color() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
double GradientStop::position() const
|
||||||
|
{
|
||||||
|
return m_position;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GradientStop::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("color"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_color = ContainerFactory::createContainer<Color>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("position"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_position = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
29
sketchlib/container/gradientstop.h
Normal file
29
sketchlib/container/gradientstop.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT GradientStop : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Color* color READ color CONSTANT)
|
||||||
|
Q_PROPERTY(double position READ position CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit GradientStop(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Color *color() const;
|
||||||
|
double position() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_color;
|
||||||
|
double m_position;
|
||||||
|
};
|
39
sketchlib/container/graphicscontextsettings.cpp
Normal file
39
sketchlib/container/graphicscontextsettings.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "graphicscontextsettings.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
GraphicsContextSettings::GraphicsContextSettings(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_blendMode(0.),
|
||||||
|
m_opacity(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double GraphicsContextSettings::blendMode() const
|
||||||
|
{
|
||||||
|
return m_blendMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
double GraphicsContextSettings::opacity() const
|
||||||
|
{
|
||||||
|
return m_opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GraphicsContextSettings::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("blendMode"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_blendMode = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("opacity"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_opacity = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
27
sketchlib/container/graphicscontextsettings.h
Normal file
27
sketchlib/container/graphicscontextsettings.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT GraphicsContextSettings : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double blendMode READ blendMode CONSTANT)
|
||||||
|
Q_PROPERTY(double opacity READ opacity CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit GraphicsContextSettings(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double blendMode() const;
|
||||||
|
double opacity() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_blendMode;
|
||||||
|
double m_opacity;
|
||||||
|
};
|
56
sketchlib/container/group.cpp
Normal file
56
sketchlib/container/group.cpp
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
#include "group.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
|
||||||
|
Group::Group(QObject *parent) :
|
||||||
|
Layer(parent),
|
||||||
|
m_hasClickThrough(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<Layer *> &Group::layers() const
|
||||||
|
{
|
||||||
|
return m_layers;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Group::hasClickThrough() const
|
||||||
|
{
|
||||||
|
return m_hasClickThrough;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Group::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("layers"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto layerValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(layerValue.isObject());
|
||||||
|
m_layers.append(ContainerFactory::createContainer<Layer>(layerValue.toObject()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("flow"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
//qWarning() << "flow not implemented";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasClickThrough"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasClickThrough = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
29
sketchlib/container/group.h
Normal file
29
sketchlib/container/group.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Layer;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Group : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<Layer*> layers READ layers CONSTANT)
|
||||||
|
Q_PROPERTY(bool hasClickThrough READ hasClickThrough CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Group(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<Layer*> &layers() const;
|
||||||
|
bool hasClickThrough() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Layer*> m_layers;
|
||||||
|
bool m_hasClickThrough;
|
||||||
|
};
|
26
sketchlib/container/imagecollection.cpp
Normal file
26
sketchlib/container/imagecollection.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "imagecollection.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
ImageCollection::ImageCollection(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImageCollection::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("images"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
for(auto imageValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "images not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
24
sketchlib/container/imagecollection.h
Normal file
24
sketchlib/container/imagecollection.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ImageCollection : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
//TODO images
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit ImageCollection(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
//TODO images
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//TODO images
|
||||||
|
};
|
110
sketchlib/container/innershadow.cpp
Normal file
110
sketchlib/container/innershadow.cpp
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#include "innershadow.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "graphicscontextsettings.h"
|
||||||
|
|
||||||
|
InnerShadow::InnerShadow(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_isEnabled(false),
|
||||||
|
m_blurRadius(0.),
|
||||||
|
m_color(Q_NULLPTR),
|
||||||
|
m_contextSettings(Q_NULLPTR),
|
||||||
|
m_offsetX(0.),
|
||||||
|
m_offsetY(0.),
|
||||||
|
m_spread(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InnerShadow::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
double InnerShadow::blurRadius() const
|
||||||
|
{
|
||||||
|
return m_blurRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *InnerShadow::color() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsContextSettings *InnerShadow::contextSettings() const
|
||||||
|
{
|
||||||
|
return m_contextSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
double InnerShadow::offsetX() const
|
||||||
|
{
|
||||||
|
return m_offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
double InnerShadow::offsetY() const
|
||||||
|
{
|
||||||
|
return m_offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
double InnerShadow::spread() const
|
||||||
|
{
|
||||||
|
return m_spread;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool InnerShadow::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("blurRadius"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_blurRadius = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("color"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_color = ContainerFactory::createContainer<Color>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("contextSettings"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_contextSettings = ContainerFactory::createContainer<GraphicsContextSettings>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("offsetX"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_offsetX = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("offsetY"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_offsetY = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("spread"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_spread = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
43
sketchlib/container/innershadow.h
Normal file
43
sketchlib/container/innershadow.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
class GraphicsContextSettings;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT InnerShadow : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(double blurRadius READ blurRadius CONSTANT)
|
||||||
|
Q_PROPERTY(Color* color READ color CONSTANT)
|
||||||
|
Q_PROPERTY(GraphicsContextSettings* contextSettings READ contextSettings CONSTANT)
|
||||||
|
Q_PROPERTY(double offsetX READ offsetX CONSTANT)
|
||||||
|
Q_PROPERTY(double offsetY READ offsetY CONSTANT)
|
||||||
|
Q_PROPERTY(double spread READ spread CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit InnerShadow(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool isEnabled() const;
|
||||||
|
double blurRadius() const;
|
||||||
|
Color *color() const;
|
||||||
|
GraphicsContextSettings *contextSettings() const;
|
||||||
|
double offsetX() const;
|
||||||
|
double offsetY() const;
|
||||||
|
double spread() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_isEnabled;
|
||||||
|
double m_blurRadius;
|
||||||
|
Color *m_color;
|
||||||
|
GraphicsContextSettings *m_contextSettings;
|
||||||
|
double m_offsetX;
|
||||||
|
double m_offsetY;
|
||||||
|
double m_spread;
|
||||||
|
};
|
68
sketchlib/container/msimmutableforeignsymbol.cpp
Normal file
68
sketchlib/container/msimmutableforeignsymbol.cpp
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
#include "msimmutableforeignsymbol.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "symbolmaster.h"
|
||||||
|
|
||||||
|
MSImmutableForeignSymbol::MSImmutableForeignSymbol(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_originalMaster(Q_NULLPTR),
|
||||||
|
m_symbolMaster(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &MSImmutableForeignSymbol::libraryID() const
|
||||||
|
{
|
||||||
|
return m_libraryID;
|
||||||
|
}
|
||||||
|
|
||||||
|
SymbolMaster *MSImmutableForeignSymbol::originalMaster() const
|
||||||
|
{
|
||||||
|
return m_originalMaster;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &MSImmutableForeignSymbol::sourceLibraryName() const
|
||||||
|
{
|
||||||
|
return m_sourceLibraryName;
|
||||||
|
}
|
||||||
|
|
||||||
|
SymbolMaster *MSImmutableForeignSymbol::symbolMaster() const
|
||||||
|
{
|
||||||
|
return m_symbolMaster;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MSImmutableForeignSymbol::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("libraryID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_libraryID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("originalMaster"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_originalMaster = ContainerFactory::createContainer<SymbolMaster>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("sourceLibraryName"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_sourceLibraryName = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("symbolMaster"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_symbolMaster = ContainerFactory::createContainer<SymbolMaster>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
35
sketchlib/container/msimmutableforeignsymbol.h
Normal file
35
sketchlib/container/msimmutableforeignsymbol.h
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SymbolMaster;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT MSImmutableForeignSymbol : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString libraryID READ libraryID CONSTANT)
|
||||||
|
Q_PROPERTY(SymbolMaster* originalMaster READ originalMaster CONSTANT)
|
||||||
|
Q_PROPERTY(QString sourceLibraryName READ sourceLibraryName CONSTANT)
|
||||||
|
Q_PROPERTY(SymbolMaster* symbolMaster READ symbolMaster CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit MSImmutableForeignSymbol(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QString &libraryID() const;
|
||||||
|
SymbolMaster *originalMaster() const;
|
||||||
|
const QString &sourceLibraryName() const;
|
||||||
|
SymbolMaster *symbolMaster() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_libraryID;
|
||||||
|
SymbolMaster *m_originalMaster;
|
||||||
|
QString m_sourceLibraryName;
|
||||||
|
SymbolMaster *m_symbolMaster;
|
||||||
|
};
|
37
sketchlib/container/msjsonfilereference.cpp
Normal file
37
sketchlib/container/msjsonfilereference.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#include "msjsonfilereference.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
MSJSONFileReference::MSJSONFileReference(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &MSJSONFileReference::_ref() const
|
||||||
|
{
|
||||||
|
return m__ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &MSJSONFileReference::_ref_class() const
|
||||||
|
{
|
||||||
|
return m__ref_class;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MSJSONFileReference::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("_ref"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m__ref = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("_ref_class"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m__ref_class = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
27
sketchlib/container/msjsonfilereference.h
Normal file
27
sketchlib/container/msjsonfilereference.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT MSJSONFileReference : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString _ref READ _ref CONSTANT)
|
||||||
|
Q_PROPERTY(QString _ref_class READ _ref_class CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit MSJSONFileReference(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QString &_ref() const;
|
||||||
|
const QString &_ref_class() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m__ref;
|
||||||
|
QString m__ref_class;
|
||||||
|
};
|
11
sketchlib/container/oval.cpp
Normal file
11
sketchlib/container/oval.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "oval.h"
|
||||||
|
|
||||||
|
Oval::Oval(QObject *parent) :
|
||||||
|
Layer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Oval::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
16
sketchlib/container/oval.h
Normal file
16
sketchlib/container/oval.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Oval : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Oval(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
};
|
135
sketchlib/container/page.cpp
Normal file
135
sketchlib/container/page.cpp
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
#include "page.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "rulerdata.h"
|
||||||
|
|
||||||
|
Page::Page(QObject *parent) :
|
||||||
|
Group(parent),
|
||||||
|
m_layerListExpandedType(0.),
|
||||||
|
m_nameIsFixed(false),
|
||||||
|
m_resizingConstraint(0.),
|
||||||
|
m_resizingType(0.),
|
||||||
|
m_shouldBreakMaskChain(false),
|
||||||
|
m_hasClickThrough(false),
|
||||||
|
m_horizontalRulerData(Q_NULLPTR),
|
||||||
|
m_includeInCloudUpload(false),
|
||||||
|
m_verticalRulerData(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double Page::layerListExpandedType() const
|
||||||
|
{
|
||||||
|
return m_layerListExpandedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Page::nameIsFixed() const
|
||||||
|
{
|
||||||
|
return m_nameIsFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Page::resizingConstraint() const
|
||||||
|
{
|
||||||
|
return m_resizingConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Page::resizingType() const
|
||||||
|
{
|
||||||
|
return m_resizingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Page::shouldBreakMaskChain() const
|
||||||
|
{
|
||||||
|
return m_shouldBreakMaskChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Page::hasClickThrough() const
|
||||||
|
{
|
||||||
|
return m_hasClickThrough;
|
||||||
|
}
|
||||||
|
|
||||||
|
RulerData *Page::horizontalRulerData() const
|
||||||
|
{
|
||||||
|
return m_horizontalRulerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Page::includeInCloudUpload() const
|
||||||
|
{
|
||||||
|
return m_includeInCloudUpload;
|
||||||
|
}
|
||||||
|
|
||||||
|
RulerData *Page::verticalRulerData() const
|
||||||
|
{
|
||||||
|
return m_verticalRulerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Page::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("layerListExpandedType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_layerListExpandedType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("nameIsFixed"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_nameIsFixed = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingConstraint"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingConstraint = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldBreakMaskChain"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldBreakMaskChain = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasClickThrough"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasClickThrough = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("horizontalRulerData"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_horizontalRulerData = ContainerFactory::createContainer<RulerData>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("includeInCloudUpload"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_includeInCloudUpload = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("verticalRulerData"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_verticalRulerData = ContainerFactory::createContainer<RulerData>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Group::parseProperty(key, value);
|
||||||
|
}
|
50
sketchlib/container/page.h
Normal file
50
sketchlib/container/page.h
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "group.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class RulerData;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Page : public Group
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double layerListExpandedType READ layerListExpandedType CONSTANT)
|
||||||
|
Q_PROPERTY(bool nameIsFixed READ nameIsFixed CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingConstraint READ resizingConstraint CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingType READ resizingType CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldBreakMaskChain READ shouldBreakMaskChain CONSTANT)
|
||||||
|
Q_PROPERTY(bool hasClickThrough READ hasClickThrough CONSTANT)
|
||||||
|
Q_PROPERTY(RulerData* horizontalRulerData READ horizontalRulerData CONSTANT)
|
||||||
|
Q_PROPERTY(bool includeInCloudUpload READ includeInCloudUpload CONSTANT)
|
||||||
|
Q_PROPERTY(RulerData* verticalRulerData READ verticalRulerData CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Page(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double layerListExpandedType() const;
|
||||||
|
bool nameIsFixed() const;
|
||||||
|
double resizingConstraint() const;
|
||||||
|
double resizingType() const;
|
||||||
|
bool shouldBreakMaskChain() const;
|
||||||
|
bool hasClickThrough() const;
|
||||||
|
RulerData *horizontalRulerData() const;
|
||||||
|
bool includeInCloudUpload() const;
|
||||||
|
RulerData *verticalRulerData() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_layerListExpandedType;
|
||||||
|
bool m_nameIsFixed;
|
||||||
|
double m_resizingConstraint;
|
||||||
|
double m_resizingType;
|
||||||
|
bool m_shouldBreakMaskChain;
|
||||||
|
bool m_hasClickThrough;
|
||||||
|
RulerData *m_horizontalRulerData;
|
||||||
|
bool m_includeInCloudUpload;
|
||||||
|
RulerData *m_verticalRulerData;
|
||||||
|
};
|
11
sketchlib/container/polygon.cpp
Normal file
11
sketchlib/container/polygon.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "polygon.h"
|
||||||
|
|
||||||
|
Polygon::Polygon(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Polygon::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
18
sketchlib/container/polygon.h
Normal file
18
sketchlib/container/polygon.h
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Polygon : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Polygon(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
78
sketchlib/container/rect.cpp
Normal file
78
sketchlib/container/rect.cpp
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
#include "rect.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
Rect::Rect(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_constrainProportions(false),
|
||||||
|
m_height(0.),
|
||||||
|
m_width(0.),
|
||||||
|
m_x(0.),
|
||||||
|
m_y(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Rect::constrainProportions() const
|
||||||
|
{
|
||||||
|
return m_constrainProportions;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Rect::height() const
|
||||||
|
{
|
||||||
|
return m_height;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Rect::width() const
|
||||||
|
{
|
||||||
|
return m_width;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Rect::x() const
|
||||||
|
{
|
||||||
|
return m_x;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Rect::y() const
|
||||||
|
{
|
||||||
|
return m_y;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Rect::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("constrainProportions"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_constrainProportions = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("height"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_height = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("width"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_width = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("x"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_x = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("y"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_y = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
36
sketchlib/container/rect.h
Normal file
36
sketchlib/container/rect.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Rect : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool constrainProportions READ constrainProportions CONSTANT)
|
||||||
|
Q_PROPERTY(double height READ height CONSTANT)
|
||||||
|
Q_PROPERTY(double width READ width CONSTANT)
|
||||||
|
Q_PROPERTY(double x READ x CONSTANT)
|
||||||
|
Q_PROPERTY(double y READ y CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Rect(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool constrainProportions() const;
|
||||||
|
double height() const;
|
||||||
|
double width() const;
|
||||||
|
double x() const;
|
||||||
|
double y() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_constrainProportions;
|
||||||
|
double m_height;
|
||||||
|
double m_width;
|
||||||
|
double m_x;
|
||||||
|
double m_y;
|
||||||
|
};
|
11
sketchlib/container/rectangle.cpp
Normal file
11
sketchlib/container/rectangle.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "rectangle.h"
|
||||||
|
|
||||||
|
Rectangle::Rectangle(QObject *parent) :
|
||||||
|
Layer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Rectangle::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
16
sketchlib/container/rectangle.h
Normal file
16
sketchlib/container/rectangle.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Rectangle : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Rectangle(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
};
|
39
sketchlib/container/rulerdata.cpp
Normal file
39
sketchlib/container/rulerdata.cpp
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
#include "rulerdata.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
RulerData::RulerData(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_base(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double RulerData::base() const
|
||||||
|
{
|
||||||
|
return m_base;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RulerData::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("base"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_base = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("guides"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto guideValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "guides not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
24
sketchlib/container/rulerdata.h
Normal file
24
sketchlib/container/rulerdata.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT RulerData : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double base READ base CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit RulerData(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double base() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_base;
|
||||||
|
};
|
110
sketchlib/container/shadow.cpp
Normal file
110
sketchlib/container/shadow.cpp
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
#include "shadow.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "graphicscontextsettings.h"
|
||||||
|
|
||||||
|
Shadow::Shadow(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_isEnabled(false),
|
||||||
|
m_blurRadius(0.),
|
||||||
|
m_color(Q_NULLPTR),
|
||||||
|
m_contextSettings(Q_NULLPTR),
|
||||||
|
m_offsetX(0.),
|
||||||
|
m_offsetY(0.),
|
||||||
|
m_spread(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Shadow::isEnabled() const
|
||||||
|
{
|
||||||
|
return m_isEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Shadow::blurRadius() const
|
||||||
|
{
|
||||||
|
return m_blurRadius;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *Shadow::color() const
|
||||||
|
{
|
||||||
|
return m_color;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsContextSettings *Shadow::contextSettings() const
|
||||||
|
{
|
||||||
|
return m_contextSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Shadow::offsetX() const
|
||||||
|
{
|
||||||
|
return m_offsetX;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Shadow::offsetY() const
|
||||||
|
{
|
||||||
|
return m_offsetY;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Shadow::spread() const
|
||||||
|
{
|
||||||
|
return m_spread;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Shadow::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("isEnabled"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isEnabled = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("blurRadius"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_blurRadius = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("color"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_color = ContainerFactory::createContainer<Color>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("contextSettings"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_contextSettings = ContainerFactory::createContainer<GraphicsContextSettings>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("offsetX"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_offsetX = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("offsetY"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_offsetY = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("spread"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_spread = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
43
sketchlib/container/shadow.h
Normal file
43
sketchlib/container/shadow.h
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
class GraphicsContextSettings;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Shadow : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool isEnabled READ isEnabled CONSTANT)
|
||||||
|
Q_PROPERTY(double blurRadius READ blurRadius CONSTANT)
|
||||||
|
Q_PROPERTY(Color* color READ color CONSTANT)
|
||||||
|
Q_PROPERTY(GraphicsContextSettings* contextSettings READ contextSettings CONSTANT)
|
||||||
|
Q_PROPERTY(double offsetX READ offsetX CONSTANT)
|
||||||
|
Q_PROPERTY(double offsetY READ offsetY CONSTANT)
|
||||||
|
Q_PROPERTY(double spread READ spread CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Shadow(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool isEnabled() const;
|
||||||
|
double blurRadius() const;
|
||||||
|
Color *color() const;
|
||||||
|
GraphicsContextSettings *contextSettings() const;
|
||||||
|
double offsetX() const;
|
||||||
|
double offsetY() const;
|
||||||
|
double spread() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_isEnabled;
|
||||||
|
double m_blurRadius;
|
||||||
|
Color *m_color;
|
||||||
|
GraphicsContextSettings *m_contextSettings;
|
||||||
|
double m_offsetX;
|
||||||
|
double m_offsetY;
|
||||||
|
double m_spread;
|
||||||
|
};
|
11
sketchlib/container/shapegroup.cpp
Normal file
11
sketchlib/container/shapegroup.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "shapegroup.h"
|
||||||
|
|
||||||
|
ShapeGroup::ShapeGroup(QObject *parent) :
|
||||||
|
Group(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShapeGroup::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Group::parseProperty(key, value);
|
||||||
|
}
|
20
sketchlib/container/shapegroup.h
Normal file
20
sketchlib/container/shapegroup.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "group.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ShapeGroup : public Group
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit ShapeGroup(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
11
sketchlib/container/shapepath.cpp
Normal file
11
sketchlib/container/shapepath.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "shapepath.h"
|
||||||
|
|
||||||
|
ShapePath::ShapePath(QObject *parent) :
|
||||||
|
Layer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShapePath::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
16
sketchlib/container/shapepath.h
Normal file
16
sketchlib/container/shapepath.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ShapePath : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit ShapePath(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
};
|
42
sketchlib/container/sharedstyle.cpp
Normal file
42
sketchlib/container/sharedstyle.cpp
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#include "sharedstyle.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "style.h"
|
||||||
|
|
||||||
|
SharedStyle::SharedStyle(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &SharedStyle::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Style *SharedStyle::value() const
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SharedStyle::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("name"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_name = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("value"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_value = ContainerFactory::createContainer<Style>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
29
sketchlib/container/sharedstyle.h
Normal file
29
sketchlib/container/sharedstyle.h
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Style;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SharedStyle : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(Style* value READ value CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SharedStyle(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QString &name() const;
|
||||||
|
Style *value() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
Style *m_value;
|
||||||
|
};
|
35
sketchlib/container/sharedstylecontainer.cpp
Normal file
35
sketchlib/container/sharedstylecontainer.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#include "sharedstylecontainer.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "sharedstyle.h"
|
||||||
|
|
||||||
|
SharedStyleContainer::SharedStyleContainer(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<SharedStyle *> &SharedStyleContainer::objects() const
|
||||||
|
{
|
||||||
|
return m_objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SharedStyleContainer::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("objects"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto objectValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(objectValue.isObject());
|
||||||
|
m_objects.append(ContainerFactory::createContainer<SharedStyle>(objectValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
26
sketchlib/container/sharedstylecontainer.h
Normal file
26
sketchlib/container/sharedstylecontainer.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SharedStyle;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SharedStyleContainer : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<SharedStyle*> objects READ objects CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SharedStyleContainer(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<SharedStyle*> &objects() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<SharedStyle*> m_objects;
|
||||||
|
};
|
34
sketchlib/container/sharedtextstylecontainer.cpp
Normal file
34
sketchlib/container/sharedtextstylecontainer.cpp
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#include "sharedtextstylecontainer.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "sharedstyle.h"
|
||||||
|
|
||||||
|
SharedTextStyleContainer::SharedTextStyleContainer(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<SharedStyle *> &SharedTextStyleContainer::objects() const
|
||||||
|
{
|
||||||
|
return m_objects;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SharedTextStyleContainer::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("objects"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto objectValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(objectValue.isObject());
|
||||||
|
m_objects.append(ContainerFactory::createContainer<SharedStyle>(objectValue.toObject(), this));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
26
sketchlib/container/sharedtextstylecontainer.h
Normal file
26
sketchlib/container/sharedtextstylecontainer.h
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SharedStyle;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SharedTextStyleContainer : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QList<SharedStyle*> objects READ objects CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SharedTextStyleContainer(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QList<SharedStyle*> &objects() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<SharedStyle*> m_objects;
|
||||||
|
};
|
44
sketchlib/container/slice.cpp
Normal file
44
sketchlib/container/slice.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "slice.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
|
Slice::Slice(QObject *parent) :
|
||||||
|
Layer(parent),
|
||||||
|
m_backgroundColor(Q_NULLPTR),
|
||||||
|
m_hasBackgroundColor(false)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *Slice::backgroundColor() const
|
||||||
|
{
|
||||||
|
return m_backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Slice::hasBackgroundColor() const
|
||||||
|
{
|
||||||
|
return m_hasBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Slice::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("backgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_backgroundColor = ContainerFactory::createContainer<Color>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasBackgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasBackgroundColor = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
25
sketchlib/container/slice.h
Normal file
25
sketchlib/container/slice.h
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Slice : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Slice(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Color *backgroundColor() const;
|
||||||
|
bool hasBackgroundColor() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_backgroundColor;
|
||||||
|
bool m_hasBackgroundColor;
|
||||||
|
};
|
169
sketchlib/container/style.cpp
Normal file
169
sketchlib/container/style.cpp
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
#include "style.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "blur.h"
|
||||||
|
#include "borderoptions.h"
|
||||||
|
#include "border.h"
|
||||||
|
#include "fill.h"
|
||||||
|
#include "graphicscontextsettings.h"
|
||||||
|
#include "textstyle.h"
|
||||||
|
|
||||||
|
Style::Style(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_blur(Q_NULLPTR),
|
||||||
|
m_borderOptions(Q_NULLPTR),
|
||||||
|
m_miterLimit(0.),
|
||||||
|
m_startDecorationType(0.),
|
||||||
|
m_textStyle(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Style::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
Blur *Style::blur() const
|
||||||
|
{
|
||||||
|
return m_blur;
|
||||||
|
}
|
||||||
|
|
||||||
|
BorderOptions *Style::borderOptions() const
|
||||||
|
{
|
||||||
|
return m_borderOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<Border *> &Style::borders() const
|
||||||
|
{
|
||||||
|
return m_borders;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QList<Fill *> &Style::fills() const
|
||||||
|
{
|
||||||
|
return m_fills;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphicsContextSettings *Style::contextSettings() const
|
||||||
|
{
|
||||||
|
return m_contextSettings;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Style::endDecorationType() const
|
||||||
|
{
|
||||||
|
return m_endDecorationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Style::miterLimit() const
|
||||||
|
{
|
||||||
|
return m_miterLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Style::sharedObjectID() const
|
||||||
|
{
|
||||||
|
return m_sharedObjectID;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Style::startDecorationType() const
|
||||||
|
{
|
||||||
|
return m_startDecorationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextStyle *Style::textStyle() const
|
||||||
|
{
|
||||||
|
return m_textStyle;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Style::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("name"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_name = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("blur"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_blur = ContainerFactory::createContainer<Blur>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("borderOptions"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_borderOptions = ContainerFactory::createContainer<BorderOptions>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("borders"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto fillValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(fillValue.isObject());
|
||||||
|
m_borders.append(ContainerFactory::createContainer<Border>(fillValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("fills"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto fillValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(fillValue.isObject());
|
||||||
|
m_fills.append(ContainerFactory::createContainer<Fill>(fillValue.toObject(), this));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("contextSettings"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_contextSettings = ContainerFactory::createContainer<GraphicsContextSettings>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("endDecorationType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_endDecorationType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("miterLimit"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_miterLimit = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("sharedObjectID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_sharedObjectID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("startDecorationType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_startDecorationType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("textStyle"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_textStyle = ContainerFactory::createContainer<TextStyle>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
61
sketchlib/container/style.h
Normal file
61
sketchlib/container/style.h
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Blur;
|
||||||
|
class BorderOptions;
|
||||||
|
class Border;
|
||||||
|
class Fill;
|
||||||
|
class GraphicsContextSettings;
|
||||||
|
class TextStyle;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Style : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(Blur* blur READ blur CONSTANT)
|
||||||
|
Q_PROPERTY(BorderOptions* borderOptions READ borderOptions CONSTANT)
|
||||||
|
Q_PROPERTY(QList<Border*> borders READ borders CONSTANT)
|
||||||
|
Q_PROPERTY(QList<Fill*> fills READ fills CONSTANT)
|
||||||
|
Q_PROPERTY(GraphicsContextSettings* contextSettings READ contextSettings CONSTANT)
|
||||||
|
Q_PROPERTY(double endDecorationType READ endDecorationType CONSTANT)
|
||||||
|
Q_PROPERTY(double miterLimit READ miterLimit CONSTANT)
|
||||||
|
Q_PROPERTY(QString sharedObjectID READ sharedObjectID CONSTANT)
|
||||||
|
Q_PROPERTY(double startDecorationType READ startDecorationType CONSTANT)
|
||||||
|
Q_PROPERTY(TextStyle* textStyle READ textStyle CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Style(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
const QString &name() const;
|
||||||
|
Blur *blur() const;
|
||||||
|
BorderOptions *borderOptions() const;
|
||||||
|
const QList<Border*> &borders() const;
|
||||||
|
const QList<Fill*> &fills() const;
|
||||||
|
GraphicsContextSettings *contextSettings() const;
|
||||||
|
double endDecorationType() const;
|
||||||
|
double miterLimit() const;
|
||||||
|
const QString &sharedObjectID() const;
|
||||||
|
double startDecorationType() const;
|
||||||
|
TextStyle *textStyle() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_name;
|
||||||
|
Blur *m_blur;
|
||||||
|
BorderOptions *m_borderOptions;
|
||||||
|
QList<Border*> m_borders;
|
||||||
|
QList<Fill*> m_fills;
|
||||||
|
GraphicsContextSettings *m_contextSettings;
|
||||||
|
double m_endDecorationType;
|
||||||
|
double m_miterLimit;
|
||||||
|
QString m_sharedObjectID;
|
||||||
|
double m_startDecorationType;
|
||||||
|
TextStyle *m_textStyle;
|
||||||
|
};
|
26
sketchlib/container/symbolcontainer.cpp
Normal file
26
sketchlib/container/symbolcontainer.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include "symbolcontainer.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
SymbolContainer::SymbolContainer(QObject *parent) :
|
||||||
|
BaseContainer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolContainer::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("objects"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto objectValue : value.toArray())
|
||||||
|
{
|
||||||
|
//TODO
|
||||||
|
//qWarning() << "objects not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
24
sketchlib/container/symbolcontainer.h
Normal file
24
sketchlib/container/symbolcontainer.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SymbolContainer : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
//TODO objects
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SymbolContainer(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
//TODO objects
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
//TODO objects
|
||||||
|
};
|
202
sketchlib/container/symbolinstance.cpp
Normal file
202
sketchlib/container/symbolinstance.cpp
Normal file
@@ -0,0 +1,202 @@
|
|||||||
|
#include "symbolinstance.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
SymbolInstance::SymbolInstance(QObject *parent) :
|
||||||
|
Layer(parent),
|
||||||
|
m_nameIsFixed(false),
|
||||||
|
m_resizingConstraint(0.),
|
||||||
|
m_resizingType(0.),
|
||||||
|
m_scale(0.),
|
||||||
|
m_shouldBreakMaskChain(false),
|
||||||
|
m_verticalSpacing(0.),
|
||||||
|
m_horizontalSpacing(0.),
|
||||||
|
m_layerListExpandedType(0.),
|
||||||
|
m_masterInfluenceEdgeMaxXPadding(0.),
|
||||||
|
m_masterInfluenceEdgeMaxYPadding(0.),
|
||||||
|
m_masterInfluenceEdgeMinXPadding(0.),
|
||||||
|
m_masterInfluenceEdgeMinYPadding(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolInstance::nameIsFixed() const
|
||||||
|
{
|
||||||
|
return m_nameIsFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::resizingConstraint() const
|
||||||
|
{
|
||||||
|
return m_resizingConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::resizingType() const
|
||||||
|
{
|
||||||
|
return m_resizingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::scale() const
|
||||||
|
{
|
||||||
|
return m_scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolInstance::shouldBreakMaskChain() const
|
||||||
|
{
|
||||||
|
return m_shouldBreakMaskChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &SymbolInstance::symbolID() const
|
||||||
|
{
|
||||||
|
return m_symbolID;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::verticalSpacing() const
|
||||||
|
{
|
||||||
|
return m_verticalSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::horizontalSpacing() const
|
||||||
|
{
|
||||||
|
return m_horizontalSpacing;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::layerListExpandedType() const
|
||||||
|
{
|
||||||
|
return m_layerListExpandedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::masterInfluenceEdgeMaxXPadding() const
|
||||||
|
{
|
||||||
|
return m_masterInfluenceEdgeMaxXPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::masterInfluenceEdgeMaxYPadding() const
|
||||||
|
{
|
||||||
|
return m_masterInfluenceEdgeMaxYPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::masterInfluenceEdgeMinXPadding() const
|
||||||
|
{
|
||||||
|
return m_masterInfluenceEdgeMinXPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolInstance::masterInfluenceEdgeMinYPadding() const
|
||||||
|
{
|
||||||
|
return m_masterInfluenceEdgeMinYPadding;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolInstance::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("nameIsFixed"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_nameIsFixed = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("overrideValues"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isArray());
|
||||||
|
for(auto overrideValue : value.toArray())
|
||||||
|
{
|
||||||
|
Q_ASSERT(overrideValue.isObject());
|
||||||
|
//qWarning() << "overrideValues not implemented";
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("overrides"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
//qWarning() << "overrides not implemented";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingConstraint"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingConstraint = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("scale"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_scale = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldBreakMaskChain"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldBreakMaskChain = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("symbolID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_symbolID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("verticalSpacing"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_verticalSpacing = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("horizontalSpacing"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_horizontalSpacing = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerListExpandedType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_layerListExpandedType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("masterInfluenceEdgeMaxXPadding"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_masterInfluenceEdgeMaxXPadding = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("masterInfluenceEdgeMaxYPadding"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_masterInfluenceEdgeMaxYPadding = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("masterInfluenceEdgeMinXPadding"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_masterInfluenceEdgeMinXPadding = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("masterInfluenceEdgeMinYPadding"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_masterInfluenceEdgeMinYPadding = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
66
sketchlib/container/symbolinstance.h
Normal file
66
sketchlib/container/symbolinstance.h
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SymbolInstance : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(bool nameIsFixed READ nameIsFixed CONSTANT)
|
||||||
|
//TODO overrideValues
|
||||||
|
//TODO overrides
|
||||||
|
Q_PROPERTY(double resizingConstraint READ resizingConstraint CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingType READ resizingType CONSTANT)
|
||||||
|
Q_PROPERTY(double scale READ scale CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldBreakMaskChain READ shouldBreakMaskChain CONSTANT)
|
||||||
|
Q_PROPERTY(QString symbolID READ symbolID CONSTANT)
|
||||||
|
Q_PROPERTY(double verticalSpacing READ verticalSpacing CONSTANT)
|
||||||
|
Q_PROPERTY(double horizontalSpacing READ horizontalSpacing CONSTANT)
|
||||||
|
Q_PROPERTY(double layerListExpandedType READ layerListExpandedType CONSTANT)
|
||||||
|
Q_PROPERTY(double masterInfluenceEdgeMaxXPadding READ masterInfluenceEdgeMaxXPadding CONSTANT)
|
||||||
|
Q_PROPERTY(double masterInfluenceEdgeMaxYPadding READ masterInfluenceEdgeMaxYPadding CONSTANT)
|
||||||
|
Q_PROPERTY(double masterInfluenceEdgeMinXPadding READ masterInfluenceEdgeMinXPadding CONSTANT)
|
||||||
|
Q_PROPERTY(double masterInfluenceEdgeMinYPadding READ masterInfluenceEdgeMinYPadding CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SymbolInstance(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
bool nameIsFixed() const;
|
||||||
|
//TODO overrideValues
|
||||||
|
//TODO overrides
|
||||||
|
double resizingConstraint() const;
|
||||||
|
double resizingType() const;
|
||||||
|
double scale() const;
|
||||||
|
bool shouldBreakMaskChain() const;
|
||||||
|
const QString &symbolID() const;
|
||||||
|
double verticalSpacing() const;
|
||||||
|
double horizontalSpacing() const;
|
||||||
|
double layerListExpandedType() const;
|
||||||
|
double masterInfluenceEdgeMaxXPadding() const;
|
||||||
|
double masterInfluenceEdgeMaxYPadding() const;
|
||||||
|
double masterInfluenceEdgeMinXPadding() const;
|
||||||
|
double masterInfluenceEdgeMinYPadding() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
bool m_nameIsFixed;
|
||||||
|
//TODO m_overrideValues;
|
||||||
|
//TODO m_overrides;
|
||||||
|
double m_resizingConstraint;
|
||||||
|
double m_resizingType;
|
||||||
|
double m_scale;
|
||||||
|
bool m_shouldBreakMaskChain;
|
||||||
|
QString m_symbolID;
|
||||||
|
double m_verticalSpacing;
|
||||||
|
double m_horizontalSpacing;
|
||||||
|
double m_layerListExpandedType;
|
||||||
|
double m_masterInfluenceEdgeMaxXPadding;
|
||||||
|
double m_masterInfluenceEdgeMaxYPadding;
|
||||||
|
double m_masterInfluenceEdgeMinXPadding;
|
||||||
|
double m_masterInfluenceEdgeMinYPadding;
|
||||||
|
};
|
240
sketchlib/container/symbolmaster.cpp
Normal file
240
sketchlib/container/symbolmaster.cpp
Normal file
@@ -0,0 +1,240 @@
|
|||||||
|
#include "symbolmaster.h"
|
||||||
|
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "color.h"
|
||||||
|
#include "rulerdata.h"
|
||||||
|
|
||||||
|
SymbolMaster::SymbolMaster(QObject *parent) :
|
||||||
|
Artboard(parent),
|
||||||
|
m_backgroundColor(Q_NULLPTR),
|
||||||
|
m_changeIdentifier(0.),
|
||||||
|
m_hasBackgroundColor(false),
|
||||||
|
m_hasClickThrough(false),
|
||||||
|
m_horizontalRulerData(Q_NULLPTR),
|
||||||
|
m_includeBackgroundColorInExport(false),
|
||||||
|
m_includeBackgroundColorInInstance(false),
|
||||||
|
m_includeInCloudUpload(false),
|
||||||
|
m_isFlowHome(false),
|
||||||
|
m_layerListExpandedType(0.),
|
||||||
|
m_nameIsFixed(false),
|
||||||
|
m_resizesContent(false),
|
||||||
|
m_resizingConstraint(0.),
|
||||||
|
m_resizingType(0.),
|
||||||
|
m_shouldBreakMaskChain(false),
|
||||||
|
m_verticalRulerData(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Color *SymbolMaster::backgroundColor() const
|
||||||
|
{
|
||||||
|
return m_backgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolMaster::changeIdentifier() const
|
||||||
|
{
|
||||||
|
return m_changeIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::hasBackgroundColor() const
|
||||||
|
{
|
||||||
|
return m_hasBackgroundColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::hasClickThrough() const
|
||||||
|
{
|
||||||
|
return m_hasClickThrough;
|
||||||
|
}
|
||||||
|
|
||||||
|
RulerData *SymbolMaster::horizontalRulerData() const
|
||||||
|
{
|
||||||
|
return m_horizontalRulerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::includeBackgroundColorInExport() const
|
||||||
|
{
|
||||||
|
return m_includeBackgroundColorInExport;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::includeBackgroundColorInInstance() const
|
||||||
|
{
|
||||||
|
return m_includeBackgroundColorInInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::includeInCloudUpload() const
|
||||||
|
{
|
||||||
|
return m_includeInCloudUpload;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::isFlowHome() const
|
||||||
|
{
|
||||||
|
return m_isFlowHome;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolMaster::layerListExpandedType() const
|
||||||
|
{
|
||||||
|
return m_layerListExpandedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::nameIsFixed() const
|
||||||
|
{
|
||||||
|
return m_nameIsFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::resizesContent() const
|
||||||
|
{
|
||||||
|
return m_resizesContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolMaster::resizingConstraint() const
|
||||||
|
{
|
||||||
|
return m_resizingConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
double SymbolMaster::resizingType() const
|
||||||
|
{
|
||||||
|
return m_resizingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::shouldBreakMaskChain() const
|
||||||
|
{
|
||||||
|
return m_shouldBreakMaskChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &SymbolMaster::symbolID() const
|
||||||
|
{
|
||||||
|
return m_symbolID;
|
||||||
|
}
|
||||||
|
|
||||||
|
RulerData *SymbolMaster::verticalRulerData() const
|
||||||
|
{
|
||||||
|
return m_verticalRulerData;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SymbolMaster::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("backgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_backgroundColor = ContainerFactory::createContainer<Color>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("changeIdentifier"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_changeIdentifier = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasBackgroundColor"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasBackgroundColor = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("hasClickThrough"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_hasClickThrough = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("horizontalRulerData"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_horizontalRulerData = ContainerFactory::createContainer<RulerData>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("includeBackgroundColorInExport"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_includeBackgroundColorInExport = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("includeBackgroundColorInInstance"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_includeBackgroundColorInInstance = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("includeInCloudUpload"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_includeInCloudUpload = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isFlowHome"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isFlowHome = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerListExpandedType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_layerListExpandedType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("nameIsFixed"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_nameIsFixed = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizesContent"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_resizesContent = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingConstraint"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingConstraint = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldBreakMaskChain"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldBreakMaskChain = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("symbolID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_symbolID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("verticalRulerData"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_verticalRulerData = ContainerFactory::createContainer<RulerData>(value.toObject(), this);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Artboard::parseProperty(key, value);
|
||||||
|
}
|
75
sketchlib/container/symbolmaster.h
Normal file
75
sketchlib/container/symbolmaster.h
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "artboard.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class Color;
|
||||||
|
class RulerData;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SymbolMaster : public Artboard
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(Color* backgroundColor READ backgroundColor CONSTANT)
|
||||||
|
Q_PROPERTY(double changeIdentifier READ changeIdentifier CONSTANT)
|
||||||
|
Q_PROPERTY(bool hasBackgroundColor READ hasBackgroundColor CONSTANT)
|
||||||
|
Q_PROPERTY(bool hasClickThrough READ hasClickThrough CONSTANT)
|
||||||
|
Q_PROPERTY(RulerData* horizontalRulerData READ horizontalRulerData CONSTANT)
|
||||||
|
Q_PROPERTY(bool includeBackgroundColorInExport READ includeBackgroundColorInExport CONSTANT)
|
||||||
|
Q_PROPERTY(bool includeBackgroundColorInInstance READ includeBackgroundColorInInstance CONSTANT)
|
||||||
|
Q_PROPERTY(bool includeInCloudUpload READ includeInCloudUpload CONSTANT)
|
||||||
|
Q_PROPERTY(bool isFlowHome READ isFlowHome CONSTANT)
|
||||||
|
Q_PROPERTY(double layerListExpandedType READ layerListExpandedType CONSTANT)
|
||||||
|
Q_PROPERTY(bool nameIsFixed READ nameIsFixed CONSTANT)
|
||||||
|
Q_PROPERTY(bool resizesContent READ resizesContent CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingConstraint READ resizingConstraint CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingType READ resizingType CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldBreakMaskChain READ shouldBreakMaskChain CONSTANT)
|
||||||
|
Q_PROPERTY(QString symbolID READ symbolID CONSTANT)
|
||||||
|
Q_PROPERTY(RulerData* verticalRulerData READ verticalRulerData CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit SymbolMaster(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Color *backgroundColor() const;
|
||||||
|
double changeIdentifier() const;
|
||||||
|
bool hasBackgroundColor() const;
|
||||||
|
bool hasClickThrough() const;
|
||||||
|
RulerData *horizontalRulerData() const;
|
||||||
|
bool includeBackgroundColorInExport() const;
|
||||||
|
bool includeBackgroundColorInInstance() const;
|
||||||
|
bool includeInCloudUpload() const;
|
||||||
|
bool isFlowHome() const;
|
||||||
|
double layerListExpandedType() const;
|
||||||
|
bool nameIsFixed() const;
|
||||||
|
bool resizesContent() const;
|
||||||
|
double resizingConstraint() const;
|
||||||
|
double resizingType() const;
|
||||||
|
bool shouldBreakMaskChain() const;
|
||||||
|
const QString &symbolID() const;
|
||||||
|
RulerData *verticalRulerData() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Color *m_backgroundColor;
|
||||||
|
double m_changeIdentifier;
|
||||||
|
bool m_hasBackgroundColor;
|
||||||
|
bool m_hasClickThrough;
|
||||||
|
RulerData *m_horizontalRulerData;
|
||||||
|
bool m_includeBackgroundColorInExport;
|
||||||
|
bool m_includeBackgroundColorInInstance;
|
||||||
|
bool m_includeInCloudUpload;
|
||||||
|
bool m_isFlowHome;
|
||||||
|
double m_layerListExpandedType;
|
||||||
|
bool m_nameIsFixed;
|
||||||
|
bool m_resizesContent;
|
||||||
|
double m_resizingConstraint;
|
||||||
|
double m_resizingType;
|
||||||
|
bool m_shouldBreakMaskChain;
|
||||||
|
QString m_symbolID;
|
||||||
|
RulerData *m_verticalRulerData;
|
||||||
|
};
|
11
sketchlib/container/text.cpp
Normal file
11
sketchlib/container/text.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "text.h"
|
||||||
|
|
||||||
|
Text::Text(QObject *parent) :
|
||||||
|
Layer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Text::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
20
sketchlib/container/text.h
Normal file
20
sketchlib/container/text.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Text : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Text(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
};
|
33
sketchlib/container/textstyle.cpp
Normal file
33
sketchlib/container/textstyle.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "textstyle.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
|
||||||
|
TextStyle::TextStyle(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_verticalAlignment(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
double TextStyle::verticalAlignment() const
|
||||||
|
{
|
||||||
|
return m_verticalAlignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool TextStyle::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("verticalAlignment"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_verticalAlignment = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("encodedAttributes"))
|
||||||
|
{
|
||||||
|
//qWarning() << "encodedAttributes not implemented";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
24
sketchlib/container/textstyle.h
Normal file
24
sketchlib/container/textstyle.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT TextStyle : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(double verticalAlignment READ verticalAlignment CONSTANT)
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit TextStyle(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
double verticalAlignment() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_verticalAlignment;
|
||||||
|
};
|
11
sketchlib/container/triangle.cpp
Normal file
11
sketchlib/container/triangle.cpp
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
#include "triangle.h"
|
||||||
|
|
||||||
|
Triangle::Triangle(QObject *parent) :
|
||||||
|
Layer(parent)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Triangle::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
return Layer::parseProperty(key, value);
|
||||||
|
}
|
16
sketchlib/container/triangle.h
Normal file
16
sketchlib/container/triangle.h
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "layer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Triangle : public Layer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
Q_INVOKABLE explicit Triangle(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
};
|
149
sketchlib/containerfactory.cpp
Normal file
149
sketchlib/containerfactory.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QFile>
|
||||||
|
#include <QJsonParseError>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "container/artboard.h"
|
||||||
|
#include "container/assetcollection.h"
|
||||||
|
#include "container/bitmap.h"
|
||||||
|
#include "container/blur.h"
|
||||||
|
#include "container/border.h"
|
||||||
|
#include "container/borderoptions.h"
|
||||||
|
#include "container/color.h"
|
||||||
|
#include "container/document.h"
|
||||||
|
#include "container/exportformat.h"
|
||||||
|
#include "container/exportoptions.h"
|
||||||
|
#include "container/fill.h"
|
||||||
|
#include "container/gradient.h"
|
||||||
|
#include "container/gradientstop.h"
|
||||||
|
#include "container/graphicscontextsettings.h"
|
||||||
|
#include "container/group.h"
|
||||||
|
#include "container/imagecollection.h"
|
||||||
|
#include "container/innershadow.h"
|
||||||
|
#include "container/msimmutableforeignsymbol.h"
|
||||||
|
#include "container/msjsonfilereference.h"
|
||||||
|
#include "container/oval.h"
|
||||||
|
#include "container/page.h"
|
||||||
|
#include "container/polygon.h"
|
||||||
|
#include "container/rect.h"
|
||||||
|
#include "container/rectangle.h"
|
||||||
|
#include "container/rulerdata.h"
|
||||||
|
#include "container/shadow.h"
|
||||||
|
#include "container/shapegroup.h"
|
||||||
|
#include "container/shapepath.h"
|
||||||
|
#include "container/sharedstyle.h"
|
||||||
|
#include "container/sharedstylecontainer.h"
|
||||||
|
#include "container/sharedtextstylecontainer.h"
|
||||||
|
#include "container/slice.h"
|
||||||
|
#include "container/style.h"
|
||||||
|
#include "container/symbolcontainer.h"
|
||||||
|
#include "container/symbolinstance.h"
|
||||||
|
#include "container/symbolmaster.h"
|
||||||
|
#include "container/text.h"
|
||||||
|
#include "container/textstyle.h"
|
||||||
|
#include "container/triangle.h"
|
||||||
|
|
||||||
|
QHash<QString, QMetaObject> ContainerFactory::m_metaObjects {
|
||||||
|
{ QStringLiteral("artboard"), Artboard::staticMetaObject },
|
||||||
|
{ QStringLiteral("assetCollection"), AssetCollection::staticMetaObject },
|
||||||
|
{ QStringLiteral("bitmap"), Bitmap::staticMetaObject },
|
||||||
|
{ QStringLiteral("blur"), Blur::staticMetaObject },
|
||||||
|
{ QStringLiteral("border"), Border::staticMetaObject },
|
||||||
|
{ QStringLiteral("borderOptions"), BorderOptions::staticMetaObject },
|
||||||
|
{ QStringLiteral("color"), Color::staticMetaObject },
|
||||||
|
{ QStringLiteral("document"), Document::staticMetaObject },
|
||||||
|
{ QStringLiteral("exportFormat"), ExportFormat::staticMetaObject },
|
||||||
|
{ QStringLiteral("exportOptions"), ExportOptions::staticMetaObject },
|
||||||
|
{ QStringLiteral("fill"), Fill::staticMetaObject },
|
||||||
|
{ QStringLiteral("gradient"), Gradient::staticMetaObject },
|
||||||
|
{ QStringLiteral("gradientStop"), GradientStop::staticMetaObject },
|
||||||
|
{ QStringLiteral("graphicsContextSettings"), GraphicsContextSettings::staticMetaObject },
|
||||||
|
{ QStringLiteral("group"), Group::staticMetaObject },
|
||||||
|
{ QStringLiteral("imageCollection"), ImageCollection::staticMetaObject },
|
||||||
|
{ QStringLiteral("innerShadow"), InnerShadow::staticMetaObject },
|
||||||
|
{ QStringLiteral("MSImmutableForeignSymbol"), MSImmutableForeignSymbol::staticMetaObject },
|
||||||
|
{ QStringLiteral("MSJSONFileReference"), MSJSONFileReference::staticMetaObject },
|
||||||
|
{ QStringLiteral("oval"), Oval::staticMetaObject },
|
||||||
|
{ QStringLiteral("page"), Page::staticMetaObject },
|
||||||
|
{ QStringLiteral("polygon"), Polygon::staticMetaObject },
|
||||||
|
{ QStringLiteral("rect"), Rect::staticMetaObject },
|
||||||
|
{ QStringLiteral("rectangle"), Rectangle::staticMetaObject },
|
||||||
|
{ QStringLiteral("rulerData"), RulerData::staticMetaObject },
|
||||||
|
{ QStringLiteral("shadow"), Shadow::staticMetaObject },
|
||||||
|
{ QStringLiteral("shapeGroup"), ShapeGroup::staticMetaObject },
|
||||||
|
{ QStringLiteral("shapePath"), ShapePath::staticMetaObject },
|
||||||
|
{ QStringLiteral("sharedStyle"), SharedStyle::staticMetaObject },
|
||||||
|
{ QStringLiteral("sharedStyleContainer"), SharedStyleContainer::staticMetaObject },
|
||||||
|
{ QStringLiteral("sharedTextStyleContainer"), SharedTextStyleContainer::staticMetaObject },
|
||||||
|
{ QStringLiteral("slice"), Slice::staticMetaObject },
|
||||||
|
{ QStringLiteral("style"), Style::staticMetaObject },
|
||||||
|
{ QStringLiteral("symbolContainer"), SymbolContainer::staticMetaObject },
|
||||||
|
{ QStringLiteral("symbolInstance"), SymbolInstance::staticMetaObject },
|
||||||
|
{ QStringLiteral("symbolMaster"), SymbolMaster::staticMetaObject },
|
||||||
|
{ QStringLiteral("text"), Text::staticMetaObject },
|
||||||
|
{ QStringLiteral("textStyle"), TextStyle::staticMetaObject },
|
||||||
|
{ QStringLiteral("triangle"), Triangle::staticMetaObject }
|
||||||
|
};
|
||||||
|
|
||||||
|
BaseContainer *ContainerFactory::createContainer(const QString &path, QObject *parent)
|
||||||
|
{
|
||||||
|
QFile file(path);
|
||||||
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
|
throw QStringLiteral("Could not open file %0 because %1").arg(path).arg(file.errorString());
|
||||||
|
|
||||||
|
return createContainer(file, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseContainer *ContainerFactory::createContainer(QIODevice &device, QObject *parent)
|
||||||
|
{
|
||||||
|
return createContainer(device.readAll(), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseContainer *ContainerFactory::createContainer(const QByteArray &content, QObject *parent)
|
||||||
|
{
|
||||||
|
QJsonParseError jsonParseError;
|
||||||
|
QJsonDocument jsonDocument = QJsonDocument::fromJson(content, &jsonParseError);
|
||||||
|
if(jsonParseError.error != QJsonParseError::NoError)
|
||||||
|
throw QStringLiteral("Could not parse json: %0").arg(jsonParseError.errorString());
|
||||||
|
|
||||||
|
return createContainer(jsonDocument, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseContainer *ContainerFactory::createContainer(const QJsonDocument &jsonDocument, QObject *parent)
|
||||||
|
{
|
||||||
|
if(!jsonDocument.isObject())
|
||||||
|
throw QStringLiteral("json document is not an object");
|
||||||
|
|
||||||
|
return createContainer(jsonDocument.object(), parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
BaseContainer *ContainerFactory::createContainer(const QJsonObject &jsonObj, QObject *parent)
|
||||||
|
{
|
||||||
|
if(!jsonObj.contains(QStringLiteral("_class")))
|
||||||
|
throw QStringLiteral("json does not contain _class");
|
||||||
|
|
||||||
|
auto classValue = jsonObj.value(QStringLiteral("_class"));
|
||||||
|
|
||||||
|
if(!classValue.isString())
|
||||||
|
throw QStringLiteral("_class is not a string");
|
||||||
|
|
||||||
|
auto classString = classValue.toString();
|
||||||
|
|
||||||
|
if(!m_metaObjects.contains(classString))
|
||||||
|
throw QStringLiteral("Unknown container type %0").arg(classString);
|
||||||
|
|
||||||
|
auto obj = m_metaObjects.value(classString).newInstance(Q_ARG(QObject *, parent));
|
||||||
|
if(!obj)
|
||||||
|
throw QStringLiteral("Container class could not be constructed");
|
||||||
|
|
||||||
|
auto container = qobject_cast<BaseContainer*>(obj);
|
||||||
|
if(!container)
|
||||||
|
throw QStringLiteral("Container object could be casted to BaseContainer");
|
||||||
|
|
||||||
|
container->parseFromJson(jsonObj);
|
||||||
|
|
||||||
|
return container;
|
||||||
|
}
|
41
sketchlib/containerfactory.h
Normal file
41
sketchlib/containerfactory.h
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QHash>
|
||||||
|
|
||||||
|
class QIODevice;
|
||||||
|
class QByteArray;
|
||||||
|
class QJsonDocument;
|
||||||
|
class QJsonObject;
|
||||||
|
|
||||||
|
class BaseContainer;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT ContainerFactory
|
||||||
|
{
|
||||||
|
static QHash<QString, QMetaObject> m_metaObjects;
|
||||||
|
|
||||||
|
public:
|
||||||
|
static BaseContainer* createContainer(const QString &path, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
static BaseContainer* createContainer(QIODevice &device, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
static BaseContainer* createContainer(const QByteArray &content, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
static BaseContainer* createContainer(const QJsonDocument &jsonDocument, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
static BaseContainer* createContainer(const QJsonObject &jsonObj, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
template<typename T1, typename T2>
|
||||||
|
static T1* createContainer(const T2 &arg, QObject *parent = Q_NULLPTR)
|
||||||
|
{
|
||||||
|
auto container = createContainer(arg, parent);
|
||||||
|
auto castedContainer = qobject_cast<T1*>(container);
|
||||||
|
|
||||||
|
if(!castedContainer)
|
||||||
|
throw QStringLiteral("not expected type");
|
||||||
|
|
||||||
|
return castedContainer;
|
||||||
|
}
|
||||||
|
};
|
226
sketchlib/layer.cpp
Normal file
226
sketchlib/layer.cpp
Normal file
@@ -0,0 +1,226 @@
|
|||||||
|
#include "layer.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QJsonValue>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "container/rect.h"
|
||||||
|
#include "container/style.h"
|
||||||
|
#include "container/exportoptions.h"
|
||||||
|
|
||||||
|
Layer::Layer(QObject *parent) :
|
||||||
|
BaseContainer(parent),
|
||||||
|
m_frame(Q_NULLPTR),
|
||||||
|
m_isFlippedVertical(false),
|
||||||
|
m_isFlippedHorizontal(false),
|
||||||
|
m_isVisible(false),
|
||||||
|
m_resizingConstraints(ResizingConstraint::None),
|
||||||
|
m_rotation(0.),
|
||||||
|
m_style(Q_NULLPTR),
|
||||||
|
m_exportOptions(Q_NULLPTR),
|
||||||
|
m_isLocked(false),
|
||||||
|
m_resizingConstraint(0.),
|
||||||
|
m_resizingType(0.),
|
||||||
|
m_shouldBreakMaskChain(false),
|
||||||
|
m_layerListExpandedType(0.)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Layer::do_objectID() const
|
||||||
|
{
|
||||||
|
return m_do_objectID;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &Layer::name() const
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::nameIsFixed() const
|
||||||
|
{
|
||||||
|
return m_nameIsFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect *Layer::frame() const
|
||||||
|
{
|
||||||
|
return m_frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::isFlippedVertical() const
|
||||||
|
{
|
||||||
|
return m_isFlippedVertical;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::isFlippedHorizontal() const
|
||||||
|
{
|
||||||
|
return m_isFlippedHorizontal;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::isVisible() const
|
||||||
|
{
|
||||||
|
return m_isVisible;
|
||||||
|
}
|
||||||
|
|
||||||
|
Layer::ResizingConstraint Layer::resizingConstraints() const
|
||||||
|
{
|
||||||
|
return m_resizingConstraints;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Layer::rotation() const
|
||||||
|
{
|
||||||
|
return m_rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
Style *Layer::style() const
|
||||||
|
{
|
||||||
|
return m_style;
|
||||||
|
}
|
||||||
|
|
||||||
|
ExportOptions *Layer::exportOptions() const
|
||||||
|
{
|
||||||
|
return m_exportOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::isLocked() const
|
||||||
|
{
|
||||||
|
return m_isLocked;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Layer::resizingConstraint() const
|
||||||
|
{
|
||||||
|
return m_resizingConstraint;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Layer::resizingType() const
|
||||||
|
{
|
||||||
|
return m_resizingType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::shouldBreakMaskChain() const
|
||||||
|
{
|
||||||
|
return m_shouldBreakMaskChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
double Layer::layerListExpandedType() const
|
||||||
|
{
|
||||||
|
return m_layerListExpandedType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Layer::parseProperty(const QString &key, const QJsonValue &value)
|
||||||
|
{
|
||||||
|
if(key == QStringLiteral("do_objectID"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_do_objectID = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("name"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isString());
|
||||||
|
m_name = value.toString();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("nameIsFixed"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_nameIsFixed = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("frame"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_frame = ContainerFactory::createContainer<Rect>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isFlippedVertical"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isFlippedVertical = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isFlippedHorizontal"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isFlippedHorizontal = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isVisible"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isVisible = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingConstraints"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingConstraints = ResizingConstraint(int(value.toDouble()));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("rotation"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_rotation = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("style"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_style = ContainerFactory::createContainer<Style>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("exportOptions"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isObject());
|
||||||
|
m_exportOptions = ContainerFactory::createContainer<ExportOptions>(value.toObject());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("isLocked"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_isLocked = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingConstraint"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingConstraint = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("resizingType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_resizingType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("shouldBreakMaskChain"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isBool());
|
||||||
|
m_shouldBreakMaskChain = value.toBool();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(key == QStringLiteral("layerListExpandedType"))
|
||||||
|
{
|
||||||
|
Q_ASSERT(value.isDouble());
|
||||||
|
m_layerListExpandedType = value.toDouble();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return BaseContainer::parseProperty(key, value);
|
||||||
|
}
|
87
sketchlib/layer.h
Normal file
87
sketchlib/layer.h
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "basecontainer.h"
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class Rect;
|
||||||
|
class Style;
|
||||||
|
class ExportOptions;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT Layer : public BaseContainer
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString do_objectID READ do_objectID CONSTANT)
|
||||||
|
Q_PROPERTY(QString name READ name CONSTANT)
|
||||||
|
Q_PROPERTY(bool nameIsFixed READ nameIsFixed CONSTANT)
|
||||||
|
Q_PROPERTY(Rect* frame READ frame CONSTANT)
|
||||||
|
Q_PROPERTY(bool isFlippedVertical READ isFlippedVertical CONSTANT)
|
||||||
|
Q_PROPERTY(bool isFlippedHorizontal READ isFlippedHorizontal CONSTANT)
|
||||||
|
Q_PROPERTY(bool isVisible READ isVisible CONSTANT)
|
||||||
|
Q_PROPERTY(ResizingConstraint resizingConstraints READ resizingConstraints CONSTANT)
|
||||||
|
Q_PROPERTY(double rotation READ rotation CONSTANT)
|
||||||
|
Q_PROPERTY(Style* style READ style CONSTANT)
|
||||||
|
Q_PROPERTY(ExportOptions* exportOptions READ exportOptions CONSTANT)
|
||||||
|
Q_PROPERTY(bool isLocked READ isLocked CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingConstraint READ resizingConstraint CONSTANT)
|
||||||
|
Q_PROPERTY(double resizingType READ resizingType CONSTANT)
|
||||||
|
Q_PROPERTY(bool shouldBreakMaskChain READ shouldBreakMaskChain CONSTANT)
|
||||||
|
Q_PROPERTY(double layerListExpandedType READ layerListExpandedType CONSTANT)
|
||||||
|
|
||||||
|
protected:
|
||||||
|
explicit Layer(QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum ResizingConstraint
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
FlexibleRightMargin = 1,
|
||||||
|
FlexibleWidth = 2,
|
||||||
|
FlexibleLeftMargin = 4,
|
||||||
|
FlexibleBottomMargin = 8,
|
||||||
|
FlexibleHeight = 16,
|
||||||
|
FlexibleTopMargin = 32
|
||||||
|
};
|
||||||
|
Q_DECLARE_FLAGS(ResizingConstraints, ResizingConstraint)
|
||||||
|
Q_FLAG(ResizingConstraints)
|
||||||
|
|
||||||
|
const QString &do_objectID() const;
|
||||||
|
const QString &name() const;
|
||||||
|
bool nameIsFixed() const;
|
||||||
|
Rect *frame() const;
|
||||||
|
bool isFlippedVertical() const;
|
||||||
|
bool isFlippedHorizontal() const;
|
||||||
|
bool isVisible() const;
|
||||||
|
ResizingConstraint resizingConstraints() const;
|
||||||
|
double rotation() const;
|
||||||
|
Style *style() const;
|
||||||
|
ExportOptions *exportOptions() const;
|
||||||
|
bool isLocked() const;
|
||||||
|
double resizingConstraint() const;
|
||||||
|
double resizingType() const;
|
||||||
|
bool shouldBreakMaskChain() const;
|
||||||
|
double layerListExpandedType() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BaseContainer interface
|
||||||
|
virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QString m_do_objectID;
|
||||||
|
QString m_name;
|
||||||
|
bool m_nameIsFixed;
|
||||||
|
Rect *m_frame;
|
||||||
|
bool m_isFlippedVertical;
|
||||||
|
bool m_isFlippedHorizontal;
|
||||||
|
bool m_isVisible;
|
||||||
|
ResizingConstraint m_resizingConstraints;
|
||||||
|
double m_rotation;
|
||||||
|
Style *m_style;
|
||||||
|
ExportOptions *m_exportOptions;
|
||||||
|
bool m_isLocked;
|
||||||
|
double m_resizingConstraint;
|
||||||
|
double m_resizingType;
|
||||||
|
bool m_shouldBreakMaskChain;
|
||||||
|
double m_layerListExpandedType;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_OPERATORS_FOR_FLAGS(Layer::ResizingConstraints)
|
179
sketchlib/sketchfile.cpp
Normal file
179
sketchlib/sketchfile.cpp
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
#include "sketchfile.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QGraphicsScene>
|
||||||
|
#include <QGraphicsTextItem>
|
||||||
|
#include <QGraphicsPixmapItem>
|
||||||
|
|
||||||
|
#include "quazip.h"
|
||||||
|
#include "quazipfile.h"
|
||||||
|
|
||||||
|
#include "containerfactory.h"
|
||||||
|
|
||||||
|
#include "container/document.h"
|
||||||
|
#include "container/msjsonfilereference.h"
|
||||||
|
#include "container/page.h"
|
||||||
|
#include "container/rect.h"
|
||||||
|
#include "container/group.h"
|
||||||
|
#include "container/text.h"
|
||||||
|
#include "container/bitmap.h"
|
||||||
|
#include "container/rectangle.h"
|
||||||
|
|
||||||
|
SketchFile::SketchFile(QObject *parent) :
|
||||||
|
QObject(parent),
|
||||||
|
m_document(Q_NULLPTR),
|
||||||
|
m_zip(Q_NULLPTR)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
const QString &SketchFile::filename() const
|
||||||
|
{
|
||||||
|
return m_filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
Document *SketchFile::document() const
|
||||||
|
{
|
||||||
|
return m_document;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SketchFile::open(const QString &filename)
|
||||||
|
{
|
||||||
|
if(m_filename != filename)
|
||||||
|
Q_EMIT filenameChanged(m_filename = filename);
|
||||||
|
|
||||||
|
delete m_zip;
|
||||||
|
|
||||||
|
m_zip = new QuaZip(filename);
|
||||||
|
if(!m_zip->open(QuaZip::mdUnzip))
|
||||||
|
throw tr("Could not unzip sketch file!");
|
||||||
|
|
||||||
|
if(m_document)
|
||||||
|
m_document->deleteLater();
|
||||||
|
|
||||||
|
m_document = createContainerZip<Document>(QStringLiteral("document.json"), this);
|
||||||
|
Q_EMIT documentChanged(m_document);
|
||||||
|
}
|
||||||
|
|
||||||
|
Page *SketchFile::loadPage(const QString &filename)
|
||||||
|
{
|
||||||
|
return createContainerZip<Page>(filename + ".json", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene *SketchFile::createScene(const QString &filename, QObject *parent)
|
||||||
|
{
|
||||||
|
Page *page;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
page = loadPage(filename);
|
||||||
|
} catch (QString msg) {
|
||||||
|
throw tr("Could not parse page: %0").arg(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene *scene;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scene = createScene(page, parent);
|
||||||
|
} catch (QString msg) {
|
||||||
|
throw tr("Could not render page: %0").arg(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene *SketchFile::createScene(Page *page, QObject *parent)
|
||||||
|
{
|
||||||
|
auto minX = page->frame()->x(), minY = page->frame()->y(),
|
||||||
|
maxX = page->frame()->x() + page->frame()->width(),
|
||||||
|
maxY = page->frame()->y() + page->frame()->height();
|
||||||
|
|
||||||
|
getBoundsRecursive(page, minX, minY, maxX, maxY, 0., 0.);
|
||||||
|
|
||||||
|
auto scene = new QGraphicsScene(minX, minY, maxX - minX + 1., maxY - minY + 1., parent);
|
||||||
|
|
||||||
|
renderItemsRecursive(scene, page, 0., 0.);
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SketchFile::getBoundsRecursive(Layer *layer, double &minX, double &minY, double &maxX, double &maxY, double xOffset, double yOffset)
|
||||||
|
{
|
||||||
|
auto x = xOffset + layer->frame()->x();
|
||||||
|
auto y = yOffset + layer->frame()->y();
|
||||||
|
if(minX > x)
|
||||||
|
minX = x;
|
||||||
|
if(minY > y)
|
||||||
|
minY = y;
|
||||||
|
if(maxX < x + layer->frame()->width())
|
||||||
|
maxX = x + layer->frame()->width();
|
||||||
|
if(maxY < y + layer->frame()->height())
|
||||||
|
maxY = y + layer->frame()->height();
|
||||||
|
|
||||||
|
if(auto group = qobject_cast<Group*>(layer))
|
||||||
|
{
|
||||||
|
for(auto subLayer : group->layers())
|
||||||
|
getBoundsRecursive(subLayer, minX, minY, maxX, maxY, x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SketchFile::renderItemsRecursive(QGraphicsScene *scene, Layer *layer, double xOffset, double yOffset)
|
||||||
|
{
|
||||||
|
if(auto text = qobject_cast<Text*>(layer))
|
||||||
|
{
|
||||||
|
auto textItem = scene->addText(text->name());
|
||||||
|
textItem->setPos(xOffset + text->frame()->x(), yOffset + text->frame()->y());
|
||||||
|
}
|
||||||
|
else if(auto bitmap = qobject_cast<Bitmap*>(layer))
|
||||||
|
{
|
||||||
|
auto path = bitmap->image()->_ref() + ".png";
|
||||||
|
|
||||||
|
if(!m_zip->setCurrentFile(path))
|
||||||
|
{
|
||||||
|
qWarning() << "could not unzip" << path;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QuaZipFile file(m_zip);
|
||||||
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
qWarning() << "Could not open" << path << "because" << file.errorString();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QImage image;
|
||||||
|
if(!image.load(&file, "PNG"))
|
||||||
|
{
|
||||||
|
qWarning() << "could not load image";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto bitmapItem = scene->addPixmap(QPixmap::fromImage(image.scaled(bitmap->frame()->width(), bitmap->frame()->height())));
|
||||||
|
bitmapItem->setPos(xOffset + bitmap->frame()->x(), yOffset + bitmap->frame()->y());
|
||||||
|
}
|
||||||
|
else if(auto group = qobject_cast<Group*>(layer))
|
||||||
|
{
|
||||||
|
for(auto subLayer : group->layers())
|
||||||
|
renderItemsRecursive(scene, subLayer, xOffset + subLayer->frame()->x(), yOffset + subLayer->frame()->y());
|
||||||
|
}
|
||||||
|
|
||||||
|
scene->addRect(xOffset + layer->frame()->x(), yOffset + layer->frame()->y(),
|
||||||
|
layer->frame()->width(), layer->frame()->height());
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T* SketchFile::createContainerZip(const QString &filename, QObject *parent)
|
||||||
|
{
|
||||||
|
if(!m_zip->setCurrentFile(filename))
|
||||||
|
throw QStringLiteral("Could not set to %0").arg(filename);
|
||||||
|
|
||||||
|
QuaZipFile file(m_zip);
|
||||||
|
if(!file.open(QIODevice::ReadOnly))
|
||||||
|
throw QStringLiteral("Could not open %0 because %1").arg(filename, file.errorString());
|
||||||
|
|
||||||
|
auto container = ContainerFactory::createContainer(file, parent);
|
||||||
|
auto castedContainer = qobject_cast<T*>(container);
|
||||||
|
|
||||||
|
if(castedContainer)
|
||||||
|
return castedContainer;
|
||||||
|
else
|
||||||
|
throw QStringLiteral("not expected type");
|
||||||
|
}
|
46
sketchlib/sketchfile.h
Normal file
46
sketchlib/sketchfile.h
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include "sketchlib_global.h"
|
||||||
|
|
||||||
|
class QGraphicsScene;
|
||||||
|
|
||||||
|
class QuaZip;
|
||||||
|
|
||||||
|
class Document;
|
||||||
|
class Page;
|
||||||
|
class Layer;
|
||||||
|
|
||||||
|
class SKETCHLIB_EXPORT SketchFile : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(QString filename READ filename NOTIFY filenameChanged)
|
||||||
|
Q_PROPERTY(Document* document READ document NOTIFY documentChanged)
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit SketchFile(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
const QString &filename() const;
|
||||||
|
Document *document() const;
|
||||||
|
|
||||||
|
void open(const QString &filename);
|
||||||
|
Page *loadPage(const QString &filename);
|
||||||
|
QGraphicsScene *createScene(const QString &filename, QObject *parent = Q_NULLPTR);
|
||||||
|
QGraphicsScene *createScene(Page *page, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void filenameChanged(const QString &filename);
|
||||||
|
void documentChanged(Document *document);
|
||||||
|
|
||||||
|
private:
|
||||||
|
template<typename T>
|
||||||
|
T* createContainerZip(const QString &filename, QObject *parent = Q_NULLPTR);
|
||||||
|
|
||||||
|
static void getBoundsRecursive(Layer *layer, double &minX, double &minY, double &maxX, double &maxY, double xOffset, double yOffset);
|
||||||
|
void renderItemsRecursive(QGraphicsScene *scene, Layer *layer,double xOffset, double yOffset);
|
||||||
|
|
||||||
|
QString m_filename;
|
||||||
|
Document *m_document;
|
||||||
|
|
||||||
|
QuaZip *m_zip;
|
||||||
|
};
|
105
sketchlib/sketchlib.pro
Normal file
105
sketchlib/sketchlib.pro
Normal file
@@ -0,0 +1,105 @@
|
|||||||
|
QT += core gui widgets
|
||||||
|
|
||||||
|
DBLIBS += quazip
|
||||||
|
|
||||||
|
PROJECT_ROOT = ../..
|
||||||
|
|
||||||
|
DEFINES += SKETCHLIB_LIBRARY
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
basecontainer.cpp \
|
||||||
|
containerfactory.cpp \
|
||||||
|
layer.cpp \
|
||||||
|
sketchfile.cpp \
|
||||||
|
container/artboard.cpp \
|
||||||
|
container/assetcollection.cpp \
|
||||||
|
container/bitmap.cpp \
|
||||||
|
container/blur.cpp \
|
||||||
|
container/border.cpp \
|
||||||
|
container/borderoptions.cpp \
|
||||||
|
container/color.cpp \
|
||||||
|
container/document.cpp \
|
||||||
|
container/exportformat.cpp \
|
||||||
|
container/exportoptions.cpp \
|
||||||
|
container/fill.cpp \
|
||||||
|
container/gradient.cpp \
|
||||||
|
container/gradientstop.cpp \
|
||||||
|
container/graphicscontextsettings.cpp \
|
||||||
|
container/group.cpp \
|
||||||
|
container/imagecollection.cpp \
|
||||||
|
container/innershadow.cpp \
|
||||||
|
container/msimmutableforeignsymbol.cpp \
|
||||||
|
container/msjsonfilereference.cpp \
|
||||||
|
container/oval.cpp \
|
||||||
|
container/page.cpp \
|
||||||
|
container/polygon.cpp \
|
||||||
|
container/rect.cpp \
|
||||||
|
container/rectangle.cpp \
|
||||||
|
container/rulerdata.cpp \
|
||||||
|
container/shadow.cpp \
|
||||||
|
container/shapegroup.cpp \
|
||||||
|
container/shapepath.cpp \
|
||||||
|
container/sharedstyle.cpp \
|
||||||
|
container/sharedstylecontainer.cpp \
|
||||||
|
container/sharedtextstylecontainer.cpp \
|
||||||
|
container/slice.cpp \
|
||||||
|
container/style.cpp \
|
||||||
|
container/symbolcontainer.cpp \
|
||||||
|
container/symbolinstance.cpp \
|
||||||
|
container/symbolmaster.cpp \
|
||||||
|
container/text.cpp \
|
||||||
|
container/textstyle.cpp \
|
||||||
|
container/triangle.cpp
|
||||||
|
|
||||||
|
HEADERS += sketchlib_global.h \
|
||||||
|
basecontainer.h \
|
||||||
|
containerfactory.h \
|
||||||
|
layer.h \
|
||||||
|
sketchfile.h \
|
||||||
|
container/artboard.h \
|
||||||
|
container/assetcollection.h \
|
||||||
|
container/bitmap.h \
|
||||||
|
container/blur.h \
|
||||||
|
container/border.h \
|
||||||
|
container/borderoptions.h \
|
||||||
|
container/color.h \
|
||||||
|
container/document.h \
|
||||||
|
container/exportformat.h \
|
||||||
|
container/exportoptions.h \
|
||||||
|
container/fill.h \
|
||||||
|
container/gradient.h \
|
||||||
|
container/gradientstop.h \
|
||||||
|
container/graphicscontextsettings.h \
|
||||||
|
container/group.h \
|
||||||
|
container/imagecollection.h \
|
||||||
|
container/innershadow.h \
|
||||||
|
container/msimmutableforeignsymbol.h \
|
||||||
|
container/msjsonfilereference.h \
|
||||||
|
container/oval.h \
|
||||||
|
container/page.h \
|
||||||
|
container/polygon.h \
|
||||||
|
container/rect.h \
|
||||||
|
container/rectangle.h \
|
||||||
|
container/rulerdata.h \
|
||||||
|
container/shadow.h \
|
||||||
|
container/shapegroup.h \
|
||||||
|
container/shapepath.h \
|
||||||
|
container/sharedstyle.h \
|
||||||
|
container/sharedstylecontainer.h \
|
||||||
|
container/sharedtextstylecontainer.h \
|
||||||
|
container/slice.h \
|
||||||
|
container/style.h \
|
||||||
|
container/symbolcontainer.h \
|
||||||
|
container/symbolinstance.h \
|
||||||
|
container/symbolmaster.h \
|
||||||
|
container/text.h \
|
||||||
|
container/textstyle.h \
|
||||||
|
container/triangle.h
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES +=
|
||||||
|
|
||||||
|
TRANSLATIONS +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/lib.pri)
|
9
sketchlib/sketchlib_global.h
Normal file
9
sketchlib/sketchlib_global.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
|
#if defined(SKETCHLIB_LIBRARY)
|
||||||
|
# define SKETCHLIB_EXPORT Q_DECL_EXPORT
|
||||||
|
#else
|
||||||
|
# define SKETCHLIB_EXPORT Q_DECL_IMPORT
|
||||||
|
#endif
|
81
sketchviewer/main.cpp
Normal file
81
sketchviewer/main.cpp
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
#include <QApplication>
|
||||||
|
#include <QDirIterator>
|
||||||
|
#include <QTabWidget>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QGraphicsView>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "sketchfile.h"
|
||||||
|
#include "container/document.h"
|
||||||
|
#include "container/page.h"
|
||||||
|
#include "container/msjsonfilereference.h"
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QApplication a(argc, argv);
|
||||||
|
|
||||||
|
qSetMessagePattern(QStringLiteral("%{time dd.MM.yyyy HH:mm:ss.zzz} "
|
||||||
|
"["
|
||||||
|
"%{if-debug}D%{endif}"
|
||||||
|
"%{if-info}I%{endif}"
|
||||||
|
"%{if-warning}W%{endif}"
|
||||||
|
"%{if-critical}C%{endif}"
|
||||||
|
"%{if-fatal}F%{endif}"
|
||||||
|
"] "
|
||||||
|
"%{function}(): "
|
||||||
|
"%{message}"));
|
||||||
|
|
||||||
|
auto parentWidget = new QTabWidget;
|
||||||
|
|
||||||
|
QDirIterator iter(QStringLiteral("sketches"), QStringList { QStringLiteral("*.sketch") }, QDir::Files);
|
||||||
|
while(iter.hasNext())
|
||||||
|
{
|
||||||
|
SketchFile file;
|
||||||
|
|
||||||
|
auto filename = iter.next();
|
||||||
|
try {
|
||||||
|
file.open(filename);
|
||||||
|
} catch(QString msg) {
|
||||||
|
parentWidget->addTab(new QLabel(QStringLiteral("<span style=\"color: red;\">Could not load sketch file: %0</span>").arg(msg), parentWidget), filename);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto tabWidget = new QTabWidget(parentWidget);
|
||||||
|
|
||||||
|
for(auto pageRef : file.document()->pages())
|
||||||
|
{
|
||||||
|
Page *page;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
page = file.loadPage(pageRef->_ref());
|
||||||
|
} catch (QString msg) {
|
||||||
|
tabWidget->addTab(new QLabel(QStringLiteral("<span style=\"color: red;\">Could not parse page: %0</span>").arg(msg), tabWidget), pageRef->_ref());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
QGraphicsScene *scene;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
scene = file.createScene(page);
|
||||||
|
} catch (QString msg) {
|
||||||
|
tabWidget->addTab(new QLabel(QStringLiteral("<span style=\"color: red;\">Could not render page: %0</span>").arg(msg), tabWidget), page->name());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tabWidget->addTab(new QGraphicsView(scene, tabWidget), page->name());
|
||||||
|
}
|
||||||
|
|
||||||
|
parentWidget->addTab(tabWidget, file.filename());
|
||||||
|
}
|
||||||
|
|
||||||
|
parentWidget->show();
|
||||||
|
|
||||||
|
qDebug() << "summary of missing properties:";
|
||||||
|
{
|
||||||
|
const auto &missing = BaseContainer::missing();
|
||||||
|
for(auto iter = missing.constBegin(); iter != missing.constEnd(); iter++)
|
||||||
|
qDebug() << iter.key() << iter.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
17
sketchviewer/sketchviewer.pro
Normal file
17
sketchviewer/sketchviewer.pro
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
QT += core gui widgets
|
||||||
|
|
||||||
|
DBLIBS += sketchlib
|
||||||
|
|
||||||
|
PROJECT_ROOT = ../..
|
||||||
|
|
||||||
|
SOURCES += main.cpp
|
||||||
|
|
||||||
|
HEADERS +=
|
||||||
|
|
||||||
|
FORMS +=
|
||||||
|
|
||||||
|
RESOURCES +=
|
||||||
|
|
||||||
|
TRANSLATIONS +=
|
||||||
|
|
||||||
|
include($${PROJECT_ROOT}/app.pri)
|
Reference in New Issue
Block a user