本文整理汇总了C++中QTextImageFormat::name方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat::name方法的具体用法?C++ QTextImageFormat::name怎么用?C++ QTextImageFormat::name使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextImageFormat
的用法示例。
在下文中一共展示了QTextImageFormat::name方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: writeInlineCharacter
void QTextOdfWriter::writeInlineCharacter(QXmlStreamWriter &writer, const QTextFragment &fragment) const
{
writer.writeStartElement(drawNS, QString::fromLatin1("frame"));
if (m_strategy == 0) {
// don't do anything.
}
else if (fragment.charFormat().isImageFormat()) {
QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
writer.writeAttribute(drawNS, QString::fromLatin1("name"), imageFormat.name());
// vvv Copy pasted mostly from Qt =================
QImage image;
QString name = imageFormat.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl::fromEncoded(name.toUtf8());
const QVariant data = m_document->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;
if (QTextImageHandler::externalLoader)
image = QTextImageHandler::externalLoader(name, context);
if (image.isNull()) { // try direct loading
name = imageFormat.name(); // remove qrc:/ prefix again
image.load(name);
}
}
// ^^^ Copy pasted mostly from Qt =================
if (! image.isNull()) {
QBuffer imageBytes;
QImageWriter imageWriter(&imageBytes, "png");
imageWriter.write(image);
QString filename = m_strategy->createUniqueImageName();
m_strategy->addFile(filename, QString::fromLatin1("image/png"), imageBytes.data());
// get the width/height from the format.
qreal width = (imageFormat.hasProperty(QTextFormat::ImageWidth)) ? imageFormat.width() : image.width();
writer.writeAttribute(svgNS, QString::fromLatin1("width"), pixelToPoint(width));
qreal height = (imageFormat.hasProperty(QTextFormat::ImageHeight)) ? imageFormat.height() : image.height();
writer.writeAttribute(svgNS, QString::fromLatin1("height"), pixelToPoint(height));
writer.writeStartElement(drawNS, QString::fromLatin1("image"));
writer.writeAttribute(xlinkNS, QString::fromLatin1("href"), filename);
writer.writeEndElement(); // image
}
}
writer.writeEndElement(); // frame
}
示例3: 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);
}
}
示例4: replaceImageUrl
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);
}
示例5: insertHtml
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);
}
示例6: 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;
}
示例7: if
QStandardItem *TextDocumentModel::formatItem(const QTextFormat &format)
{
QStandardItem *item = new QStandardItem;
if (!format.isValid()) {
item->setText(tr("no format"));
} else if (format.isImageFormat()) {
const QTextImageFormat imgformat = format.toImageFormat();
item->setText(tr("Image: %1").arg(imgformat.name()));
} else {
item->setText(tr("Format type: %1").arg(format.type()));
}
return item;
}
示例8: if
QStandardItem *TextDocumentModel::formatItem(const QTextFormat &format)
{
auto *item = new QStandardItem;
if (!format.isValid()) {
item->setText(tr("no format"));
} else if (format.isImageFormat()) {
const QTextImageFormat imgformat = format.toImageFormat();
item->setText(tr("Image: %1").arg(imgformat.name()));
} else {
item->setText(formatTypeToString(format.type()));
}
item->setEditable(false);
return item;
}
示例9: getImageTag
QString TextDocumentSerializer::getImageTag(QTextImageFormat format)
{
int width = format.width();
int height = format.height();
QString text;
resources->setDocument(document);
resources->saveImage(format.name());
if(width == 0 || height == 0)
text = QString("<img src=\"%1\">").arg(relativeImagePath(format));
else
text = QString("<img src=\"%1\" width=\"%2\" height=\"%3\">")
.arg(relativeImagePath(format))
.arg(width)
.arg(height);
return text;
}
示例10: extractSanitizedText
QString Text::extractSanitizedText(int from, int to) const
{
if (!doc)
return "";
QString txt;
QTextBlock begin = doc->findBlock(from);
QTextBlock end = doc->findBlock(to);
for (QTextBlock block = begin; block != end.next() && block.isValid(); block = block.next()) {
for (QTextBlock::Iterator itr = block.begin(); itr != block.end(); ++itr) {
int pos =
itr.fragment()
.position(); // fragment position -> position of the first character in the fragment
if (itr.fragment().charFormat().isImageFormat()) {
QTextImageFormat imgFmt = itr.fragment().charFormat().toImageFormat();
QString key = imgFmt.name(); // img key (eg. key::D for :D)
QString rune = key.mid(4);
if (pos >= from && pos < to) {
txt += rune;
++pos;
}
} else {
for (QChar c : itr.fragment().text()) {
if (pos >= from && pos < to)
txt += c;
++pos;
}
}
}
txt += '\n';
}
txt.chop(1);
return txt;
}
示例11: getPixmap
static QPixmap getPixmap(QTextDocument *doc, const QTextImageFormat &format, const qreal devicePixelRatio = 1.0)
{
QPixmap pm;
QString name = format.name();
if (name.startsWith(QLatin1String(":/"))) // auto-detect resources and convert them to url
name.prepend(QLatin1String("qrc"));
QUrl url = QUrl(name);
name = resolveFileName(name, &url, devicePixelRatio);
const QVariant data = doc->resource(QTextDocument::ImageResource, url);
if (data.type() == QVariant::Pixmap || data.type() == QVariant::Image) {
pm = qvariant_cast<QPixmap>(data);
} else if (data.type() == QVariant::ByteArray) {
pm.loadFromData(data.toByteArray());
}
if (pm.isNull()) {
#if 0
QString context;
// ### Qt5
QTextBrowser *browser = qobject_cast<QTextBrowser *>(doc->parent());
if (browser)
context = browser->source().toString();
#endif
// try direct loading
QImage img;
if (name.isEmpty() || !img.load(name))
return QPixmap(QLatin1String(":/qt-project.org/styles/commonstyle/images/file-16.png"));
pm = QPixmap::fromImage(img);
doc->addResource(QTextDocument::ImageResource, url, pm);
}
if (name.contains(QStringLiteral("@2x")))
pm.setDevicePixelRatio(2.0);
return pm;
}
示例12: getPlainText
QString TextEditEx::getPlainText(int _from, int _to) const
{
if (_from == _to)
return "";
if (_to != -1 && _to < _from)
{
assert(!"invalid data");
return "";
}
QString out_string;
QTextStream result(&out_string);
int pos_start = 0;
int length = 0;
bool first = true;
for (QTextBlock it_block = document()->begin(); it_block != document()->end(); it_block = it_block.next())
{
if (!first)
result << '\n';
pos_start = it_block.position();
if (_to != -1 && pos_start >= _to)
break;
for (QTextBlock::iterator it_fragment = it_block.begin(); it_fragment != it_block.end(); ++it_fragment)
{
QTextFragment currentFragment = it_fragment.fragment();
if (currentFragment.isValid())
{
pos_start = currentFragment.position();
length = currentFragment.length();
if (pos_start + length <= _from)
continue;
if (_to != -1 && pos_start >= _to)
break;
first = false;
if (currentFragment.charFormat().isImageFormat())
{
if (pos_start < _from)
continue;
QTextImageFormat imgFmt = currentFragment.charFormat().toImageFormat();
auto iter = resource_index_.find(imgFmt.name());
if (iter != resource_index_.end())
result << iter->second;
}
else
{
QString fragment_text = currentFragment.text();
int c_start = std::max((_from - pos_start), 0);
int count = -1;
if (_to != -1 && _to <= pos_start + length)
count = _to - pos_start - c_start;
QString txt = fragment_text.mid(c_start, count);
txt.remove(QChar::SoftHyphen);
QChar *uc = txt.data();
QChar *e = uc + txt.size();
for (; uc != e; ++uc) {
switch (uc->unicode()) {
case 0xfdd0: // QTextBeginningOfFrame
case 0xfdd1: // QTextEndOfFrame
case QChar::ParagraphSeparator:
case QChar::LineSeparator:
*uc = QLatin1Char('\n');
break;
case QChar::Nbsp:
*uc = QLatin1Char(' ');
break;
default:
;
}
}
result << txt;
}
}
}
}
return out_string;
}
示例13: SetFormat
void Interface::SetFormat( QTextImageFormat e )
{
nowimage = e;
SetPic(e.name());
}
示例14: relativeImagePath
QString TextDocumentSerializer::relativeImagePath(QTextImageFormat format)
{
QString text = format.name();
text.replace("file://", QString("./%1/").arg(resources->imageFolderName()));
return text;
}
示例15: emitFragment
//.........这里部分代码省略.........
if ( !closeAnchor )
html += QLatin1String( "<u>" );
break;
case code:
html += QLatin1String( "<code>" );
break;
case sub:
html += QLatin1String( "<sub>" );
break;
case sup:
html += QLatin1String( "<sup>" );
break;
}
}
/* QLatin1String styleTag("<span style=\"");
html += styleTag;
const bool attributesEmitted = emitCharFormatStyle(format);
if (attributesEmitted)
html += QLatin1String("\">");
else
html.chop(qstrlen(styleTag.latin1()));
*/
QString txt = fragment.text();
// kDebug() << txt ;
if ( txt.count() == 1 && txt.at( 0 ) == QChar::ObjectReplacementCharacter ) {
if ( format.isImageFormat() ) {
QTextImageFormat imgFmt = format.toImageFormat();
html += QLatin1String( "<img" );
if ( imgFmt.hasProperty( QTextFormat::ImageName ) ) {
emitAttribute( "src", imgFmt.name() );
}
if ( imgFmt.hasProperty( BilboTextFormat::ImageTitle ) ) {
const QString title = imgFmt.stringProperty( BilboTextFormat::ImageTitle );
if ( !title.isEmpty() ) {
emitAttribute( "title", imgFmt.stringProperty( BilboTextFormat::ImageTitle ) );
}
}
if ( imgFmt.hasProperty( BilboTextFormat::ImageAlternateText ) ) {
const QString alternate = imgFmt.stringProperty( BilboTextFormat::ImageAlternateText );
if ( !alternate.isEmpty() ) {
emitAttribute( "alt", imgFmt.stringProperty( BilboTextFormat::ImageAlternateText ) );
}
}
if ( imgFmt.hasProperty( QTextFormat::ImageWidth ) ) {
emitAttribute( "width", QString::number( imgFmt.width() ) );
}
if ( imgFmt.hasProperty( QTextFormat::ImageHeight ) ) {
emitAttribute( "height", QString::number( imgFmt.height() ) );
}
if ( QTextFrame *imageFrame = qobject_cast<QTextFrame *>( doc->objectForFormat( imgFmt ) ) ) {
emitFloatStyle( imageFrame->frameFormat().position() );
}
html += QLatin1String( " />" );
}
} else {
// Q_ASSERT(!txt.contains(QChar::ObjectReplacementCharacter));