Ejemplo n.º 1
0
void CreateBlogMsg::addPostSplitter()
{
    QTextBlockFormat f = ui.msgEdit->textCursor().blockFormat();
    QTextBlockFormat f1 = f;

    f.setProperty( TextFormat::IsHtmlTagSign, true );
    f.setProperty( QTextFormat::BlockTrailingHorizontalRulerWidth, 
             QTextLength( QTextLength::PercentageLength, 80 ) );
    if ( ui.msgEdit->textCursor().block().text().isEmpty() ) {
        ui.msgEdit->textCursor().mergeBlockFormat( f );
    } else {
        ui.msgEdit->textCursor().insertBlock( f );
    }
    ui.msgEdit->textCursor().insertBlock( f1 );
}
Ejemplo n.º 2
0
void ChatView::doTrackBar()
{
	// save position, because our manipulations could change it
	int scrollbarValue = verticalScrollBar()->value();

	QTextCursor cursor = textCursor();
	cursor.beginEditBlock();
	PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor);

	//removeTrackBar(cursor);
	if (oldTrackBarPosition) {
		cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor);
		QTextBlockFormat blockFormat = cursor.blockFormat();
		blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth);
		cursor.clearSelection();
		cursor.setBlockFormat(blockFormat);
	}

	//addTrackBar(cursor);
	cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
	oldTrackBarPosition = cursor.position();
	QTextBlockFormat blockFormat = cursor.blockFormat();
	blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true));
	cursor.clearSelection();
	cursor.setBlockFormat(blockFormat);

	PsiRichText::restoreSelection(this, cursor, selection);
	cursor.endEditBlock();
	setTextCursor(cursor);

	verticalScrollBar()->setValue(scrollbarValue);
}
Ejemplo n.º 3
0
void KoList::add(const QTextBlock &block, int level)
{
    if (!block.isValid())
        return;

    if (level == 0) { // fetch the first proper level we have
        level = 1; // if nothing works...
        for (int i = 1; i <= 10; i++) {
            if (d->style->hasLevelProperties(i)) {
                level = i;
                break;
            }
        }
    }
    remove(block);

    QTextList *textList = d->textLists.value(level-1).data();
    if (!textList) {
        QTextCursor cursor(block);
        QTextListFormat format = d->style->listFormat(level);
        if (continueNumbering(level))
            format.setProperty(KListStyle::ContinueNumbering, true);
        textList = cursor.createList(format);
        format.setProperty(KListStyle::ListId, (KListStyle::ListIdType)(textList));
        textList->setFormat(format);
        d->textLists[level-1] = textList;
        d->textListIds[level-1] = (KListStyle::ListIdType)textList;
    } else {
        textList->add(block);
    }

    QTextCursor cursor(block);
    QTextBlockFormat blockFormat = cursor.blockFormat();
    if (d->style->styleId()) {
        blockFormat.setProperty(KParagraphStyle::ListStyleId, d->style->styleId());
    } else {
        blockFormat.clearProperty(KParagraphStyle::ListStyleId);
    }
    if (d->type == KoList::TextList) {
        blockFormat.clearProperty(KParagraphStyle::ListLevel);
    } else {
        blockFormat.setProperty(KParagraphStyle::ListLevel, level);
    }
    cursor.setBlockFormat(blockFormat);

    d->invalidate(block);
}
Ejemplo n.º 4
0
void CreateBlogMsg::blockQuote()
{
    QTextBlockFormat blockFormat = ui.msgEdit->textCursor().blockFormat();
    QTextBlockFormat f;

    if ( blockFormat.hasProperty( TextFormat::IsBlockQuote ) && 
         blockFormat.boolProperty( TextFormat::IsBlockQuote ) ) {
        f.setProperty( TextFormat::IsBlockQuote, QVariant( false ) );
        f.setLeftMargin( 0 );
        f.setRightMargin( 0 );
    } else {
        f.setProperty( TextFormat::IsBlockQuote, QVariant( true ) );
        f.setLeftMargin( 40 );
        f.setRightMargin( 40 );
    }
    ui.msgEdit->textCursor().mergeBlockFormat( f );
}
Ejemplo n.º 5
0
void TestDocumentLayout::testCenteredItems()
{
    initForNewTest("ListItem\nListItem\nListItem");

    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    listStyle.setLevelProperties(llp);

    QTextBlock block = m_doc->begin(); // normal block
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    block = block.next(); // centered block
    QVERIFY(block.isValid());
    listStyle.applyStyle(block);
    QTextBlockFormat fmt;
    fmt.setAlignment(Qt::AlignHCenter);
    QTextCursor cursor(block);
    cursor.mergeBlockFormat(fmt);
    block = block.next(); // centered RTL text.
    listStyle.applyStyle(block);
    cursor = QTextCursor(block);
    fmt.setProperty(KoParagraphStyle::TextProgressionDirection, KoText::RightLeftTopBottom);
    cursor.mergeBlockFormat(fmt);

    m_layout->layout();

    block = m_doc->begin();
    QTextLayout *layout = block.layout();
    QTextLine line1 = layout->lineAt(0);
    KoTextBlockData *data1 = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(line1.isValid());
    QVERIFY(line1.width() < 200); // the counter takes some space.

    block = block.next();
    layout = block.layout();
    QTextLine line2 = layout->lineAt(0);
    KoTextBlockData *data2 = dynamic_cast<KoTextBlockData *>(block.userData());
    QVERIFY(line2.isValid());
    QVERIFY(line2.width() < 200); // the counter takes some space.
    QCOMPARE(line1.width(), line2.width());

    const qreal width1 = line1.naturalTextWidth() + data1->counterWidth() + data1->counterSpacing();
    const qreal width2 = line2.naturalTextWidth() + data2->counterWidth() + data2->counterSpacing();
    QCOMPARE(width1, width2);
    QVERIFY(data1->counterPosition().x() < data2->counterPosition().x());
    const qreal padding = (200 - width2) / 2;
    QVERIFY(padding > 0);// not really a layout test, but the rest will be bogus otherwise.
    QCOMPARE(data2->counterPosition().x(), padding); // close to the centered text.

    // right to left parag places the counter on the right. Its centered, so not the far right.
    block = block.next();
    layout = block.layout();
    QTextLine line = layout->lineAt(0);
    KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
    QCOMPARE(data->counterPosition().x(), 200 - padding - data->counterWidth());
}
Ejemplo n.º 6
0
void CreateBlogMsg::changeFormatType(int styleIndex )
{
    ui.msgEdit->setFocus( Qt::OtherFocusReason );

    QTextCursor cursor = ui.msgEdit->textCursor();
    //QTextBlockFormat bformat = cursor.blockFormat();
    QTextBlockFormat bformat;
    QTextCharFormat cformat;

    switch (styleIndex) {
         default:
            case 0:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 0 ) );
            cformat.setFontWeight( QFont::Normal );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
            break;
        case 1:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 1 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 3 ) );
            break;
        case 2:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 2 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 2 ) );
            break;
        case 3:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 3 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 1 ) );
            break;
        case 4:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 4 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( 0 ) );
            break;
        case 5:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 5 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -1 ) );
            break;
        case 6:
            bformat.setProperty( TextFormat::HtmlHeading, QVariant( 6 ) );
            cformat.setFontWeight( QFont::Bold );
            cformat.setProperty( QTextFormat::FontSizeAdjustment, QVariant( -2 ) );
            break;
    }
    //cformat.clearProperty( TextFormat::HasCodeStyle );

    cursor.beginEditBlock();
    cursor.mergeBlockFormat( bformat );
    cursor.select( QTextCursor::BlockUnderCursor );
    cursor.mergeCharFormat( cformat );
    cursor.endEditBlock();
}
void TextBrowserHelpWidget::setSource(const QUrl &name)
{
    QTextBrowser::setSource(name);

    QTextCursor cursor(document());
    while (!cursor.atEnd()) {
        QTextBlockFormat fmt = cursor.blockFormat();
        if (fmt.hasProperty(QTextFormat::LineHeightType) && fmt.lineHeightType() == QTextBlockFormat::FixedHeight) {
           fmt.setProperty(QTextFormat::LineHeightType, QTextBlockFormat::MinimumHeight);
           cursor.setBlockFormat(fmt);
        }
        if (!cursor.movePosition(QTextCursor::NextBlock))
            break;
    }
}
Ejemplo n.º 8
0
void TestDocumentLayout::testRestartNumbering()
{
    // create 5 items; restart the 3th. Check numbering.
    initForNewTest("a\nb\na\nb\nc");

    KoParagraphStyle h1;
    m_styleManager->add(&h1);
    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    llp.setStartValue(1);
    listStyle.setLevelProperties(llp);
    h1.setListStyle(&listStyle);

    QTextBlock block = m_doc->begin();
    while (block.isValid()) {
        h1.applyStyle(block);
        block = block.next();
    }

    QTextCursor cursor(m_doc);
    cursor.setPosition(5);
    QCOMPARE(cursor.block().text(), QString("a"));
    QTextBlockFormat format = cursor.blockFormat();
    format.setProperty(KoParagraphStyle::RestartListNumbering, true);
    cursor.setBlockFormat(format);

    m_layout->layout();

    static const char *const values[] = { "1", "2", "1", "2", "3" };
    block = m_doc->begin();
    int i = 0;
    while (block.isValid()) {
        KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
        QVERIFY(data);
        // qDebug() << data->counterText() << QString(values[i]);
        QCOMPARE(data->counterText(), QString(values[i++]));

        block = block.next();
    }
}
Ejemplo n.º 9
0
QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes()
{
    switch (currentNode->id) {
        case Html_body:
            if (currentNode->charFormat.background().style() != Qt::NoBrush) {
                QTextFrameFormat fmt = doc->rootFrame()->frameFormat();
                fmt.setBackground(currentNode->charFormat.background());
                doc->rootFrame()->setFrameFormat(fmt);
                const_cast<QTextHtmlParserNode *>(currentNode)->charFormat.clearProperty(QTextFormat::BackgroundBrush);
            }
            break;

        case Html_ol:
        case Html_ul: {
            QTextListFormat::Style style = currentNode->listStyle;

            if (currentNode->id == Html_ul && !currentNode->hasOwnListStyle && currentNode->parent) {
                const QTextHtmlParserNode *n = &at(currentNode->parent);
                while (n) {
                    if (n->id == Html_ul) {
                        style = nextListStyle(currentNode->listStyle);
                    }
                    if (n->parent)
                        n = &at(n->parent);
                    else
                        n = 0;
                }
            }

            QTextListFormat listFmt;
            listFmt.setStyle(style);

            ++indent;
            if (currentNode->hasCssListIndent)
                listFmt.setIndent(currentNode->cssListIndent);
            else
                listFmt.setIndent(indent);

            List l;
            l.format = listFmt;
            l.listNode = currentNodeIdx;
            lists.append(l);
            compressNextWhitespace = true;

            // broken html: <ul>Text here<li>Foo
            const QString simpl = currentNode->text.simplified();
            if (simpl.isEmpty() || simpl.at(0).isSpace())
                return ContinueWithNextNode;
            break;
        }

        case Html_table: {
            Table t = scanTable(currentNodeIdx);
            tables.append(t);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_tr:
            return ContinueWithNextNode;

        case Html_img: {
            QTextImageFormat fmt;
            fmt.setName(currentNode->imageName);

            fmt.merge(currentNode->charFormat);

            if (currentNode->imageWidth >= 0)
                fmt.setWidth(currentNode->imageWidth);
            if (currentNode->imageHeight >= 0)
                fmt.setHeight(currentNode->imageHeight);

            cursor.insertImage(fmt, QTextFrameFormat::Position(currentNode->cssFloat));

            cursor.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor);
            cursor.mergeCharFormat(currentNode->charFormat);
            cursor.movePosition(QTextCursor::Right);

            hasBlock = false;
            return ContinueWithNextNode;
        }

        case Html_hr: {
            QTextBlockFormat blockFormat = currentNode->blockFormat;
            blockFormat.setTopMargin(topMargin(currentNodeIdx));
            blockFormat.setBottomMargin(bottomMargin(currentNodeIdx));
            blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, currentNode->width);
            if (hasBlock && importMode == ImportToDocument)
                cursor.mergeBlockFormat(blockFormat);
            else
                appendBlock(blockFormat);
            hasBlock = false;
            return ContinueWithNextNode;
        }

        default: break;
    }
    return ContinueWithCurrentNode;
}
Ejemplo n.º 10
0
void TestDocumentLayout::testNumberedList()
{
    initForNewTest("Base\nListItem1\nListItem2\nListItem3\nListItem4\nListItem5\nListItem6\nListItem6\nListItem7\nListItem8\nListItem9\nListItem10\nListItem11\nListItem12\n");

    KoParagraphStyle style;
    m_styleManager->add(&style);
    QTextBlock block = m_doc->begin();
    style.applyStyle(block);
    block = block.next();

    KoListStyle listStyle;
    KoListLevelProperties llp;
    llp.setStyle(KoListStyle::DecimalItem);
    listStyle.setLevelProperties(llp);
    style.setListStyle(&listStyle);

    QTextList *previous = 0;
    int i;
    for (i = 1; i <= 9; i++) {
        QVERIFY(block.isValid());
        // qDebug() << "->" << block.text();
        style.applyStyle(block);
        QTextList *textList = block.textList();
        QVERIFY(textList);
        if (previous == 0) {
            previous = textList;
        } else {
            QCOMPARE(textList, previous);
        }
        QCOMPARE(textList->format().intProperty(QTextListFormat::ListStyle), (int)(KoListStyle::DecimalItem));
        block = block.next();
    }
    m_layout->layout();
    QTextLayout *blockLayout = m_block.layout();

    QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
    QTextBlock blok = m_doc->begin().next();
    qreal indent = blok.layout()->lineAt(0).x();
    QVERIFY(indent > 0.0);
    for (i = 1; i <= 9; ++i) {
        // qDebug() << "=>" << blok.text();
        QTextList *textList = blok.textList();
        QVERIFY(textList);
        QCOMPARE(blok.layout()->lineAt(0).x(), indent); // all the same indent.
        blok = blok.next();
    }

    // now make number of listitems be more than 10, so we use 2 digits.
    for (i = 9; i <= 12; ++i) {
        QVERIFY(block.isValid());
        style.applyStyle(block);
        // qDebug() << "->" << block.text();
        block = block.next();
    }
    m_layout->layout();
    blockLayout = m_block.layout();

    QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
    blok = m_doc->begin().next();
    qreal indent2 = blok.layout()->lineAt(0).x();
    QVERIFY(indent2 > indent); // since it takes an extra digit
    for (i = 2; i <= 12; ++i) {
        // qDebug() << "=>" << blok.text();
        QCOMPARE(blok.layout()->lineAt(0).x(), indent2); // all the same indent.
        blok = blok.next();
    }

    // now to make sure the text is actually properly set.
    block = m_doc->begin().next();
    i = 1;
    while (block.isValid() && i < 13) {
        KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
        QVERIFY(data);
        QCOMPARE(data->counterText(), QString::number(i++));
        block = block.next();
    }

    llp.setListItemSuffix(".");
    llp.setStartValue(4);
    listStyle.setLevelProperties(llp);

    QTextCursor cursor(m_doc);
    cursor.setPosition(10); // listItem1
    QTextBlockFormat format = cursor.blockFormat();
    format.setProperty(KoParagraphStyle::ListStartValue, 4);
    cursor.setBlockFormat(format);

    cursor.setPosition(40); // listItem4
    format = cursor.blockFormat();
    format.setProperty(KoParagraphStyle::ListStartValue, 12);
    cursor.setBlockFormat(format);

    // at this point we start numbering at 4. Have 4, 5, 6, 12, 13, 14, 15 etc
    m_layout->layout();

    // now to make sur the text is actually properly set.
    block = m_doc->begin().next();
    i = 4;
    while (block.isValid() && i < 22) {
        if (i == 7) {
            i = 12;
        }
        KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
        QVERIFY(data);
        QCOMPARE(data->counterText(), QString::number(i++));
        block = block.next();
    }
}
Ejemplo n.º 11
0
Theme::Theme(const QString& name)
	: m_name(name)
{
	if (m_name.isEmpty()) {
		QString untitled;
		int count = 0;
		do {
			count++;
			untitled = tr("Untitled %1").arg(count);
		} while (QFile::exists(filePath(untitled)));
		setValue(m_name, untitled);
	}
	QSettings settings(filePath(m_name), QSettings::IniFormat);

	// Load background settings
	m_background_type = settings.value("Background/Type", 0).toInt();
	m_background_color = settings.value("Background/Color", "#cccccc").toString();
	m_background_path = settings.value("Background/Image").toString();
	m_background_image = settings.value("Background/ImageFile").toString();
	if (!m_background_path.isEmpty() && m_background_image.isEmpty()) {
		setValue(m_background_image, copyImage(m_background_path));
	}

	// Load foreground settings
	m_foreground_color = settings.value("Foreground/Color", "#cccccc").toString();
	m_foreground_opacity = qBound(0, settings.value("Foreground/Opacity", 100).toInt(), 100);
	m_foreground_width = qBound(500, settings.value("Foreground/Width", 700).toInt(), 2000);
	m_foreground_rounding = qBound(0, settings.value("Foreground/Rounding", 0).toInt(), 100);
	m_foreground_margin = qBound(0, settings.value("Foreground/Margin", 65).toInt(), 250);
	m_foreground_padding = qBound(0, settings.value("Foreground/Padding", 0).toInt(), 250);
	m_foreground_position = qBound(0, settings.value("Foreground/Position", 1).toInt(), 3);

	// Load text settings
	m_text_color = settings.value("Text/Color", "#000000").toString();
	m_text_font.fromString(settings.value("Text/Font", QFont().toString()).toString());
	m_misspelled_color = settings.value("Text/Misspelled", "#ff0000").toString();

        QStringList blocktypes;
        blocktypes<<"default"<<"H1"<<"H2"<<"H3"<<"H4"<<"H5"<<"BLOCKQUOTE"<<"ATTRIBUTION"<<"DIVIDER1"<<"DIVIDER2"<<"DIVIDER3"<<"DIVIDER4"<<"DIVIDER5"<<"PRE";
        QStringListIterator it(blocktypes);

        while(it.hasNext())
        {
            QString thetype=it.next();
            QTextBlockFormat format;
            if(settings.contains(QString("Styles/")+thetype+QString("/FontWeight")))
            {
                int weight=settings.value(QString("Styles/")+thetype+QString("/FontWeight")).toInt();
                if(weight!=0)
                    format.setProperty(QTextFormat::FontWeight,QFont::Bold);
            }
            else if(thetype.startsWith("H")&&thetype.at(1).isDigit())
                format.setProperty(QTextFormat::FontWeight,QFont::Bold);

            if(settings.contains(QString("Styles/")+thetype+QString("/FontItalic")))
            {
                bool italic=settings.value(QString("Styles/")+thetype+QString("/FontItalic")).toBool();
                if(italic)
                    format.setProperty(QTextFormat::FontItalic,true);
            }
            else if(thetype=="BLOCKQUOTE" || thetype=="ATTRIBUTION")
                format.setProperty(QTextFormat::FontItalic,true);

            if(settings.contains(QString("Styles/")+thetype+QString("/FontSizeAdjustment")))
            {
                int adjustment=settings.value(QString("Styles/")+thetype+QString("/FontSizeAdjustment")).toInt();
                if(adjustment!=0)
                    format.setProperty(QTextFormat::FontSizeAdjustment,adjustment);
            }
            else if(thetype.startsWith("H")&&thetype.at(1).isDigit())
                format.setProperty(QTextFormat::FontSizeAdjustment,4-QString(thetype.at(1)).toInt());

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockLeftMargin")))
            {
                double margin=settings.value(QString("Styles/")+thetype+QString("/BlockLeftMargin")).toDouble();
                if(margin!=0)
                    format.setProperty(QTextFormat::BlockLeftMargin,margin);
            }
            else if(thetype=="BLOCKQUOTE" || thetype=="ATTRIBUTION")
                format.setProperty(QTextFormat::BlockLeftMargin,50.0);

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockRightMargin")))
            {
                double margin=settings.value(QString("Styles/")+thetype+QString("/BlockRightMargin")).toDouble();
                if(margin!=0)
                    format.setProperty(QTextFormat::BlockRightMargin,margin);
            }
            else if(thetype=="BLOCKQUOTE" || thetype=="ATTRIBUTION")
                format.setProperty(QTextFormat::BlockRightMargin,50.0);

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockTopMargin")))
            {
                double margin=settings.value(QString("Styles/")+thetype+QString("/BlockTopMargin")).toDouble();
                if(margin!=0)
                    format.setProperty(QTextFormat::BlockTopMargin,margin);
            }
            else if(thetype.startsWith("DIVIDER"))
            {
                double arr[]={0.0,5.0,5.0,10.0,15.0};
                int dl=QString(thetype.at(7)).toInt();
                format.setProperty(QTextFormat::BlockTopMargin,arr[dl-1]);
            }

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockBottomMargin")))
            {
                double margin=settings.value(QString("Styles/")+thetype+QString("/BlockBottomMargin")).toDouble();
                if(margin!=0)
                    format.setProperty(QTextFormat::BlockBottomMargin,margin);
            }
            else if(thetype.startsWith("DIVIDER"))
            {
                double arr[]={0.0,5.0,10.0,15.0,25.0};
                int dl=QString(thetype.at(7)).toInt();
                format.setProperty(QTextFormat::BlockBottomMargin,arr[dl-1]);
            }
            else if(thetype!="PRE")
                format.setProperty(QTextFormat::BlockBottomMargin,10.0);

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockAlignment")))
            {
                int align=settings.value(QString("Styles/")+thetype+QString("/BlockAlignment")).toInt();
                format.setProperty(QTextFormat::BlockAlignment,align);
            }
            else if(thetype=="ATTRIBUTION")
                format.setProperty(QTextFormat::BlockAlignment,Qt::AlignRight);
            else
                format.setProperty(QTextFormat::BlockAlignment,Qt::AlignLeft);

            if(settings.contains(QString("Styles/")+thetype+QString("/BlockTrailingHorizontalRulerWidth")))
            {
                double rulewidth=settings.value(QString("Styles/")+thetype+QString("/BlockTrailingHorizontalRulerWidth")).toDouble();
                if(rulewidth!=0)
                    format.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth,QTextLength(QTextLength::PercentageLength,rulewidth));
            }
            else if(thetype.startsWith("DIVIDER"))
            {
                double arr[]={0.0,0.0,20.0,50.0,100.0};
                int dl=QString(thetype.at(7)).toInt();
                format.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth,QTextLength(QTextLength::PercentageLength,arr[dl-1]));
            }
            if(settings.contains(QString("Styles/")+thetype+QString("/BlockNonBreakableLines")))
            {
                bool nobreak=settings.value(QString("Styles/")+thetype+QString("/BlockNonBreakableLines")).toBool();
                if(nobreak)
                    format.setProperty(QTextFormat::BlockNonBreakableLines,nobreak);
            }
            else if(thetype=="ATTRIBUTION"||thetype=="PRE")
                format.setProperty(QTextFormat::BlockNonBreakableLines,true);

            if(thetype!="default")
                format.setProperty(QTextFormat::UserProperty,thetype);
            m_block_default_format.insert(thetype,format);
        }

        //setup paragraph styles
//        QTextBlockFormat baseformat;
//        baseformat.setBottomMargin(10.0);
//        baseformat.setAlignment(Qt::AlignLeft);
//        m_block_default_format.insert("default",baseformat);
//        QTextBlockFormat h1format=QTextBlockFormat(baseformat),h2format=QTextBlockFormat(baseformat),h3format=QTextBlockFormat(baseformat),h4format=QTextBlockFormat(baseformat),h5format=QTextBlockFormat(baseformat);
//        h1format.setProperty(QTextFormat::UserProperty,"H1");
//        h1format.setProperty(QTextFormat::FontWeight,QFont::Bold);
//        h1format.setProperty(QTextFormat::FontSizeAdjustment,3);
//        h2format.setProperty(QTextFormat::UserProperty,"H2");
//        h2format.setProperty(QTextFormat::FontWeight,QFont::Bold);
//        h2format.setProperty(QTextFormat::FontSizeAdjustment,2);
//        h3format.setProperty(QTextFormat::UserProperty,"H3");
//        h3format.setProperty(QTextFormat::FontWeight,QFont::Bold);
//        h3format.setProperty(QTextFormat::FontSizeAdjustment,1);
//        h4format.setProperty(QTextFormat::UserProperty,"H4");
//        h4format.setProperty(QTextFormat::FontWeight,QFont::Bold);
//        h4format.setProperty(QTextFormat::FontSizeAdjustment,0);
//        h5format.setProperty(QTextFormat::UserProperty,"H5");
//        h5format.setProperty(QTextFormat::FontWeight,QFont::Bold);
//        h5format.setProperty(QTextFormat::FontSizeAdjustment,-1);
//        m_block_default_format.insert("H1",h1format);
//        m_block_default_format.insert("H2",h2format);
//        m_block_default_format.insert("H3",h3format);
//        m_block_default_format.insert("H4",h4format);
//        m_block_default_format.insert("H5",h5format);
//        QTextBlockFormat bqformat=QTextBlockFormat(baseformat);
//        bqformat.setProperty(QTextFormat::UserProperty,"BLOCKQUOTE");
//        bqformat.setProperty(QTextFormat::FontItalic,true);
//        bqformat.setLeftMargin(50.0);
//        bqformat.setRightMargin(50.0);
//        m_block_default_format.insert("BLOCKQUOTE",bqformat);
//        QTextBlockFormat attformat=QTextBlockFormat(baseformat);
//        attformat.setAlignment(Qt::AlignRight);
//        attformat.setProperty(QTextFormat::UserProperty,"ATTRIBUTION");
//        attformat.setProperty(QTextFormat::FontItalic,true);
//        attformat.setBottomMargin(15.0);
//        attformat.setLeftMargin(50.0);
//        attformat.setRightMargin(50.0);
//        attformat.setNonBreakableLines(true);
//        m_block_default_format.insert("ATTRIBUTION",attformat);
//        QTextBlockFormat preformat=QTextBlockFormat();
//        preformat.setProperty(QTextFormat::UserProperty,"PRE");
//        preformat.setNonBreakableLines(true);
//        m_block_default_format.insert("PRE",preformat);
//        QTextBlockFormat d1format=QTextBlockFormat();
//        d1format.setProperty(QTextFormat::UserProperty,"DIVIDER1");
//        m_block_default_format.insert("DIVIDER1",d1format);
//        QTextBlockFormat d2format=QTextBlockFormat();
//        d2format.setProperty(QTextFormat::UserProperty,"DIVIDER2");
//        d2format.setTopMargin(5);
//        d2format.setBottomMargin(5);
//        m_block_default_format.insert("DIVIDER2",d2format);
//        QTextBlockFormat d3format=QTextBlockFormat();
//        d3format.setProperty(QTextFormat::UserProperty,"DIVIDER3");
//        d3format.setTopMargin(5);
//        d3format.setBottomMargin(10);
//        d3format.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth,QTextLength(QTextLength::PercentageLength,20));
//        m_block_default_format.insert("DIVIDER3",d3format);
//        QTextBlockFormat d4format=QTextBlockFormat();
//        d4format.setProperty(QTextFormat::UserProperty,"DIVIDER4");
//        d4format.setTopMargin(10);
//        d4format.setBottomMargin(15);
//        d4format.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth,QTextLength(QTextLength::PercentageLength,50));
//        m_block_default_format.insert("DIVIDER4",d4format);
//        QTextBlockFormat d5format=QTextBlockFormat();
//        d5format.setProperty(QTextFormat::UserProperty,"DIVIDER5");
//        d5format.setTopMargin(15);
//        d5format.setBottomMargin(25);
//        d5format.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth,QTextLength(QTextLength::PercentageLength,100));
//        m_block_default_format.insert("DIVIDER5",d5format);

}