Ejemplo n.º 1
0
void GradientModel::addStop(qreal position, const QColor &color)
{
    if (m_lock)
        return;

    if (!m_itemNode.isValid() || gradientPropertyName().isEmpty())
        return;

    if (m_itemNode.modelNode().hasNodeProperty(gradientPropertyName().toUtf8())) {
        //QmlDesigner::RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction();
        //### TODO does not work

        QmlDesigner::ModelNode gradientNode =  m_itemNode.modelNode().nodeProperty(gradientPropertyName().toUtf8()).modelNode();

        QmlDesigner::ModelNode gradientStopNode =
                m_itemNode.modelNode().view()->createModelNode("QtQuick.GradientStop",
                                                               m_itemNode.modelNode().view()->majorQtQuickVersion(), 0);
        gradientStopNode.variantProperty("position").setValue(position);
        gradientStopNode.variantProperty("color").setValue(color);
        gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode);

        const QList<QmlDesigner::ModelNode> stopNodes = gradientNode.nodeListProperty("stops").toModelNodeList();

        int properPos = 0;
        for (int i = 0; i < stopNodes.count(); i++) {
            if (QmlDesigner::QmlObjectNode(stopNodes.at(i)).modelValue("position").toReal() < position)
                properPos = i + 1;
        }
        gradientNode.nodeListProperty("stops").slide(stopNodes.count() - 1, properPos);

        setupModel();
    }
}
Ejemplo n.º 2
0
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
    if (modelNode.hasParentProperty() && QmlDesigner::QmlItemNode::isValidQmlItemNode(modelNode.parentProperty().parentModelNode())) {
        QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
        QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
        modelNode.variantProperty("x").setValue(localPos.toPoint().x());
        modelNode.variantProperty("y").setValue(localPos.toPoint().y());
    }
}
Ejemplo n.º 3
0
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
    QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();
    if (parentNode.isValid()) {
        QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
        modelNode.variantProperty(QLatin1String("x")) = localPos.toPoint().x();
        modelNode.variantProperty(QLatin1String("y")) = localPos.toPoint().y();
    }
}
Ejemplo n.º 4
0
void GradientModel::addGradient()
{
    if (m_locked)
        return;

    if (!m_itemNode.isValid() || gradientPropertyName().isEmpty())
        return;

    if (!m_itemNode.modelNode().hasNodeProperty(gradientPropertyName().toUtf8())) {

        QColor color = m_itemNode.instanceValue("color").value<QColor>();

        if (!color.isValid())
            color = QColor(Qt::white);

        QmlDesigner::RewriterTransaction transaction = m_itemNode.modelNode().view()->beginRewriterTransaction(QByteArrayLiteral("GradientModel::addGradient"));

        QmlDesigner::ModelNode gradientNode =
                m_itemNode.modelNode().view()->createModelNode("QtQuick.Gradient",
                                                               m_itemNode.modelNode().view()->majorQtQuickVersion(), 0);
        m_itemNode.modelNode().nodeProperty(gradientPropertyName().toUtf8()).reparentHere(gradientNode);


        QmlDesigner::ModelNode gradientStopNode =
                m_itemNode.modelNode().view()->createModelNode("QtQuick.GradientStop",
                                                             m_itemNode.modelNode().view()->majorQtQuickVersion(), 0);
        gradientStopNode.variantProperty("position").setValue(0.0);
        gradientStopNode.variantProperty("color").setValue(color);
        gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode);

        gradientStopNode = m_itemNode.modelNode().view()->createModelNode(
                    "QtQuick.GradientStop",
                     m_itemNode.modelNode().view()->majorQtQuickVersion(), 0);
        gradientStopNode.variantProperty("position").setValue(1.0);
        gradientStopNode.variantProperty("color").setValue(QColor(Qt::black));
        gradientNode.nodeListProperty("stops").reparentHere(gradientStopNode);

    }
    setupModel();

    emit hasGradientChanged();
}
Ejemplo n.º 5
0
static inline void setScenePos(const QmlDesigner::ModelNode &modelNode,const QPointF &pos)
{
    if (modelNode.hasParentProperty() && QmlDesigner::QmlItemNode::isValidQmlItemNode(modelNode.parentProperty().parentModelNode())) {
        QmlDesigner::QmlItemNode parentNode = modelNode.parentProperty().parentQmlObjectNode().toQmlItemNode();

        if (!parentNode.modelNode().metaInfo().isLayoutable()) {
            QPointF localPos = parentNode.instanceSceneTransform().inverted().map(pos);
            modelNode.variantProperty("x").setValue(localPos.toPoint().x());
            modelNode.variantProperty("y").setValue(localPos.toPoint().y());
        } else { //Items in Layouts do not have a position
            modelNode.removeProperty("x");
            modelNode.removeProperty("y");
        }
    }
}