forked from qt-creator/qt-creator
AssetExport: Add text node parsing
Change-Id: I86e40aef49d27515d798f8511a6ed15786b2358e Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -54,6 +54,7 @@ add_qtc_plugin(assetexporterplugin
|
||||
assetexporterplugin/filepathmodel.h assetexporterplugin/filepathmodel.cpp
|
||||
assetexporterplugin/parsers/modelitemnodeparser.h assetexporterplugin/parsers/modelitemnodeparser.cpp
|
||||
assetexporterplugin/parsers/modelnodeparser.h assetexporterplugin/parsers/modelnodeparser.cpp
|
||||
assetexporterplugin/parsers/textnodeparser.h assetexporterplugin/parsers/textnodeparser.cpp
|
||||
assetexporterplugin/assetexporterplugin.qrc
|
||||
PLUGIN_PATH ${QmlDesignerPluginInstallPrefix}
|
||||
SKIP_DEBUG_CMAKE_FILE_CHECK
|
||||
|
@@ -33,6 +33,7 @@
|
||||
#include "componentexporter.h"
|
||||
|
||||
#include "parsers/modelitemnodeparser.h"
|
||||
#include "parsers/textnodeparser.h"
|
||||
|
||||
#include "coreplugin/actionmanager/actionmanager.h"
|
||||
#include "coreplugin/actionmanager/actioncontainer.h"
|
||||
@@ -68,6 +69,7 @@ AssetExporterPlugin::AssetExporterPlugin() :
|
||||
|
||||
// Add parsers templates for factory instantiation.
|
||||
ComponentExporter::addNodeParser<ItemNodeParser>();
|
||||
ComponentExporter::addNodeParser<TextNodeParser>();
|
||||
|
||||
// Instantiate actions created by the plugin.
|
||||
addActions();
|
||||
|
@@ -16,7 +16,8 @@ HEADERS += \
|
||||
exportnotification.h \
|
||||
filepathmodel.h \
|
||||
parsers/modelitemnodeparser.h \
|
||||
parsers/modelnodeparser.h
|
||||
parsers/modelnodeparser.h \
|
||||
parsers/textnodeparser.h
|
||||
|
||||
SOURCES += \
|
||||
assetexportdialog.cpp \
|
||||
@@ -27,7 +28,8 @@ SOURCES += \
|
||||
exportnotification.cpp \
|
||||
filepathmodel.cpp \
|
||||
parsers/modelitemnodeparser.cpp \
|
||||
parsers/modelnodeparser.cpp
|
||||
parsers/modelnodeparser.cpp \
|
||||
parsers/textnodeparser.cpp
|
||||
|
||||
FORMS += \
|
||||
assetexportdialog.ui
|
||||
|
@@ -50,6 +50,8 @@ QtcProduct {
|
||||
"parsers/modelitemnodeparser.cpp",
|
||||
"parsers/modelitemnodeparser.h",
|
||||
"parsers/modelnodeparser.cpp",
|
||||
"parsers/modelnodeparser.h"
|
||||
"parsers/modelnodeparser.h",
|
||||
"parsers/textnodeparser.cpp",
|
||||
"parsers/textnodeparser.h"
|
||||
]
|
||||
}
|
||||
|
@@ -31,5 +31,47 @@ const char EXPORT_QML[] = "Designer.ExportPlugin.ExportQml";
|
||||
|
||||
const char TASK_CATEGORY_ASSET_EXPORT[] = "AssetExporter.Export";
|
||||
|
||||
//***************************************************************************
|
||||
// Metadata tags
|
||||
//***************************************************************************
|
||||
// Plugin info tags
|
||||
const char PluginInfoTag[] = "pluginInfo";
|
||||
const char MetadataVersionTag[] = "metadataVersion";
|
||||
|
||||
const char DocumentInfoTag[] = "documentInfo";
|
||||
const char DocumentNameTag[] = "name";
|
||||
|
||||
// Layer data tags
|
||||
const char ArtboardListTag[] = "artboards";
|
||||
|
||||
const char XPosTag[] = "x";
|
||||
const char YPosTag[] = "y";
|
||||
const char WidthTag[] = "width";
|
||||
const char HeightTag[] = "height";
|
||||
|
||||
|
||||
const char QmlIdTag[] = "qmlId";
|
||||
const char ExportTypeTag[] = "exportType";
|
||||
const char QmlPropertiesTag[] = "qmlProperties";
|
||||
const char ImportsTag[] = "extraImports";
|
||||
const char UuidTag[] = "uuid";
|
||||
const char ClipTag[] = "clip";
|
||||
const char AssetDataTag[] = "assetData";
|
||||
const char AssetPath[] = "assetPath";
|
||||
const char AssetBoundsTag[] = "assetBounds";
|
||||
const char OpacityTag[] = "opacity";
|
||||
|
||||
const char TextDetailsTag[] = "textDetails";
|
||||
const char FontFamilyTag[] = "fontFamily";
|
||||
const char FontSizeTag[] = "fontSize";
|
||||
const char FontStyleTag[] = "fontStyle";
|
||||
const char LetterSpacingTag[] = "kerning";
|
||||
const char TextColorTag[] = "textColor";
|
||||
const char TextContentTag[] = "contents";
|
||||
const char IsMultilineTag[] = "multiline";
|
||||
const char LineHeightTag[] = "lineHeight";
|
||||
const char HAlignTag[] = "horizontalAlignment";
|
||||
const char VAlignTag[] = "verticalAlignment";
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -26,13 +26,10 @@
|
||||
#include "modelitemnodeparser.h"
|
||||
#include "assetexportpluginconstants.h"
|
||||
|
||||
#include "modelnode.h"
|
||||
#include "qmlitemnode.h"
|
||||
#include "variantproperty.h"
|
||||
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
using namespace Constants;
|
||||
ItemNodeParser::ItemNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||
ModelNodeParser(lineage, node)
|
||||
{
|
||||
@@ -41,25 +38,25 @@ ItemNodeParser::ItemNodeParser(const QByteArrayList &lineage, const ModelNode &n
|
||||
|
||||
bool QmlDesigner::ItemNodeParser::isExportable() const
|
||||
{
|
||||
return m_lineage.contains("QtQuick.Item");
|
||||
return lineage().contains("QtQuick.Item");
|
||||
}
|
||||
|
||||
QJsonObject QmlDesigner::ItemNodeParser::json() const
|
||||
{
|
||||
// TODO parse other relevant properties i.e. dimensions etc
|
||||
const QmlObjectNode &qmlObjectNode = objectNode();
|
||||
QJsonObject jsonObject;
|
||||
jsonObject.insert("qmlid", m_node.id());
|
||||
QmlItemNode itemNode(m_node);
|
||||
jsonObject.insert(QmlIdTag, qmlObjectNode.id());
|
||||
QmlItemNode itemNode = qmlObjectNode.toQmlItemNode();
|
||||
|
||||
// Position relative to parent
|
||||
QPointF pos = itemNode.instancePosition();
|
||||
jsonObject.insert("x", pos.x());
|
||||
jsonObject.insert("y", pos.y());
|
||||
jsonObject.insert(XPosTag, pos.x());
|
||||
jsonObject.insert(YPosTag, pos.y());
|
||||
|
||||
// size
|
||||
QSizeF size = itemNode.instanceSize();
|
||||
jsonObject.insert("width", size.width());
|
||||
jsonObject.insert("height", size.height());
|
||||
jsonObject.insert(WidthTag, size.width());
|
||||
jsonObject.insert(HeightTag, size.height());
|
||||
|
||||
return jsonObject;
|
||||
}
|
||||
|
@@ -27,9 +27,15 @@
|
||||
namespace QmlDesigner {
|
||||
ModelNodeParser::ModelNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||
m_node(node),
|
||||
m_objectNode(node),
|
||||
m_lineage(lineage)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant ModelNodeParser::propertyValue(const PropertyName &name) const
|
||||
{
|
||||
return m_objectNode.instanceValue(name);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,6 +24,8 @@
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "qmlobjectnode.h"
|
||||
|
||||
#include <QJsonObject>
|
||||
#include <QByteArrayList>
|
||||
|
||||
@@ -41,8 +43,13 @@ public:
|
||||
virtual bool isExportable() const = 0;
|
||||
virtual QJsonObject json() const = 0;
|
||||
|
||||
protected:
|
||||
const QByteArrayList& lineage() const { return m_lineage; }
|
||||
const QmlObjectNode& objectNode() const { return m_objectNode; }
|
||||
QVariant propertyValue(const PropertyName &name) const;
|
||||
|
||||
private:
|
||||
const ModelNode &m_node;
|
||||
const QByteArrayList m_lineage;
|
||||
QmlObjectNode m_objectNode;
|
||||
QByteArrayList m_lineage;
|
||||
};
|
||||
}
|
||||
|
@@ -0,0 +1,86 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "textnodeparser.h"
|
||||
#include "assetexportpluginconstants.h"
|
||||
|
||||
#include <QColor>
|
||||
#include <QHash>
|
||||
|
||||
namespace {
|
||||
const QHash<QString, QString> AlignMapping{
|
||||
{"AlignRight", "RIGHT"},
|
||||
{"AlignHCenter", "CENTER"},
|
||||
{"AlignJustify", "JUSTIFIED"},
|
||||
{"AlignLeft", "LEFT"},
|
||||
{"AlignTop", "TOP"},
|
||||
{"AlignVCenter", "CENTER"},
|
||||
{"AlignBottom", "BOTTOM"}
|
||||
};
|
||||
|
||||
QString toJsonAlignEnum(QString value) {
|
||||
if (value.isEmpty() || !AlignMapping.contains(value))
|
||||
return "";
|
||||
return AlignMapping[value];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace QmlDesigner {
|
||||
using namespace Constants;
|
||||
TextNodeParser::TextNodeParser(const QByteArrayList &lineage, const ModelNode &node) :
|
||||
ItemNodeParser(lineage, node)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool TextNodeParser::isExportable() const
|
||||
{
|
||||
return lineage().contains("QtQuick.Text");
|
||||
}
|
||||
|
||||
QJsonObject TextNodeParser::json() const
|
||||
{
|
||||
QJsonObject jsonObject = ItemNodeParser::json();
|
||||
|
||||
QJsonObject textDetails;
|
||||
textDetails.insert(TextContentTag, propertyValue("text").toString());
|
||||
textDetails.insert(FontFamilyTag, propertyValue("font.family").toString());
|
||||
textDetails.insert(FontStyleTag, propertyValue("font.styleName").toString());
|
||||
textDetails.insert(FontSizeTag, propertyValue("font.pixelSize").toInt());
|
||||
textDetails.insert(LetterSpacingTag, propertyValue("font.letterSpacing").toFloat());
|
||||
|
||||
QColor fontColor(propertyValue("font.color").toString());
|
||||
textDetails.insert(TextColorTag, fontColor.name(QColor::HexArgb));
|
||||
|
||||
textDetails.insert(HAlignTag, toJsonAlignEnum(propertyValue("horizontalAlignment").toString()));
|
||||
textDetails.insert(VAlignTag, toJsonAlignEnum(propertyValue("verticalAlignment").toString()));
|
||||
|
||||
textDetails.insert(IsMultilineTag, propertyValue("wrapMode").toString().compare("NoWrap") != 0);
|
||||
|
||||
jsonObject.insert(TextDetailsTag, textDetails);
|
||||
return jsonObject;
|
||||
}
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2020 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
#pragma once
|
||||
|
||||
#include "modelitemnodeparser.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
class TextNodeParser : public ItemNodeParser
|
||||
{
|
||||
public:
|
||||
TextNodeParser(const QByteArrayList &lineage, const ModelNode &node);
|
||||
~TextNodeParser() override = default;
|
||||
|
||||
bool isExportable() const override;
|
||||
int priority() const override { return 200; }
|
||||
QJsonObject json() const override;
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user