예제 #1
0
void KoEnhancedPathShape::moveHandleAction( int handleId, const QPointF & point, Qt::KeyboardModifiers modifiers )
{
    Q_UNUSED( modifiers );
    KoEnhancedPathHandle *handle = m_enhancedHandles[ handleId ];
    if( handle )
    {
        handle->changePosition( shapeToViewbox( point ) );
        evaluateHandles();
    }
}
예제 #2
0
bool KoEnhancedPathShape::loadOdf( const KoXmlElement & element, KoShapeLoadingContext &context )
{
    reset();

    KoXmlElement child;
    forEachElement( child, element )
    {
        if( child.localName() == "enhanced-geometry" && child.namespaceURI() == KoXmlNS::draw )
        {
            // load the viewbox
            QRectF viewBox = loadOdfViewbox( child );
            if( ! viewBox.isEmpty() )
                m_viewBox = viewBox;

            // load the modifiers
            QString modifiers = child.attributeNS( KoXmlNS::draw, "modifiers", "" );
            if( ! modifiers.isEmpty() )
            {
                addModifiers( modifiers );
            }

            KoXmlElement grandChild;
            forEachElement( grandChild, child )
            {
                if( grandChild.namespaceURI() != KoXmlNS::draw )
                    continue;
                if( grandChild.localName() == "equation" )
                {
                    QString name = grandChild.attributeNS( KoXmlNS::draw, "name" );
                    QString formula = grandChild.attributeNS( KoXmlNS::draw, "formula" );
                    addFormula( name, formula );
                }
                else if( grandChild.localName() == "handle" )
                {
                    KoEnhancedPathHandle * handle = new KoEnhancedPathHandle( this );
                    if( handle->loadOdf( grandChild ) )
                    {
                        m_enhancedHandles.append( handle );
                        evaluateHandles();
                    }
                    else
                        delete handle;
                }

            }
            // load the enhanced path data
            QString path = child.attributeNS( KoXmlNS::draw, "enhanced-path", "" );
#ifndef NWORKAROUND_ODF_BUGS
            KoOdfWorkaround::fixEnhancedPath(path, child, context);
#endif
            if ( !path.isEmpty() ) {
                parsePathData( path );
            }
        }
    }
예제 #3
0
void KoEnhancedPathShape::addHandle( const QMap<QString,QVariant> &handle )
{
    if( handle.isEmpty() )
        return;

    if( ! handle.contains( "draw:handle-position" ) )
        return;
    QVariant position = handle.value("draw:handle-position");

    QStringList tokens = position.toString().simplified().split( ' ' );
    if( tokens.count() < 2 )
        return;

    KoEnhancedPathHandle *newHandle = new KoEnhancedPathHandle( this );
    newHandle->setPosition( parameter( tokens[0] ), parameter( tokens[1] ) );

    // check if we have a polar handle
    if( handle.contains( "draw:handle-polar" ) )
    {
        QVariant polar = handle.value( "draw:handle-polar" );
        QStringList tokens = polar.toString().simplified().split( ' ' );
        if( tokens.count() == 2 )
        {
            newHandle->setPolarCenter( parameter( tokens[0] ), parameter( tokens[1] ) );

            QVariant minRadius = handle.value( "draw:handle-radius-range-minimum" );
            QVariant maxRadius = handle.value( "draw:handle-radius-range-maximum" );
            if( minRadius.isValid() && maxRadius.isValid() )
                newHandle->setRadiusRange( parameter( minRadius.toString() ), parameter( maxRadius.toString() ) );
        }
    }
    else
    {
        QVariant minX = handle.value( "draw:handle-range-x-minimum" );
        QVariant maxX = handle.value( "draw:handle-range-x-maximum" );
        if( minX.isValid() && maxX.isValid() )
            newHandle->setRangeX( parameter( minX.toString() ), parameter( maxX.toString() ) );

        QVariant minY = handle.value( "draw:handle-range-y-minimum" );
        QVariant maxY = handle.value( "draw:handle-range-y-maximum" );
        if( minY.isValid() && maxY.isValid() )
            newHandle->setRangeY( parameter( minY.toString() ), parameter( maxY.toString() ) );
    }

    m_enhancedHandles.append( newHandle );

    evaluateHandles();
}
예제 #4
0
bool EnhancedPathShape::loadOdf(const KXmlElement & element, KShapeLoadingContext &context)
{
    reset();
    loadOdfAttributes(element, context, OdfAdditionalAttributes | OdfCommonChildElements);

    const KXmlElement enhancedGeometry(KoXml::namedItemNS(element, KOdfXmlNS::draw, "enhanced-geometry" ) );
    if (!enhancedGeometry.isNull()) {
        // load the modifiers
        QString modifiers = enhancedGeometry.attributeNS(KOdfXmlNS::draw, "modifiers");
        if (!modifiers.isEmpty()) {
            addModifiers(modifiers);
        }

        KXmlElement grandChild;
        forEachElement(grandChild, enhancedGeometry) {
            if (grandChild.namespaceURI() != KOdfXmlNS::draw)
                continue;
            if (grandChild.localName() == "equation") {
                QString name = grandChild.attributeNS(KOdfXmlNS::draw, "name");
                QString formula = grandChild.attributeNS(KOdfXmlNS::draw, "formula");
                addFormula(name, formula);
            } else if (grandChild.localName() == "handle") {
                EnhancedPathHandle * handle = new EnhancedPathHandle(this);
                if (handle->loadOdf(grandChild, context)) {
                    m_enhancedHandles.append(handle);
                    evaluateHandles();
                } else {
                    delete handle;
                }
            }
        }

        setMirrorHorizontally(enhancedGeometry.attributeNS(KOdfXmlNS::draw, "mirror-horizontal") == "true");
        setMirrorVertically(enhancedGeometry.attributeNS(KOdfXmlNS::draw, "mirror-vertical") == "true");

        // load the enhanced path data
        QString path = enhancedGeometry.attributeNS(KOdfXmlNS::draw, "enhanced-path");
#ifndef NWORKAROUND_ODF_BUGS
        KOdfWorkaround::fixEnhancedPath(path, enhancedGeometry, context);
#endif
        if (!path.isEmpty()) {
            parsePathData(path);
        }

        // load the viewbox
        QRectF viewBox = loadOdfViewbox(enhancedGeometry);
        if (! viewBox.isEmpty()) {
            m_viewBox = viewBox;
        } else {
            // if there is no view box defined make it is big as the path.
            m_viewBox = m_viewBound;
        }

        QString gluePoints(enhancedGeometry.attributeNS(KOdfXmlNS::draw, "glue-points"));
        if (!gluePoints.isEmpty()) {
            qreal x = -1;
            foreach (const QString &token, gluePoints.split(' ')) {
                if (x == -1) { // processing 'x'
                    x = token.toInt();
                } else {
                    addConnectionPoint(QPointF(x, token.toInt()));
                    x = -1;
                }
            }
        }