Beispiel #1
0
QList<QPair<QString, KParagraphStyle *> > KTextSharedLoadingData::loadParagraphStyles(KShapeLoadingContext &context, QList<KXmlElement*> styleElements,
        int styleTypes, KStyleManager *styleManager)
{
    QList<QPair<QString, KParagraphStyle *> > paragraphStyles;
    QHash<KParagraphStyle*,QString> nextStyles;
    QHash<KParagraphStyle*,QString> parentStyles;

    foreach(KXmlElement *styleElem, styleElements) {
        Q_ASSERT(styleElem);
        Q_ASSERT(!styleElem->isNull());

        QString name = styleElem->attributeNS(KOdfXmlNS::style, "name");
        KParagraphStyle *parastyle = 0;
        if (styleManager) {
            QString displayName = styleElem->attributeNS(KOdfXmlNS::style, "display-name", name);
            parastyle = styleManager->paragraphStyle(displayName);
        }
        if (parastyle == 0) {
            parastyle = new KParagraphStyle();
            parastyle->loadOdf(styleElem, context);
            QString listStyleName = styleElem->attributeNS(KOdfXmlNS::style, "list-style-name");
            KListStyle *list = listStyle(listStyleName, styleTypes & StylesDotXml);
            if (list) {
                KListStyle *newListStyle = new KListStyle(parastyle);
                newListStyle->copyProperties(list);
                parastyle->setListStyle(newListStyle);
            }
            if (styleManager)
                styleManager->add(parastyle);
            else
                d->paragraphStylesToDelete.append(parastyle);
        }
        paragraphStyles.append(QPair<QString, KParagraphStyle *>(name, parastyle));
        d->namedParagraphStyles.insert(name, parastyle);

        if (styleElem->hasAttributeNS(KOdfXmlNS::style, "next-style-name"))
            nextStyles.insert(parastyle, styleElem->attributeNS(KOdfXmlNS::style, "next-style-name"));
        if (styleElem->hasAttributeNS(KOdfXmlNS::style, "parent-style-name"))
            parentStyles.insert(parastyle, styleElem->attributeNS(KOdfXmlNS::style, "parent-style-name"));

        // TODO check if it a know style set the styleid so that the custom styles are kept during copy and paste
        // in case styles are not added to the style manager they have to be deleted after loading to avoid leaking memeory
    }
Beispiel #2
0
QString KoParagStyle::saveStyle( KoGenStyles& genStyles, int styleType, const QString& parentStyleName, KoSavingContext& context ) const
{
    KoGenStyle gs( styleType, "paragraph", parentStyleName );

    gs.addAttribute( "style:display-name", m_displayName );
    if ( m_paragLayout.counter ) {
        if ( m_bOutline )
            gs.addAttribute( "style:default-outline-level", (int)m_paragLayout.counter->depth() + 1 );
        else if ( m_paragLayout.counter->depth() )
            // ### kword-specific attribute, see loadOasis
            gs.addAttribute( "style:default-level", (int)m_paragLayout.counter->depth() + 1 );

        if ( m_paragLayout.counter->numbering() != KoParagCounter::NUM_NONE &&
             m_paragLayout.counter->style() != KoParagCounter::STYLE_NONE )
        {
            KoGenStyle listStyle( KoGenStyle::STYLE_LIST /*, no family*/ );
            m_paragLayout.counter->saveOasis( listStyle, true );
            // This display-name will probably look nicer in OO, but this also means
            // no re-use possible between list styles...
            listStyle.addAttribute( "style:display-name",
                                    i18n( "Numbering Style for %1" ).arg( m_displayName ) );

            QString autoListStyleName = genStyles.lookup( listStyle, "L", KoGenStyles::ForceNumbering );
            gs.addAttribute( "style:list-style-name", autoListStyleName );
        }
    }

    m_paragLayout.saveOasis( gs, context, true );

    m_format.save( gs, context );

    // try to preserve existing internal name, if it looks adequate (no spaces)
    // ## TODO: check XML-Schemacs NCName conformity
    bool nameIsConform = !m_name.isEmpty() && m_name.find( ' ' ) == -1;
    QString newName;
    if ( nameIsConform )
        newName = genStyles.lookup( gs, m_name, KoGenStyles::DontForceNumbering );
    else
        newName = genStyles.lookup( gs, "U", KoGenStyles::ForceNumbering );
    const_cast<KoParagStyle*>( this )->m_name = newName;
    return m_name;
}
Beispiel #3
0
void TestKoGenStyles::testWriteStyle()
{
    kDebug();
    KOdfGenericStyles coll;

    QBuffer buffer;
    buffer.open(QIODevice::WriteOnly);
    KXmlWriter styleChildWriter(&buffer);
    styleChildWriter.startElement("styleChild");
    styleChildWriter.addAttribute("foo", "bar");
    styleChildWriter.endElement();
    QString styleChildContents = QString::fromUtf8(buffer.buffer(), buffer.buffer().size());

    KOdfGenericStyle style(KOdfGenericStyle::ParagraphStyle, "paragraph");
    style.addProperty("style:foo", "bar");
    style.addProperty("style:paragraph", "property", KOdfGenericStyle::ParagraphType);
    style.addProperty("style:graphic", "property", KOdfGenericStyle::GraphicType);
    style.addProperty("styleChild", styleChildContents, KOdfGenericStyle::StyleChildElement);
    QString styleName = coll.insert(style, "P");

    // XML for style
    TEST_BEGIN(0, 0);
    style.writeStyle(&writer, coll, "style:style", styleName, "style:paragraph-properties");
    TEST_END_QTTEST("<r>\n <style:style style:name=\"P1\" style:family=\"paragraph\">\n  <style:paragraph-properties style:foo=\"bar\" style:paragraph=\"property\"/>\n  <style:graphic-properties style:graphic=\"property\"/>\n  <styleChild foo=\"bar\"/>\n </style:style>\n</r>\n");

    KOdfGenericStyle pageLayoutStyle(KOdfGenericStyle::PageLayoutStyle);
    pageLayoutStyle.addProperty("style:print-orientation", "portrait");
    QString pageLayoutStyleName = coll.insert(pageLayoutStyle, "pm");

    // XML for page layout style
    TEST_BEGIN(0, 0);
    pageLayoutStyle.writeStyle(&writer, coll, "style:page-layout", pageLayoutStyleName, "style:page-layout-properties");
    TEST_END_QTTEST("<r>\n <style:page-layout style:name=\"pm1\">\n  <style:page-layout-properties style:print-orientation=\"portrait\"/>\n </style:page-layout>\n</r>\n");

    KOdfGenericStyle listStyle(KOdfGenericStyle::ListStyle);
    QString listStyleName = coll.insert(listStyle, "L");
    // XML for list layout style
    TEST_BEGIN(0, 0);
    listStyle.writeStyle(&writer, coll, "text:list-style", listStyleName, 0);
    TEST_END_QTTEST("<r>\n <text:list-style style:name=\"L1\"/>\n</r>\n");
}
Beispiel #4
0
int QTextParag::numberOfSubParagraph() const
{
    if ( list_val != -1 )
        return list_val;
    if ( numSubParag != -1 )
        return numSubParag;
    int n = 0;
    QTextParag *p = (QTextParag*)this;
    while ( p && ( styleSheetItemsVec.size() >= p->styleSheetItemsVec.size() &&
                   styleSheetItemsVec[ (int)p->styleSheetItemsVec.size() - 1 ] == p->style() ||
                   p->styleSheetItemsVec.size() >= styleSheetItemsVec.size() &&
                   p->styleSheetItemsVec[ (int)styleSheetItemsVec.size() - 1 ] == style() ) ) {
        if ( p->style() == style() && listStyle() != p->listStyle()
                && p->styleSheetItemsVec.size() == styleSheetItemsVec.size() )
            break;
        if ( p->style()->displayMode() == QStyleSheetItem::DisplayListItem
                && p->style() != style() || styleSheetItemsVec.size() == p->styleSheetItemsVec.size() )
            ++n;
        p = p->prev();
    }
    ( (QTextParag*)this )->numSubParag = n;
    return n;
}