本文整理汇总了C++中QTextBlock::blockFormat方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextBlock::blockFormat方法的具体用法?C++ QTextBlock::blockFormat怎么用?C++ QTextBlock::blockFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextBlock
的用法示例。
在下文中一共展示了QTextBlock::blockFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: textChanged
void NumberedTextView::textChanged( int pos, int removed, int added )
{
Q_UNUSED( pos );
if ( removed == 0 && added == 0 )
return;
QTextBlock block = highlight.block();
QTextBlockFormat fmt = block.blockFormat();
QColor bg = view->palette().base().color();
fmt.setBackground( bg );
highlight.setBlockFormat( fmt );
int lineCount = 1;
for ( QTextBlock block = view->document()->begin();
block.isValid(); block = block.next(), ++lineCount )
{
if ( lineCount == markedLine )
{
fmt = block.blockFormat();
QColor bg = Qt::red;
fmt.setBackground( bg.light(150) );
highlight = QTextCursor( block );
highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
highlight.setBlockFormat( fmt );
break;
}
}
}
示例2: 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;
}
示例3: highlightListItems
void MainWindow::highlightListItems()
{
QTextCursor cursor = editor->textCursor();
QTextList *list = cursor.currentList();
if (!list)
return;
cursor.beginEditBlock();
//! [0]
for (int index = 0; index < list->count(); ++index) {
QTextBlock listItem = list->item(index);
//! [0]
QTextBlockFormat newBlockFormat = listItem.blockFormat();
newBlockFormat.setBackground(Qt::lightGray);
QTextCursor itemCursor = cursor;
itemCursor.setPosition(listItem.position());
//itemCursor.movePosition(QTextCursor::StartOfBlock);
itemCursor.movePosition(QTextCursor::EndOfBlock,
QTextCursor::KeepAnchor);
itemCursor.setBlockFormat(newBlockFormat);
/*
//! [1]
processListItem(listItem);
//! [1]
*/
//! [2]
}
//! [2]
cursor.endEditBlock();
}
示例4: documentLayoutFinished
void TextContentsModelImpl::documentLayoutFinished()
{
QTextBlock block = d->textDocument->firstBlock();
d->entries.clear();
while (block.isValid())
{
QTextBlockFormat format = block.blockFormat();
if (format.hasProperty(KoParagraphStyle::OutlineLevel))
{
ContentsEntry entry;
entry.title = block.text();
entry.level = format.intProperty(KoParagraphStyle::OutlineLevel);
auto rootArea = d->layout->rootAreaForPosition(block.position());
if (rootArea) {
if (rootArea->page()) {
entry.pageNumber = rootArea->page()->visiblePageNumber();
entry.page = static_cast<KWPage*>(rootArea->page());
}
}
d->entries.append(entry);
}
block = block.next();
}
emit listContentsCompleted();
}
示例5: 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();
}
示例6: fontMetrics
template<> void
QConsoleWidget::_pf<void, UpdatePromptWidget>(
QConsoleWidget * thisp
) {
//TODO: UpdatePromptWidget
{
QFontMetricsF fontMetrics(
thisp->thisp->textCharFormat.font());
{
QTextDocument * doc = thisp->document();
QTextBlock textBlock =
doc->findBlock(thisp->promptEndPos_);
QTextCursor cursor_(textBlock);
QTextBlockFormat bf_ = textBlock.blockFormat();
float fh =
fontMetrics.height()
+1.55f;
thisp->thisp->setFixedHeight(fh);
thisp->thisp->setFixedWidth(fh);
bf_.setTextIndent( thisp->thisp->width() );
cursor_.setBlockFormat(bf_);
thisp->setTextCursor(cursor_);
}
}
_pf<void, UpdatePromptWidgetPositon>(thisp);
thisp->raise();
}
示例7: cursor
void KoTextWriter::Private::writeBlocks(QTextDocument *document, int from, int to, QHash<QTextList *, QString> &listStyles, QTextTable *currentTable, QTextList *currentList)
{
pairedInlineObjectsStackStack.push(currentPairedInlineObjectsStack);
currentPairedInlineObjectsStack = new QStack<KoInlineObject*>();
QTextBlock block = document->findBlock(from);
int sectionLevel = 0;
while (block.isValid() && ((to == -1) || (block.position() <= to))) {
QTextCursor cursor(block);
int frameType = cursor.currentFrame()->format().intProperty(KoText::SubFrameType);
if (frameType == KoText::AuxillaryFrameType) {
break; // we've reached the "end" (end/footnotes saved by themselves)
// note how NoteFrameType passes through here so the notes can
// call writeBlocks to save their contents.
}
QTextBlockFormat format = block.blockFormat();
if (format.hasProperty(KoParagraphStyle::SectionStartings)) {
QVariant v = format.property(KoParagraphStyle::SectionStartings);
QList<QVariant> sectionStarts = v.value<QList<QVariant> >();
foreach (const QVariant &sv, sectionStarts) {
KoSection* section = (KoSection*)(sv.value<void*>());
if (section) {
++sectionLevel;
section->saveOdf(context);
}
}
}
示例8: fillFrameIterator
void TextDocumentModel::fillFrameIterator(const QTextFrame::iterator &it, QStandardItem *parent)
{
if (QTextFrame *frame = it.currentFrame()) {
const QRectF b = m_document->documentLayout()->frameBoundingRect(frame);
QTextTable *table = qobject_cast<QTextTable *>(frame);
auto item = new QStandardItem;
if (table) {
item->setText(tr("Table"));
appendRow(parent, item, table->format(), b);
fillTable(table, item);
} else {
item->setText(tr("Frame"));
appendRow(parent, item, frame->frameFormat(), b);
fillFrame(frame, item);
}
}
const QTextBlock block = it.currentBlock();
if (block.isValid()) {
auto item = new QStandardItem;
item->setText(tr("Block: %1").arg(block.text()));
const QRectF b = m_document->documentLayout()->blockBoundingRect(block);
appendRow(parent, item, block.blockFormat(), b);
fillBlock(block, item);
}
}
示例9: remove
/*!
Removes the given \a block from the list.
\sa add(), removeItem()
*/
void QTextList::remove(const QTextBlock &block)
{
QTextBlockFormat fmt = block.blockFormat();
fmt.setIndent(fmt.indent() + format().indent());
fmt.setObjectIndex(-1);
block.docHandle()->setBlockFormat(block, block, fmt, QTextDocumentPrivate::SetFormat);
}
示例10: resizeEvent
void NoteEditWidget::resizeEvent(QResizeEvent *)
{
int screenWidth = width();
int screenHeight = height();
if (screenWidth > screenHeight) { // we have a classical landscape monitor
noteEditHeight = screenHeight - TextEditMargin;
noteEditWidth = static_cast<int>(noteEditHeight * NoteEditWidthMultiplier);
} else { // we have monitor standing in portrait
noteEditWidth = screenWidth - TextEditMargin;
noteEditHeight = static_cast<int>(noteEditWidth / NoteEditWidthMultiplier);
}
noteEditXPos = (screenWidth - noteEditWidth) / 2;
noteEditYPos = (screenHeight - noteEditHeight) / 2;
visualCover->setGeometry(0, 0, width(), height());
textEdit->setGeometry(noteEditXPos, noteEditYPos, noteEditWidth, noteEditHeight);
textEdit->setFocus();
textEdit->setFont(getFontForTextEditWith(noteEditWidth));
for (QTextBlock block = textEdit->document()->begin(); block.isValid(); block = block.next())
{
QTextCursor tc = QTextCursor(block);
QTextBlockFormat fmt = block.blockFormat();
fmt.setLineHeight(LineHeightPercentage, QTextBlockFormat::ProportionalHeight);
tc.setBlockFormat(fmt);
}
}
示例11: 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();
}
}
示例12: 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();
}
示例13: textChanged
void QLineNumberTextEdit::textChanged( int pos, int removed, int added )
{
return;
Q_UNUSED( pos );
#if 0
if ( removed == 0 && added == 0 )
return;
if(doHighlighting)
{
QTextBlock block = highlight.block();
QTextBlockFormat fmt = block.blockFormat();
QColor bg = view->palette().base().color();
fmt.setBackground( bg );
highlight.setBlockFormat( fmt );
int lineCount = 1;
for ( QTextBlock block = view->document()->begin();
block.isValid(); block = block.next(), ++lineCount ) {
// if ( lineCount == infoLine ) {
// fmt = block.blockFormat();
// QColor bg = view->palette().highlight().color().light(150);
// fmt.setBackground( bg );
// highlight = QTextCursor( block );
// highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
// highlight.setBlockFormat( fmt );
// break;
// } else if ( lineCount == warningLine ) {
// fmt = block.blockFormat();
// QColor bg = view->palette().highlight().color().light(100);
// fmt.setBackground( bg );
// highlight = QTextCursor( block );
// highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
// highlight.setBlockFormat( fmt );
// break;
// } else if ( lineCount == errorLine ) {
// fmt = block.blockFormat();
// QColor bg = view->palette().highlight().color().light(100);
// fmt.setBackground( bg );
// highlight = QTextCursor( block );
// highlight.movePosition( QTextCursor::EndOfBlock, QTextCursor::KeepAnchor );
// highlight.setBlockFormat( fmt );
// break;
// }
}
}
#endif
}
示例14: 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;
}
示例15: 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);
}