本文整理汇总了C++中QTextBlock::begin方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::begin方法的具体用法?C++ QTextBlock::begin怎么用?C++ QTextBlock::begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::begin方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: readFragment
void XmlWriter::readFragment(const QTextBlock ¤tBlock,
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]
}
示例2: getMentionHashtagStart
void FlatTextarea::getMentionHashtagStart(QString &start) const {
int32 pos = textCursor().position();
if (textCursor().anchor() != pos) return;
QTextDocument *doc(document());
QTextBlock block = doc->findBlock(pos);
for (QTextBlock::Iterator iter = block.begin(); !iter.atEnd(); ++iter) {
QTextFragment fr(iter.fragment());
if (!fr.isValid()) continue;
int32 p = fr.position(), e = (p + fr.length());
if (p >= pos || e < pos) continue;
QTextCharFormat f = fr.charFormat();
if (f.isImageFormat()) continue;
QString t(fr.text());
for (int i = pos - p; i > 0; --i) {
if (t.at(i - 1) == '@') {
if ((pos - p - i < 1 || t.at(i).isLetter()) && (i < 2 || !(t.at(i - 2).isLetterOrNumber() || t.at(i - 2) == '_'))) {
start = t.mid(i - 1, pos - p - i + 1);
}
return;
} else if (t.at(i - 1) == '#') {
if (i < 2 || !(t.at(i - 2).isLetterOrNumber() || t.at(i - 2) == '_')) {
start = t.mid(i - 1, pos - p - i + 1);
}
return;
}
if (pos - p - i > 63) break;
if (!t.at(i - 1).isLetterOrNumber() && t.at(i - 1) != '_') break;
}
return;
}
}
示例3: fillBlock
void TextDocumentModel::fillBlock(const QTextBlock &block, QStandardItem *parent)
{
for (auto it = block.begin(); it != block.end(); ++it) {
QStandardItem *item = new QStandardItem(tr("Fragment: %1").arg(it.fragment().text()));
const QRectF b = m_document->documentLayout()->blockBoundingRect(block);
appendRow(parent, item, it.fragment().charFormat(), b);
if (!block.layout())
continue;
#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
foreach (const auto &range, block.layout()->formats()) {
const auto start = std::max(range.start, it.fragment().position() - block.position());
const auto end = std::min(range.start + range.length,
it.fragment().position() + it.fragment().length()
- block.position());
if (start >= end)
continue;
auto child
= new QStandardItem(tr("Layout Range: %1").arg(it.fragment().text().mid(start,
end
-start)));
appendRow(item, child, range.format, QRectF());
}
#endif
}
}
示例4: spatiumChanged
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();
}
}
示例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: visitBlock
virtual void visitBlock(QTextBlock &block, const QTextCursor &caret)
{
m_formats.clear();
m_cursors.clear();
for (QTextBlock::iterator it = block.begin(); it != block.end(); ++it) {
QTextCursor fragmentSelection(caret);
fragmentSelection.setPosition(it.fragment().position());
fragmentSelection.setPosition(it.fragment().position() + it.fragment().length(), QTextCursor::KeepAnchor);
if (fragmentSelection.anchor() >= fragmentSelection.position()) {
continue;
}
visitFragmentSelection(fragmentSelection);
}
QTextCursor cursor(caret);
cursor.mergeBlockFormat(m_deltaBlockFormat);
cursor.mergeBlockCharFormat(m_deltaCharFormat);
QList<QTextCharFormat>::Iterator it = m_formats.begin();
foreach(QTextCursor cursor, m_cursors) {
cursor.setCharFormat(*it);
++it;
}
示例7: fillBlock
void TextDocumentModel::fillBlock(const QTextBlock &block, QStandardItem *parent)
{
for (QTextBlock::iterator it = block.begin(); it != block.end(); ++it) {
QStandardItem *item = new QStandardItem(tr("Fragment: %1").arg(it.fragment().text()));
const QRectF b = m_document->documentLayout()->blockBoundingRect(block);
appendRow(parent, item, it.fragment().charFormat(), b);
}
}
示例8: processUpdates
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();
}
}
示例9: processDocumentContentsChange
void FlatTextarea::processDocumentContentsChange(int position, int charsAdded) {
int32 emojiPosition = 0, emojiLen = 0;
const EmojiData *emoji = 0;
QTextDocument *doc(document());
while (true) {
int32 start = position, end = position + charsAdded;
QTextBlock from = doc->findBlock(start), till = doc->findBlock(end);
if (till.isValid()) till = till.next();
for (QTextBlock b = from; b != till; b = b.next()) {
for (QTextBlock::Iterator iter = b.begin(); !iter.atEnd(); ++iter) {
QTextFragment fragment(iter.fragment());
if (!fragment.isValid()) continue;
int32 fp = fragment.position(), fe = fp + fragment.length();
if (fp >= end || fe <= start) {
continue;
}
QString t(fragment.text());
const QChar *ch = t.constData(), *e = ch + t.size();
for (; ch != e; ++ch) {
emoji = emojiFromText(ch, e, emojiLen);
if (emoji) {
emojiPosition = fp + (ch - t.constData());
break;
}
if (ch + 1 < e && ch->isHighSurrogate() && (ch + 1)->isLowSurrogate()) ++ch;
}
if (emoji) break;
}
if (emoji) break;
}
if (emoji) {
if (!document()->pageSize().isNull()) {
document()->setPageSize(QSizeF(0, 0));
}
QTextCursor c(doc->docHandle(), emojiPosition);
c.setPosition(emojiPosition + emojiLen, QTextCursor::KeepAnchor);
int32 removedUpto = c.position();
insertEmoji(emoji, c);
charsAdded -= removedUpto - position;
position = emojiPosition + 1;
emoji = 0;
emojiPosition = 0;
} else {
break;
}
}
}
示例10: writeAutomaticStyles
void OdtWriter::writeAutomaticStyles(const QTextDocument* document)
{
m_xml.writeStartElement(QString::fromLatin1("office:automatic-styles"));
QVector<QTextFormat> formats = document->allFormats();
// Find all used styles
QVector<int> text_styles;
QVector<int> paragraph_styles;
int index = 0;
for (QTextBlock block = document->begin(); block.isValid(); block = block.next()) {
index = block.blockFormatIndex();
if (!paragraph_styles.contains(index)) {
int heading = block.blockFormat().property(QTextFormat::UserProperty).toInt();
if (!heading) {
paragraph_styles.append(index);
} else {
m_styles.insert(index, QString("Heading-%1").arg(heading));
}
}
for (QTextBlock::iterator iter = block.begin(); !(iter.atEnd()); ++iter) {
index = iter.fragment().charFormatIndex();
if (!text_styles.contains(index) && formats.at(index).propertyCount()) {
text_styles.append(index);
}
}
}
// Write text styles
int text_style = 1;
for (int i = 0; i < text_styles.size(); ++i) {
int index = text_styles.at(i);
const QTextFormat& format = formats.at(index);
QString name = QString::fromLatin1("T") + QString::number(text_style);
if (writeTextStyle(format.toCharFormat(), name)) {
m_styles.insert(index, name);
++text_style;
}
}
// Write paragraph styles
int paragraph_style = 1;
for (int i = 0; i < paragraph_styles.size(); ++i) {
int index = paragraph_styles.at(i);
const QTextFormat& format = formats.at(index);
QString name = QString::fromLatin1("P") + QString::number(paragraph_style);
if (writeParagraphStyle(format.toBlockFormat(), name)) {
m_styles.insert(index, name);
++paragraph_style;
} else {
m_styles.insert(index, "Normal");
}
}
m_xml.writeEndElement();
}
示例11: caret
FontDia::FontDia(QTextCursor* cursor, QWidget* parent)
: KDialog(parent),
m_cursor(cursor)
{
//First find out if we have more than one charFormat in our selection. If so, m_initialFormat/m_style will get initialised with the charFormat at the cursor's position. The tabs will get informed of this.
if (m_cursor->hasSelection()) {
int begin = qMin(m_cursor->anchor(), m_cursor->position());
int end = qMax(m_cursor->anchor(), m_cursor->position());
QTextBlock block = m_cursor->block().document()->findBlock(begin);
m_uniqueFormat = true;
QTextCursor caret(*m_cursor);
caret.setPosition(begin+1);
m_initialFormat = caret.charFormat();
while (block.isValid() && block.position() < end) {
QTextBlock::iterator iter = block.begin();
while (! iter.atEnd()) {
QTextFragment fragment = iter.fragment();
if (fragment.position() >= end)
break;
if (fragment.position() + fragment.length() <= begin) {
iter++;
continue;
}
if (!(m_uniqueFormat = (fragment.charFormat() == m_initialFormat)))
break;
iter++;
}
if (!m_uniqueFormat)
break;
block = block.next();
}
}
else {
m_initialFormat = cursor->charFormat();
m_uniqueFormat = true;
}
setCaption(i18n("Select Font"));
setModal(true);
setButtons(Ok | Cancel | Reset | Apply);
setDefaultButton(Ok);
m_characterGeneral = new CharacterGeneral(this, m_uniqueFormat);
m_characterGeneral->hideStyleName(true);
setMainWidget(m_characterGeneral);
connect(this, SIGNAL(applyClicked()), this, SLOT(slotApply()));
connect(this, SIGNAL(okClicked()), this, SLOT(slotOk()));
connect(this, SIGNAL(resetClicked()), this, SLOT(slotReset()));
initTabs();
}
示例12: getMentionHashtagBotCommandPart
QString FlatTextarea::getMentionHashtagBotCommandPart(bool &start) const {
start = false;
int32 pos = textCursor().position();
if (textCursor().anchor() != pos) return QString();
// check mention / hashtag / bot command
QTextDocument *doc(document());
QTextBlock block = doc->findBlock(pos);
for (QTextBlock::Iterator iter = block.begin(); !iter.atEnd(); ++iter) {
QTextFragment fr(iter.fragment());
if (!fr.isValid()) continue;
int32 p = fr.position(), e = (p + fr.length());
if (p >= pos || e < pos) continue;
QTextCharFormat f = fr.charFormat();
if (f.isImageFormat()) continue;
bool mentionInCommand = false;
QString t(fr.text());
for (int i = pos - p; i > 0; --i) {
if (t.at(i - 1) == '@') {
if ((pos - p - i < 1 || t.at(i).isLetter()) && (i < 2 || !(t.at(i - 2).isLetterOrNumber() || t.at(i - 2) == '_'))) {
start = (i == 1) && (p == 0);
return t.mid(i - 1, pos - p - i + 1);
} else if ((pos - p - i < 1 || t.at(i).isLetter()) && i > 2 && (t.at(i - 2).isLetterOrNumber() || t.at(i - 2) == '_') && !mentionInCommand) {
mentionInCommand = true;
--i;
continue;
}
return QString();
} else if (t.at(i - 1) == '#') {
if (i < 2 || !(t.at(i - 2).isLetterOrNumber() || t.at(i - 2) == '_')) {
start = (i == 1) && (p == 0);
return t.mid(i - 1, pos - p - i + 1);
}
return QString();
} else if (t.at(i - 1) == '/') {
if (i < 2) {
start = (i == 1) && (p == 0);
return t.mid(i - 1, pos - p - i + 1);
}
return QString();
}
if (pos - p - i > 127 || (!mentionInCommand && (pos - p - i > 63))) break;
if (!t.at(i - 1).isLetterOrNumber() && t.at(i - 1) != '_') break;
}
break;
}
return QString();
}
示例13: hasText
bool FlatTextarea::hasText() const {
QTextDocument *doc(document());
QTextBlock from = doc->begin(), till = doc->end();
if (from == till) return false;
for (QTextBlock::Iterator iter = from.begin(); !iter.atEnd(); ++iter) {
QTextFragment fragment(iter.fragment());
if (!fragment.isValid()) continue;
if (!fragment.text().isEmpty()) return true;
}
return (from.next() != till);
}
示例14: 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();
}
示例15: fileNameFromDiffSpecification
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();
}