当前位置: 首页>>代码示例>>C++>>正文


C++ QTextImageFormat类代码示例

本文整理汇总了C++中QTextImageFormat的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat类的具体用法?C++ QTextImageFormat怎么用?C++ QTextImageFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了QTextImageFormat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: textCursor

void TextResultItem::setLatex(Cantor::LatexResult* result)
{
    QTextCursor cursor = textCursor();
    cursor.movePosition(QTextCursor::Start);
    cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor);
    QString latex = result->toLatex().trimmed();
    if (latex.startsWith(QLatin1String("\\begin{eqnarray*}")) &&
        latex.endsWith(QLatin1String("\\end{eqnarray*}"))) {
        latex = latex.mid(17);
        latex = latex.left(latex.size() - 15);
    }
    if (result->isCodeShown()) {
        if (latex.isEmpty())
            cursor.removeSelectedText();
        else
            cursor.insertText(latex);
    } else {
        QTextImageFormat format;
        format = epsRenderer()->render(cursor.document(),
                                       result->data().toUrl());
        format.setProperty(EpsRenderer::CantorFormula,
                           EpsRenderer::LatexFormula);
        format.setProperty(EpsRenderer::Code, latex);
        format.setProperty(EpsRenderer::Delimiter, QLatin1String("$$"));
        if(format.isValid())
            cursor.insertText(QString(QChar::ObjectReplacementCharacter), format);
        else
            cursor.insertText(i18n("Cannot render Eps file. You may need additional packages"));
    }
}
开发者ID:KDE,项目名称:cantor,代码行数:30,代码来源:textresultitem.cpp

示例2: QDir

/**
 * 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);
}
开发者ID:1cy1c3,项目名称:scribo,代码行数:33,代码来源:mainwindow.cpp

示例3: getImage

static QImage getImage(QTextDocument *doc, const QTextImageFormat &format)
{
    QImage image;

    QString name = format.name();
    if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
        name.prepend(QLatin1String("qrc"));
    QUrl url = QUrl::fromEncoded(name.toUtf8());
    const QVariant data = doc->resource(QTextDocument::ImageResource, url);
    if (data.type() == QVariant::Image) {
        image = qvariant_cast<QImage>(data);
    } else if (data.type() == QVariant::ByteArray) {
        image.loadFromData(data.toByteArray());
    }

    if (image.isNull()) {
        QString context;
#ifndef QT_NO_TEXTBROWSER
        QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
        if (browser)
            context = browser->source().toString();
#endif
        if (QTextImageHandler::externalLoader)
            image = QTextImageHandler::externalLoader(name, context);

        if (image.isNull()) { // try direct loading
            name = format.name(); // remove qrc:/ prefix again
            if (name.isEmpty() || !image.load(name))
                return QImage(QLatin1String(":/trolltech/styles/commonstyle/images/file-16.png"));
        }
        doc->addResource(QTextDocument::ImageResource, url, image);
    }

    return image;
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:35,代码来源:qtextimagehandler.cpp

示例4: insertFragment

void KTextCursor::insertFragment( QList<QPair<QString,QTextCharFormat>>& frags )
{
	for(QList<QPair<QString,QTextCharFormat>>::iterator iter = frags.begin(); iter != frags.end(); iter++)
	{
		QPair<QString,QTextCharFormat>& item = *iter;
		QString text = item.first;
		QTextCharFormat fmt = item.second;
		if(text.at(0) == QChar::ObjectReplacementCharacter)
		{
			//图片
			QTextImageFormat imgFmt = fmt.toImageFormat();
			QString file = imgFmt.name();
			if(!file.isEmpty())
			{
				if(moviePool()->insertMovie(file, file))
				{
					fmt.setProperty(KAnimationImage, true);
					document()->addResource(QTextDocument::ImageResource, QUrl(file), moviePool()->currentImage(file));
				}
				else
				{
					QImage image(file);
					if(!image.isNull())
					{
						document()->addResource(QTextDocument::ImageResource, QUrl(file), image);
					}
				}
			}
		}
		insertText(text, fmt);
	}
}
开发者ID:kxtry,项目名称:kxfw,代码行数:32,代码来源:ktextcursor.cpp

示例5: getImageSize

static QSize getImageSize(QTextDocument *doc, const QTextImageFormat &format)
{
    QImage image;

    const bool hasWidth = format.hasProperty(QTextFormat::ImageWidth);
    const int width = qRound(format.width());
    const bool hasHeight = format.hasProperty(QTextFormat::ImageHeight);
    const int height = qRound(format.height());

    QSize size(width, height);
    if (!hasWidth || !hasHeight) {
        image = getImage(doc, format);
        if (!hasWidth)
            size.setWidth(image.width());
        if (!hasHeight)
            size.setHeight(image.height());
    }

    qreal scale = 1.0;
    QPaintDevice *pdev = doc->documentLayout()->paintDevice();
    if (pdev) {
        extern int qt_defaultDpi();
        if (image.isNull())
            image = getImage(doc, format);
        if (!image.isNull())
            scale = qreal(pdev->logicalDpiY()) / qreal(qt_defaultDpi());
    }
    size *= scale;

    return size;
}
开发者ID:Nacto1,项目名称:qt-everywhere-opensource-src-4.6.2,代码行数:31,代码来源:qtextimagehandler.cpp

示例6: parseBlock

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 );
            }
          }
        }
      }
    }
  }
}
开发者ID:cornelius,项目名称:todoodle,代码行数:60,代码来源:format.cpp

示例7: main

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();
}
开发者ID:Akheon23,项目名称:chromecast-mirrored-source.vendor,代码行数:25,代码来源:main.cpp

示例8: insertImage

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);
}
开发者ID:kxtry,项目名称:kxfw,代码行数:28,代码来源:ktextcursor.cpp

示例9: begin

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);
	}
开发者ID:WalterSullivan,项目名称:qNotesManager,代码行数:29,代码来源:textdocument.cpp

示例10: document

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);
}
开发者ID:kxtry,项目名称:kxfw,代码行数:56,代码来源:ktextcursor.cpp

示例11: extractImgTooltip

QString Text::extractImgTooltip(int pos) const
{
    for (QTextBlock::Iterator itr = doc->firstBlock().begin(); itr != doc->firstBlock().end(); ++itr) {
        if (itr.fragment().contains(pos) && itr.fragment().charFormat().isImageFormat()) {
            QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
            return imgFmt.toolTip();
        }
    }

    return QString();
}
开发者ID:iphydf,项目名称:qTox,代码行数:11,代码来源:text.cpp

示例12: insertEmoji

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);
}
开发者ID:noscripter,项目名称:tdesktop,代码行数:11,代码来源:flatinput.cpp

示例13: createImage

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
}
开发者ID:metaxy,项目名称:openBibleViewer,代码行数:11,代码来源:TextDocumentRtfOutput.cpp

示例14: Q_ASSERT

void QTextBrowserEx::insertFromMimeData( const QMimeData *source )
{
	Q_ASSERT(source);

	if(m_pasteFlags == NotSupport)
		return;

	QByteArray bytes = source->data(KTextEditMime);

	KTextCursor tc = textCursor();

	if(!bytes.isEmpty() && m_pasteFlags.testFlag(Custom))
	{
		QDataStream ds(bytes);
		QList<QByteArray> lstFrags;
		ds >> lstFrags;
		for(int i = 0; i < lstFrags.count(); i++)
		{
			const QByteArray frags = lstFrags.at(i);
			QDataStream ds(frags);
			QString text;
			QTextCharFormat format;
			ds >> text >> format;
			bool bHandled = false;
			/*自定义控件,则可由外部处理*/
			emit insertMimiData(tc, text, format, bHandled);
			if(bHandled)
				continue;
			/*尝试主动处理相关信息。*/
			if(text.at(0) == QChar::ObjectReplacementCharacter)
			{
				for(int i = 0; i < text.length(); i++)
				{
					QTextImageFormat fmt = format.toImageFormat();
					if(!fmt.isValid())
					{
						/*自定义控件出现比较多*/
						continue;
					}
					QVariant vimgkey = fmt.property(KImageKey);
					QString imgkey = vimgkey.toString();
					tc.insertImage(imgkey, fmt);
				}
			}
			else
			{
				/*文字处理*/
				tc.insertText(text, format);
			}
		}
		return;
	}
开发者ID:kxtry,项目名称:kxfw,代码行数:52,代码来源:qtextbrowserex.cpp

示例15: render

QTextImageFormat EpsRenderer::render(QTextDocument *document,
                                     const Cantor::LatexRenderer* latex)
{
    QTextImageFormat format = render(document, QUrl::fromLocalFile(latex->imagePath()));

    if (!format.name().isEmpty()) {
        format.setProperty(CantorFormula, latex->method());
        format.setProperty(ImagePath, latex->imagePath());
        format.setProperty(Code, latex->latexCode());
    }

    return format;
}
开发者ID:KDE,项目名称:cantor,代码行数:13,代码来源:epsrenderer.cpp


注:本文中的QTextImageFormat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。