本文整理汇总了C++中QTextDocument::firstBlock方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::firstBlock方法的具体用法?C++ QTextDocument::firstBlock怎么用?C++ QTextDocument::firstBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::firstBlock方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: updatePreview
void CppCodeStylePreferencesWidget::updatePreview()
{
CppCodeStylePreferences *cppCodeStylePreferences = m_preferences
? m_preferences
: CppToolsSettings::instance()->cppCodeStyle();
const CppCodeStyleSettings ccss = cppCodeStylePreferences->currentCodeStyleSettings();
const TextEditor::TabSettings ts = cppCodeStylePreferences->currentTabSettings();
QtStyleCodeFormatter formatter(ts, ccss);
foreach (TextEditor::SnippetEditorWidget *preview, m_previews) {
preview->setTabSettings(ts);
preview->setCodeStyle(cppCodeStylePreferences);
QTextDocument *doc = preview->document();
formatter.invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
preview->indenter()->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
applyRefactorings(doc, preview, ccss);
tc.endEditBlock();
}
示例2: updateFontIfUniform
void AnnotationSettings::updateFontIfUniform()
{
bool uniformFontFamily = true;
bool uniformSize = true;
bool uniformColor = true;
QTextDocument *doc = _ui->content->document();
QTextBlock b = doc->firstBlock();
QTextCharFormat fmt1;
bool first=true;
// Check all character formats in all blocks. If they are the same,
// we can reset the font for the wole document.
while(b.isValid()) {
for(const QTextLayout::FormatRange &fr : b.textFormats()) {
if(first) {
fmt1 = fr.format;
first = false;
} else {
uniformFontFamily &= fr.format.fontFamily() == fmt1.fontFamily();
uniformSize &= fr.format.fontPointSize() == fmt1.fontPointSize();
uniformColor &= fr.format.foreground() == fmt1.foreground();
}
}
b = b.next();
}
resetContentFont(uniformFontFamily, uniformSize, uniformColor);
}
示例3: firstBlock
QTextBlock QTextDocumentProto::firstBlock() const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->firstBlock();
return QTextBlock();
}
示例4: showTextBlock
// 遍历文本块
void MainWindow::showTextBlock()
{
QTextDocument *document = ui->textEdit->document();
// 获取文档的第一个文本块
QTextBlock block = document->firstBlock();
for(int i=0; i<document->blockCount(); i++){
qDebug() << tr("文本块%1,文本块首行行号为:%2,长度为:%3,内容为:")
.arg(i).arg(block.firstLineNumber()).arg(block.length())
<< block.text();
// 获取下一个文本块
block = block.next();
}
}
示例5: 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);
}
}
}
示例6: updatePreview
void CodeStyleEditor::updatePreview()
{
QTextDocument *doc = m_preview->document();
m_preview->indenter()->invalidateCache(doc);
QTextBlock block = doc->firstBlock();
QTextCursor tc = m_preview->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
m_preview->indenter()->indentBlock(doc, block, QChar::Null, m_codeStyle->currentTabSettings());
block = block.next();
}
tc.endEditBlock();
}
示例7: updatePreview
void NimCodeStylePreferencesWidget::updatePreview()
{
QTextDocument *doc = m_ui->previewTextEdit->document();
const TabSettings &ts = m_preferences
? m_preferences->currentTabSettings()
: TextEditorSettings::codeStyle()->tabSettings();
m_ui->previewTextEdit->textDocument()->setTabSettings(ts);
QTextBlock block = doc->firstBlock();
QTextCursor tc = m_ui->previewTextEdit->textCursor();
tc.beginEditBlock();
while (block.isValid()) {
m_ui->previewTextEdit->textDocument()->indenter()
->indentBlock(doc, block, QChar::Null, ts);
block = block.next();
}
tc.endEditBlock();
}
示例8: FormatDocument
void FormatDocument(QTextDocument &doc, const int lineHeight)
{
assert(lineHeight > 0);
if (platform::is_apple())
{
doc.setDocumentMargin(0);
return;
}
for (auto block = doc.firstBlock(); block.isValid(); block = block.next())
{
QTextCursor c(block);
auto f = c.blockFormat();
f.setLineHeight(lineHeight, QTextBlockFormat::FixedHeight);
c.setBlockFormat(f);
}
doc.setDocumentMargin(0);
}
示例9: documentChanged
/*! \reimp
*/
void TextDocumentLayout::documentChanged(int from, int /*charsRemoved*/, int charsAdded)
{
QTextDocument *doc = document();
int newBlockCount = doc->blockCount();
QTextBlock changeStartBlock = doc->findBlock(from);
QTextBlock changeEndBlock = doc->findBlock(qMax(0, from + charsAdded - 1));
if (changeStartBlock == changeEndBlock && newBlockCount == d->blockCount) {
QTextBlock block = changeStartBlock;
if (block.isValid() && block.layout()->lineCount()) {
QRectF oldBr = blockBoundingRect(block);
layoutBlock(block);
QRectF newBr = blockBoundingRect(block);
if (newBr.height() == oldBr.height()) {
if (!d->blockUpdate)
emit updateBlock(block);
return;
}
}
} else {
QTextBlock block = changeStartBlock;
do {
block.clearLayout();
if (block == changeEndBlock)
break;
block = block.next();
} while(block.isValid());
}
if (newBlockCount != d->blockCount) {
int changeEnd = changeEndBlock.blockNumber();
int blockDiff = newBlockCount - d->blockCount;
int oldChangeEnd = changeEnd - blockDiff;
if (d->maximumWidthBlockNumber > oldChangeEnd)
d->maximumWidthBlockNumber += blockDiff;
d->blockCount = newBlockCount;
if (d->blockCount == 1)
d->maximumWidth = blockWidth(doc->firstBlock());
if (!d->blockDocumentSizeChanged)
emit documentSizeChanged(documentSize());
if (blockDiff == 1 && changeEnd == newBlockCount -1 ) {
if (!d->blockUpdate)
{
QTextBlock b = changeStartBlock;
for(;;) {
emit updateBlock(b);
if (b == changeEndBlock)
break;
b = b.next();
}
}
return;
}
}
if (!d->blockUpdate)
emit update(QRectF(0., -doc->documentMargin(), 1000000000., 1000000000.)); // optimization potential
}
示例10: layoutBlock
void TextDocumentLayout::layoutBlock(const QTextBlock &block)
{
QTextDocument *doc = document();
qreal margin = doc->documentMargin();
qreal blockMaximumWidth = 0;
qreal height = 0;
QTextLayout *tl = block.layout();
QTextOption option = doc->defaultTextOption();
tl->setTextOption(option);
int extraMargin = 0;
if (option.flags() & QTextOption::AddSpaceForLineAndParagraphSeparators) {
QFontMetrics fm(block.charFormat().font());
extraMargin += fm.width(QChar(0x21B5));
}
tl->beginLayout();
qreal availableWidth = d->width;
if (availableWidth <= 0) {
availableWidth = qreal(INT_MAX); // similar to text edit with pageSize.width == 0
}
availableWidth -= 2*margin + extraMargin;
qreal indentMargin = 0;
while (1) {
QTextLine line = tl->createLine();
if (!line.isValid())
break;
line.setLeadingIncluded(true);
line.setLineWidth(availableWidth - indentMargin);
line.setPosition(QPointF(margin + indentMargin, height));
if(!height) //enter only in the first iteration
{
indentMargin = indentWidth(block);
}
height += line.height();
blockMaximumWidth = qMax(blockMaximumWidth, line.naturalTextWidth() + 2*margin);
}
tl->endLayout();
int previousLineCount = doc->lineCount();
const_cast<QTextBlock&>(block).setLineCount(block.isVisible() ? tl->lineCount() : 0);
int lineCount = doc->lineCount();
bool emitDocumentSizeChanged = previousLineCount != lineCount;
if (blockMaximumWidth > d->maximumWidth) {
// new longest line
d->maximumWidth = blockMaximumWidth;
d->maximumWidthBlockNumber = block.blockNumber();
emitDocumentSizeChanged = true;
} else if (block.blockNumber() == d->maximumWidthBlockNumber && blockMaximumWidth < d->maximumWidth) {
// longest line shrinking
QTextBlock b = doc->firstBlock();
d->maximumWidth = 0;
QTextBlock maximumBlock;
while (b.isValid()) {
qreal blockMaximumWidth = blockWidth(b);
if (blockMaximumWidth > d->maximumWidth) {
d->maximumWidth = blockMaximumWidth;
maximumBlock = b;
}
b = b.next();
}
if (maximumBlock.isValid()) {
d->maximumWidthBlockNumber = maximumBlock.blockNumber();
emitDocumentSizeChanged = true;
}
}
if (emitDocumentSizeChanged)// && !d->blockDocumentSizeChanged)
emit documentSizeChanged(documentSize());
emit updateBlock(block);
}
示例11: completionPrefixChanged
void LiteWordCompleter::completionPrefixChanged(QString prefix,bool force)
{
LiteCompleter::completionPrefixChanged(prefix,force);
if (m_bExternalMode) {
return;
}
if (!m_editor) {
return;
}
if (!m_bSearchSeparator) {
if (prefix.indexOf(".") >= 0) {
return;
}
}
bool isSep = false;
if (prefix.startsWith("@.")) {
isSep = true;
prefix = prefix.mid(1);
}
QTextCursor tc = m_editor->textCursor();
QTextDocument *doc = m_editor->document();
int maxNumber = tc.blockNumber();
int blockNumber = tc.blockNumber();
QTextBlock block = doc->firstBlock();
if (maxNumber < 500) {
maxNumber = 500;
} else {
int firstNumber = maxNumber-500;
if (firstNumber > 0) {
block = doc->findBlockByNumber(firstNumber);
}
}
QRegExp rx("([\\w\\-\\_\\.]+)");
Qt::CaseSensitivity cs = m_completer->caseSensitivity();
int count = 0;
while (block.isValid()) {
if (block.blockNumber() >= maxNumber) {
break;
}
if (block.blockNumber() == blockNumber) {
block = block.next();
continue;
}
QString line = block.text().trimmed();
if (!line.isEmpty()) {
int pos = 0;
while ((pos = rx.indexIn(line, pos)) != -1) {
QString cap = rx.cap(1);
if (cap.length() < 20 && cap.startsWith(prefix,cs)) {
if (isSep) {
cap = "@"+cap;
}
count++;
appendItem(cap,m_icon,true);
}
pos += rx.matchedLength();
}
}
block = block.next();
}
if (count > 0) {
this->updateCompleterModel();
this->showPopup();
}
}