Ejemplo n.º 1
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);
}
Ejemplo n.º 2
0
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"));
    }
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
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;
}
Ejemplo n.º 5
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);
}
Ejemplo n.º 6
0
void KTextCursor::insertImage( const QString &name, const QString &key )
{
	QTextImageFormat imageFormat;
	imageFormat.setName(name);
	imageFormat.setProperty(KImageKey, key);

	insertImage(name, imageFormat);
}
Ejemplo n.º 7
0
void KTextCursor::insertImage( const QString & name )
{
	QTextImageFormat format;
	format.setName(name);
	format.setProperty(KImageKey, name);

	insertImage(name, format);
}
Ejemplo n.º 8
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);
}