本文整理汇总了C++中QTextBlock::textList方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::textList方法的具体用法?C++ QTextBlock::textList怎么用?C++ QTextBlock::textList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::textList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: appendFragment
int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex)
{
QTextDocumentPrivate::FragmentIterator fragIt = src->find(pos);
const QTextFragmentData * const frag = fragIt.value();
Q_ASSERT(objectIndex == -1
|| (frag->size_array[0] == 1 && src->formatCollection()->format(frag->format).objectIndex() != -1));
int charFormatIndex;
if (forceCharFormat)
charFormatIndex = primaryCharFormatIndex;
else
charFormatIndex = convertFormatIndex(frag->format, objectIndex);
const int inFragmentOffset = qMax(0, pos - fragIt.position());
int charsToCopy = qMin(int(frag->size_array[0] - inFragmentOffset), endPos - pos);
QTextBlock nextBlock = src->blocksFind(pos + 1);
int blockIdx = -2;
if (nextBlock.position() == pos + 1) {
blockIdx = convertFormatIndex(nextBlock.blockFormat());
} else if (pos == 0 && insertPos == 0) {
dst->setBlockFormat(dst->blocksBegin(), dst->blocksBegin(), convertFormat(src->blocksBegin().blockFormat()).toBlockFormat());
dst->setCharFormat(-1, 1, convertFormat(src->blocksBegin().charFormat()).toCharFormat());
}
QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy);
if (txtToInsert.length() == 1
&& (txtToInsert.at(0) == QChar::ParagraphSeparator
|| txtToInsert.at(0) == QTextBeginningOfFrame
|| txtToInsert.at(0) == QTextEndOfFrame
)
) {
dst->insertBlock(txtToInsert.at(0), insertPos, blockIdx, charFormatIndex);
++insertPos;
} else {
if (nextBlock.textList()) {
QTextBlock dstBlock = dst->blocksFind(insertPos);
if (!dstBlock.textList()) {
// insert a new text block with the block and char format from the
// source block to make sure that the following text fragments
// end up in a list as they should
int listBlockFormatIndex = convertFormatIndex(nextBlock.blockFormat());
int listCharFormatIndex = convertFormatIndex(nextBlock.charFormat());
dst->insertBlock(insertPos, listBlockFormatIndex, listCharFormatIndex);
++insertPos;
}
}
dst->insert(insertPos, txtToInsert, charFormatIndex);
const int userState = nextBlock.userState();
if (userState != -1)
dst->blocksFind(insertPos).setUserState(userState);
insertPos += txtToInsert.length();
}
return charsToCopy;
}
示例2: level
int KoList::level(const QTextBlock &block)
{
if (!block.textList())
return 0;
int l = block.blockFormat().intProperty(KParagraphStyle::ListLevel);
if (!l) { // not a numbered-paragraph
QTextListFormat format = block.textList()->format();
l = format.intProperty(KListStyle::Level);
}
return l;
}
示例3: updateStoredList
void KoList::updateStoredList(const QTextBlock &block)
{
if (block.textList()) {
int level = block.textList()->format().property(KListStyle::Level).toInt();
QTextList *textList = block.textList();
QTextListFormat format = textList->format();
format.setProperty(KListStyle::ListId, (KListStyle::ListIdType)(textList));
textList->setFormat(format);
d->textLists[level-1] = textList;
d->textListIds[level-1] = (KListStyle::ListIdType)textList;
}
}
示例4: visit
void visit(QTextBlock &block) const {
QTextBlockFormat format = block.blockFormat();
// TODO make the 10 configurable.
format.setLeftMargin(qMax(qreal(0.0), format.leftMargin() - 10));
if (block.textList()) {
const QTextListFormat listFormat = block.textList()->format();
if (format.leftMargin() < listFormat.doubleProperty(KoListStyle::Margin)) {
format.setLeftMargin(listFormat.doubleProperty(KoListStyle::Margin));
}
}
QTextCursor cursor(block);
cursor.setBlockFormat(format);
}
示例5: KoTextCommandBase
ChangeListLevelCommand::ChangeListLevelCommand(const QTextCursor &cursor, ChangeListLevelCommand::CommandType type,
int coef, KUndo2Command *parent)
: KoTextCommandBase(parent),
m_type(type),
m_coefficient(coef),
m_first(true)
{
setText(kundo2_i18n("Change List Level"));
int selectionStart = qMin(cursor.anchor(), cursor.position());
int selectionEnd = qMax(cursor.anchor(), cursor.position());
QTextBlock block = cursor.block().document()->findBlock(selectionStart);
bool oneOf = (selectionStart == selectionEnd); //ensures the block containing the cursor is selected in that case
while (block.isValid() && ((block.position() < selectionEnd) || oneOf)) {
m_blocks.append(block);
if (block.textList()) {
m_lists.insert(m_blocks.size() - 1, KoTextDocument(block.document()).list(block.textList()));
Q_ASSERT(m_lists.value(m_blocks.size() - 1));
m_levels.insert(m_blocks.size() - 1, effectiveLevel(m_lists.value(m_blocks.size() - 1)->level(block)));
}
oneOf = false;
block = block.next();
}
}
示例6: testInvalidateLists
void TestDocumentLayout::testInvalidateLists()
{
initForNewTest("Base\nListItem1\nListItem2");
//KoParagraphStyle style;
KoListStyle listStyle;
KoListLevelProperties llp;
llp.setStyle(KoListStyle::DecimalItem);
listStyle.setLevelProperties(llp);
//style.setListStyle(&listStyle);
QTextBlock block = m_doc->begin().next();
QVERIFY(block.isValid());
listStyle.applyStyle(block);
block = block.next();
QVERIFY(block.isValid());
listStyle.applyStyle(block);
m_layout->layout();
// check the list items were done (semi) properly
block = m_doc->begin().next();
QVERIFY(block.textList());
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
QVERIFY(data->hasCounterData());
QTextCursor cursor(m_doc);
cursor.setPosition(10); // list item1
cursor.insertText("x");
QCOMPARE(data->hasCounterData(), true); // nothing changed
cursor.setPosition(22); // list item2
cursor.insertText("x");
QCOMPARE(data->hasCounterData(), true); // nothing changed
cursor.deleteChar();
QCOMPARE(data->hasCounterData(), true); // nothing changed
cursor.setPosition(25); // end of doc
cursor.insertBlock();
block = cursor.block();
QVERIFY(block.textList());
QVERIFY(block.userData() == 0);
QCOMPARE(data->hasCounterData(), false); // inserting a new block on this list made the list be invalidated
}
示例7: testBasicList
void TestDocumentLayout::testBasicList()
{
initForNewTest("Base\nListItem\nListItem2: The quick brown fox jums over the lazy dog.\nNormal\nNormal");
KoParagraphStyle style;
QTextBlock block = m_doc->begin();
style.applyStyle(block);
block = block.next();
QVERIFY(block.isValid());
KoListStyle listStyle;
KoListLevelProperties level1;
level1.setStyle(KoListStyle::Bullet);
listStyle.setLevelProperties(level1);
style.setListStyle(&listStyle);
style.applyStyle(block); // make this a listStyle
QVERIFY(block.textList());
QCOMPARE(block.textList()->format().intProperty(QTextListFormat::ListStyle), (int) KoListStyle::Bullet);
block = block.next();
QVERIFY(block.isValid());
style.applyStyle(block); // make this a listStyle
m_layout->layout();
QTextLayout *blockLayout = m_block.layout();
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
block = m_doc->begin().next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 2
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
qreal counterSpacing = data->counterSpacing();
QVERIFY(counterSpacing > 0.);
// 12 is hardcoded to be the width of a discitem (taken from the default font):
QCOMPARE(blockLayout->lineAt(0).x(), 12.0 + counterSpacing);
block = block.next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 3
QCOMPARE(blockLayout->lineAt(0).x(), 12.0 + counterSpacing);
QVERIFY(blockLayout->lineCount() > 1);
QCOMPARE(blockLayout->lineAt(1).x(), 12.0 + counterSpacing); // make sure not only the first line is indented
block = block.next();
QVERIFY(block.isValid());
blockLayout = block.layout(); // parag 4
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
}
示例8: processBlock
QString TextDocumentSerializer::processBlock(QTextBlock block,
QTextFrame::iterator &it)
{
if(block.textList())
return processList(it);
else
return processBlockContent(block);
}
示例9: remove
void KoList::remove(const QTextBlock &block)
{
if (QTextList *textList = block.textList()) {
// invalidate the list before we remove the item
// (since the list might disappear if the block is the only item)
KoListPrivate::invalidateList(block);
textList->remove(block);
}
KoListPrivate::invalidate(block);
}
示例10: documentChanged
void KTextDocumentLayout::documentChanged(int position, int charsRemoved, int charsAdded)
{
Q_UNUSED(charsRemoved);
if (shapes().count() == 0) // nothing to do.
return;
/*
switch (document()->documentLayout()->property("KoTextRelayoutForPage").toInt()) {
case KTextShapeData::NormalState:
kDebug() << "KoTextRelayoutForPage in NormalState"; break;
case KTextShapeData::LayoutCopyShape:
kDebug() << "KoTextRelayoutForPage in LayoutCopyShape"; break;
case KTextShapeData::LayoutOrig:
kDebug() << "KoTextRelayoutForPage in LayoutOrig, skipping relayout"; break;
}
*/
if (document()->documentLayout()->property("KoTextRelayoutForPage").toInt() == KTextShapeData::LayoutOrig) {
// don't refresh if we relayout after a relayout-for-page
return;
}
int from = position;
const int to = from + charsAdded;
while (from < to) { // find blocks that have been added
QTextBlock block = document()->findBlock(from);
if (! block.isValid())
break;
if (from == block.position() && block.textList()) {
KTextBlockData *data = dynamic_cast<KTextBlockData*>(block.userData());
if (data)
data->setCounterWidth(-1); // invalidate whole list.
}
from = block.position() + block.length();
}
foreach (KShape *shape, shapes()) {
KTextShapeData *data = qobject_cast<KTextShapeData*>(shape->userData());
Q_ASSERT(data);
if (data && data->position() <= position && data->endPosition() >= position) {
// found our (first) shape to re-layout
data->foul();
m_state->interrupted = true;
scheduleLayout();
return;
}
}
示例11: processList
QString TextDocumentSerializer::processList(QTextFrame::iterator &it)
{
QString text;
QTextBlock block = it.currentBlock();
while(block.textList()){
text += processBlockContent(block);
++it;
block = it.currentBlock();
}
--it;
return QString("<ul>%1</ul>").arg(text);
}
示例12: processBlockContent
QString TextDocumentSerializer::processBlockContent(QTextBlock block)
{
QTextBlock::iterator it = block.begin();
QString text;
while(!it.atEnd()){
QTextFragment currentFragment = it.fragment();
if (currentFragment.isValid())
text += processFragment(currentFragment);
++it;
}
if(block.textList())
return QString("<li>%1</li>").arg(text);
else
return QString("%1<br>").arg(text);
}
示例13: testMultiLevel
void TestDocumentLayout::testMultiLevel()
{
initForNewTest("ListItem1\n");
KoListStyle listStyle;
KoListLevelProperties llp;
llp.setStyle(KoListStyle::DecimalItem);
llp.setLevel(3);
llp.setDisplayLevel(4); // we won't show a .0 at the end so this is truncated to 3
listStyle.setLevelProperties(llp);
QTextBlock block = m_doc->begin();
QVERIFY(block.isValid());
listStyle.applyStyle(block);
QVERIFY(block.textList());
m_layout->layout();
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
QVERIFY(data->hasCounterData());
QCOMPARE(data->counterText(), QString("1.1.1"));
}
示例14: document
QHash<QTextList *, QString> KoTextWriter::saveListStyles(QTextBlock block, int to)
{
QHash<KoList *, QString> generatedLists;
QHash<QTextList *, QString> listStyles;
KoTextDocument document(block.document());
for (;block.isValid() && ((to == -1) || (block.position() < to)); block = block.next()) {
QTextList *textList = block.textList();
if (!textList)
continue;
if (KoList *list = document.list(block)) {
if (generatedLists.contains(list)) {
if (!listStyles.contains(textList))
listStyles.insert(textList, generatedLists.value(list));
continue;
}
KoListStyle *listStyle = list->style();
bool automatic = listStyle->styleId() == 0;
KoGenStyle style(automatic ? KoGenStyle::StyleListAuto : KoGenStyle::StyleList);
listStyle->saveOdf(style);
QString generatedName = d->context.mainStyles().lookup(style, listStyle->name(), KoGenStyles::AllowDuplicates);
listStyles[textList] = generatedName;
generatedLists.insert(list, generatedName);
} else {
if (listStyles.contains(textList))
continue;
KoListLevelProperties llp = KoListLevelProperties::fromTextList(textList);
KoGenStyle style(KoGenStyle::StyleListAuto);
KoListStyle listStyle;
listStyle.setLevelProperties(llp);
listStyle.saveOdf(style);
QString generatedName = d->context.mainStyles().lookup(style, listStyle.name());
listStyles[textList] = generatedName;
}
}
return listStyles;
}
示例15: processFrame
QString TextDocumentSerializer::processFrame(QTextFrame *frame)
{
QString text;
QTextFrame::iterator it = frame->begin();
while(!it.atEnd()){
QTextFrame *childFrame = it.currentFrame();
QTextBlock childBlock = it.currentBlock();
if(childFrame)
text += processFrame(childFrame);
else if(childBlock.isValid()){
if(childBlock.textList())
text = removeTrailingLineBreaks(text);
text += processBlock(childBlock, it);
}
++it;
}
text = removeTrailingLineBreaks(text);
return text;
}