/*! * \class TextCursorInsertImage * \author Anders Fernström * \date 2005-11-18 * * \brief Command for inserting an image */ void TextCursorInsertImage::execute() { QTextCursor cursor( document()->getCursor()->currentCell()->textCursor() ); if( !cursor.isNull() ) { QImage* image = new QImage( filepath_ ); if( !image->isNull() ) { QString imagename = document()->addImage( image ); QTextCursor cursor( document()->getCursor()->currentCell()->textCursor() ); if( !cursor.isNull() ) { QTextEdit *editor = document()->getCursor()->currentCell()->textEdit(); if( editor ) { // save text settings and set them after image have been inserted QTextCharFormat format = cursor.charFormat(); if( editor->toPlainText().isEmpty() ) format = *document()->getCursor()->currentCell()->style()->textCharFormat(); QTextImageFormat imageformat; imageformat.merge( format ); imageformat.setHeight( height_ ); imageformat.setWidth( width_ ); imageformat.setName( imagename ); cursor.insertImage( imageformat ); } } } else { string str = string("Could not open image: ") + filepath_.toStdString().c_str(); throw runtime_error( str.c_str() ); } } }
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; }