本文整理汇总了C++中QTextImageFormat::setName方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat::setName方法的具体用法?C++ QTextImageFormat::setName怎么用?C++ QTextImageFormat::setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextImageFormat
的用法示例。
在下文中一共展示了QTextImageFormat::setName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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 );
}
}
}
}
}
}
}
示例2: main
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();
}
示例3: convertFrame
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;
}
示例4: 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();
}
示例5: 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);
}
示例6: 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);
}
示例7: on_actionImage_triggered
/**
* 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: 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);
}
示例9: 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
}
示例10: 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);
}
示例11: insertEmoji
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);
}
示例12: insertImage
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 );
}
示例13: r
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 );
}
示例14: render
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;
}
示例15: refresh
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);
}
}
}