本文整理汇总了C++中QAbstractTextDocumentLayout::blockBoundingRect方法的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractTextDocumentLayout::blockBoundingRect方法的具体用法?C++ QAbstractTextDocumentLayout::blockBoundingRect怎么用?C++ QAbstractTextDocumentLayout::blockBoundingRect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QAbstractTextDocumentLayout
的用法示例。
在下文中一共展示了QAbstractTextDocumentLayout::blockBoundingRect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: isBlockVisible
bool VMdEditor::isBlockVisible(const QTextBlock &p_block)
{
if (!p_block.isValid() || !p_block.isVisible()) {
return false;
}
QScrollBar *vbar = verticalScrollBar();
if (!vbar || !vbar->isVisible()) {
// No vertical scrollbar.
return true;
}
int height = rect().height();
QScrollBar *hbar = horizontalScrollBar();
if (hbar && hbar->isVisible()) {
height -= hbar->height();
}
QAbstractTextDocumentLayout *layout = document()->documentLayout();
QRectF rect = layout->blockBoundingRect(p_block);
int y = GETVISUALOFFSETY;
int rectHeight = (int)rect.height();
return (y >= 0 && y < height) || (y < 0 && y + rectHeight > 0);
}
示例2: paintEvent
void NumberBar::paintEvent(QPaintEvent *event)
{
QPainter painter(this);
QAbstractTextDocumentLayout *layout = edit->document()->documentLayout();
QTextBlock block = edit->document()->begin();
int vscrollValue = edit->verticalScrollBar()->value();
for (int i=1; block.isValid(); i++, block=block.next())
{
const QRectF rect = layout->blockBoundingRect(block);
if (block.isVisible()) {
painter.drawText(-1, qRound(rect.top())-vscrollValue+1,
width(), fontMetrics().height(), Qt::AlignRight, QString::number(i));
}
else if (rect.top() > vscrollValue)
{
break;
}
}
}
示例3: paintEvent
void QLineNumberArea::paintEvent(QPaintEvent *)
{
QAbstractTextDocumentLayout* layout = textEditor->document()->documentLayout();
int contentsY = textEditor->verticalScrollBar()->value();
qreal pageBottom = contentsY + textEditor->viewport()->height();
const QFontMetrics fm = fontMetrics();
const int ascent = fontMetrics().ascent() + 1;
int lineCount = 1;
QPainter p(this);
// textEditor->document()->
QTextBlock block = textEditor->document()->begin();
for(;block.isValid(); block = block.next(), lineCount++)
{
const QRectF boundingRect = layout->blockBoundingRect(block);
QPointF position = boundingRect.topLeft();
if(position.y() + boundingRect.height() < contentsY)
continue;
if(position.y() > pageBottom)
break;
const QString txt = QString::number(lineCount);
QFont f = p.font();
QFont q = p.font();
const int i = boldLines.indexOf(lineCount);
if(i!=-1)
{
//float r = ((float)i) / ((float)max_run_hist);
f.setBold(true);
p.setFont(f);
}
p.drawText(width() - fm.width(txt), qRound( position.y() ) - contentsY + ascent, txt);
if(i!=-1)
{
p.setFont(q);
}
}
}
示例4: paintEvent
/*! \brief Dessine la barre.
Cette méthode est appelée automatiquement dès que nécessaire.
\param pEvent <Inutilisé> Évènement de dessin
*/
void BarreNombres::paintEvent(QPaintEvent */*pEvent*/) {
QAbstractTextDocumentLayout *layout = m_edit->document()->documentLayout();
int contentsY = m_edit->verticalScrollBar()->value();
qreal pageBottom = contentsY + m_edit->viewport()->height();
const QFontMetrics fm = fontMetrics();
const int ascent = fontMetrics().ascent() + 1;
int lineCount = 1;
QPainter p(this);
for (QTextBlock block = m_edit->document()->begin(); block.isValid(); block = block.next(), lineCount++) {
const QRectF boundingRect = layout->blockBoundingRect(block);
QPointF position = boundingRect.topLeft();
if (position.y() + boundingRect.height() < contentsY)
continue;
if (position.y() > pageBottom)
break;
const QString txt = QString::number(lineCount);
p.drawText(width() - fm.width(txt), qRound(position.y()) - contentsY + ascent, txt);
}
}
示例5: paintEvent
void NumberBar::paintEvent( QPaintEvent * )
{
QAbstractTextDocumentLayout *layout = edit->document()->documentLayout();
int contentsY = edit->verticalScrollBar()->value();
qreal pageBottom = contentsY + edit->viewport()->height();
const QFontMetrics fm = fontMetrics();
const int ascent = fontMetrics().ascent() + 1; // height = ascent + descent + 1
int lineCount = 1;
QPainter p(this);
markedRect = QRect();
for ( QTextBlock block = edit->document()->begin();
block.isValid(); block = block.next(), ++lineCount )
{
const QRectF boundingRect = layout->blockBoundingRect( block );
QPointF position = boundingRect.topLeft();
if ( position.y() + boundingRect.height() < contentsY )
continue;
if ( position.y() > pageBottom )
break;
const QString txt = QString::number( lineCount );
p.drawText( width() - fm.width(txt), qRound( position.y() ) - contentsY + ascent, txt );
// marker
if ( markedLine == lineCount )
{
p.drawPixmap( 1, qRound( position.y() ) - contentsY, markerIcon );
markedRect = QRect( 1, qRound( position.y() ) - contentsY, markerIcon.width(), markerIcon.height() );
}
}
}
示例6: paintEvent
void QFCompleterTextEditNumberBar::paintEvent(QPaintEvent */*event*/) {
QTextDocument* doc=editor->document();
QAbstractTextDocumentLayout *layout = doc->documentLayout();
qreal yPosition=editor->verticalScrollBar()->value();
qreal vpHeight=editor->viewport()->height();
QPainter p(this);
p.setFont(linenumberFont);
int linenumberWidth=QString::number(doc->blockCount()).size()*p.fontMetrics().width("0")+4;
int markerheight=p.fontMetrics().ascent()+2;
// set the width of the widget
setFixedWidth(linenumberWidth+markerWidth+2);
// first we draw the background
p.setBrush(QBrush(linenumberColumnColor));
p.setPen(QPen(linenumberColumnColor));
p.drawRect(0,0,width(),vpHeight);
p.setPen(QPen(markerColumnColor));
p.setBrush(QBrush(markerColumnColor));
p.drawRect(linenumberWidth,0,width()-linenumberWidth,vpHeight);
// reset the rect of all markers
QMutableMapIterator<int, itemData> i(markers);
while (i.hasNext()) {
i.next();
itemData d=i.value();
d.rect=QRect(0,0,0,0);
i.setValue(d);
}
// now we draw the line numbers
p.setPen(QPen(linenumberColor));
for (QTextBlock it = doc->begin(); it != doc->end(); it = it.next()) {
QRectF brect=layout->blockBoundingRect(it);
qreal bottompos=brect.y()+brect.height();
markerheight=brect.height()-8;
// we end this loop if the current block lies below the viewport
if (brect.y() > yPosition+ vpHeight)
break;
// if we are inside the viewport, we have to paint a line number for this line
if (bottompos >= yPosition) {
QString txt = QString::number(it.blockNumber()+1);
p.drawText(1, brect.y()-yPosition, linenumberWidth-2, brect.height(), Qt::AlignRight|Qt::AlignVCenter, txt);
if (markers.contains(it.blockNumber()+1)) {
itemData d=markers[it.blockNumber()+1];
QRect markerrect=QRect(linenumberWidth+2, brect.y()-yPosition+4, width()-linenumberWidth-4, markerheight);
markers[it.blockNumber()+1].rect=markerrect;
if (d.type==mtInfo) {
//p.drawImage(linenumberWidth+2, brect.y()-yPosition, QIcon(":/event_info.png"));
p.setBrush(infoMarkerColor);
QPen pe=p.pen();
pe.setColor(QColor("black"));
pe.setCosmetic(true);
pe.setWidth(1);
p.setPen(pe);
p.drawRect(markerrect);
} else if (d.type==mtError) {
//p.drawImage(linenumberWidth+2, brect.y()-yPosition, QIcon(":/event_error.png"));
p.setBrush(errorMarkerColor);
QPen pe=p.pen();
pe.setColor(QColor("black"));
pe.setCosmetic(true);
pe.setWidth(1);
p.setPen(pe);
p.drawRect(markerrect);
} else {
//p.drawImage(linenumberWidth+2, brect.y()-yPosition, QIcon(":/event_warning.png"));
p.setBrush(warningMarkerColor);
QPen pe=p.pen();
pe.setColor(QColor("black"));
pe.setCosmetic(true);
pe.setWidth(1);
p.setPen(pe);
p.drawRect(markerrect);
}
}
}
}
}
示例7: makeBlockVisible
void VMdEditor::makeBlockVisible(const QTextBlock &p_block)
{
if (!p_block.isValid() || !p_block.isVisible()) {
return;
}
QScrollBar *vbar = verticalScrollBar();
if (!vbar || (vbar->minimum() == vbar->maximum())) {
// No vertical scrollbar. No need to scroll.
return;
}
int height = rect().height();
QScrollBar *hbar = horizontalScrollBar();
if (hbar && (hbar->minimum() != hbar->maximum())) {
height -= hbar->height();
}
bool moved = false;
QAbstractTextDocumentLayout *layout = document()->documentLayout();
QRectF rect = layout->blockBoundingRect(p_block);
int y = GETVISUALOFFSETY;
int rectHeight = (int)rect.height();
// Handle the case rectHeight >= height.
if (rectHeight >= height) {
if (y < 0) {
// Need to scroll up.
while (y + rectHeight < height && vbar->value() > vbar->minimum()) {
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
} else if (y > 0) {
// Need to scroll down.
while (y > 0 && vbar->value() < vbar->maximum()) {
moved = true;
vbar->setValue(vbar->value() + vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (y < 0) {
// One step back.
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
}
}
if (moved) {
qDebug() << "scroll to make huge block visible";
}
return;
}
while (y < 0 && vbar->value() > vbar->minimum()) {
moved = true;
vbar->setValue(vbar->value() - vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (moved) {
qDebug() << "scroll page down to make block visible";
return;
}
while (y + rectHeight > height && vbar->value() < vbar->maximum()) {
moved = true;
vbar->setValue(vbar->value() + vbar->singleStep());
rect = layout->blockBoundingRect(p_block);
rectHeight = (int)rect.height();
y = GETVISUALOFFSETY;
}
if (moved) {
qDebug() << "scroll page up to make block visible";
}
}