diff --git a/DbSketch.pro b/DbSketch.pro new file mode 100644 index 0000000..c0cf9fa --- /dev/null +++ b/DbSketch.pro @@ -0,0 +1,6 @@ +TEMPLATE = subdirs + +SUBDIRS += sketchlib \ + sketchviewer + +sketchviewer.depends += sketchlib diff --git a/sketchlib/basecontainer.cpp b/sketchlib/basecontainer.cpp new file mode 100644 index 0000000..06807cc --- /dev/null +++ b/sketchlib/basecontainer.cpp @@ -0,0 +1,59 @@ +#include "basecontainer.h" + +#include +#include + +const QHash 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 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 &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; +} diff --git a/sketchlib/basecontainer.h b/sketchlib/basecontainer.h new file mode 100644 index 0000000..6b182e4 --- /dev/null +++ b/sketchlib/basecontainer.h @@ -0,0 +1,36 @@ +#pragma once + +#include +#include "sketchlib_global.h" + +#include +#include +#include + +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 &missing(); + +protected: + virtual bool parseProperty(const QString &key, const QJsonValue &value); + +private: + static const QHash m_types; + static QMap m_missing; + + QString m_do_objectID; +}; diff --git a/sketchlib/container/artboard.cpp b/sketchlib/container/artboard.cpp new file mode 100644 index 0000000..3ffeca8 --- /dev/null +++ b/sketchlib/container/artboard.cpp @@ -0,0 +1,44 @@ +#include "artboard.h" + +#include +#include + +#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(value.toObject()); + return true; + } + + if(key == QStringLiteral("hasBackgroundColor")) + { + Q_ASSERT(value.isBool()); + m_hasBackgroundColor = value.toBool(); + return true; + } + + return Group::parseProperty(key, value); +} diff --git a/sketchlib/container/artboard.h b/sketchlib/container/artboard.h new file mode 100644 index 0000000..0472704 --- /dev/null +++ b/sketchlib/container/artboard.h @@ -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; +}; diff --git a/sketchlib/container/assetcollection.cpp b/sketchlib/container/assetcollection.cpp new file mode 100644 index 0000000..dc15905 --- /dev/null +++ b/sketchlib/container/assetcollection.cpp @@ -0,0 +1,72 @@ +#include "assetcollection.h" + +#include +#include +#include +#include + +#include "containerfactory.h" + +#include "color.h" +#include "imagecollection.h" + +AssetCollection::AssetCollection(QObject *parent) : + BaseContainer(parent), + m_imageCollection(Q_NULLPTR) +{ +} + +const QList &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(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(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); +} diff --git a/sketchlib/container/assetcollection.h b/sketchlib/container/assetcollection.h new file mode 100644 index 0000000..659b3ea --- /dev/null +++ b/sketchlib/container/assetcollection.h @@ -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 colors READ colors CONSTANT) + Q_PROPERTY(ImageCollection* imageCollection READ imageCollection CONSTANT) + +public: + Q_INVOKABLE explicit AssetCollection(QObject *parent = Q_NULLPTR); + + const QList &colors() const; + ImageCollection *imageCollection() const; + +protected: + // BaseContainer interface + virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE; + +private: + QList m_colors; + //TODO gradients + ImageCollection *m_imageCollection; + //TODO images +}; diff --git a/sketchlib/container/bitmap.cpp b/sketchlib/container/bitmap.cpp new file mode 100644 index 0000000..30a3397 --- /dev/null +++ b/sketchlib/container/bitmap.cpp @@ -0,0 +1,31 @@ +#include "bitmap.h" + +#include +#include + +#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(value.toObject()); + return true; + } + + return Layer::parseProperty(key, value); +} diff --git a/sketchlib/container/bitmap.h b/sketchlib/container/bitmap.h new file mode 100644 index 0000000..aa09b0b --- /dev/null +++ b/sketchlib/container/bitmap.h @@ -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; +}; diff --git a/sketchlib/container/blur.cpp b/sketchlib/container/blur.cpp new file mode 100644 index 0000000..e33b659 --- /dev/null +++ b/sketchlib/container/blur.cpp @@ -0,0 +1,73 @@ +#include "blur.h" + +#include + +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); +} diff --git a/sketchlib/container/blur.h b/sketchlib/container/blur.h new file mode 100644 index 0000000..3f82499 --- /dev/null +++ b/sketchlib/container/blur.h @@ -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; +}; diff --git a/sketchlib/container/border.cpp b/sketchlib/container/border.cpp new file mode 100644 index 0000000..336ccc6 --- /dev/null +++ b/sketchlib/container/border.cpp @@ -0,0 +1,83 @@ +#include "border.h" + +#include +#include + +#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(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); +} diff --git a/sketchlib/container/border.h b/sketchlib/container/border.h new file mode 100644 index 0000000..0c2942e --- /dev/null +++ b/sketchlib/container/border.h @@ -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; +}; diff --git a/sketchlib/container/borderoptions.cpp b/sketchlib/container/borderoptions.cpp new file mode 100644 index 0000000..04f820f --- /dev/null +++ b/sketchlib/container/borderoptions.cpp @@ -0,0 +1,66 @@ +#include "borderoptions.h" + +#include +#include + +BorderOptions::BorderOptions(QObject *parent) : + BaseContainer(parent) +{ +} + +const QList &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); +} diff --git a/sketchlib/container/borderoptions.h b/sketchlib/container/borderoptions.h new file mode 100644 index 0000000..8bf827a --- /dev/null +++ b/sketchlib/container/borderoptions.h @@ -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 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 &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 m_dashPattern; + bool m_isEnabled; + double m_lineCapStyle; + double m_lineJoinStyle; +}; diff --git a/sketchlib/container/color.cpp b/sketchlib/container/color.cpp new file mode 100644 index 0000000..eefe469 --- /dev/null +++ b/sketchlib/container/color.cpp @@ -0,0 +1,65 @@ +#include "color.h" + +#include + +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); +} diff --git a/sketchlib/container/color.h b/sketchlib/container/color.h new file mode 100644 index 0000000..560bc6a --- /dev/null +++ b/sketchlib/container/color.h @@ -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; +}; diff --git a/sketchlib/container/document.cpp b/sketchlib/container/document.cpp new file mode 100644 index 0000000..8304d52 --- /dev/null +++ b/sketchlib/container/document.cpp @@ -0,0 +1,160 @@ +#include "document.h" + +#include +#include +#include + +#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 &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 &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(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(pageValue.toObject(), this)); + } + return true; + } + + if(key == QStringLiteral("layerStyles")) + { + Q_ASSERT(value.isObject()); + m_layerStyles = ContainerFactory::createContainer(value.toObject(), this); + return true; + } + + if(key == QStringLiteral("layerSymbols")) + { + Q_ASSERT(value.isObject()); + m_layerSymbols = ContainerFactory::createContainer(value.toObject(), this); + return true; + } + + if(key == QStringLiteral("layerTextStyles")) + { + Q_ASSERT(value.isObject()); + m_layerTextStyles = ContainerFactory::createContainer(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(pageValue.toObject(), this)); + } + return true; + } + + return BaseContainer::parseProperty(key, value); +} diff --git a/sketchlib/container/document.h b/sketchlib/container/document.h new file mode 100644 index 0000000..d94fc1d --- /dev/null +++ b/sketchlib/container/document.h @@ -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 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 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 &foreignSymbols() const; + SharedStyleContainer *layerStyles() const; + SymbolContainer *layerSymbols() const; + SharedTextStyleContainer *layerTextStyles() const; + const QList &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 m_foreignSymbols; + SharedStyleContainer *m_layerStyles; + SymbolContainer *m_layerSymbols; + SharedTextStyleContainer *m_layerTextStyles; + QList m_pages; +}; diff --git a/sketchlib/container/exportformat.cpp b/sketchlib/container/exportformat.cpp new file mode 100644 index 0000000..c55baf4 --- /dev/null +++ b/sketchlib/container/exportformat.cpp @@ -0,0 +1,85 @@ +#include "exportformat.h" + +#include + +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); +} diff --git a/sketchlib/container/exportformat.h b/sketchlib/container/exportformat.h new file mode 100644 index 0000000..293a702 --- /dev/null +++ b/sketchlib/container/exportformat.h @@ -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; +}; diff --git a/sketchlib/container/exportoptions.cpp b/sketchlib/container/exportoptions.cpp new file mode 100644 index 0000000..9455f5d --- /dev/null +++ b/sketchlib/container/exportoptions.cpp @@ -0,0 +1,75 @@ +#include "exportoptions.h" + +#include +#include +#include +#include + +#include + +#include "containerfactory.h" + +#include "exportformat.h" + +ExportOptions::ExportOptions(QObject *parent) : + BaseContainer(parent), + m_layerOptions(0.), + m_shouldTrim(false) +{ +} + +const QList &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(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); +} diff --git a/sketchlib/container/exportoptions.h b/sketchlib/container/exportoptions.h new file mode 100644 index 0000000..7ff5370 --- /dev/null +++ b/sketchlib/container/exportoptions.h @@ -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 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 &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 m_exportFormats; + //TODO includedLayerIds + double m_layerOptions; + bool m_shouldTrim; +}; diff --git a/sketchlib/container/fill.cpp b/sketchlib/container/fill.cpp new file mode 100644 index 0000000..a0262c3 --- /dev/null +++ b/sketchlib/container/fill.cpp @@ -0,0 +1,144 @@ +#include "fill.h" + +#include +#include + +#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(value.toObject(), this); + return true; + } + + if(key == QStringLiteral("contextSettings")) + { + Q_ASSERT(value.isObject()); + m_contextSettings = ContainerFactory::createContainer(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(value.toObject(), this); + return true; + } + + if(key == QStringLiteral("gradient")) + { + Q_ASSERT(value.isObject()); + m_gradient = ContainerFactory::createContainer(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); +} diff --git a/sketchlib/container/fill.h b/sketchlib/container/fill.h new file mode 100644 index 0000000..2c9c7df --- /dev/null +++ b/sketchlib/container/fill.h @@ -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; +}; diff --git a/sketchlib/container/gradient.cpp b/sketchlib/container/gradient.cpp new file mode 100644 index 0000000..525b24f --- /dev/null +++ b/sketchlib/container/gradient.cpp @@ -0,0 +1,98 @@ +#include "gradient.h" + +#include +#include +#include + +#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 &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(gradientStopValue.toObject(), this)); + } + return true; + } + + if(key == QStringLiteral("to")) + { + Q_ASSERT(value.isString()); + m_to = value.toString(); + return true; + } + + return BaseContainer::parseProperty(key, value); +} diff --git a/sketchlib/container/gradient.h b/sketchlib/container/gradient.h new file mode 100644 index 0000000..bb152b4 --- /dev/null +++ b/sketchlib/container/gradient.h @@ -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 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 &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 m_stops; + QString m_to; +}; diff --git a/sketchlib/container/gradientstop.cpp b/sketchlib/container/gradientstop.cpp new file mode 100644 index 0000000..669131c --- /dev/null +++ b/sketchlib/container/gradientstop.cpp @@ -0,0 +1,42 @@ +#include "gradientstop.h" + +#include +#include + +#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(value.toObject(), this); + return true; + } + + if(key == QStringLiteral("position")) + { + Q_ASSERT(value.isDouble()); + m_position = value.toDouble(); + return true; + } + + return BaseContainer::parseProperty(key, value); +} diff --git a/sketchlib/container/gradientstop.h b/sketchlib/container/gradientstop.h new file mode 100644 index 0000000..7ce224b --- /dev/null +++ b/sketchlib/container/gradientstop.h @@ -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; +}; diff --git a/sketchlib/container/graphicscontextsettings.cpp b/sketchlib/container/graphicscontextsettings.cpp new file mode 100644 index 0000000..f2cbae5 --- /dev/null +++ b/sketchlib/container/graphicscontextsettings.cpp @@ -0,0 +1,39 @@ +#include "graphicscontextsettings.h" + +#include + +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); +} diff --git a/sketchlib/container/graphicscontextsettings.h b/sketchlib/container/graphicscontextsettings.h new file mode 100644 index 0000000..e5f2f79 --- /dev/null +++ b/sketchlib/container/graphicscontextsettings.h @@ -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; +}; diff --git a/sketchlib/container/group.cpp b/sketchlib/container/group.cpp new file mode 100644 index 0000000..fca107b --- /dev/null +++ b/sketchlib/container/group.cpp @@ -0,0 +1,56 @@ +#include "group.h" + +#include +#include +#include +#include + +#include "containerfactory.h" + +#include "layer.h" + +Group::Group(QObject *parent) : + Layer(parent), + m_hasClickThrough(false) +{ +} + +const QList &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(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); +} diff --git a/sketchlib/container/group.h b/sketchlib/container/group.h new file mode 100644 index 0000000..f1055b4 --- /dev/null +++ b/sketchlib/container/group.h @@ -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 layers READ layers CONSTANT) + Q_PROPERTY(bool hasClickThrough READ hasClickThrough CONSTANT) + +public: + Q_INVOKABLE explicit Group(QObject *parent = Q_NULLPTR); + + const QList &layers() const; + bool hasClickThrough() const; + +protected: + // BaseContainer interface + virtual bool parseProperty(const QString &key, const QJsonValue &value) Q_DECL_OVERRIDE; + +private: + QList m_layers; + bool m_hasClickThrough; +}; diff --git a/sketchlib/container/imagecollection.cpp b/sketchlib/container/imagecollection.cpp new file mode 100644 index 0000000..3615ebb --- /dev/null +++ b/sketchlib/container/imagecollection.cpp @@ -0,0 +1,26 @@ +#include "imagecollection.h" + +#include +#include +#include + +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); +} diff --git a/sketchlib/container/imagecollection.h b/sketchlib/container/imagecollection.h new file mode 100644 index 0000000..09d7614 --- /dev/null +++ b/sketchlib/container/imagecollection.h @@ -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 +}; diff --git a/sketchlib/container/innershadow.cpp b/sketchlib/container/innershadow.cpp new file mode 100644 index 0000000..31147dc --- /dev/null +++ b/sketchlib/container/innershadow.cpp @@ -0,0 +1,110 @@ +#include "innershadow.h" + +#include +#include + +#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(value.toObject()); + return true; + } + + if(key == QStringLiteral("contextSettings")) + { + Q_ASSERT(value.isObject()); + m_contextSettings = ContainerFactory::createContainer(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); +} diff --git a/sketchlib/container/innershadow.h b/sketchlib/container/innershadow.h new file mode 100644 index 0000000..772722f --- /dev/null +++ b/sketchlib/container/innershadow.h @@ -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; +}; diff --git a/sketchlib/container/msimmutableforeignsymbol.cpp b/sketchlib/container/msimmutableforeignsymbol.cpp new file mode 100644 index 0000000..26f5df9 --- /dev/null +++ b/sketchlib/container/msimmutableforeignsymbol.cpp @@ -0,0 +1,68 @@ +#include "msimmutableforeignsymbol.h" + +#include +#include + +#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(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(value.toObject(), this); + return true; + } + + return BaseContainer::parseProperty(key, value); +} diff --git a/sketchlib/container/msimmutableforeignsymbol.h b/sketchlib/container/msimmutableforeignsymbol.h new file mode 100644 index 0000000..15a2a70 --- /dev/null +++ b/sketchlib/container/msimmutableforeignsymbol.h @@ -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; +}; diff --git a/sketchlib/container/msjsonfilereference.cpp b/sketchlib/container/msjsonfilereference.cpp new file mode 100644 index 0000000..d9ec76b --- /dev/null +++ b/sketchlib/container/msjsonfilereference.cpp @@ -0,0 +1,37 @@ +#include "msjsonfilereference.h" + +#include + +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); +} diff --git a/sketchlib/container/msjsonfilereference.h b/sketchlib/container/msjsonfilereference.h new file mode 100644 index 0000000..a10106e --- /dev/null +++ b/sketchlib/container/msjsonfilereference.h @@ -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; +}; diff --git a/sketchlib/container/oval.cpp b/sketchlib/container/oval.cpp new file mode 100644 index 0000000..ad9b9a3 --- /dev/null +++ b/sketchlib/container/oval.cpp @@ -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); +} diff --git a/sketchlib/container/oval.h b/sketchlib/container/oval.h new file mode 100644 index 0000000..69f5d31 --- /dev/null +++ b/sketchlib/container/oval.h @@ -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; +}; diff --git a/sketchlib/container/page.cpp b/sketchlib/container/page.cpp new file mode 100644 index 0000000..4183e47 --- /dev/null +++ b/sketchlib/container/page.cpp @@ -0,0 +1,135 @@ +#include "page.h" + +#include +#include + +#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(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(value.toObject(), this); + return true; + } + + return Group::parseProperty(key, value); +} diff --git a/sketchlib/container/page.h b/sketchlib/container/page.h new file mode 100644 index 0000000..d743ca2 --- /dev/null +++ b/sketchlib/container/page.h @@ -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; +}; diff --git a/sketchlib/container/polygon.cpp b/sketchlib/container/polygon.cpp new file mode 100644 index 0000000..d7ea24d --- /dev/null +++ b/sketchlib/container/polygon.cpp @@ -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); +} diff --git a/sketchlib/container/polygon.h b/sketchlib/container/polygon.h new file mode 100644 index 0000000..b5653bc --- /dev/null +++ b/sketchlib/container/polygon.h @@ -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: +}; diff --git a/sketchlib/container/rect.cpp b/sketchlib/container/rect.cpp new file mode 100644 index 0000000..55128e4 --- /dev/null +++ b/sketchlib/container/rect.cpp @@ -0,0 +1,78 @@ +#include "rect.h" + +#include + +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); +} diff --git a/sketchlib/container/rect.h b/sketchlib/container/rect.h new file mode 100644 index 0000000..b364670 --- /dev/null +++ b/sketchlib/container/rect.h @@ -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; +}; diff --git a/sketchlib/container/rectangle.cpp b/sketchlib/container/rectangle.cpp new file mode 100644 index 0000000..aa87189 --- /dev/null +++ b/sketchlib/container/rectangle.cpp @@ -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); +} diff --git a/sketchlib/container/rectangle.h b/sketchlib/container/rectangle.h new file mode 100644 index 0000000..4415a85 --- /dev/null +++ b/sketchlib/container/rectangle.h @@ -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; +}; diff --git a/sketchlib/container/rulerdata.cpp b/sketchlib/container/rulerdata.cpp new file mode 100644 index 0000000..d6a8644 --- /dev/null +++ b/sketchlib/container/rulerdata.cpp @@ -0,0 +1,39 @@ +#include "rulerdata.h" + +#include +#include +#include + +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); +} diff --git a/sketchlib/container/rulerdata.h b/sketchlib/container/rulerdata.h new file mode 100644 index 0000000..a22520a --- /dev/null +++ b/sketchlib/container/rulerdata.h @@ -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; +}; diff --git a/sketchlib/container/shadow.cpp b/sketchlib/container/shadow.cpp new file mode 100644 index 0000000..0fa560d --- /dev/null +++ b/sketchlib/container/shadow.cpp @@ -0,0 +1,110 @@ +#include "shadow.h" + +#include +#include + +#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(value.toObject()); + return true; + } + + if(key == QStringLiteral("contextSettings")) + { + Q_ASSERT(value.isObject()); + m_contextSettings = ContainerFactory::createContainer(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); +} diff --git a/sketchlib/container/shadow.h b/sketchlib/container/shadow.h new file mode 100644 index 0000000..2f8dfd0 --- /dev/null +++ b/sketchlib/container/shadow.h @@ -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; +}; diff --git a/sketchlib/container/shapegroup.cpp b/sketchlib/container/shapegroup.cpp new file mode 100644 index 0000000..8045384 --- /dev/null +++ b/sketchlib/container/shapegroup.cpp @@ -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); +} diff --git a/sketchlib/container/shapegroup.h b/sketchlib/container/shapegroup.h new file mode 100644 index 0000000..29c72d9 --- /dev/null +++ b/sketchlib/container/shapegroup.h @@ -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: +}; diff --git a/sketchlib/container/shapepath.cpp b/sketchlib/container/shapepath.cpp new file mode 100644 index 0000000..7a6550f --- /dev/null +++ b/sketchlib/container/shapepath.cpp @@ -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); +} diff --git a/sketchlib/container/shapepath.h b/sketchlib/container/shapepath.h new file mode 100644 index 0000000..bee909a --- /dev/null +++ b/sketchlib/container/shapepath.h @@ -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; +}; diff --git a/sketchlib/container/sharedstyle.cpp b/sketchlib/container/sharedstyle.cpp new file mode 100644 index 0000000..fe35f44 --- /dev/null +++ b/sketchlib/container/sharedstyle.cpp @@ -0,0 +1,42 @@ +#include "sharedstyle.h" + +#include +#include + +#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