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


C++ QTextFragment类代码示例

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


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

示例1: showSelectionInFragment

bool XLHighlighter::showSelectionInFragment(QTextFragment fragment)
// ----------------------------------------------------------------------------
//    Highlight (part of) fragment containing code related to a selected object
// ----------------------------------------------------------------------------
{
    bool matched = false;
    int spos= fragment.position();
    int epos = spos + fragment.length();
    int blockstart = currentBlock().begin().fragment().position();

    XL::stream_range frag(spos, epos);
    XL::stream_ranges::iterator r;
    for (r = selected.begin(); r != selected.end(); r++)
    {
        XL::stream_range i = intersect((*r), frag);
        if (i.first != -1)
        {
            int hstart = (int)(i.first) - blockstart;
            int hcount = (int)(i.second - i.first);
            setFormat(hstart, hcount, selectedFormat);
            matched = true;
        }
    }
    return matched;
}
开发者ID:caivega,项目名称:tao-3D,代码行数:25,代码来源:xl_highlighter.cpp

示例2: c

void Text::spatiumChanged(qreal oldVal, qreal newVal)
      {
      Element::spatiumChanged(oldVal, newVal);

      if (!sizeIsSpatiumDependent() || styled())
            return;
      qreal v = newVal / oldVal;

      QTextCursor c(_doc);
      QTextBlock cb = _doc->begin();
      while (cb.isValid()) {
            QTextBlock::iterator i(cb.begin());
            for (; !i.atEnd(); ++i) {
                  QTextFragment f = i.fragment();
                  if (f.isValid()) {
                        int pos = f.position();
                        int len = f.length();
                        c.setPosition(pos, QTextCursor::MoveAnchor);
                        c.setPosition(pos + len, QTextCursor::KeepAnchor);
                        QTextCharFormat cf = c.charFormat();
                        QFont font = cf.font();
                        font.setPointSizeF(font.pointSizeF() * v);
                        cf.setFont(font);
                        c.setCharFormat(cf);
                        }
                  }
            cb = cb.next();
            }
      }
开发者ID:aeliot,项目名称:MuseScore,代码行数:29,代码来源:text.cpp

示例3: readFragment

void XmlWriter::readFragment(const QTextBlock &currentBlock,
                             QDomElement blockElement,
                             QDomDocument *document)
{
//! [3] //! [4]
    QTextBlock::iterator it;
    for (it = currentBlock.begin(); !(it.atEnd()); ++it) {
        QTextFragment currentFragment = it.fragment();
        if (currentFragment.isValid())
//! [3] //! [5]
            processFragment(currentFragment);
//! [4] //! [5]

        if (currentFragment.isValid()) {
            QDomElement fragmentElement = document->createElement("fragment");
            blockElement.appendChild(fragmentElement);

            fragmentElement.setAttribute("length", currentFragment.length());
            QDomText fragmentText = document->createTextNode(currentFragment.text());

            fragmentElement.appendChild(fragmentText);
        }
//! [6] //! [7]
    }
//! [7] //! [6]
}
开发者ID:3163504123,项目名称:phantomjs,代码行数:26,代码来源:xmlwriter.cpp

示例4: processCustomFragment

void AudioTextDocumentDirector::processCustomFragment(const QTextFragment& fragment, const QTextDocument* doc)
{
  if ( fragment.charFormat().objectType() != AudioType )
    return Grantlee::MarkupDirector::processCustomFragment( fragment, doc );

  QString name = fragment.charFormat().property( AudioProperty ).toString();

  m_builder->addAudioTag( name );
}
开发者ID:cutelyst,项目名称:grantlee,代码行数:9,代码来源:audiotextdocumentoutputter.cpp

示例5: 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
}
开发者ID:Fale,项目名称:qtmoko,代码行数:56,代码来源:qtextodfwriter.cpp

示例6: deleteLater

void ChangeFollower::processUpdates(const QList<int> &changedStyles)
{
    KoStyleManager *sm = m_styleManager.data();
    if (!sm) {
        // since the stylemanager would be the one calling this method, I doubt this
        // will ever happen.  But better safe than sorry..
        deleteLater();
        return;
    }

    // optimization strategy;  store the formatid of the formats we checked into
    // a qset for 'hits' and 'ignores' and avoid the copying of the format
    // (fragment.charFormat() / block.blockFormat()) when the formatId is
    // already checked previosly

    QTextCursor cursor(m_document);
    QTextBlock block = cursor.block();
    while (block.isValid()) {
        QTextBlockFormat bf = block.blockFormat();
        int id = bf.intProperty(KoParagraphStyle::StyleId);
        if (id > 0 && changedStyles.contains(id)) {
            cursor.setPosition(block.position());
            KoParagraphStyle *style = sm->paragraphStyle(id);
            Q_ASSERT(style);

            style->applyStyle(bf);
            cursor.setBlockFormat(bf);
        }
        QTextCharFormat cf = block.charFormat();
        id = cf.intProperty(KoCharacterStyle::StyleId);
        if (id > 0 && changedStyles.contains(id)) {
            KoCharacterStyle *style = sm->characterStyle(id);
            Q_ASSERT(style);
            style->applyStyle(block);
        }

        QTextBlock::iterator iter = block.begin();
        while (! iter.atEnd()) {
            QTextFragment fragment = iter.fragment();
            cf = fragment.charFormat();
            id = cf.intProperty(KoCharacterStyle::StyleId);
            if (id > 0 && changedStyles.contains(id)) {
                // create selection
                cursor.setPosition(fragment.position());
                cursor.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
                KoCharacterStyle *style = sm->characterStyle(id);
                Q_ASSERT(style);

                style->applyStyle(cf);
                cursor.mergeCharFormat(cf);
            }
            iter++;
        }
        block = block.next();
    }
}
开发者ID:KDE,项目名称:calligra-history,代码行数:56,代码来源:ChangeFollower.cpp

示例7: getSingleEmoji

EmojiPtr FlatTextarea::getSingleEmoji() const {
	QString text;
	QTextFragment fragment;

	getSingleEmojiFragment(text, fragment);
	
	if (!text.isEmpty()) {
		QTextCharFormat format = fragment.charFormat();
		return emojiFromUrl(static_cast<const QTextImageFormat*>(&format)->name());
	}
	return 0;
}
开发者ID:AarashFarahani,项目名称:tdesktop,代码行数:12,代码来源:flattextarea.cpp

示例8: cursor

QTextFragment ChatView::getFragmentUnderMouse(const QPoint &pos) const
{
	QTextCursor cursor(cursorForPosition(pos));
	QTextBlock block(cursor.block());
	QTextBlock::iterator it;
	for (it = block.begin(); !(it.atEnd()); ++it) {
		QTextFragment frag = it.fragment();
		if (frag.contains(cursor.position()))
			return frag;
	}
	return QTextFragment();
}
开发者ID:LordHelmchen,项目名称:Cockatrice,代码行数:12,代码来源:chatview.cpp

示例9: getSingleEmoji

EmojiPtr FlatTextarea::getSingleEmoji() const {
	QString text;
	QTextFragment fragment;

	getSingleEmojiFragment(text, fragment);

	if (!text.isEmpty()) {
		QTextCharFormat format = fragment.charFormat();
		QString imageName = static_cast<const QTextImageFormat*>(&format)->name();
		return getEmoji(imageName.mid(8).toUInt(0, 16));
	}
	return 0;
}
开发者ID:jubalh,项目名称:tdesktop,代码行数:13,代码来源:flattextarea.cpp

示例10: removeSingleEmoji

void FlatTextarea::removeSingleEmoji() {
	QString text;
	QTextFragment fragment;

	getSingleEmojiFragment(text, fragment);

	if (!text.isEmpty()) {
		QTextCursor t(textCursor());
		t.setPosition(fragment.position());
		t.setPosition(fragment.position() + fragment.length(), QTextCursor::KeepAnchor);
		t.removeSelectedText();
		setTextCursor(t);
	}
}
开发者ID:AarashFarahani,项目名称:tdesktop,代码行数:14,代码来源:flattextarea.cpp

示例11: getFragmentUnderMouse

void ChatView::mouseMoveEvent(QMouseEvent *event)
{
    QTextFragment frag = getFragmentUnderMouse(event->pos());
    QString cardName = getCardNameUnderMouse(frag);
    if (!cardName.isEmpty()) {
        viewport()->setCursor(Qt::PointingHandCursor);
        emit cardNameHovered(cardName);
    } else if (frag.charFormat().isAnchor())
        viewport()->setCursor(Qt::PointingHandCursor);
    else
        viewport()->setCursor(Qt::IBeamCursor);

    QTextBrowser::mouseMoveEvent(event);
}
开发者ID:nilrook,项目名称:Cockatrice,代码行数:14,代码来源:chatview.cpp

示例12: filechangeId

QString MercurialEditor::fileNameFromDiffSpecification(const QTextBlock &diffFileSpec) const
{
   const QString filechangeId(QLatin1String("+++ b/"));
    QTextBlock::iterator iterator;
    for (iterator = diffFileSpec.begin(); !(iterator.atEnd()); iterator++) {
        QTextFragment fragment = iterator.fragment();
        if(fragment.isValid()) {
            if (fragment.text().startsWith(filechangeId)) {
                const QString filename = fragment.text().remove(0, filechangeId.size());
                return findDiffFile(filename, MercurialPlugin::instance()->versionControl());
            }
        }
    }
    return QString();
}
开发者ID:NoobSaibot,项目名称:qtcreator-minimap,代码行数:15,代码来源:mercurialeditor.cpp

示例13: getSingleEmoji

EmojiPtr FlatTextarea::getSingleEmoji() const {
	QString text;
	QTextFragment fragment;

	getSingleEmojiFragment(text, fragment);

	if (!text.isEmpty()) {
		QTextCharFormat format = fragment.charFormat();
		QString imageName = static_cast<QTextImageFormat*>(&format)->name();
		if (imageName.startsWith(qstr("emoji://e."))) {
			return emojiFromUrl(imageName);
		}
	}
	return 0;
}
开发者ID:4ker,项目名称:tdesktop,代码行数:15,代码来源:flattextarea.cpp

示例14: setHtml

/*!
  Replaces the entire contents of the document
  with the given HTML-formatted text in the \a text string
*/
void RichString::setHtml(const QString &text)
{
    QTextDocument doc;
    doc.setHtml(text);
    QTextBlock block = doc.firstBlock();
    QTextBlock::iterator it;
    for (it = block.begin(); !(it.atEnd()); ++it) {
        QTextFragment textFragment = it.fragment();
        if (textFragment.isValid()) {
            Format fmt;
            fmt.setFont(textFragment.charFormat().font());
            fmt.setFontColor(textFragment.charFormat().foreground().color());
            addFragment(textFragment.text(), fmt);
        }
    }
}
开发者ID:olegyurchenko,项目名称:QtXlsxWriter,代码行数:20,代码来源:xlsxrichstring.cpp

示例15: PyBool_FromLong

static PyObject *meth_QTextFragment_isValid(PyObject *sipSelf, PyObject *sipArgs)
{
    PyObject *sipParseErr = NULL;

    {
        QTextFragment *sipCpp;

        if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QTextFragment, &sipCpp))
        {
            bool sipRes;

            Py_BEGIN_ALLOW_THREADS
            sipRes = sipCpp->isValid();
            Py_END_ALLOW_THREADS

            return PyBool_FromLong(sipRes);
        }
    }
开发者ID:ClydeMojura,项目名称:android-python27,代码行数:18,代码来源:sipQtGuiQTextFragment.cpp


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