本文整理汇总了C++中QTextList::format方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextList::format方法的具体用法?C++ QTextList::format怎么用?C++ QTextList::format使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextList
的用法示例。
在下文中一共展示了QTextList::format方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: indentLessClicked
void TextTools::indentLessClicked()
{
QTextList* list = cursor()->currentList();
if (list == 0) {
QTextBlockFormat format = cursor()->blockFormat();
int indent = format.indent();
if (indent) {
indent--;
format.setIndent(indent);
cursor()->insertBlock(format);
updateText();
}
return;
}
QTextCharFormat format = cursor()->blockCharFormat();
QTextListFormat listFormat = list->format();
QTextBlock block = cursor()->block();
if (block.next().isValid())
block = block.next();
else {
block = QTextBlock();
}
cursor()->insertBlock(block.blockFormat());
cursor()->setCharFormat(block.charFormat());
updateText();
}
示例2: exp
QTextList *tryReadList(QTextList *list, const QString &line)
{
QTextList *listOut = list;
QRegularExpression exp("^( *)(\\d+\\.|\\*) (.*)$");
QRegularExpressionMatch match = exp.match(line);
if (match.hasMatch())
{
const int indent = match.captured(1).size() / 2 + 1;
const QString contents = match.captured(3);
const bool ordered = match.captured(2) != "*";
QTextListFormat fmt;
fmt.setStyle(ordered ? QTextListFormat::ListDecimal : QTextListFormat::ListDisc);
fmt.setIndent(indent);
if (!listOut || fmt != listOut->format())
{
listOut = cursor.insertList(fmt);
}
else
{
cursor.insertBlock();
}
readInlineText(contents);
listOut->add(cursor.block());
return listOut;
}
else
{
return 0;
}
}
示例3: sl_IncreaseListIndent_Triggered
void TextEditWidget::sl_IncreaseListIndent_Triggered() {
QTextCursor cursor = this->textField->textCursor();
QTextList *textList = cursor.currentList();
if (!textList) {return;}
QTextListFormat format = textList->format();
format.setIndent(format.indent() + 1);
textList->setFormat(format);
}
示例4: testListDelete
void TestChangeTrackedDelete::testListDelete()
{
TextTool *textTool = new TextTool(new MockCanvas);
KoTextEditor *textEditor = textTool->textEditor();
QVERIFY(textEditor);
QTextDocument *document = textEditor->document();
KTextDocumentLayout *layout = qobject_cast<KTextDocumentLayout*>(document->documentLayout());
QTextCursor *cursor = textEditor->cursor();
insertSampleList(document);
cursor->setPosition(16);
cursor->setPosition(152, QTextCursor::KeepAnchor);
ChangeTrackedDeleteCommand *delCommand = new ChangeTrackedDeleteCommand(ChangeTrackedDeleteCommand::NextChar, textTool);
textEditor->addCommand(delCommand);
QCOMPARE(document->characterAt(16).unicode(), (ushort)(QChar::ObjectReplacementCharacter));
// This is wierd. Without this loop present the succeeding call to inlineTextObject returs NULL. Why ??????
for (int i=0; i<document->characterCount(); i++) {
cursor->setPosition(i);
}
cursor->setPosition(17);
KDeleteChangeMarker *testMarker = dynamic_cast<KDeleteChangeMarker*>(layout->inlineTextObjectManager()->inlineTextObject(*cursor));
QTextDocumentFragment deleteData = KTextDocument(document).changeTracker()->elementById(testMarker->changeId())->deleteData();
QTextDocument deleteDocument;
QTextCursor deleteCursor(&deleteDocument);
deleteCursor.insertFragment(deleteData);
bool listFound = false;
for (int i=0; i < deleteDocument.characterCount(); i++) {
deleteCursor.setPosition(i);
if (deleteCursor.currentList()) {
listFound = true;
continue;
}
}
QVERIFY(listFound == true);
QTextList *deletedList = deleteCursor.currentList();
bool deletedListStatus = deletedList->format().boolProperty(KDeleteChangeMarker::DeletedList);
QVERIFY (deletedListStatus == true);
bool deletedListItemStatus;
deletedListItemStatus = deletedList->item(0).blockFormat().boolProperty(KDeleteChangeMarker::DeletedListItem);
QVERIFY(deletedListItemStatus == true);
deletedListItemStatus = deletedList->item(1).blockFormat().boolProperty(KDeleteChangeMarker::DeletedListItem);
QVERIFY(deletedListItemStatus == true);
deletedListItemStatus = deletedList->item(2).blockFormat().boolProperty(KDeleteChangeMarker::DeletedListItem);
QVERIFY(deletedListItemStatus == true);
deletedListItemStatus = deletedList->item(3).blockFormat().boolProperty(KDeleteChangeMarker::DeletedListItem);
QVERIFY(deletedListItemStatus == true);
deletedListItemStatus = deletedList->item(4).blockFormat().boolProperty(KDeleteChangeMarker::DeletedListItem);
QVERIFY(deletedListItemStatus == true);
delete textTool;
}
示例5: 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;
}
}
示例6: slotCursorPositionChanged
void MRichTextEdit::slotCursorPositionChanged()
{
QTextList *pTextList = f_textedit->textCursor().currentList();
if (m_lastBlockList && (pTextList == m_lastBlockList || (pTextList != 0 && m_lastBlockList != 0
&& pTextList->format().style() == m_lastBlockList->format().style())))
{
return;
}
m_lastBlockList = pTextList;
if (pTextList)
{
QTextListFormat lfmt = pTextList->format();
if (lfmt.style() == QTextListFormat::ListDisc)
{
f_list_bullet->setChecked(true);
f_list_ordered->setChecked(false);
}
else if (lfmt.style() == QTextListFormat::ListDecimal)
{
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(true);
}
else
{
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
}
else
{
f_list_bullet->setChecked(false);
f_list_ordered->setChecked(false);
}
}
示例7: orderedListClicked
void TextTools::orderedListClicked()
{
QTextCharFormat format = cursor()->charFormat();
QTextListFormat listFormat;
QTextList* list = cursor()->currentList();
if (list) {
listFormat = list->format();
int indent = listFormat.indent();
listFormat.setIndent(indent + 1);
}
listFormat.setStyle(QTextListFormat::ListDecimal);
cursor()->insertList(listFormat);
cursor()->setCharFormat(format);
updateText();
}
示例8: insertList
void MainWindow::insertList()
{
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
QTextList *list = cursor.currentList();
QTextListFormat listFormat;
if (list)
listFormat = list->format();
listFormat.setStyle(QTextListFormat::ListDisc);
listFormat.setIndent(listFormat.indent() + 1);
cursor.insertList(listFormat);
cursor.endEditBlock();
}
示例9: sl_ListButton_Triggered
void TextEditWidget::sl_ListButton_Triggered(QAction* action) {
if (!action) {
WARNING("Null pointer recieved");
return;
}
QTextListFormat::Style style = (QTextListFormat::Style)action->data().toInt();
QTextCursor cursor = this->textField->textCursor();
QTextList *textList = cursor.currentList();
if (!textList) {
WARNING("Wrong button state");
return;
}
QTextListFormat format = textList->format();
format.setStyle(style);
textList->setFormat(format);
}
示例10: insertList
void MainWindow::insertList()
{
QTextCursor cursor = editor->textCursor();
cursor.beginEditBlock();
QTextList *list = cursor.currentList();
//! [0]
listFormat = QTextListFormat()
if list:
listFormat = list.format()
listFormat.setIndent(listFormat.indent() + 1)
listFormat.setStyle(QTextListFormat.ListDisc)
cursor.insertList(listFormat)
//! [0]
cursor.endEditBlock();
}
示例11: setContinueNumbering
void KoList::setContinueNumbering(int level, bool enable)
{
Q_ASSERT(level > 0 && level <= 10);
level = qMax(qMin(level, 10), 1);
QBitArray bitArray = d->properties[ContinueNumbering].toBitArray();
if (bitArray.isEmpty())
bitArray.resize(10);
bitArray.setBit(level-1, enable);
d->properties[ContinueNumbering] = bitArray;
QTextList *textList = d->textLists.value(level-1).data();
if (!textList)
return;
QTextListFormat format = textList->format();
if (enable) {
format.setProperty(KListStyle::ContinueNumbering, true);
} else {
format.clearProperty(KListStyle::ContinueNumbering);
}
textList->setFormat(format);
}
示例12: testNumberedList
void TestDocumentLayout::testNumberedList()
{
initForNewTest("Base\nListItem1\nListItem2\nListItem3\nListItem4\nListItem5\nListItem6\nListItem6\nListItem7\nListItem8\nListItem9\nListItem10\nListItem11\nListItem12\n");
KoParagraphStyle style;
m_styleManager->add(&style);
QTextBlock block = m_doc->begin();
style.applyStyle(block);
block = block.next();
KoListStyle listStyle;
KoListLevelProperties llp;
llp.setStyle(KoListStyle::DecimalItem);
listStyle.setLevelProperties(llp);
style.setListStyle(&listStyle);
QTextList *previous = 0;
int i;
for (i = 1; i <= 9; i++) {
QVERIFY(block.isValid());
// qDebug() << "->" << block.text();
style.applyStyle(block);
QTextList *textList = block.textList();
QVERIFY(textList);
if (previous == 0) {
previous = textList;
} else {
QCOMPARE(textList, previous);
}
QCOMPARE(textList->format().intProperty(QTextListFormat::ListStyle), (int)(KoListStyle::DecimalItem));
block = block.next();
}
m_layout->layout();
QTextLayout *blockLayout = m_block.layout();
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
QTextBlock blok = m_doc->begin().next();
qreal indent = blok.layout()->lineAt(0).x();
QVERIFY(indent > 0.0);
for (i = 1; i <= 9; ++i) {
// qDebug() << "=>" << blok.text();
QTextList *textList = blok.textList();
QVERIFY(textList);
QCOMPARE(blok.layout()->lineAt(0).x(), indent); // all the same indent.
blok = blok.next();
}
// now make number of listitems be more than 10, so we use 2 digits.
for (i = 9; i <= 12; ++i) {
QVERIFY(block.isValid());
style.applyStyle(block);
// qDebug() << "->" << block.text();
block = block.next();
}
m_layout->layout();
blockLayout = m_block.layout();
QCOMPARE(blockLayout->lineAt(0).x(), 0.0);
blok = m_doc->begin().next();
qreal indent2 = blok.layout()->lineAt(0).x();
QVERIFY(indent2 > indent); // since it takes an extra digit
for (i = 2; i <= 12; ++i) {
// qDebug() << "=>" << blok.text();
QCOMPARE(blok.layout()->lineAt(0).x(), indent2); // all the same indent.
blok = blok.next();
}
// now to make sure the text is actually properly set.
block = m_doc->begin().next();
i = 1;
while (block.isValid() && i < 13) {
KoTextBlockData *data = dynamic_cast<KoTextBlockData *>(block.userData());
QVERIFY(data);
QCOMPARE(data->counterText(), QString::number(i++));
block = block.next();
}
llp.setListItemSuffix(".");
llp.setStartValue(4);
listStyle.setLevelProperties(llp);
QTextCursor cursor(m_doc);
cursor.setPosition(10); // listItem1
QTextBlockFormat format = cursor.blockFormat();
format.setProperty(KoParagraphStyle::ListStartValue, 4);
cursor.setBlockFormat(format);
cursor.setPosition(40); // listItem4
format = cursor.blockFormat();
format.setProperty(KoParagraphStyle::ListStartValue, 12);
cursor.setBlockFormat(format);
// at this point we start numbering at 4. Have 4, 5, 6, 12, 13, 14, 15 etc
m_layout->layout();
// now to make sur the text is actually properly set.
block = m_doc->begin().next();
i = 4;
while (block.isValid() && i < 22) {
if (i == 7) {
//.........这里部分代码省略.........
示例13: 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";
}
//.........这里部分代码省略.........
示例14: testListStyle
void TestListStyle::testListStyle()
{
KListStyle ls;
KListLevelProperties llp = ls.levelProperties(2);
QCOMPARE(llp.level(), 2);
llp.setStyle(KListStyle::AlphaLowerItem);
KListLevelProperties llp2 = ls.levelProperties(2);
QVERIFY(llp2.style() != llp.style());
ls.setLevelProperties(llp);
QCOMPARE(llp.level(), 2);
QCOMPARE(llp.style(), KListStyle::AlphaLowerItem);
llp = ls.levelProperties(2);
QCOMPARE(llp.level(), 2);
QCOMPARE(llp.style(), KListStyle::AlphaLowerItem);
QTextDocument doc;
KTextDocument kodoc(&doc);
kodoc.setStyleManager(new KStyleManager);
QTextCursor cursor(&doc);
cursor.insertText("foo\nbar\nBaz\n");
QTextBlock block = doc.begin();
ls.applyStyle(block, 2);
QVERIFY(block.textList());
QTextList *textList = block.textList();
QTextListFormat format = textList->format();
QCOMPARE(format.intProperty(QTextListFormat::ListStyle), (int)(KListStyle::AlphaLowerItem));
block = block.next();
QVERIFY(block.isValid());
ls.applyStyle(block, 2);
QVERIFY(block.textList());
QCOMPARE(block.textList(), textList);
ls.applyStyle(block, 10); // should set the properties of the only one that is set, level 1
QVERIFY(block.textList());
textList = block.textList();
format = textList->format();
QCOMPARE(format.intProperty(QTextListFormat::ListStyle), (int)(KListStyle::AlphaLowerItem));
// getting a properties without setting it doesn't change the list.
KListLevelProperties l4 = ls.levelProperties(4);
QCOMPARE(l4.level(), 4);
QCOMPARE(l4.displayLevel(), 0); // default
l4.setDisplayLevel(3);
QCOMPARE(l4.displayLevel(), 3);
QCOMPARE(ls.hasLevelProperties(4), false);
KListLevelProperties anotherL4 = ls.levelProperties(4);
QCOMPARE(anotherL4.level(), 4);
QCOMPARE(anotherL4.displayLevel(), 0); // default
QCOMPARE(ls.hasLevelProperties(4), false);
QCOMPARE(ls.hasLevelProperties(5), false);
// new levels are a copy of the existing level.
KListLevelProperties l5 = ls.levelProperties(5);
QCOMPARE(l5.displayLevel(), 0);
QCOMPARE(l5.style(), KListStyle::AlphaLowerItem);
QCOMPARE(l5.indent(), 0.);
}
示例15: emitBlock
void HtmlExporter::emitBlock( const QTextBlock &block )
{
// save and later restore, in case we 'change' the default format by
// emitting block char format information
// NOTE the bottom line is commented, to use default charFormat, which can be set from outside.
//QTextCharFormat oldDefaultCharFormat = defaultCharFormat;
QString blockTag;
bool isBlockQuote = false;
const QTextBlockFormat blockFormat = block.blockFormat();
if ( blockFormat.hasProperty( BilboTextFormat::IsBlockQuote ) &&
blockFormat.boolProperty( BilboTextFormat::IsBlockQuote ) ) {
isBlockQuote = true;
}
QTextList *list = block.textList();
if ( list ) {
if ( list->itemNumber( block ) == 0 ) { // first item? emit <ul> or appropriate
// qDebug() << "first item" << endl;
if ( isBlockQuote ) {
html += QLatin1String( "<blockquote>" );
}
const QTextListFormat format = list->format();
const int style = format.style();
switch ( style ) {
case QTextListFormat::ListDecimal:
html += QLatin1String( "<ol" );
break;
case QTextListFormat::ListDisc:
html += QLatin1String( "<ul" );
break;
case QTextListFormat::ListCircle:
html += QLatin1String( "<ul type=\"circle\"" );
break;
case QTextListFormat::ListSquare:
html += QLatin1String( "<ul type=\"square\"" );
break;
case QTextListFormat::ListLowerAlpha:
html += QLatin1String( "<ol type=\"a\"" );
break;
case QTextListFormat::ListUpperAlpha:
html += QLatin1String( "<ol type=\"A\"" );
break;
default:
html += QLatin1String( "<ul" ); // ### should not happen
//qDebug() << html;
}
/*
if (format.hasProperty(QTextFormat::ListIndent)) {
html += QLatin1String(" style=\"-qt-list-indent: ");
html += QString::number(format.indent());
html += QLatin1String(";\"");
}*/
html += QLatin1Char( '>' );
}
blockTag = QLatin1String( "li" );
// html += QLatin1String( "<li " );
}
// const QTextBlockFormat blockFormat = block.blockFormat();
if ( blockFormat.hasProperty( QTextFormat::BlockTrailingHorizontalRulerWidth ) ) {
if ( ( blockFormat.hasProperty( BilboTextFormat::IsHtmlTagSign ) ) &&
( blockFormat.boolProperty( BilboTextFormat::IsHtmlTagSign ) ) ) {
html += QLatin1String( "<!--split-->" );
return;
} else {
html += QLatin1String( "<hr" );
QTextLength width = blockFormat.lengthProperty( QTextFormat::BlockTrailingHorizontalRulerWidth );
if ( width.type() != QTextLength::VariableLength ) {
emitTextLength( "width", width );
} else {
html += QLatin1Char( ' ' );
}
html += QLatin1String( "/>" );
return;
}
}
const bool pre = blockFormat.nonBreakableLines();
if ( pre ) {
// qDebug() << "NonBreakable lines" << endl;
// if (list) {
// html += QLatin1Char('>');
// }
// html += QLatin1String( "<pre" );
// emitBlockAttributes( block );
// html += QLatin1Char( '>' );
blockTag = QLatin1String( "pre" );
} else {
if (!list) {
if ( isBlockQuote ) {
html += QLatin1String( "<blockquote>" );
}
if ( ( blockFormat.hasProperty( BilboTextFormat::HtmlHeading ) ) && (
//.........这里部分代码省略.........