本文整理汇总了C++中QTextDocument::findBlockByLineNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextDocument::findBlockByLineNumber方法的具体用法?C++ QTextDocument::findBlockByLineNumber怎么用?C++ QTextDocument::findBlockByLineNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextDocument
的用法示例。
在下文中一共展示了QTextDocument::findBlockByLineNumber方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getInputString
QString PythonConsoleViewImpl::getInputString()
{
QTextDocument* doc = document();
QString line = doc->findBlockByLineNumber(doc->lineCount() - 1).text();
line.remove(0, inputColumnOffset);
return line;
}
示例2: findBlockByLineNumber
QTextBlock QTextDocumentProto::findBlockByLineNumber(int lineNumber) const
{
QTextDocument *item = qscriptvalue_cast<QTextDocument*>(thisObject());
if (item)
return item->findBlockByLineNumber(lineNumber);
return QTextBlock();
}
示例3: paintEvent
void CodeFoldingPanel::paintEvent(QPaintEvent *e)
{
QTextDocument *doc = editorWidget()->document();
TextDocumentLayout *documentLayout = qobject_cast<TextDocumentLayout*>(doc->documentLayout());
if(!documentLayout)
return;
QPalette pal = areaWidget()->palette();
pal.setCurrentColorGroup(QPalette::Active);
QPainter painter(this);
const QFontMetrics fm(areaWidget()->font());
const int collapseColumnWidth = d->m_codeFoldingVisible ? foldBoxWidth(fm): 0;
const int extraAreaWidth = d->m_extraArea->width() - collapseColumnWidth;
painter.fillRect(e->rect(), pal.color(QPalette::Background));
QTextBlock block = editorWidget()->firstVisibleBlock();
int blockNumber = block.blockNumber();
qreal top = editorWidget()->blockBoundingGeometry(block).translated(editorWidget()->contentOffset()).top();
qreal bottom = top;
while (block.isValid() && top <= e->rect().bottom()) {
top = bottom;
const qreal height = editorWidget()->blockBoundingRect(block).height();
bottom = top + height;
QTextBlock nextBlock = block.next();
QTextBlock nextVisibleBlock = nextBlock;
int nextVisibleBlockNumber = blockNumber + 1;
if (!nextVisibleBlock.isVisible()) {
// invisible blocks do have zero line count
nextVisibleBlock = doc->findBlockByLineNumber(nextVisibleBlock.firstLineNumber());
nextVisibleBlockNumber = nextVisibleBlock.blockNumber();
}
if (bottom < e->rect().top()) {
block = nextVisibleBlock;
blockNumber = nextVisibleBlockNumber;
continue;
}
painter.setPen(pal.color(QPalette::Dark));
painter.save();
painter.setRenderHint(QPainter::Antialiasing, false);
int extraAreaHighlightFoldBlockNumber = -1;
int extraAreaHighlightFoldEndBlockNumber = -1;
bool endIsVisible = false;
if (!d->m_highlightBlocksInfo.isEmpty()) {
extraAreaHighlightFoldBlockNumber = d->m_highlightBlocksInfo.open.last();
extraAreaHighlightFoldEndBlockNumber = d->m_highlightBlocksInfo.close.first();
endIsVisible = doc->findBlockByNumber(extraAreaHighlightFoldEndBlockNumber).isVisible();
// QTextBlock before = doc->findBlockByNumber(extraAreaHighlightCollapseBlockNumber-1);
// if (TextBlockUserData::hasCollapseAfter(before)) {
// extraAreaHighlightCollapseBlockNumber--;
// }
}
TextBlockUserData *nextBlockUserData = TextDocumentLayout::testUserData(nextBlock);
bool drawBox = nextBlockUserData
&& TextDocumentLayout::foldingIndent(block) < nextBlockUserData->foldingIndent();
bool active = blockNumber == extraAreaHighlightFoldBlockNumber;
bool drawStart = active;
bool drawEnd = blockNumber == extraAreaHighlightFoldEndBlockNumber || (drawStart && !endIsVisible);
bool hovered = blockNumber >= extraAreaHighlightFoldBlockNumber
&& blockNumber <= extraAreaHighlightFoldEndBlockNumber;
int boxWidth = foldBoxWidth(fm);
if (hovered) {
int itop = qRound(top);
int ibottom = qRound(bottom);
QRect box = QRect(extraAreaWidth + 1, itop, boxWidth - 2, ibottom - itop);
drawRectBox(&painter, box, drawStart, drawEnd, pal);
}
if (drawBox) {
bool expanded = nextBlock.isVisible();
int size = boxWidth/4;
QRect box(extraAreaWidth + size, top + size,
2 * (size) + 1, 2 * (size) + 1);
d->drawFoldingMarker(&painter, pal, box, expanded, active, hovered);
}
painter.restore();
block = nextVisibleBlock;
blockNumber = nextVisibleBlockNumber;
}
}