本文整理汇总了C++中QTextImageFormat::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextImageFormat::isValid方法的具体用法?C++ QTextImageFormat::isValid怎么用?C++ QTextImageFormat::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextImageFormat
的用法示例。
在下文中一共展示了QTextImageFormat::isValid方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setLatex
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"));
}
}
示例2: insertFromMimeData
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;
}
示例3: 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();
}
示例4: frameToString
QString Format::frameToString( QTextFrame *frame )
{
QString out;
QTextFrame::iterator it;
for( it = frame->begin(); it != frame->end(); ++it ) {
QTextBlock block = it.currentBlock();
if ( block.isValid() ) {
out += "<block";
QTextCursor c( block );
QDateTime dt = TextFormats::lastModified( c );
if ( dt.isValid() ) {
out += " lastmodified=\"" + dt.toString( Qt::ISODate ) + "\"";
}
if ( TextFormats::isTitle( c ) ) {
out += " titlestyle=\"title\"";
} else if ( TextFormats::isSubTitle( c ) ) {
out += " titlestyle=\"subtitle\"";
}
QTextBlockFormat blockFormat = block.blockFormat();
if ( blockFormat.isValid() ) {
QTextList *list = block.textList();
if ( list ) {
QTextListFormat f = list->format();
out += " liststyle=\"";
switch( f.style() ) {
default:
case QTextListFormat::ListDisc:
out += "disc";
break;
case QTextListFormat::ListDecimal:
out += "decimal";
break;
}
out += "\"";
out += " listindent=\"" + QString::number( f.indent() ) + "\"";
} else {
if ( blockFormat.indent() != 0 ) {
out += " blockindent=\"" + QString::number( blockFormat.indent() ) +
"\"";
}
}
}
out += ">\n";
QTextBlock::iterator it2;
for( it2 = block.begin(); it2 != block.end(); ++it2 ) {
QTextFragment fragment = it2.fragment();
if ( !fragment.isValid() ) continue;
QString text = fragment.text();
QString outText;
for( int i = 0; i < text.size(); ++i ) {
if ( text.at( i ) == 0xfffc ) {
outText += "<todo status=\"";
QTextImageFormat imageFormat = fragment.charFormat().toImageFormat();
if ( imageFormat.isValid() ) {
if ( imageFormat.name().contains( "done" ) ) outText += "done";
else outText += "todo";
} else {
dbg() << "NO IMAGE FORMAT" << endl;
}
outText += "\"/>";
} else {
outText += escape( QString( text.at( i ) ) );
}
}
out += " <fragment";
QTextCharFormat format = fragment.charFormat();
if ( !format.anchorHref().isEmpty() ) {
out += " link=\"" + escape( format.anchorHref() ) + "\"";
}
if ( format.fontWeight() == QFont::Bold ) {
out += " bold=\"true\"";
}
if ( format.fontItalic() ) {
out += " italic=\"true\"";
}
if ( format.hasProperty( QTextFormat::FontPointSize ) &&
format.fontPointSize() != 10 ) {
out += " fontsize=\"" + QString::number( format.fontPointSize() ) +
"\"";
}
if ( outText.trimmed().isEmpty() ) outText.replace( " ", "[FIXME:space]" );
out += ">" + outText + "</fragment>\n";
}
//.........这里部分代码省略.........