int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);

    QImage image(64, 64, QImage::Format_RGB32);
    image.fill(qRgb(255, 160, 128));

//! [Adding a resource]
    document->addResource(QTextDocument::ImageResource,
        QUrl("mydata://image.png"), QVariant(image));
//! [Adding a resource]

//! [Inserting an image with a cursor]
    QTextImageFormat imageFormat;
    imageFormat.setName("mydata://image.png");
    cursor.insertImage(imageFormat);
//! [Inserting an image with a cursor]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Images"));
    editor->resize(320, 480);
    editor->show();

//! [Inserting an image using HTML]
    editor->append("<img src=\"mydata://image.png\" />");
//! [Inserting an image using HTML]

    return app.exec();
}
示例#2
0
void Format::parseBlock( QTextCursor &cursor, const QDomElement &element )
{
//  dbg() << "Format::parseBlock()" << endl;

  QDomNode n;
  for( n = element.firstChild(); !n.isNull(); n = n.nextSibling() ) {
    QDomElement e = n.toElement();
    if ( e.tagName() == "fragment" ) {
      QTextCharFormat format;
      if ( e.hasAttribute( "link" ) ) {
        format.setAnchor( true );
        QString href = e.attribute( "link" );
        format.setAnchorHref( href );
        format.setFontUnderline( true );
        if ( href.startsWith( "todoodle:" ) ) {
          format = TextFormats::topicLinkCharFormat( href );
        } else {
          format = TextFormats::hyperLinkCharFormat( href );
        }
      }
      if ( e.attribute( "bold" ) == "true" ) {
        format.setFontWeight( QFont::Bold );
      }
      if ( e.attribute( "italic" ) == "true" ) {
        format.setFontItalic( true );
      }
      int fontSize = 0;
      if ( e.hasAttribute( "fontsize" ) ) {
        fontSize = e.attribute( "fontsize" ).toInt();
      } else {
        fontSize = 10;
      }
      if ( fontSize > 0 ) format.setFontPointSize( fontSize );
      
      QDomNode n2;
      for( n2 = e.firstChild(); !n2.isNull(); n2 = n2.nextSibling() ) {
//        dbg() << "TICK" << endl;
        QDomText t = n2.toText();
        if ( !t.isNull() ) {
//          dbg() << "TEXT: '" << t.data() << "'" << endl;
          cursor.insertText( t.data(), format );
//          dbg() << "done" << endl;
        } else {
          QDomElement e2 = n2.toElement();
          if ( !e2.isNull() ) {
            if ( e2.tagName() == "todo" ) {
              QTextImageFormat f;
              if ( e2.attribute( "status" ) == "todo" ) {
                f.setName( ":/images/todo.png" );
              } else {
                f.setName( ":/images/tododone.png" );
              }
              cursor.insertImage( f );
            }
          }
        }
      }
    }
  }
}
示例#3
0
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);

    QTextImageFormat imageFormat;
    imageFormat.setName(":/images/advert.png");
    cursor.insertImage(imageFormat);

    QTextBlock block = cursor.block();
    QTextFragment fragment;
    QTextBlock::iterator it;

    for (it = block.begin(); !(it.atEnd()); ++it) {
        fragment = it.fragment();

        if (fragment.contains(cursor.position()))
            break;
    }

//! [0]
    if (fragment.isValid()) {
        QTextImageFormat newImageFormat = fragment.charFormat().toImageFormat();

        if (newImageFormat.isValid()) {
            newImageFormat.setName(":/images/newimage.png");
            QTextCursor helper = cursor;

            helper.setPosition(fragment.position());
            helper.setPosition(fragment.position() + fragment.length(),
                               QTextCursor::KeepAnchor);
            helper.setCharFormat(newImageFormat);
//! [0] //! [1]
        }
//! [1] //! [2]
    }
//! [2]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Image Format"));
    editor->resize(320, 480);
    editor->show();

    return app.exec();
}
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QTextEdit *editor = new QTextEdit;

//! [0]
    QTextDocument *document = new QTextDocument(editor);
    QTextCursor cursor(document);
//! [0]

//! [1]
    QTextImageFormat imageFormat;
    imageFormat.setName(":/images/advert.png");
    cursor.insertImage(imageFormat);
//! [1]

    cursor.insertBlock();
    cursor.insertText("Code less. Create more.");

    editor->setDocument(document);
    editor->setWindowTitle(tr("Text Document Images"));
    editor->resize(320, 480);
    editor->show();
    return app.exec();
}
示例#5
0
void KTextCursor::insertImage( const QString &name, const QTextImageFormat &format )
{
	QTextImageFormat imageForamt = format;

	imageForamt.setName(name);
	if(!imageForamt.hasProperty(KImageKey))
	{
		imageForamt.setProperty(KImageKey, name);
	}

	if(moviePool()->insertMovie(name, name))
	{
		Q_D(KTextCursor);

		imageForamt.setProperty(KAnimationImage,true);
		document()->addResource(QTextDocument::ImageResource, QUrl(name), moviePool()->currentImage(name));
	}
	else
	{
		QImage image(name);
		if(!image.isNull())
		{
			document()->addResource(QTextDocument::ImageResource,QUrl(name), image);
		}
	}

	__super::insertImage(imageForamt);
}
void TextDocument::replaceImageUrl(const QUrl &oldName, const QString &newName) {
	QList <QPair<int, int> > fragments;

	QTextBlock block = begin();

	while(block.isValid()) {
		QTextBlock::iterator iterator;
		for(iterator = block.begin(); !(iterator.atEnd()); ++iterator) {
			QTextFragment fragment = iterator.fragment();
			if(fragment.isValid() && fragment.charFormat().isImageFormat()) {
				QTextImageFormat format = fragment.charFormat().toImageFormat();
				if (QUrl::fromEncoded(format.name().toUtf8()) != oldName) {continue;}
				fragments.append(QPair<int, int>(fragment.position(), fragment.length()));
			}
		}
		block = block.next();
	}


	QTextCursor cursor(this);
	cursor.beginEditBlock();
	QPair<int, int> pair;
	foreach (pair, fragments) {
		cursor.setPosition(pair.first);
		cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, pair.second);
		QTextImageFormat format = cursor.charFormat().toImageFormat();
		format.setName(newName);
		cursor.mergeCharFormat(format);
	}
示例#7
0
/**
 * Inserts an valid image
 * Copies the specific image in the program folder
 */
void MainWindow::on_actionImage_triggered()
{
    QString scriboDir = QDir::home().absolutePath() + QDir::separator() + "scribo";

    if ( !QDir(scriboDir + QDir::separator() + "img").exists() )
        QDir().mkdir(scriboDir + QDir::separator() + "img");

    QString filePath = QFileDialog::getOpenFileName(this, tr("Select an image"),
                                      QDir::home().absolutePath(), "Bitmap Files (*.bmp)\n"
                                        "JPEG (*.jpg *jpeg)\n"
                                        "GIF (*.gif)\n"
                                        "PNG (*.png)");
    QStringList list = filePath.split( "/" );
    QString imageName = list.value(list.length() - 1 );
    QString imagePath = scriboDir + QDir::separator() + "img" + QDir::separator() + imageName;

    QFile::copy(filePath, imagePath);
    QUrl Uri ( QString ( "file://%1" ).arg ( imagePath ) );
    QImage image = QImageReader ( imagePath ).read();

    QTextDocument * textDocument = ui->textEdit_mainWindow_surface->document();
    textDocument->addResource( QTextDocument::ImageResource, Uri, QVariant ( image ) );
    cursor = ui->textEdit_mainWindow_surface->textCursor();
    QTextImageFormat imageFormat;
    imageFormat.setWidth( image.width() );
    imageFormat.setHeight( image.height() );
    imageFormat.setName( Uri.toString() );
    cursor.insertImage(imageFormat);
}
示例#8
0
bool Converter::convertFrame(const QDomElement &element)
{
    QDomElement child = element.firstChildElement();
    QDomElement suchild = element.lastChildElement("title");
    /// svg:title alt && title 
    while (!child.isNull())
    {
        if (child.tagName() == QLatin1String("image"))
        {
            const QString href = child.attribute("href");
            const QString xname = element.attribute("name");
            QString alttitle = QString("Name:%1 - Ref:%2").arg(xname).arg(href);
            if (suchild.tagName() == QLatin1String("title"))
            {
                alttitle.append(QString(" - Title:%1").arg(suchild.text()));
            }
            QTextImageFormat format;
            format.setToolTip(alttitle);
            format.setWidth(4.0/3.0*StyleParser::convertUnit(element.attribute("width")));
            format.setHeight(4.0/3.0*StyleParser::convertUnit(element.attribute("height")));
            format.setName(href);
            format.setBackground(Qt::white);
            m_Cursor->insertImage(format);
        }

        child = child.nextSiblingElement();
    }

    return true;
}
示例#9
0
void KTextCursor::insertImage( const QString & name )
{
	QTextImageFormat format;
	format.setName(name);
	format.setProperty(KImageKey, name);

	insertImage(name, format);
}
示例#10
0
void KTextCursor::insertImage( const QString &name, const QString &key )
{
	QTextImageFormat imageFormat;
	imageFormat.setName(name);
	imageFormat.setProperty(KImageKey, key);

	insertImage(name, imageFormat);
}
示例#11
0
void KTextCursor::insertHtml( const QString &text, const QMap<QString, QString>& imgs )
{
	if(!imgs.isEmpty())
	{
		for(QMap<QString,QString>::const_iterator iter = imgs.begin(); iter != imgs.end(); iter++)
		{
			QString key = iter.key();
			QString file = iter.value();
			if(moviePool()->insertMovie(file, file))
			{
				//修改属性为动画。
				document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file));
			}
			else
			{
				QImage image(file);
				if(!image.isNull())
				{
					document()->addResource(QTextDocument::ImageResource, QUrl(file), image);
				}
			}
		}
	}

	int istart = position();
	insertHtml(text);
	int inow = position();

	if(!imgs.isEmpty() && inow > istart)
	{
		setPosition(istart);
		movePosition(NextCharacter, KeepAnchor, inow-istart);
		QString txt = selectedText();
		int index = txt.indexOf(QChar::ObjectReplacementCharacter, 0);
		while(index >= 0)
		{
			/*修改字体类型。*/
			setPosition(istart+index);
			movePosition(NextCharacter, KeepAnchor, 1);
			QTextCharFormat fmt = charFormat();			
			QTextImageFormat imgFmt = fmt.toImageFormat();
			QString key = imgFmt.name();
			if(imgs.contains(key))
			{
				imgFmt.setProperty(KImageKey, key);
				imgFmt.setName(imgs.value(key));
				imgFmt.setProperty(KAnimationImage, true);
				setCharFormat(imgFmt);
			}
			int idx = index+1;
			index = txt.indexOf(QChar::ObjectReplacementCharacter, idx);
		}
	}

	setPosition(inow);
}
示例#12
0
void InputField::insertEmoji(EmojiPtr emoji, QTextCursor c) {
	QTextImageFormat imageFormat;
	int32 ew = ESize + st::emojiPadding * cIntRetinaFactor() * 2, eh = _st->font->height * cIntRetinaFactor();
	imageFormat.setWidth(ew / cIntRetinaFactor());
	imageFormat.setHeight(eh / cIntRetinaFactor());
	imageFormat.setName(qsl("emoji://e.") + QString::number(emojiKey(emoji), 16));
	imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);

	static QString objectReplacement(QChar::ObjectReplacementCharacter);
	c.insertText(objectReplacement, imageFormat);
}
void TextDocumentRtfOutput::createImage(const QImage &image, const QTextImageFormat &format)
{
#if 0
    QString imageUuid = QString("rtfparser://") + QUuid::createUuid().toString();
    m_document->addResource(QTextDocument::ImageResource, QUrl(imageUuid), QVariant(image));
    format.setName(imageUuid);
    m_cursor->insertImage(format);
#else
    m_cursor->insertImage(image.scaled(format.width(), format.height()));
#endif
}
示例#14
0
void KTextCursor::insertImage( const QString &name, const QImage &image, const QTextImageFormat &format )
{
	QTextImageFormat inserFormat = format;
	inserFormat.setName(name);
	if(!inserFormat.hasProperty(KImageKey))
	{
		inserFormat.setProperty(KImageKey, name);
	}

	document()->addResource(QTextDocument::ImageResource, QUrl(name), image);
	__super::insertImage(inserFormat);
}
示例#15
0
void FlatTextarea::insertEmoji(EmojiPtr emoji, QTextCursor c) {
	c.removeSelectedText();

	QPixmap img(App::emojiSingle(emoji, _st.font->height));
	QString url = qsl("emoji://e.") + QString::number(emojiKey(emoji), 16);
	document()->addResource(QTextDocument::ImageResource, QUrl(url), QVariant(img));
	QTextImageFormat imageFormat;
	imageFormat.setWidth(img.width() / cIntRetinaFactor());
	imageFormat.setHeight(img.height() / cIntRetinaFactor());
	imageFormat.setName(url);
	imageFormat.setVerticalAlignment(QTextCharFormat::AlignBaseline);
	c.insertImage(imageFormat);
}
示例#16
0
void TextEdit::insertImage( const QString & path ) {
    QPair< QString, QSize > imgKey( this->p_->addImageResource( path ) );

    QTextCursor cursor( this->textCursor() );

    QTextImageFormat format;
    format.setName( imgKey.first );
    format.setToolTip( imgKey.first );
    format.setWidth( imgKey.second.width() );
    format.setHeight( imgKey.second.height() );
    cursor.insertImage( format );

    this->setTextCursor( cursor );
}
示例#17
0
void TextEdit::Private::replaceImage( std::map< QString, QUrl > & mapping, const QFileInfo & oldP, const QFileInfo & newP ) {
    QVariant r( this->host->document()->resource( QTextDocument::ImageResource, QUrl( oldP.fileName() ) ) );
    this->host->document()->addResource( QTextDocument::ImageResource, QUrl( oldP.fileName() ), QVariant() );
    this->host->document()->addResource( QTextDocument::ImageResource, QUrl( newP.fileName() ), r );

    this->currentCursor.deletePreviousChar();
    QTextImageFormat format;
    format.setName( newP.fileName() );
    format.setToolTip( newP.fileName() );
    this->currentCursor.insertImage( format );

    mapping.erase( oldP.fileName() );
    mapping.insert( std::make_pair( newP.fileName(), QUrl::fromLocalFile( newP.absoluteFilePath() ) ) );
    this->testCase->setImageMapping( mapping );
}
示例#18
0
void KTextCursor::insertImage( const QString &name, const QString &key, const QString &linkValue, const QString &linkKey )
{
	QTextImageFormat imageFormat;

	imageFormat.setAnchor(true);
	imageFormat.setAnchorHref(linkValue);
	imageFormat.setName(name);
	imageFormat.setProperty(KImageKey, key);

	if(!linkKey.isEmpty())
	{
		imageFormat.setProperty( KLinkKey, linkKey );
	}

	insertImage(name, imageFormat);
}
示例#19
0
QTextImageFormat EpsRenderer::render(QTextDocument *document, const QUrl &url)
{
    QTextImageFormat epsCharFormat;

    QSizeF s = renderToResource(document, url);

    QUrl internal = url;
    internal.setScheme(QLatin1String("internal"));
    if(s.isValid())
    {
        epsCharFormat.setName(internal.url());
        epsCharFormat.setWidth(s.width());
        epsCharFormat.setHeight(s.height());
    }

    return epsCharFormat;
}
示例#20
0
void TextEmojiWrapper::refresh()
{
    if(!p->document)
        return;
    if(!p->emojis)
        return;

    QTextDocument *document = p->document->textDocument();
    document->clear();

    QTextCursor cursor(document);
    cursor.setPosition(0);

    QString &text = p->text;
    const QHash<QString,QString> &emojis = p->emojis->emojis();
    for( int i=0; i<text.size(); i++ )
    {
        QString image;
        for( int j=1; j<5; j++ )
        {
            QString emoji = text.mid(i,j);
            if( !emojis.contains(emoji) )
                continue;

            image = emojis.value(emoji);
            i += emoji.size()-1;
            break;
        }

        if(image.isEmpty())
        {
            cursor.insertText(QString(text[i]));
        }
        else
        {
            QTextImageFormat format;
            format.setName(AsemanDevices::localFilesPrePath()+image);
            format.setHeight(18);
            format.setWidth(18);

            cursor.insertImage(format);
        }
    }
}
示例#21
0
文件: converter.cpp 项目: KDE/okular
bool Converter::convertFrame( const QDomElement &element )
{
  QDomElement child = element.firstChildElement();
  while ( !child.isNull() ) {
    if ( child.tagName() == QLatin1String( "image" ) ) {
      const QString href = child.attribute( QStringLiteral("href") );
      QTextImageFormat format;
      format.setWidth( StyleParser::convertUnit( element.attribute( QStringLiteral("width") ) ) );
      format.setHeight( StyleParser::convertUnit( element.attribute( QStringLiteral("height") ) ) );
      format.setName( href );

      mCursor->insertImage( format );
    }

    child = child.nextSiblingElement();
  }

  return true;
}
示例#22
0
void QTextPanel::stressTestPaint()
{
    /////////pageClear();  /* remove all if exist text */
    
    
    QTextDocument *playdoc = new QTextDocument();
    QTextCursor c(playdoc);
    c.setPosition(0,QTextCursor::MoveAnchor);
    
    int loop = -1;
    c.beginEditBlock();
    
    QStringList colorNames = QColor::colorNames();
    foreach (QString name, colorNames) {
        loop++;
        
        if (loop != 0) { 
        c.insertBlock();
        }
        
        ////////qDebug() << "### name ->" << name;
        
        QPixmap e = createColorMaps( name );
        playdoc->addResource(QTextDocument::ImageResource,QUrl(name),e);
        QTextImageFormat format;
        format.setName( name );
        format.setHeight ( e.height() );
        format.setWidth ( e.width() );
        format.setToolTip(name);
        c.insertImage( format );
        c.insertText(QString(QChar::LineSeparator));   /* br */
        ////////////QTextBlockFormat bbformat = c.blockFormat();
        /////////bbformat.setPageBreakPolicy(QTextFormat::PageBreak_AlwaysAfter);
        ////////c.setBlockFormat(bbformat);
        
        for (int i = 0; i < 15; ++i)  {
        c.insertText(name+ "   .");   
        }
        c.endEditBlock();
        c.atBlockEnd();
        
    }
示例#23
0
void MailViewer::displayAttachments(const MessageHeader& msg)
{   
#if 0 //code doesn't yet work
   QTextDocument* textDocument = ui->message_content->document();
   QImage image;
   int i = 1;
   foreach (const bts::bitchat::attachment& attachment, msg.attachments)
      {
      image.fromData(attachment.body.data());
      QUrl url(QString("attachment_image_%1").arg(i++));
      textDocument->addResource( QTextDocument::ImageResource, url, QVariant ( image ) );
      QTextCursor cursor = ui->message_content->textCursor();
      QTextImageFormat imageFormat;
      imageFormat.setWidth( image.width() );
      imageFormat.setHeight( image.height() );
      imageFormat.setName( url.toString() );
      cursor.insertImage(imageFormat);
      }
#endif
}
示例#24
0
文件: Utils.cpp 项目: Jichao/avchat
void Utils::addImageToTextEdit(const QString& fileName, QTextEdit* textEdit)
{
	if (!fileName.isNull()) {
		QTextCursor c(textEdit->document());
		c.movePosition(QTextCursor::End);

		QImage image;
		image.load(fileName);
		QTextImageFormat imageFormat;
		float maxImageWidth = textEdit->width() / 2.f;
		if (image.width() < maxImageWidth) {
			imageFormat.setWidth(image.width());
			imageFormat.setHeight(image.height());
		} else {
			imageFormat.setWidth(maxImageWidth);
			imageFormat.setHeight(maxImageWidth / image.width() * image.height());
		}
		imageFormat.setName(fileName);
		c.insertImage(imageFormat);
	}
}
示例#25
0
void MainWindow::on_insertImage_clicked()
{
    //get select image
    QString fn = QFileDialog::getOpenFileName(this, tr("插入图像"),
                                              QString(),
                                              tr("Joint Photographic Experts Group (*.jpg *.jpeg);;") +
                                              "Portable Network Graphics (*.png);;" +
                                              "Windows Bitmap (*.bmp);;" +
                                              "GIF (*.gif);;" +
                                              "Portable Bitmap (*.pbm);;" +
                                              "Portable Graymap (*.pgm);;" +
                                              "Portable Pixmap (*.ppm);;" +
                                              "X11 Bitmap (*.xbm);;" +
                                              "X11 Pixmap (*.xpm);;" +
                                              "Scalable Vector Graphics (*.svg);;" +
                                              "All Files (*)");

    if (fn.isEmpty())
        return;
    if (!(fn.endsWith(".jpg", Qt::CaseInsensitive)
          || fn.endsWith(".jpeg", Qt::CaseInsensitive)
          || fn.endsWith(".png", Qt::CaseInsensitive)
          || fn.endsWith(".gif", Qt::CaseInsensitive)
          || fn.endsWith(".pbm", Qt::CaseInsensitive)
          || fn.endsWith(".pgm", Qt::CaseInsensitive)
          || fn.endsWith(".ppm", Qt::CaseInsensitive)
          || fn.endsWith(".xbm", Qt::CaseInsensitive)
          || fn.endsWith(".xpm", Qt::CaseInsensitive)
          || fn.endsWith(".svg", Qt::CaseInsensitive))) {
        QMessageBox::warning(this, tr("自动出卷系统"), tr("不支持的文件格式。"));
        return;
    }

    QTextEdit *pEdit = textEditor.editor;
    QTextCursor cursor = pEdit->textCursor();
    QTextImageFormat imageFormat;
    imageFormat.setName(fn);
    //pEdit->setText();
    cursor.insertImage(imageFormat);
}
示例#26
0
  /*!
     * \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() );
      }
    }
  }
示例#27
0
void STextEditWidget::insertFromMimeData(const QMimeData * source) {
    if(source->hasImage()) {
        QImage image = qvariant_cast<QImage>(source->imageData());
        QByteArray ba;
        QBuffer buffer(&ba);
        buffer.open(QIODevice::WriteOnly);
        image.save(&buffer, "PNG");
        buffer.close();

        int counter = *S_PROJECT->resourceCounter();
        QString name = QString("resources\\mimeres%1.png")
                .arg(counter);

        counter ++;
        S_PROJECT->addData(ba, name);

        QTextImageFormat imageFormat;
        imageFormat.setName(name);
        textCursor().insertImage(image, name);
    }
    else
        QTextEdit::insertFromMimeData(source);
}
示例#28
0
void ContactListEdit::addContactEntry(const QString& contactText, const bts::addressbook::contact& c)
  {
  QFont        default_font;
  default_font.setPointSize( default_font.pointSize() - 1 );
  QFontMetrics font_metrics(default_font);
  QRect        bounding = font_metrics.boundingRect(contactText);
  int          completion_width = font_metrics.width(contactText);
  int          completion_height = bounding.height();

  completion_width += 20;

  QImage   completion_image(completion_width, completion_height + 4, QImage::Format_ARGB32);
  completion_image.fill(QColor(0, 0, 0, 0) );
  QPainter painter;
  painter.begin(&completion_image);
  painter.setFont(default_font);
  painter.setRenderHint(QPainter::Antialiasing);

  QBrush brush(Qt::SolidPattern);
  brush.setColor( QColor( 205, 220, 241 ) );
  QPen  pen;

  bool isKeyhoteeFounder = Contact::isKeyhoteeFounder(c);

  if (isKeyhoteeFounder)
    {
    QLinearGradient grad(QPointF(0, 0), QPointF(0, 1));
    grad.setCoordinateMode(QGradient::ObjectBoundingMode);
    grad.setColorAt(0, QColor(35, 40, 3));
    grad.setColorAt(0.102273, QColor(136, 106, 22));
    grad.setColorAt(0.225, QColor(166, 140, 41));
    grad.setColorAt(0.285, QColor(204, 181, 74));
    grad.setColorAt(0.345, QColor(235, 219, 102));
    grad.setColorAt(0.415, QColor(245, 236, 112));
    grad.setColorAt(0.52, QColor(209, 190, 76));
    grad.setColorAt(0.57, QColor(187, 156, 51));
    grad.setColorAt(0.635, QColor(168, 142, 42));
    grad.setColorAt(0.695, QColor(202, 174, 68));
    grad.setColorAt(0.75, QColor(218, 202, 86));
    grad.setColorAt(0.815, QColor(208, 187, 73));
    grad.setColorAt(0.88, QColor(187, 156, 51));
    grad.setColorAt(0.935, QColor(137, 108, 26));
    grad.setColorAt(1, QColor(35, 40, 3));

    brush = QBrush(grad);
    pen.setColor( QColor( 103, 51, 1 ) );
    }
  else
    {
    brush.setColor( QColor( 205, 220, 241 ) );
    pen.setColor( QColor( 105,110,180 ) );
    }

  painter.setBrush(brush);
  painter.setPen(pen);
  painter.drawRoundedRect(0, 0, completion_width - 1, completion_image.height() - 1, 8, 8,
    Qt::AbsoluteSize);
  painter.setPen(QPen());
  painter.drawText(QPoint(10, completion_height - 2), contactText);

  QTextDocument* doc = document();
  doc->addResource(QTextDocument::ImageResource, QUrl(contactText), completion_image);
  QTextImageFormat format;
  format.setName(contactText);

  encodePublicKey(c.public_key, &format);

  QTextCursor txtCursor = textCursor();
  txtCursor.insertImage(format);

  txtCursor.insertText(" ");
  setTextCursor(txtCursor);
  }
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;
}