本文整理汇总了C++中QTextLine::height方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextLine::height方法的具体用法?C++ QTextLine::height怎么用?C++ QTextLine::height使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextLine
的用法示例。
在下文中一共展示了QTextLine::height方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addLine
bool addLine(QTextLine &line) {
if (line.height() > 20)
m_y += line.height();
else
m_y += 14.4;
return false;
}
示例2: layoutText
void YTDelegate::layoutText(QTextLayout& textLayout, QString text, QSize constraint) const
{
QTextOption textOption(Qt::AlignJustify);
textLayout.setTextOption(textOption);
textLayout.setText(text);
textLayout.beginLayout();
int lHeight = 0;
while(true){
QTextLine line = textLayout.createLine();
if(!line.isValid())
break;
line.setLineWidth(constraint.width());
line.setPosition(QPointF(0, lHeight));
if(lHeight + line.height() > constraint.height())
{
QTextLine lastLine = textLayout.lineAt(textLayout.lineCount() - 2);
QString lastString = text.mid(lastLine.textStart());
QFontMetrics fm(textLayout.font());
text.chop(lastString.length());
text += fm.elidedText(lastString, Qt::ElideRight, constraint.width()-1);
textLayout.endLayout();
layoutText(textLayout, text, constraint);
return;
}
lHeight += line.height();
lHeight += line.leading();
}
textLayout.endLayout();
}
示例3: cursor
void TestDocumentLayout::placeAnchoredFrame3()
{
// basic inline frame that acts like a really big character
initForNewTest(QString(loremIpsum));
MockShape *picture = new MockShape();
picture->setSize(QSizeF(100, 100));
KTextAnchor *anchor = new KTextAnchor(picture);
anchor->setAlignment(KTextAnchor::VerticalOffset);
anchor->setAlignment(KTextAnchor::HorizontalOffset);
QTextCursor cursor(doc);
KInlineTextObjectManager *manager = new KInlineTextObjectManager();
layout->setInlineTextObjectManager(manager);
MockLayoutState *state = new MockLayoutState(doc);
layout->setLayout(state);
state->shape = shape1;
manager->insertInlineObject(cursor, anchor);
layout->layout();
/*
I have two goals with 'offset'.
One is that I want to be able to change the baseline of my anchored object.
The other is that OOo / ODF allows me to have an arbitairy distance from my anchor
so I can place something at the center of my page or whatever.
So what about I switch from the first to the latter based on the font height.
If my offset 'x' != 0, make the image floating.
If my offset 'y' is such that it would be above or below my line; make floating.
*/
QTextLayout *lay = doc->begin().layout();
QVERIFY(lay->lineCount() >= 2);
QTextLine line = lay->lineAt(0);
QCOMPARE(line.descent(), (qreal) 100);
QCOMPARE(line.position(), QPointF());
line = lay->lineAt(1);
QVERIFY(line.height() < 20);
// now move the character which makes it a shape to run around and no longer
// a big character.
anchor->setOffset(QPointF(50, 20));
layout->layout();
lay = doc->begin().layout();
QVERIFY(lay->lineCount() >= 2);
line = lay->lineAt(0);
QVERIFY(line.height() < 20);
QCOMPARE(line.position(), QPointF());
line = lay->lineAt(1);
QVERIFY(line.height() < 20);
QCOMPARE(line.position().x(), 0.);
QVERIFY(qAbs(line.position().y() - 14.4) < 0.125);
}
示例4: qMax
void KTextDocumentLayout::Private::adjustSize()
{
if (parent->resizeMethod() == KTextDocument::NoResize)
return;
if (parent->shapes().isEmpty())
return;
// Limit auto-resizing to the first shape only (there won't be more
// with auto-resizing turned on, unless specifically set)
KShape *shape = parent->shapes().first();
// Determine the maximum width of all text lines
qreal width = 0;
for (QTextBlock block = parent->document()->begin(); block.isValid(); block = block.next()) {
// The block layout's wrap mode must be QTextOption::NoWrap, thus the line count
// of a valid block must be 1 (otherwise this resizing scheme wouldn't work)
Q_ASSERT(block.layout()->lineCount() == 1);
QTextLine line = block.layout()->lineAt(0);
width = qMax(width, line.naturalTextWidth());
}
// Use position and height of last text line to calculate height
QTextLine line = parent->document()->lastBlock().layout()->lineAt(0);
qreal height = line.position().y() + line.height();
shape->setSize(QSizeF(width, height));
}
示例5: calculateBoundingRect
static void calculateBoundingRect( QTextDocument *document, int startPosition, int endPosition,
QRectF &rect )
{
const QTextBlock startBlock = document->findBlock( startPosition );
const QRectF startBoundingRect = document->documentLayout()->blockBoundingRect( startBlock );
const QTextBlock endBlock = document->findBlock( endPosition );
const QRectF endBoundingRect = document->documentLayout()->blockBoundingRect( endBlock );
QTextLayout *startLayout = startBlock.layout();
QTextLayout *endLayout = endBlock.layout();
int startPos = startPosition - startBlock.position();
int endPos = endPosition - endBlock.position();
const QTextLine startLine = startLayout->lineForTextPosition( startPos );
const QTextLine endLine = endLayout->lineForTextPosition( endPos );
double x = startBoundingRect.x() + startLine.cursorToX( startPos );
double y = startBoundingRect.y() + startLine.y();
double r = endBoundingRect.x() + endLine.cursorToX( endPos );
double b = endBoundingRect.y() + endLine.y() + endLine.height();
const QSizeF size = document->size();
rect = QRectF( x / size.width(), y / size.height(),
(r - x) / size.width(), (b - y) / size.height() );
}
示例6: textFontMetrics
//virtual
void PixButton::redoLabelTextLayout()
{
//TODO: somewhat wasteful. If there is no label, should just exit early and leave a layout that will be left unrendered by paint()
m_textLayoutObject.clearLayout();
m_textLayoutObject.setText(m_label);
m_textLayoutObject.setFont(m_textFont);
QTextOption textOpts;
textOpts.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
textOpts.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
m_textLayoutObject.setTextOption(textOpts);
QFontMetrics textFontMetrics(m_textFont);
int leading = textFontMetrics.leading();
int rise = textFontMetrics.ascent();
qreal height = 0;
m_textLayoutObject.beginLayout();
while (height < m_labelMaxGeom.height()) {
QTextLine line = m_textLayoutObject.createLine();
if (!line.isValid())
break;
line.setLineWidth(m_labelMaxGeom.width());
if (m_textLayoutObject.lineCount() > 1)
{
height += leading;
}
line.setPosition(QPointF(0, height));
height += line.height();
}
height = qMin((quint32)DimensionsGlobal::roundUp(height),(quint32)m_labelMaxGeom.height());
height = DimensionsGlobal::roundDown(height) - (DimensionsGlobal::roundDown(height) % 2); //force to an even #
m_textLayoutObject.endLayout();
//TODO: PIXEL-ALIGN
m_labelGeom = DimensionsGlobal::realRectAroundRealPoint(QSizeF(m_textLayoutObject.boundingRect().width(),height)).toAlignedRect();
}
示例7: drawDisplay
void PluginListDelegate::drawDisplay(QPainter* painter, const QStyleOptionViewItem &option, const QRect &rect, const QString &text) const
{
QTextDocument textDocument;
textDocument.setHtml(text);
QTextLayout textLayout(textDocument.begin());
textLayout.setFont(option.font);
const int textMargin = QApplication::style()->pixelMetric(QStyle::PM_FocusFrameHMargin, 0) + 1;
QRect textRect = rect.adjusted(textMargin, 0, -textMargin, 0); // remove width padding
textLayout.beginLayout();
qreal height = 0;
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid()) {
break;
}
line.setLineWidth(textRect.width());
height += 3;
line.setPosition(QPoint(0, height));
height += line.height();
}
textLayout.endLayout();
textLayout.draw(painter, QPointF(textRect.left(), textRect.top()));
}
示例8: paint_QTextLayout
void paint_QTextLayout(QPainter &p, bool useCache)
{
static bool first = true;
static QTextLayout *textLayout[lines];
if (first) {
for (int i = 0; i < lines; ++i) {
textLayout[i] = new QTextLayout(strings[i]);
int leading = p.fontMetrics().leading();
qreal height = 0;
qreal widthUsed = 0;
textLayout[i]->setCacheEnabled(useCache);
textLayout[i]->beginLayout();
while (1) {
QTextLine line = textLayout[i]->createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
height += leading;
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout[i]->endLayout();
}
first = false;
}
for (int i = 0; i < count; ++i) {
for (int j = 0; j < lines; ++j) {
textLayout[j]->draw(&p, QPoint(0, j*spacing));
}
}
}
示例9: layoutText
void TextLabel::layoutText(QTextLayout &layout, const QString &text, const QSize &constraints)
{
QFontMetrics metrics(layout.font());
int leading = metrics.leading();
int height = 0;
int maxWidth = constraints.width();
int widthUsed = 0;
int lineSpacing = metrics.lineSpacing();
QTextLine line;
layout.setText(text);
layout.beginLayout();
while ((line = layout.createLine()).isValid()) {
height += leading;
// Make the last line that will fit infinitely long.
// drawTextLayout() will handle this by fading the line out
// if it won't fit in the constraints.
if (height + 2 * lineSpacing > constraints.height()) {
line.setPosition(QPoint(0, height));
break;
}
line.setLineWidth(maxWidth);
line.setPosition(QPoint(0, height));
height += int(line.height());
widthUsed = int(qMax(qreal(widthUsed), line.naturalTextWidth()));
}
layout.endLayout();
}
示例10: hitTestIterated
int KTextDocumentLayout::hitTestIterated(QTextFrame::iterator begin, QTextFrame::iterator end, const QPointF &point, Qt::HitTestAccuracy accuracy) const
{
int position = -1;
QTextFrame::iterator it = begin;
for (it = begin; it != end; ++it) {
QTextBlock block = it.currentBlock();
QTextTable *table = qobject_cast<QTextTable*>(it.currentFrame());
QTextFrame *subFrame = it.currentFrame();
if (table) {
QTextTableCell cell = m_state->hitTestTable(table, point);
if (cell.isValid()) {
position = hitTestIterated(cell.begin(), cell.end(), point,
accuracy);
if (position == -1)
position = cell.lastPosition();
return position;
}
continue;
} else if (subFrame) {
position = hitTestIterated(subFrame->begin(), subFrame->end(), point, accuracy);
if (position != -1)
return position;
continue;
} else {
if (!block.isValid())
continue;
}
// kDebug(32500) <<"hitTest[" << point.x() <<"," << point.y() <<"]";
QTextLayout *layout = block.layout();
if (point.y() > layout->boundingRect().bottom()) {
// just skip this block. position = block.position() + block.length() - 1;
continue;
}
for (int i = 0; i < layout->lineCount(); i++) {
QTextLine line = layout->lineAt(i);
// kDebug(32500) <<" + line[" << line.textStart() <<"]:" << line.y() <<"-" << line.height();
if (point.y() > line.y() + line.height()) {
position = line.textStart() + line.textLength();
continue;
}
if (accuracy == Qt::ExactHit && point.y() < line.y()) // between lines
return -1;
if (accuracy == Qt::ExactHit && // left or right of line
(point.x() < line.x() || point.x() > line.x() + line.width()))
return -1;
if (point.x() > line.width() && layout->textOption().textDirection() == Qt::RightToLeft) {
// totally right of RTL text means the position is the start of the text.
return block.position() + line.textStart();
}
return block.position() + line.xToCursor(point.x());
}
}
return -1;
}
示例11: drawTextLayout
void TextLabel::drawTextLayout(QPainter *painter, const QTextLayout &layout, const QRect &rect)
{
if (rect.width() < 1 || rect.height() < 1) {
return;
}
QPixmap pixmap(rect.size());
pixmap.fill(Qt::transparent);
QPainter p(&pixmap);
p.setPen(painter->pen());
// Create the alpha gradient for the fade out effect
QLinearGradient alphaGradient(0, 0, 1, 0);
alphaGradient.setCoordinateMode(QGradient::ObjectBoundingMode);
if (layout.textOption().textDirection() == Qt::LeftToRight) {
alphaGradient.setColorAt(0, QColor(0, 0, 0, 255));
alphaGradient.setColorAt(1, QColor(0, 0, 0, 0));
} else {
alphaGradient.setColorAt(0, QColor(0, 0, 0, 0));
alphaGradient.setColorAt(1, QColor(0, 0, 0, 255));
}
QFontMetrics fm(layout.font());
int textHeight = layout.lineCount() * fm.lineSpacing();
QPointF position(0, (rect.height() - textHeight) / 2);
QList<QRect> fadeRects;
int fadeWidth = 30;
// Draw each line in the layout
for (int i = 0; i < layout.lineCount(); i++) {
QTextLine line = layout.lineAt(i);
line.draw(&p, position);
// Add a fade out rect to the list if the line is too long
if (line.naturalTextWidth() > rect.width())
{
int x = int(qMin(line.naturalTextWidth(), (qreal)pixmap.width())) - fadeWidth;
int y = int(line.position().y() + position.y());
QRect r = QStyle::visualRect(layout.textOption().textDirection(), pixmap.rect(),
QRect(x, y, fadeWidth, int(line.height())));
fadeRects.append(r);
}
}
// Reduce the alpha in each fade out rect using the alpha gradient
if (!fadeRects.isEmpty()) {
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
foreach (const QRect &rect, fadeRects) {
p.fillRect(rect, alphaGradient);
}
示例12: viewItemTextLayout
// Origin: Qt
static void viewItemTextLayout ( QTextLayout &textLayout, int lineWidth, qreal &height, qreal &widthUsed )
{
height = 0;
widthUsed = 0;
textLayout.beginLayout();
while ( true )
{
QTextLine line = textLayout.createLine();
if ( !line.isValid() )
break;
line.setLineWidth ( lineWidth );
line.setPosition ( QPointF ( 0, height ) );
height += line.height();
widthUsed = qMax ( widthUsed, line.naturalTextWidth() );
}
textLayout.endLayout();
}
示例13: layoutText
static int layoutText(QTextLayout *layout, int maxWidth) {
qreal height = 0;
int textWidth = 0;
layout->beginLayout();
while (true) {
QTextLine line = layout->createLine();
if (!line.isValid()) {
break;
}
line.setLineWidth(maxWidth);
line.setPosition(QPointF(0, height));
height += line.height();
textWidth = qMax(textWidth, qRound(line.naturalTextWidth() + 0.5));
}
layout->endLayout();
return textWidth;
}
示例14: doTextLayout
// copied from QItemDelegate for drawDisplay
QSizeF doTextLayout(QTextLayout *textLayout, int lineWidth)
{
qreal height = 0;
qreal widthUsed = 0;
textLayout->beginLayout();
while (true) {
QTextLine line = textLayout->createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout->endLayout();
return QSizeF(widthUsed, height);
}
示例15: doTextLayout
QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const
{
qreal height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (true) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(lineWidth);
line.setPosition(QPointF(0, height));
height += line.height();
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout.endLayout();
return QSizeF(widthUsed, height);
}