本文整理汇总了C++中QAbstractTextDocumentLayout类的典型用法代码示例。如果您正苦于以下问题:C++ QAbstractTextDocumentLayout类的具体用法?C++ QAbstractTextDocumentLayout怎么用?C++ QAbstractTextDocumentLayout使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAbstractTextDocumentLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: qwtUnscaleFont
/*!
Draw a text document into a rectangle
\param painter Painter
\param rect Traget rectangle
\param flags Alignments/Text flags, see QPainter::drawText()
\param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
int flags, const QTextDocument &text )
{
QTextDocument *txt = text.clone();
painter->save();
painter->setFont( txt->defaultFont() );
qwtUnscaleFont( painter );
txt->setDefaultFont( painter->font() );
txt->setPageSize( QSizeF( rect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = txt->documentLayout();
const double height = layout->documentSize().height();
double y = rect.y();
if ( flags & Qt::AlignBottom )
y += ( rect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( rect.height() - height ) / 2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->translate( rect.x(), y );
layout->draw( painter, context );
painter->restore();
delete txt;
}
示例2: mousePressEvent
void mousePressEvent(QMouseEvent *event)
{
QAbstractTextDocumentLayout *layout = m_document->documentLayout();
if (layout) {
m_anchor = layout->anchorAt(event->pos());
}
}
示例3: qRound
void QwtPainter::drawSimpleRichText(QPainter *painter, const QRect &rect,
int flags, QTextDocument &text)
{
const QRect scaledRect = d_metricsMap.layoutToDevice(rect, painter);
text.setPageSize(QSize(scaledRect.width(), QWIDGETSIZE_MAX));
QAbstractTextDocumentLayout* layout = text.documentLayout();
const int height = qRound(layout->documentSize().height());
int y = scaledRect.y();
if (flags & Qt::AlignBottom)
y += (scaledRect.height() - height);
else if (flags & Qt::AlignVCenter)
y += (scaledRect.height() - height)/2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor(QPalette::Text, painter->pen().color());
painter->save();
painter->translate(scaledRect.x(), y);
layout->draw(painter, context);
painter->restore();
}
示例4: p
void PsiTipLabel::paintEvent(QPaintEvent *)
{
QStylePainter p(this);
QStyleOptionFrame opt;
opt.init(this);
p.drawPrimitive(QStyle::PE_PanelTipLabel, opt);
p.end();
// stolen from QLabel::paintEvent
QPainter painter(this);
drawFrame(&painter);
QRect cr = contentsRect();
cr.adjust(margin, margin, -margin, -margin);
PsiRichText::ensureTextLayouted(doc, width() - 2*margin);
QAbstractTextDocumentLayout *layout = doc->documentLayout();
// QRect lr = rect();
QRect lr = cr;
QAbstractTextDocumentLayout::PaintContext context;
// Adjust the palette
context.palette = palette();
if (foregroundRole() != QPalette::Text && isEnabled())
context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
painter.save();
painter.translate(lr.x() + 1, lr.y() + 1);
painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1));
layout->draw(&painter, context);
painter.restore();
}
示例5: verticalScrollBar
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);
}
示例6: mouseReleaseEvent
void mouseReleaseEvent(QMouseEvent *event)
{
QAbstractTextDocumentLayout *layout = m_document->documentLayout();
if (layout) {
QString anchor = layout->anchorAt(event->pos());
if (anchor == m_anchor) {
m_toolTip->linkActivated(m_anchor, event);
}
m_anchor.clear();
}
}
示例7: QTextEdit
QT_BEGIN_NAMESPACE
ExpandingTextEdit::ExpandingTextEdit(QWidget *parent)
: QTextEdit(parent)
{
setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding));
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QAbstractTextDocumentLayout *docLayout = document()->documentLayout();
connect(docLayout, SIGNAL(documentSizeChanged(QSizeF)), SLOT(updateHeight(QSizeF)));
connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(reallyEnsureCursorVisible()));
m_minimumHeight = qRound(docLayout->documentSize().height()) + frameWidth() * 2;
}
示例8: qwtScreenResolution
/*!
Draw a text document into a rectangle
\param painter Painter
\param rect Traget rectangle
\param flags Alignments/Text flags, see QPainter::drawText()
\param text Text document
*/
void QwtPainter::drawSimpleRichText( QPainter *painter, const QRectF &rect,
int flags, const QTextDocument &text )
{
QTextDocument *txt = text.clone();
painter->save();
QRectF unscaledRect = rect;
if ( painter->font().pixelSize() < 0 )
{
const QSize res = qwtScreenResolution();
const QPaintDevice *pd = painter->device();
if ( pd->logicalDpiX() != res.width() ||
pd->logicalDpiY() != res.height() )
{
QTransform transform;
transform.scale( res.width() / double( pd->logicalDpiX() ),
res.height() / double( pd->logicalDpiY() ));
painter->setWorldTransform( transform, true );
unscaledRect = transform.inverted().mapRect(rect);
}
}
txt->setDefaultFont( painter->font() );
txt->setPageSize( QSizeF( unscaledRect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = txt->documentLayout();
const double height = layout->documentSize().height();
double y = unscaledRect.y();
if ( flags & Qt::AlignBottom )
y += ( unscaledRect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( unscaledRect.height() - height ) / 2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->translate( unscaledRect.x(), y );
layout->draw( painter, context );
painter->restore();
delete txt;
}
示例9: painter
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;
}
}
}
示例10: 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);
}
}
}
示例11: QSize
void
PlaylistLargeItemDelegate::drawRichText( QPainter* painter, const QRect& rect, int flags, QTextDocument& text ) const
{
text.setPageSize( QSize( rect.width(), QWIDGETSIZE_MAX ) );
QAbstractTextDocumentLayout* layout = text.documentLayout();
const int height = qRound( layout->documentSize().height() );
int y = rect.y();
if ( flags & Qt::AlignBottom )
y += ( rect.height() - height );
else if ( flags & Qt::AlignVCenter )
y += ( rect.height() - height ) / 2;
QAbstractTextDocumentLayout::PaintContext context;
context.palette.setColor( QPalette::Text, painter->pen().color() );
painter->save();
painter->translate( rect.x(), y );
layout->draw( painter, context );
painter->restore();
}
示例12: 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);
}
}
示例13: 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() );
}
}
}
示例14: 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);
}
}
}
}
}
示例15: Q_D
/*!\reimp
*/
void QLabel::paintEvent(QPaintEvent *)
{
Q_D(QLabel);
QStyle *style = QWidget::style();
QPainter painter(this);
drawFrame(&painter);
QRect cr = contentsRect();
cr.adjust(d->margin, d->margin, -d->margin, -d->margin);
int align = QStyle::visualAlignment(layoutDirection(), QFlag(d->align));
#ifndef QT_NO_MOVIE
if (d->movie) {
if (d->scaledcontents)
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap().scaled(cr.size()));
else
style->drawItemPixmap(&painter, cr, align, d->movie->currentPixmap());
}
else
#endif
if (d->isTextLabel) {
QRectF lr = d->layoutRect();
if (d->control) {
#ifndef QT_NO_SHORTCUT
const bool underline = (bool)style->styleHint(QStyle::SH_UnderlineShortcut, 0, this, 0);
if (d->shortcutId != 0
&& underline != d->shortcutCursor.charFormat().fontUnderline()) {
QTextCharFormat fmt;
fmt.setFontUnderline(underline);
d->shortcutCursor.mergeCharFormat(fmt);
}
#endif
d->ensureTextLayouted();
QAbstractTextDocumentLayout::PaintContext context;
QStyleOption opt(0);
opt.init(this);
if (!isEnabled() && style->styleHint(QStyle::SH_EtchDisabledText, &opt, this)) {
context.palette = palette();
context.palette.setColor(QPalette::Text, context.palette.light().color());
painter.save();
painter.translate(lr.x() + 1, lr.y() + 1);
painter.setClipRect(lr.translated(-lr.x() - 1, -lr.y() - 1));
QAbstractTextDocumentLayout *layout = d->control->document()->documentLayout();
layout->draw(&painter, context);
painter.restore();
}
// Adjust the palette
context.palette = palette();
if (foregroundRole() != QPalette::Text && isEnabled())
context.palette.setColor(QPalette::Text, context.palette.color(foregroundRole()));
painter.save();
painter.translate(lr.topLeft());
painter.setClipRect(lr.translated(-lr.x(), -lr.y()));
d->control->setPalette(context.palette);
d->control->drawContents(&painter, QRectF(), this);
painter.restore();
} else {
int flags = align;
if (d->hasShortcut) {
flags |= Qt::TextShowMnemonic;
QStyleOption opt;
opt.initFrom(this);
if (!style->styleHint(QStyle::SH_UnderlineShortcut, &opt, this))
flags |= Qt::TextHideMnemonic;
}
style->drawItemText(&painter, lr.toRect(), flags, palette(), isEnabled(), d->text, foregroundRole());
}
} else
#ifndef QT_NO_PICTURE
if (d->picture) {
QRect br = d->picture->boundingRect();
int rw = br.width();
int rh = br.height();
if (d->scaledcontents) {
painter.save();
painter.translate(cr.x(), cr.y());
painter.scale((double)cr.width()/rw, (double)cr.height()/rh);
painter.drawPicture(-br.x(), -br.y(), *d->picture);
painter.restore();
} else {
int xo = 0;
int yo = 0;
if (align & Qt::AlignVCenter)
yo = (cr.height()-rh)/2;
else if (align & Qt::AlignBottom)
yo = cr.height()-rh;
if (align & Qt::AlignRight)
xo = cr.width()-rw;
else if (align & Qt::AlignHCenter)
xo = (cr.width()-rw)/2;
painter.drawPicture(cr.x()+xo-br.x(), cr.y()+yo-br.y(), *d->picture);
}
} else
#endif
if (d->pixmap && !d->pixmap->isNull()) {
//.........这里部分代码省略.........