Exemplo n.º 1
0
    QwtRichTextDocument( const QString &text, int flags, const QFont &font )
    {
        setUndoRedoEnabled( false );
        setDefaultFont( font );
        setHtml( text );

        // make sure we have a document layout
        ( void )documentLayout();

        QTextOption option = defaultTextOption();
        if ( flags & Qt::TextWordWrap )
            option.setWrapMode( QTextOption::WordWrap );
        else
            option.setWrapMode( QTextOption::NoWrap );

        option.setAlignment( ( Qt::Alignment ) flags );
        setDefaultTextOption( option );

        QTextFrame *root = rootFrame();
        QTextFrameFormat fm = root->frameFormat();
        fm.setBorder( 0 );
        fm.setMargin( 0 );
        fm.setPadding( 0 );
        fm.setBottomMargin( 0 );
        fm.setLeftMargin( 0 );
        root->setFrameFormat( fm );

        adjustSize();
    }
Exemplo n.º 2
0
void WymsingTxt::UpdateVars()  {

    BorderDicks = MarginSize->value();
    InitValue.setWidth( BoxLarghezza->value() );
    InitValue.setHeight ( BoxAltezza->value() );
    BGColor.setAlpha ( AlphaColor );
    rootformat.setBottomMargin ( psud->value() );
    rootformat.setLeftMargin ( pwest->value() );
    rootformat.setRightMargin ( post->value() );
    rootformat.setTopMargin ( pnord->value() );
    rootformat.setBackground ( BGColor ); 
    tdoc = wtxt->document()->clone();
    QTextFrame  *TfNewFo = tdoc->rootFrame();
    TfNewFo->setFrameFormat ( rootformat );
    DocFrameFormings = rootformat;
    wtxt->setDocument ( tdoc );
    wtxt->document()->setUseDesignMetrics (true );
    destimage->setDocument ( tdoc );
    destimage->setPos ( QPointF(XXset->value(),YYset->value()) );
    emit RetocValues(InitValue,BorderDicks,BGColor,MarginColor,tdoc,wtxt->GetListBlock());
    DocFrameFormings.setWidth( BoxLarghezza->value() );
    wtxt->document()->rootFrame()->setFrameFormat ( DocFrameFormings ); 
        

}
Exemplo n.º 3
0
TextLayer::TextLayer(const int layer_id , QGraphicsItem *parent , QGraphicsScene *scene )
    : QGraphicsItem(parent,scene),evesum(0),modus(Show),border(1.),currentprintrender(false),
    hi(Metric("30px")),wi(Metric("110px")),bgcolor(QColor(Qt::white)),SwapLockBreak(false),
    bordercolor(QColor(Qt::red)),Rotate(0),check_view_area_time(0),ActionHover(false),
    format(DIV_ABSOLUTE),mount(new TextController)
{
    mount->q = this;
    setAcceptsHoverEvents(true);
    wisub_border = wi + border;
    history.clear();
    id = layer_id;
    setAcceptDrops(true);
    setFlag(QGraphicsItem::ItemIsSelectable,true);
    setFlag(QGraphicsItem::ItemIsFocusable,true);
    setFlag(QGraphicsItem::ItemIsMovable,false);
    setSelected(false);
    _doc = new QTextDocument();  
    _doc->setHtml(tr("<p>Write your text<p>"));
        QTextFrame  *Tframe = _doc->rootFrame();
        QTextFrameFormat rootformats = Tframe->frameFormat();
        rootformats.setWidth(wi);
        rootformats.setBorder(0);
        Tframe->setFrameFormat(rootformats);
        _doc->setPageSize(QSizeF(wi,hi)); 
        DLayout = _doc->documentLayout();
    setDocument(_doc);
    mount->txtControl()->document()->toHtml().size();  /* connect all */
    setZValue(1.99999);
    RestoreMoveAction();
    init();
}
Exemplo n.º 4
0
ClientTextEdit::ClientTextEdit(QWidget* parent) : QTextEdit(parent) {
    setReadOnly(true);
    setOverwriteMode(true);
    setUndoRedoEnabled(false);
    setDocumentTitle("mClient");
    setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::LinksAccessibleByMouse);
    setTabChangesFocus(false);

    //_doc->setMaximumBlockCount(Config().scrollbackSize); // max number of lines?
    document()->setUndoRedoEnabled(false);
    QTextFrame* frame = document()->rootFrame();
    _cursor = frame->firstCursorPosition();

    // Default Colors
    _foregroundColor = Qt::lightGray;
    _backgroundColor = Qt::black;
    _blackColor = Qt::darkGray;
    _redColor = Qt::darkRed;
    _greenColor = Qt::darkGreen;
    _yellowColor = Qt::darkYellow;
    _blueColor = Qt::darkBlue;
    _magentaColor = Qt::darkMagenta;
    _cyanColor = Qt::darkCyan;
    _grayColor = Qt::lightGray;
    _darkGrayColor = Qt::gray;
    _brightRedColor = Qt::red;
    _brightGreenColor = Qt::green;
    _brightYellowColor = Qt::yellow;
    _brightBlueColor = Qt::blue;
    _brightMagentaColor = Qt::magenta;
    _brightCyanColor = Qt::cyan;
    _whiteColor = Qt::white;
    // Default Fonts
    _serverOutputFont = QFont("Monospace", 10);
    _inputLineFont = QFont("Monospace", 10); //QApplication::font();
    _serverOutputFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);

    QTextFrameFormat frameFormat = frame->frameFormat();
    frameFormat.setBackground(_backgroundColor);
    frameFormat.setForeground(_foregroundColor);
    frame->setFrameFormat(frameFormat);

    _format = _cursor.charFormat();
    setDefaultFormat(_format);
    _defaultFormat = _format;
    _cursor.setCharFormat(_format);

    QFontMetrics fm(_serverOutputFont);
    setTabStopWidth(fm.width(" ") * 8); // A tab is 8 spaces wide
    QScrollBar* scrollbar = verticalScrollBar();
    scrollbar->setSingleStep(fm.leading()+fm.height());

    connect(scrollbar, SIGNAL(sliderReleased()), 
                this, SLOT(scrollBarReleased()));

    previous = 0;
}
Exemplo n.º 5
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // 获取文档对象
    QTextDocument *document = ui->textEdit->document();

    // 获取根框架
    QTextFrame *rootFrame = document->rootFrame();

    // 创建框架格式
    QTextFrameFormat format;
    // 边界颜色
    format.setBorderBrush(Qt::red);
    // 边界宽度
    format.setBorder(3);
    // 框架使用格式
    rootFrame->setFrameFormat(format);

    QTextFrameFormat frameFormat;
    // 设置背景颜色
    frameFormat.setBackground(Qt::lightGray);
    // 设置边距
    frameFormat.setMargin(10);
    // 设置填衬
    frameFormat.setPadding(5);
    frameFormat.setBorder(2);
    frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Dotted); //设置边框样式

    // 获取光标
    QTextCursor cursor = ui->textEdit->textCursor();
    // 在光标处插入框架
    cursor.insertFrame(frameFormat);

   //以下是5.2.2节内容
    QAction *action_textFrame = new QAction(tr("框架"),this);
    connect(action_textFrame,SIGNAL(triggered()),this,SLOT(showTextFrame()));
    // 在工具栏添加动作
    ui->mainToolBar->addAction(action_textFrame);

    QAction *action_textBlock = new QAction(tr("文本块"),this);
    connect(action_textBlock,SIGNAL(triggered()),this,SLOT(showTextBlock()));
    ui->mainToolBar->addAction(action_textBlock);

    QAction *action_font = new QAction(tr("字体"),this);
    // 设置动作可以被选中
    action_font->setCheckable(true);
    connect(action_font,SIGNAL(toggled(bool)),this,SLOT(setTextFont(bool)));
    ui->mainToolBar->addAction(action_font);
}
Exemplo n.º 6
0
void KoSectionStyle::unapplyStyle(QTextFrame &section) const
{
    if (d->parentStyle)
        d->parentStyle->unapplyStyle(section);

    QTextFrameFormat format = section.frameFormat();

    QList<int> keys = d->stylesPrivate.keys();
    for (int i = 0; i < keys.count(); i++) {
        QVariant variant = d->stylesPrivate.value(keys[i]);
        if (variant == format.property(keys[i]))
            format.clearProperty(keys[i]);
    }
    section.setFrameFormat(format);
}
Exemplo n.º 7
0
QTextDocument* Converter::convert( const QString &fileName )
{
    Document *textDocument = new Document( fileName );

    textDocument->setPageSize(QSizeF( 600, 800 ));

    QTextFrameFormat frameFormat;
    frameFormat.setMargin( 20 );

    QTextFrame *rootFrame = textDocument->rootFrame();
    rootFrame->setFrameFormat( frameFormat );

    emit addMetaData( Okular::DocumentInfo::MimeType, "text/plain" );

    return textDocument;
}
Exemplo n.º 8
0
/* form qtexdocument to this margin an papersize */
void M_PageSize::HandlePrint( QTextDocument *doc )
{
			const qreal RightMargin = P_margin.y();
			const qreal LeftMargin = P_margin.height();
			const qreal LargeDoc = G_regt.width() - RightMargin  - LeftMargin;
			doc->setPageSize ( G_regt.size() );
			QTextFrame  *Tframe = doc->rootFrame();
	    QTextFrameFormat Ftf = Tframe->frameFormat();
	    Ftf.setLeftMargin(P_margin.height());
	    Ftf.setBottomMargin(P_margin.width());
	    Ftf.setTopMargin(P_margin.x());
	   Ftf.setBackground(QBrush(Qt::transparent));
			Ftf.setRightMargin(P_margin.y());
	    Ftf.setPadding ( 0);
			Tframe->setFrameFormat(Ftf);
		  doc->setPageSize ( G_regt.size() );
}
Exemplo n.º 9
0
//! [2]
void MainWindow::newLetter()
{
    textEdit->clear();

    QTextCursor cursor(textEdit->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextFrame *topFrame = cursor.currentFrame();
    QTextFrameFormat topFrameFormat = topFrame->frameFormat();
    topFrameFormat.setPadding(16);
    topFrame->setFrameFormat(topFrameFormat);

    QTextCharFormat textFormat;
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);
    QTextCharFormat italicFormat;
    italicFormat.setFontItalic(true);

    QTextTableFormat tableFormat;
    tableFormat.setBorder(1);
    tableFormat.setCellPadding(16);
    tableFormat.setAlignment(Qt::AlignRight);
    cursor.insertTable(1, 1, tableFormat);
    cursor.insertText("The Firm", boldFormat);
    cursor.insertBlock();
    cursor.insertText("321 City Street", textFormat);
    cursor.insertBlock();
    cursor.insertText("Industry Park");
    cursor.insertBlock();
    cursor.insertText("Some Country");
    cursor.setPosition(topFrame->lastPosition());
    cursor.insertText(QDate::currentDate().toString("d MMMM yyyy"), textFormat);
    cursor.insertBlock();
    cursor.insertBlock();
    cursor.insertText("Dear ", textFormat);
    cursor.insertText("NAME", italicFormat);
    cursor.insertText(",", textFormat);
    for (int i = 0; i < 3; ++i)
        cursor.insertBlock();
    cursor.insertText(tr("Yours sincerely,"), textFormat);
    for (int i = 0; i < 3; ++i)
        cursor.insertBlock();
    cursor.insertText("The Boss", textFormat);
    cursor.insertBlock();
    cursor.insertText("ADDRESS", italicFormat);
}
Exemplo n.º 10
0
void MainWindow::newLetter(){
    chatbox->clear();


    QTextCursor cursor(chatbox->textCursor());
    cursor.movePosition(QTextCursor::Start);
    QTextFrame *topFrame = cursor.currentFrame();
    QTextFrameFormat topFrameFormat = topFrame->frameFormat();
    topFrameFormat.setPadding(16);
    topFrame->setFrameFormat(topFrameFormat);

    QTextCharFormat textFormat;
    QTextCharFormat boldFormat;
    boldFormat.setFontWeight(QFont::Bold);
    QTextCharFormat italicFormat;
    italicFormat.setFontItalic(true);

    /*QTextTableFormat tableFormat;
    tableFormat.setBorder(1);
    tableFormat.setCellPadding(16);
    tableFormat.setAlignment(Qt::AlignRight);
    cursor.insertTable(1, 1, tableFormat);
    cursor.insertText("The Firm", boldFormat);
    cursor.insertBlock();
    cursor.insertText("321 City Street", textFormat);
    cursor.insertBlock();
    cursor.insertText("Industry Park");
    cursor.insertBlock();
    cursor.insertText("Some Country"); */
    cursor.setPosition(topFrame->lastPosition());
    cursor.insertText("Railguy: ", boldFormat);
    cursor.insertText("lol nub", textFormat);
    cursor.insertBlock();
    cursor.insertText("Chaos: ", boldFormat);
    cursor.insertText("nou", textFormat);
    cursor.insertBlock();

    QFont font = chattitle->font();
    font.setBold(true);
    chattitle->setFont(font);
    chattitle->setText("#General");
}
Exemplo n.º 11
0
QTextDocument* Converter::convert( const QString &fileName )
{
  MobiDocument* newDocument=new MobiDocument(fileName);
  if (!newDocument->mobi()->isValid()) {
    emit error(i18n("Error while opening the Mobipocket document."), -1);
    delete newDocument;
    return NULL;
  }
  if (newDocument->mobi()->hasDRM()) {
    emit error(i18n("This book is protected by DRM and can be displayed only on designated device"), -1);
    delete newDocument;
    return NULL;
  }
  
  handleMetadata(newDocument->mobi()->metadata());
  newDocument->setPageSize(QSizeF(600, 800));

  QTextFrameFormat frameFormat;
  frameFormat.setMargin( 20 );
  QTextFrame *rootFrame = newDocument->rootFrame();
  rootFrame->setFrameFormat( frameFormat ); 
  QMap<QString,QPair<int,int> > links;
  QMap<QString,QTextBlock> targets;

  // go over whole document and add all <a> tags to links or targets map
  for (QTextBlock it = newDocument->begin(); it != newDocument->end(); it = it.next()) 
   for (QTextBlock::iterator fit=it.begin(); !fit.atEnd(); ++fit) {
    QTextFragment frag=fit.fragment();
    QTextCharFormat format=frag.charFormat();
    if (!format.isAnchor()) continue;
    //link
    if (!format.anchorHref().isEmpty()) links[format.anchorHref()]=
      QPair<int,int>(frag.position(), frag.position()+frag.length());
    if (!format.anchorNames().isEmpty()) {
      // link targets
      Q_FOREACH(const QString& name, format.anchorNames()) 
	targets['#'+name]=it;
    }
  }
Exemplo n.º 12
0
//! [5]
void MainWindow::insertCalendar()
{
    editor->clear();
    QTextCursor cursor = editor->textCursor();
    cursor.beginEditBlock();

    QDate date(selectedDate.year(), selectedDate.month(), 1);
//! [5]

//! [6]
    QTextTableFormat tableFormat;
    tableFormat.setAlignment(Qt::AlignHCenter);
    tableFormat.setBackground(QColor("#e0e0e0"));
    tableFormat.setCellPadding(2);
    tableFormat.setCellSpacing(4);
//! [6] //! [7]
    QVector<QTextLength> constraints;
    constraints << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14)
                << QTextLength(QTextLength::PercentageLength, 14);
    tableFormat.setColumnWidthConstraints(constraints);
//! [7]

//! [8]
    QTextTable *table = cursor.insertTable(1, 7, tableFormat);
//! [8]

//! [9]
    QTextFrame *frame = cursor.currentFrame();
    QTextFrameFormat frameFormat = frame->frameFormat();
    frameFormat.setBorder(1);
    frame->setFrameFormat(frameFormat);
//! [9]

//! [10]
    QTextCharFormat format = cursor.charFormat();
    format.setFontPointSize(fontSize);

    QTextCharFormat boldFormat = format;
    boldFormat.setFontWeight(QFont::Bold);

    QTextCharFormat highlightedFormat = boldFormat;
    highlightedFormat.setBackground(Qt::yellow);
//! [10]

//! [11]
    for (int weekDay = 1; weekDay <= 7; ++weekDay) {
        QTextTableCell cell = table->cellAt(0, weekDay-1);
//! [11] //! [12]
        QTextCursor cellCursor = cell.firstCursorPosition();
        cellCursor.insertText(QString("%1").arg(QDate::longDayName(weekDay)),
                              boldFormat);
    }
//! [12]

//! [13]
    table->insertRows(table->rows(), 1);
//! [13]

    while (date.month() == selectedDate.month()) {
        int weekDay = date.dayOfWeek();
        QTextTableCell cell = table->cellAt(table->rows()-1, weekDay-1);
        QTextCursor cellCursor = cell.firstCursorPosition();

        if (date == QDate::currentDate())
            cellCursor.insertText(QString("%1").arg(date.day()), highlightedFormat);
        else
            cellCursor.insertText(QString("%1").arg(date.day()), format);

        date = date.addDays(1);
        if (weekDay == 7 && date.month() == selectedDate.month())
            table->insertRows(table->rows(), 1);
    }

    cursor.endEditBlock();
//! [14]
    setWindowTitle(tr("Calendar for %1 %2"
        ).arg(QDate::longMonthName(selectedDate.month())
        ).arg(selectedDate.year()));
}
Exemplo n.º 13
0
void KoSectionStyle::applyStyle(QTextFrame &section) const
{
    QTextFrameFormat format = section.frameFormat();
    applyStyle(format);
    section.setFrameFormat(format);
}
Exemplo n.º 14
0
TextEditor::TextEditor(Graph *g): QTextEdit(g), d_graph(g)
{
	setAttribute(Qt::WA_DeleteOnClose);
	setFrameShadow(QFrame::Plain);
	setFrameShape(QFrame::Box);
	setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

	QPalette palette = this->palette();
	palette.setColor(QPalette::Active, QPalette::WindowText, Qt::blue);
	palette.setColor(QPalette::Active, QPalette::Base, Qt::white);
	setPalette(palette);

	bool moveCrs = true;
	QString text;
	if (g->activeText()){
		setParent(g->multiLayer()->canvas());
		d_target = g->activeText();
		setGeometry(d_target->geometry());
		text = ((LegendWidget*)d_target)->text();
		d_target->hide();
		setFont(((LegendWidget*)d_target)->font());
	} else if (g->titleSelected()){
		d_target = g->titleLabel();
		QwtText t = g->title();
		text = t.text();
		setAlignment((Qt::Alignment)t.renderFlags());
		setFont(t.font());
		setGeometry(d_target->geometry());
	} else if (g->selectedScale()){
		d_target = g->selectedScale();
		QwtScaleWidget *scale = (QwtScaleWidget*)d_target;
		QwtText t = scale->title();
		text = t.text();
		setAlignment((Qt::Alignment)t.renderFlags());
		setFont(t.font());

		QRect rect = g->axisTitleRect(scale);
		if (scale->alignment() == QwtScaleDraw::BottomScale ||
			scale->alignment() == QwtScaleDraw::TopScale){
			resize(rect.size());
			move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y()));
		} else {
			resize(QSize(rect.height(), rect.width()));
			if (scale->alignment() == QwtScaleDraw::LeftScale)
                move(QPoint(d_target->x() + rect.x(), d_target->y() + rect.y() + rect.height()/2));
            else if (scale->alignment() == QwtScaleDraw::RightScale)
                move(QPoint(d_target->x() - rect.height(), d_target->y() + rect.y() + rect.height()/2));

			t.setText(" ");
			t.setBackgroundPen(QPen(Qt::NoPen));
			scale->setTitle(t);
			moveCrs = false;
		}
	}

	QTextCursor cursor = textCursor();
	cursor.insertText(text);
	d_initial_text = text;

	setWordWrapMode (QTextOption::NoWrap);
	setAlignment(Qt::AlignCenter);

	QTextFrame *frame = document()->rootFrame();
	QTextFrameFormat format = frame->frameFormat();
	format.setTopMargin(format.topMargin () + 3);
	frame->setFrameFormat(format);
	show();

	if (moveCrs)
		setTextCursor(cursorForPosition(mapFromGlobal(QCursor::pos())));
	setFocus();
}
Exemplo n.º 15
0
QTextDocument* Converter::convert(const QString &fileName)
{
    firstTime = true;
    Document oooDocument(fileName);
    if (!oooDocument.open())
    {
        return 0;
    }
    m_TextDocument = new QTextDocument;
    m_Cursor = new QTextCursor(m_TextDocument);

    /**
     * Create the dom of the content
     */
    QXmlSimpleReader reader;

    QXmlInputSource source;
    source.setData(oooDocument.content());
    QString errorMsg;
    QDomDocument document;
    if (!document.setContent(&source, &reader, &errorMsg))
    {
        setError(QString("Invalid XML document: %1").arg(errorMsg), -1);
        delete m_Cursor;
        return m_TextDocument;
    }

    /**
     * Read the style properties, so the are available when
     * parsing the content.
     */

    m_StyleInformation = new StyleInformation();

    if (oooDocument.content().size() == 0)
    {
        setError("Empty document", -1);
    }

    StyleParser styleParser(&oooDocument, document, m_StyleInformation);
    if (!styleParser.parse())
    {
        setError("Unable to read style information", -1);
        delete m_Cursor;
        return 0;
    }

    /**
    * Add all images of the document to resource framework
    */

    QMap<QString, QByteArray> imageLIST = oooDocument.images();
    QMapIterator<QString, QByteArray> it(imageLIST);
    while (it.hasNext())
    {
        it.next();
        m_TextDocument->addResource(QTextDocument::ImageResource, QUrl(it.key()), QImage::fromData(it.value()));
    }

    /**
     * Set the correct page size
     */

    const QString masterLayout = m_StyleInformation->masterPageName();

    if (m_StyleInformation->pagePropertyExists(masterLayout))
    {
        const int DPX = 231; /// im.logicalDpiX(); // 231
        const int DPY = 231; // im.logicalDpiY(); // 231
        const int A4Width = MM_TO_POINT(210); /// A4 210 x297 mm
        const int A4Height = MM_TO_POINT(297);

        const PageFormatProperty property = m_StyleInformation->pageProperty(masterLayout);
        int pageWidth = qRound(property.width() / 72.0 * DPX);
        if (pageWidth < 1) {
            pageWidth = A4Width;
        }
        int pageHeight = qRound(property.height() / 72.0 * DPY);
        if (pageHeight < 1) {
            pageHeight = A4Height;
        }
        m_TextDocument->setPageSize(QSize(pageWidth, pageHeight));

        QTextFrameFormat frameFormat;
        frameFormat.setMargin(qRound(property.margin()));

        QTextFrame *rootFrame = m_TextDocument->rootFrame();
        rootFrame->setFrameFormat(frameFormat);
    }

    /**
     * Parse the content of the document
     */
    const QDomElement documentElement = document.documentElement();

    QDomElement element = documentElement.firstChildElement();
    while (!element.isNull())
    {
        if (element.tagName() == QLatin1String("body"))
        {
            if (!convertBody(element))
            {
                setError("Unable to convert document content", -1);
                delete m_Cursor;
                return 0;
            }
        }

        element = element.nextSiblingElement();
    }

    return m_TextDocument;
}
Exemplo n.º 16
0
Okular::Document::OpenResult Converter::convertWithPassword( const QString &fileName, const QString &password )
{
  Document oooDocument( fileName );
  if ( !oooDocument.open( password ) ) {
    if ( !oooDocument.anyFileEncrypted() )
        emit error( oooDocument.lastErrorString(), -1 );
    return oooDocument.anyFileEncrypted() ? Okular::Document::OpenNeedsPassword : Okular::Document::OpenError;
  }

  mTextDocument = new QTextDocument;
  mCursor = new QTextCursor( mTextDocument );

  /**
   * Create the dom of the content
   */
  QXmlSimpleReader reader;

  QXmlInputSource source;
  source.setData( oooDocument.content() );

  QString errorMsg;
  QDomDocument document;
  if ( !document.setContent( &source, &reader, &errorMsg ) ) {
    if ( !oooDocument.anyFileEncrypted() )
      emit error( i18n( "Invalid XML document: %1", errorMsg ), -1 );
    delete mCursor;
    return oooDocument.anyFileEncrypted() ? Okular::Document::OpenNeedsPassword : Okular::Document::OpenError;
  }

  mStyleInformation = new StyleInformation();

  /**
   * Read the style properties, so the are available when
   * parsing the content.
   */
  StyleParser styleParser( &oooDocument, document, mStyleInformation );
  if ( !styleParser.parse() ) {
    if ( !oooDocument.anyFileEncrypted() )
      emit error( i18n( "Unable to read style information" ), -1 );
    delete mCursor;
    return oooDocument.anyFileEncrypted() ? Okular::Document::OpenNeedsPassword : Okular::Document::OpenError;
  }

  /**
   * Add all images of the document to resource framework
   */
  const QMap<QString, QByteArray> images = oooDocument.images();
  QMapIterator<QString, QByteArray> it( images );
  while ( it.hasNext() ) {
    it.next();

    mTextDocument->addResource( QTextDocument::ImageResource, QUrl( it.key() ), QImage::fromData( it.value() ) );
  }

  /**
   * Set the correct page size
   */
  const QString masterLayout = mStyleInformation->masterPageName();
  const PageFormatProperty property = mStyleInformation->pageProperty( masterLayout );

  const QSizeF dpi = Okular::Utils::realDpi(nullptr);
  int pageWidth = qRound(property.width() / 72.0 * dpi.width());
  int pageHeight = qRound(property.height() / 72.0 * dpi.height());

  if ( pageWidth == 0 )
      pageWidth = 600;
  if ( pageHeight == 0 )
      pageHeight = 800;

  mTextDocument->setPageSize( QSize( pageWidth, pageHeight ) );

  QTextFrameFormat frameFormat;
  frameFormat.setMargin( qRound( property.margin() ) );

  QTextFrame *rootFrame = mTextDocument->rootFrame();
  rootFrame->setFrameFormat( frameFormat );

  /**
   * Parse the content of the document
   */
  const QDomElement documentElement = document.documentElement();

  QDomElement element = documentElement.firstChildElement();
  while ( !element.isNull() ) {
    if ( element.tagName() == QLatin1String( "body" ) ) {
      if ( !convertBody( element ) ) {
        if ( !oooDocument.anyFileEncrypted() )
          emit error( i18n( "Unable to convert document content" ), -1 );
        delete mCursor;
        return oooDocument.anyFileEncrypted() ? Okular::Document::OpenNeedsPassword : Okular::Document::OpenError;
      }
    }

    element = element.nextSiblingElement();
  }

  MetaInformation::List metaInformation = mStyleInformation->metaInformation();
  for ( int i = 0; i < metaInformation.count(); ++i ) {
    emit addMetaData( metaInformation[ i ].key(),
                      metaInformation[ i ].value(),
                      metaInformation[ i ].title() );
  }

  delete mCursor;
  delete mStyleInformation;
  mStyleInformation = 0;

  setDocument( mTextDocument );
  return Okular::Document::OpenSuccess;
}